Bug 1570115 - Move LoadURIDelegate to Actor. r=kmag,snorp

Differential Revision: https://phabricator.services.mozilla.com/D44051

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2019-09-20 18:15:25 +00:00
parent 3a3968887a
commit ebe6d184ab
11 changed files with 135 additions and 69 deletions

View File

@ -69,6 +69,7 @@
#include "mozilla/dom/ChildSHistory.h"
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/net/DocumentChannelChild.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
@ -197,6 +198,7 @@
#include "nsPingListener.h"
#include "nsPoint.h"
#include "nsQueryObject.h"
#include "nsQueryActor.h"
#include "nsRect.h"
#include "nsRefreshTimer.h"
#include "nsSandboxFlags.h"
@ -2063,14 +2065,18 @@ nsDocShell::SetSecurityUI(nsISecureBrowserUI* aSecurityUI) {
NS_IMETHODIMP
nsDocShell::GetLoadURIDelegate(nsILoadURIDelegate** aLoadURIDelegate) {
NS_IF_ADDREF(*aLoadURIDelegate = mLoadURIDelegate);
nsCOMPtr<nsILoadURIDelegate> delegate = GetLoadURIDelegate();
delegate.forget(aLoadURIDelegate);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetLoadURIDelegate(nsILoadURIDelegate* aLoadURIDelegate) {
mLoadURIDelegate = aLoadURIDelegate;
return NS_OK;
already_AddRefed<nsILoadURIDelegate> nsDocShell::GetLoadURIDelegate() {
if (nsCOMPtr<nsILoadURIDelegate> result =
do_QueryActor(u"LoadURIDelegate", GetWindow())) {
return result.forget();
}
return nullptr;
}
NS_IMETHODIMP
@ -4301,12 +4307,13 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
}
}
if (mLoadURIDelegate) {
if (nsCOMPtr<nsILoadURIDelegate> loadURIDelegate = GetLoadURIDelegate()) {
nsCOMPtr<nsIURI> errorPageURI;
rv = mLoadURIDelegate->HandleLoadError(aURI, aError,
NS_ERROR_GET_MODULE(aError),
getter_AddRefs(errorPageURI));
if (NS_FAILED(rv)) {
rv = loadURIDelegate->HandleLoadError(aURI, aError,
NS_ERROR_GET_MODULE(aError),
getter_AddRefs(errorPageURI));
// If the docshell is going away there's no point in showing an error page.
if (NS_FAILED(rv) || mIsBeingDestroyed) {
*aDisplayedErrorPage = false;
return NS_OK;
}
@ -8639,9 +8646,11 @@ nsresult nsDocShell::MaybeHandleLoadDelegate(nsDocShellLoadState* aLoadState,
aWindowType == nsIBrowserDOMWindow::OPEN_CURRENTWINDOW);
*aDidHandleLoad = false;
nsCOMPtr<nsILoadURIDelegate> loadURIDelegate = GetLoadURIDelegate();
// If we don't have a delegate or we're trying to load the error page, we
// shouldn't be trying to do sandbox loads.
if (!mLoadURIDelegate || aLoadState->LoadType() == LOAD_ERROR_PAGE) {
if (!loadURIDelegate || aLoadState->LoadType() == LOAD_ERROR_PAGE) {
return NS_OK;
}
@ -8660,7 +8669,7 @@ nsresult nsDocShell::MaybeHandleLoadDelegate(nsDocShellLoadState* aLoadState,
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
return mLoadURIDelegate->LoadURI(
return loadURIDelegate->LoadURI(
aLoadState->URI(), aWindowType, aLoadState->LoadFlags(),
aLoadState->TriggeringPrincipal(), aDidHandleLoad);
}

View File

@ -580,6 +580,8 @@ class nsDocShell final : public nsDocLoader,
nsIStreamListener** aContentHandler,
nsIContentViewer** aViewer);
already_AddRefed<nsILoadURIDelegate> GetLoadURIDelegate();
nsresult SetupNewViewer(
nsIContentViewer* aNewViewer,
mozilla::dom::WindowGlobalChild* aWindowActor = nullptr);
@ -1087,7 +1089,6 @@ class nsDocShell final : public nsDocLoader,
RefPtr<nsDSURIContentListener> mContentListener;
RefPtr<nsGlobalWindowOuter> mScriptGlobal;
nsCOMPtr<nsIPrincipal> mParentCharsetPrincipal;
nsCOMPtr<nsILoadURIDelegate> mLoadURIDelegate;
nsCOMPtr<nsIMutableArray> mRefreshURIList;
nsCOMPtr<nsIMutableArray> mSavedRefreshURIList;
nsCOMPtr<nsIDOMStorageManager> mSessionStorageManager;

View File

@ -388,7 +388,7 @@ interface nsIDocShell : nsIDocShellTreeItem
* Currently only set for GeckoView to allow handling of load requests
* at the application level.
*/
attribute nsILoadURIDelegate loadURIDelegate;
readonly attribute nsILoadURIDelegate loadURIDelegate;
/**
* Cancel the XPCOM timers for each meta-refresh URI in this docshell,

View File

@ -202,6 +202,9 @@ function OnRefTestLoad(win)
doc.firstChild.remove();
}
doc.appendChild(g.browser);
// TODO Bug 1156817: reftests don't have most of GeckoView infra so we
// can't register this actor
ChromeUtils.unregisterWindowActor("LoadURIDelegate");
} else {
document.getElementById("reftest-window").appendChild(g.browser);
}

View File

@ -0,0 +1,63 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { GeckoViewActorChild } = ChromeUtils.import(
"resource://gre/modules/GeckoViewActorChild.jsm"
);
const { LoadURIDelegate } = ChromeUtils.import(
"resource://gre/modules/LoadURIDelegate.jsm"
);
var EXPORTED_SYMBOLS = ["LoadURIDelegateChild"];
// Implements nsILoadURIDelegate.
class LoadURIDelegateChild extends GeckoViewActorChild {
// nsILoadURIDelegate.
loadURI(aUri, aWhere, aFlags, aTriggeringPrincipal) {
debug`loadURI: uri=${aUri && aUri.spec}
where=${aWhere} flags=0x${aFlags.toString(16)}
tp=${aTriggeringPrincipal &&
aTriggeringPrincipal.URI &&
aTriggeringPrincipal.URI.spec}`;
return LoadURIDelegate.load(
this.contentWindow,
this.eventDispatcher,
aUri,
aWhere,
aFlags,
aTriggeringPrincipal
);
}
// nsILoadURIDelegate.
handleLoadError(aUri, aError, aErrorModule) {
debug`handleLoadError: uri=${aUri && aUri.spec}
displaySpec=${aUri && aUri.displaySpec}
error=${aError}`;
if (aUri && LoadURIDelegate.isSafeBrowsingError(aError)) {
const message = {
type: "GeckoView:ContentBlocked",
uri: aUri.spec,
error: aError,
};
this.eventDispatcher.sendRequest(message);
}
return LoadURIDelegate.handleLoadError(
this.contentWindow,
this.eventDispatcher,
aUri,
aError,
aErrorModule
);
}
}
LoadURIDelegateChild.prototype.QueryInterface = ChromeUtils.generateQI([
Ci.nsILoadURIDelegate,
]);
const { debug, warn } = LoadURIDelegateChild.initLogging("LoadURIDelegate"); // eslint-disable-line no-unused-vars

View File

@ -0,0 +1,10 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
with Files('**'):
BUG_COMPONENT = ('GeckoView', 'General')
FINAL_TARGET_FILES.actors += [
'LoadURIDelegateChild.jsm',
]

View File

@ -15,14 +15,11 @@ XPCOMUtils.defineLazyModuleGetters(this, {
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
ErrorPageEventHandler: "chrome://geckoview/content/ErrorPageEventHandler.js",
LoadURIDelegate: "resource://gre/modules/LoadURIDelegate.jsm",
});
// Implements nsILoadURIDelegate.
class GeckoViewNavigationChild extends GeckoViewChildModule {
onInit() {
docShell.loadURIDelegate = this;
if (Services.androidBridge.isFennec) {
addEventListener("DOMContentLoaded", this);
}
@ -37,58 +34,6 @@ class GeckoViewNavigationChild extends GeckoViewChildModule {
}
}
// nsILoadURIDelegate.
loadURI(aUri, aWhere, aFlags, aTriggeringPrincipal) {
debug`loadURI: uri=${aUri && aUri.spec}
where=${aWhere} flags=${aFlags}
tp=${aTriggeringPrincipal &&
aTriggeringPrincipal.URI &&
aTriggeringPrincipal.URI.spec}`;
if (!this.enabled) {
return false;
}
return LoadURIDelegate.load(
content,
this.eventDispatcher,
aUri,
aWhere,
aFlags,
aTriggeringPrincipal
);
}
// nsILoadURIDelegate.
handleLoadError(aUri, aError, aErrorModule) {
debug`handleLoadError: uri=${aUri && aUri.spec}
uri2=${aUri && aUri.displaySpec}
error=${aError}`;
if (aUri && LoadURIDelegate.isSafeBrowsingError(aError)) {
const message = {
type: "GeckoView:ContentBlocked",
uri: aUri.spec,
error: aError,
};
this.eventDispatcher.sendRequest(message);
}
if (!this.enabled) {
Components.returnCode = Cr.NS_ERROR_ABORT;
return null;
}
return LoadURIDelegate.handleLoadError(
content,
this.eventDispatcher,
aUri,
aError,
aErrorModule
);
}
// nsIWebBrowserChrome
onBeforeLinkTraversal(aOriginalTarget, aLinkURI, aLinkNode, aIsAppTab) {
debug`onBeforeLinkTraversal ${aLinkURI.displaySpec}`;

View File

@ -21,6 +21,14 @@ XPCOMUtils.defineLazyModuleGetters(this, {
const { debug, warn } = GeckoViewUtils.initLogging("Startup"); // eslint-disable-line no-unused-vars
const ACTORS = {
LoadURIDelegate: {
child: {
moduleURI: "resource:///actors/LoadURIDelegateChild.jsm",
},
},
};
function GeckoViewStartup() {}
GeckoViewStartup.prototype = {
@ -122,6 +130,7 @@ GeckoViewStartup.prototype = {
if (
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT
) {
ActorManagerParent.addActors(ACTORS);
ActorManagerParent.flush();
Services.mm.loadFrameScript(

View File

@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { GeckoViewUtils } = ChromeUtils.import(
"resource://gre/modules/GeckoViewUtils.jsm"
);
var EXPORTED_SYMBOLS = ["GeckoViewActorChild"];
class GeckoViewActorChild extends JSWindowActorChild {
static initLogging(aModuleName) {
const tag = aModuleName.replace("GeckoView", "") + "[C]";
return GeckoViewUtils.initLogging(tag);
}
actorCreated() {
this.eventDispatcher = GeckoViewUtils.getDispatcherForWindow(
this.docShell.domWindow
);
}
}
const { debug, warn } = GeckoViewUtils.initLogging("Actor[C]"); // eslint-disable-line no-unused-vars

View File

@ -10,6 +10,7 @@ EXTRA_JS_MODULES += [
'ContentCrashHandler.jsm',
'DelayedInit.jsm',
'GeckoViewAccessibility.jsm',
'GeckoViewActorChild.jsm',
'GeckoViewAutoFill.jsm',
'GeckoViewChildModule.jsm',
'GeckoViewConsole.jsm',

View File

@ -49,6 +49,7 @@ DIRS += [
]
DIRS += [
'actors',
'base',
'chrome',
'components',