Bug 1538028 - Part 4: Pass TriggeringRemoteType through the frontend, r=Gijs,emilio

Propagate the ability to pass triggeringRemoteType through the desktop frontend
in various places, such that it is set when using the context menu or content
click handler.

Differential Revision: https://phabricator.services.mozilla.com/D161834
This commit is contained in:
Nika Layzell 2022-11-29 20:41:46 +00:00
parent 399a2f946d
commit 39cfe43333
8 changed files with 51 additions and 0 deletions

View File

@ -103,6 +103,7 @@ export class ClickHandlerParent extends JSWindowActorParent {
openerBrowser: browser,
// The child ensures that untrusted events have a valid user activation.
hasValidUserGestureActivation: true,
triggeringRemoteType: this.manager.domProcess?.remoteType,
};
if (data.globalHistoryOptions) {

View File

@ -2290,6 +2290,7 @@ var gBrowserInit = {
let hasValidUserGestureActivation = undefined;
let fromExternal = undefined;
let globalHistoryOptions = undefined;
let triggeringRemoteType = undefined;
if (window.arguments[1]) {
if (!(window.arguments[1] instanceof Ci.nsIPropertyBag2)) {
throw new Error(
@ -2318,6 +2319,11 @@ var gBrowserInit = {
);
}
}
if (extraOptions.hasKey("triggeringRemoteType")) {
triggeringRemoteType = extraOptions.getPropertyAsACString(
"triggeringRemoteType"
);
}
}
try {
@ -2339,6 +2345,7 @@ var gBrowserInit = {
hasValidUserGestureActivation,
fromExternal,
globalHistoryOptions,
triggeringRemoteType,
});
} catch (e) {
Cu.reportError(e);

View File

@ -268,6 +268,8 @@ class nsContextMenu {
);
}
this.remoteType = this.actor?.domProcess?.remoteType;
const { gBrowser } = this.browser.ownerGlobal;
this.textSelected = this.selectionInfo.text;
@ -1363,6 +1365,7 @@ class nsContextMenu {
originPrincipal: this.principal,
originStoragePrincipal: this.storagePrincipal,
triggeringPrincipal: this.principal,
triggeringRemoteType: this.remoteType,
csp: this.csp,
frameID: this.contentData.frameID,
hasValidUserGestureActivation: true,
@ -1580,6 +1583,7 @@ class nsContextMenu {
openUILink(this.imageDescURL, e, {
referrerInfo: this.contentData.referrerInfo,
triggeringPrincipal: this.principal,
triggeringRemoteType: this.remoteType,
csp: this.csp,
});
}
@ -1634,6 +1638,7 @@ class nsContextMenu {
referrerInfo,
forceAllowDataURI: true,
triggeringPrincipal: this.principal,
triggeringRemoteType: this.remoteType,
csp: this.csp,
});
}
@ -1699,6 +1704,7 @@ class nsContextMenu {
referrerInfo: this.contentData.referrerInfo,
forceAllowDataURI: true,
triggeringPrincipal: this.principal,
triggeringRemoteType: this.remoteType,
csp: this.csp,
});
}

View File

