зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1515789 - Ensure nsILoadURIDelegate::loadURI() is only called for toplevel redirects. r=smaug,geckoview-reviewers,esawin
Differential Revision: https://phabricator.services.mozilla.com/D16990 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
44e3c9066d
Коммит
84984eac60
|
@ -20,7 +20,7 @@ interface nsIPrincipal;
|
|||
interface nsILoadURIDelegate : nsISupports
|
||||
{
|
||||
/**
|
||||
* Delegates the URI load.
|
||||
* Delegates the URI load. This should only be called for top-level loads.
|
||||
*
|
||||
* @param aURI The URI to load.
|
||||
* @param aWhere See possible values described in nsIBrowserDOMWindow.
|
||||
|
@ -34,7 +34,8 @@ interface nsILoadURIDelegate : nsISupports
|
|||
in nsIPrincipal aTriggeringPrincipal);
|
||||
|
||||
/**
|
||||
* Delegates page load error handling.
|
||||
* Delegates page load error handling. This may be called for either top-level
|
||||
* loads or subframes.
|
||||
*
|
||||
* @param aURI The URI that failed to load.
|
||||
* @param aError The error code.
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
Some stuff
|
||||
<iframe src="http://example.org/tests/robocop/simple_redirect.sjs?http://example.org"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
Some stuff
|
||||
<iframe src="http://jigsaw.w3.org/HTTP/300/301.html"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -47,7 +47,9 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
|
|||
const val VIDEO_BAD_PATH = "/assets/www/badVideoPath.html"
|
||||
const val UNKNOWN_HOST_URI = "http://www.test.invalid/"
|
||||
const val FULLSCREEN_PATH = "/assets/www/fullscreen.html"
|
||||
const val VEIWPORT_PATH = "/assets/www/viewport.html"
|
||||
const val VIEWPORT_PATH = "/assets/www/viewport.html"
|
||||
const val IFRAME_REDIRECT_LOCAL = "/assets/www/iframe_redirect_local.html"
|
||||
const val IFRAME_REDIRECT_AUTOMATION = "/assets/www/iframe_redirect_automation.html"
|
||||
}
|
||||
|
||||
@get:Rule val sessionRule = GeckoSessionTestRule()
|
||||
|
|
|
@ -240,6 +240,30 @@ class NavigationDelegateTest : BaseSessionTest() {
|
|||
})
|
||||
}
|
||||
|
||||
@Test fun redirectLoadIframe() {
|
||||
val path = if (sessionRule.env.isAutomation) {
|
||||
IFRAME_REDIRECT_AUTOMATION
|
||||
} else {
|
||||
IFRAME_REDIRECT_LOCAL
|
||||
}
|
||||
|
||||
sessionRule.session.loadTestPath(path)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
// We shouldn't be firing onLoadRequest for iframes, including redirects.
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onLoadRequest(session: GeckoSession,
|
||||
request: LoadRequest):
|
||||
GeckoResult<AllowOrDeny>? {
|
||||
assertThat("Session should not be null", session, notNullValue())
|
||||
assertThat("URI should not be null", request.uri, notNullValue())
|
||||
assertThat("URI should match", request.uri, startsWith("resource://android"))
|
||||
return null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun bypassClassifier() {
|
||||
val phishingUri = "https://www.itisatrap.org/firefox/its-a-trap.html"
|
||||
|
||||
|
@ -489,7 +513,7 @@ class NavigationDelegateTest : BaseSessionTest() {
|
|||
@WithDevToolsAPI
|
||||
@WithDisplay(width = 600, height = 200)
|
||||
@Test fun viewportMode() {
|
||||
sessionRule.session.loadTestPath(VEIWPORT_PATH)
|
||||
sessionRule.session.loadTestPath(VIEWPORT_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
val desktopInnerWidth = 980.0
|
||||
|
|
|
@ -3040,8 +3040,8 @@ public class GeckoSession implements Parcelable {
|
|||
}
|
||||
|
||||
/**
|
||||
* A request to open an URI. This is called before each page load to
|
||||
* allow custom behavior implementation.
|
||||
* A request to open an URI. This is called before each top-level page load to
|
||||
* allow custom behavior.
|
||||
* For example, this can be used to override the behavior of
|
||||
* TAGET_WINDOW_NEW requests, which defaults to requesting a new
|
||||
* GeckoSession via onNewSession.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nspr.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
|
||||
|
@ -40,6 +41,7 @@
|
|||
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::LogLevel;
|
||||
using mozilla::dom::Document;
|
||||
|
||||
//
|
||||
// Log module for nsIDocumentLoader logging...
|
||||
|
@ -1342,12 +1344,19 @@ NS_IMETHODIMP nsDocLoader::AsyncOnChannelRedirect(
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIURI> newURI;
|
||||
nsCOMPtr<nsILoadInfo> info;
|
||||
if (delegate) {
|
||||
// No point in getting the URI if we don't have a LoadURIDelegate.
|
||||
aNewChannel->GetURI(getter_AddRefs(newURI));
|
||||
aNewChannel->GetLoadInfo(getter_AddRefs(info));
|
||||
}
|
||||
|
||||
if (newURI) {
|
||||
RefPtr<Document> loadingDoc;
|
||||
if (info) {
|
||||
info->GetLoadingDocument(getter_AddRefs(loadingDoc));
|
||||
}
|
||||
|
||||
if (newURI && info && !loadingDoc) {
|
||||
const int where = nsIBrowserDOMWindow::OPEN_CURRENTWINDOW;
|
||||
bool loadURIHandled = false;
|
||||
nsresult rv = delegate->LoadURI(
|
||||
|
|
Загрузка…
Ссылка в новой задаче