@ -1691,6 +1691,7 @@
var aCsp;
var aSkipLoad;
var aGlobalHistoryOptions;
var aTriggeringRemoteType;
if (
arguments.length == 2 &&
typeof arguments[1] == "object" &&
@ -1721,6 +1722,7 @@
aCsp = params.csp;
aSkipLoad = params.skipLoad;
aGlobalHistoryOptions = params.globalHistoryOptions;
aTriggeringRemoteType = params.triggeringRemoteType;
}
// all callers of loadOneTab need to pass a valid triggeringPrincipal.
@ -1761,6 +1763,7 @@
csp: aCsp,
skipLoad: aSkipLoad,
globalHistoryOptions: aGlobalHistoryOptions,
triggeringRemoteType: aTriggeringRemoteType,
});
if (!bgLoad) {
this.selectedTab = tab;
@ -2611,6 +2614,7 @@
skipLoad,
batchInsertingTabs,
globalHistoryOptions,
triggeringRemoteType,
} = {}
) {
// all callers of addTab that pass a params object need to pass
@ -2943,6 +2947,7 @@
postData,
csp,
globalHistoryOptions,
triggeringRemoteType,
});
} catch (ex) {
Cu.reportError(ex);

View File

@ -306,6 +306,7 @@ function openLinkIn(url, where, params) {
var aPrincipal = params.originPrincipal;
var aStoragePrincipal = params.originStoragePrincipal;
var aTriggeringPrincipal = params.triggeringPrincipal;
var aTriggeringRemoteType = params.triggeringRemoteType;
var aCsp = params.csp;
var aForceAboutBlankViewerInCurrent = params.forceAboutBlankViewerInCurrent;
var aResolveOnNewTabCreated = params.resolveOnNewTabCreated;
@ -416,6 +417,12 @@ function openLinkIn(url, where, params) {
let extraOptions = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
Ci.nsIWritablePropertyBag2
);
if (aTriggeringRemoteType) {
extraOptions.setPropertyAsACString(
"triggeringRemoteType",
aTriggeringRemoteType
);
}
if (params.hasValidUserGestureActivation !== undefined) {
extraOptions.setPropertyAsBool(
"hasValidUserGestureActivation",
@ -626,6 +633,7 @@ function openLinkIn(url, where, params) {
userContextId: aUserContextId,
hasValidUserGestureActivation: params.hasValidUserGestureActivation,
globalHistoryOptions: aGlobalHistoryOptions,
triggeringRemoteType: aTriggeringRemoteType,
});
if (aResolveOnContentBrowserReady) {
aResolveOnContentBrowserReady(targetBrowser);
@ -659,6 +667,7 @@ function openLinkIn(url, where, params) {
originStoragePrincipal: aStoragePrincipal,
triggeringPrincipal: aTriggeringPrincipal,
allowInheritPrincipal: aAllowInheritPrincipal,
triggeringRemoteType: aTriggeringRemoteType,
csp: aCsp,
focusUrlBar,
openerBrowser: params.openerBrowser,

View File

@ -435,6 +435,17 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
nsDocShell::MaybeNotifyKeywordSearchLoading(searchProvider, keyword);
}
if (aLoadURIOptions.mTriggeringRemoteType.WasPassed()) {
if (XRE_IsParentProcess()) {
loadState->SetTriggeringRemoteType(
aLoadURIOptions.mTriggeringRemoteType.Value());
} else if (ContentChild::GetSingleton()->GetRemoteType() !=
aLoadURIOptions.mTriggeringRemoteType.Value()) {
NS_WARNING("Invalid TriggeringRemoteType from LoadURIOptions in content");
return NS_ERROR_INVALID_ARG;
}
}
if (aLoadURIOptions.mRemoteTypeOverride.WasPassed()) {
loadState->SetRemoteTypeOverride(
aLoadURIOptions.mRemoteTypeOverride.Value());

View File

@ -74,6 +74,16 @@ dictionary LoadURIOptions {
* responsible for causing the load.
*/
unsigned long triggeringSandboxFlags = 0;
/**
* The RemoteType of the entity that's responsible for the load. Defaults to
* the current process.
*
* When starting a load in a content process, `triggeringRemoteType` must be
* either unset, or match the current remote type.
*/
UTF8String? triggeringRemoteType;
/**
* If non-0, a value to pass to nsIDocShell::setCancelContentJSEpoch
* when initiating the load.

View File

@ -802,6 +802,7 @@
let {
referrerInfo,
triggeringPrincipal,
triggeringRemoteType,
postData,
headers,
csp,
@ -813,6 +814,7 @@
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
let loadURIOptions = {
triggeringPrincipal,
triggeringRemoteType,
csp,
referrerInfo,
loadFlags,