Bug 1505909 - Merge remote and non-remote context menu handlers. r=NeilDeakin

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Conley 2019-06-07 14:28:33 +00:00
Родитель b6375d3ca2
Коммит cef09f3647
5 изменённых файлов: 46 добавлений и 112 удалений

Просмотреть файл

@ -486,7 +486,7 @@ class ContextMenuChild extends ActorChild {
// The same-origin check will be done in nsContextMenu.openLinkInTab.
let parentAllowsMixedContent = !!this.docShell.mixedContentChannel;
let disableSetDesktopBg = null;
let disableSetDesktopBackground = null;
// Media related cache info parent needs for saving
let contentType = null;
@ -494,7 +494,8 @@ class ContextMenuChild extends ActorChild {
if (aEvent.composedTarget.nodeType == aEvent.composedTarget.ELEMENT_NODE &&
aEvent.composedTarget instanceof Ci.nsIImageLoadingContent &&
aEvent.composedTarget.currentURI) {
disableSetDesktopBg = this._disableSetDesktopBackground(aEvent.composedTarget);
disableSetDesktopBackground =
this._disableSetDesktopBackground(aEvent.composedTarget);
try {
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
@ -529,37 +530,32 @@ class ContextMenuChild extends ActorChild {
let referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(Ci.nsIReferrerInfo);
referrerInfo.initWithNode(context.onLink ? context.link : aEvent.composedTarget);
referrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
let targetAsCPOW = context.target;
if (targetAsCPOW) {
this._cleanContext();
}
let isRemote = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
editFlags = SpellCheckHelper.isEditable(aEvent.composedTarget, this.content);
if (isRemote) {
editFlags = SpellCheckHelper.isEditable(aEvent.composedTarget, this.content);
if (editFlags & SpellCheckHelper.SPELLCHECKABLE) {
spellInfo = InlineSpellCheckerContent.initContextMenu(aEvent, editFlags, this.mm);
}
// Set the event target first as the copy image command needs it to
// determine what was context-clicked on. Then, update the state of the
// commands on the context menu.
this.docShell.contentViewer.QueryInterface(Ci.nsIContentViewerEdit)
.setCommandNode(aEvent.composedTarget);
aEvent.composedTarget.ownerGlobal.updateCommands("contentcontextmenu");
customMenuItems = PageMenuChild.build(aEvent.composedTarget);
principal = doc.nodePrincipal;
if (editFlags & SpellCheckHelper.SPELLCHECKABLE) {
spellInfo = InlineSpellCheckerContent.initContextMenu(aEvent, editFlags, this.mm);
}
// Set the event target first as the copy image command needs it to
// determine what was context-clicked on. Then, update the state of the
// commands on the context menu.
this.docShell.contentViewer.QueryInterface(Ci.nsIContentViewerEdit)
.setCommandNode(aEvent.composedTarget);
aEvent.composedTarget.ownerGlobal.updateCommands("contentcontextmenu");
principal = doc.nodePrincipal;
let data = {
context,
charSet,
baseURI,
isRemote,
referrerInfo,
editFlags,
principal,
@ -573,7 +569,7 @@ class ContextMenuChild extends ActorChild {
contentDisposition,
frameOuterWindowID,
popupNodeSelectors,
disableSetDesktopBg,
disableSetDesktopBackground,
parentAllowsMixedContent,
};
@ -581,28 +577,22 @@ class ContextMenuChild extends ActorChild {
data.frameReferrerInfo = doc.referrerInfo;
}
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
data.customMenuItems = PageMenuChild.build(aEvent.composedTarget);
}
Services.obs.notifyObservers({wrappedJSObject: data}, "on-prepare-contextmenu");
if (isRemote) {
data.referrerInfo = E10SUtils.serializeReferrerInfo(data.referrerInfo);
if (data.frameReferrerInfo) {
data.frameReferrerInfo = E10SUtils.serializeReferrerInfo(data.frameReferrerInfo);
}
// In the event that the content is running in the parent process, we don't
// actually want the contextmenu events to reach the parent - we'll dispatch
// a new contextmenu event after the async message has reached the parent
// instead.
aEvent.preventDefault();
aEvent.stopPropagation();
this.mm.sendAsyncMessage("contextmenu", data, {
targetAsCPOW,
});
} else {
let browser = this.docShell.chromeEventHandler;
let mainWin = browser.ownerGlobal;
data.documentURIObject = doc.documentURIObject;
data.disableSetDesktopBackground = data.disableSetDesktopBg;
delete data.disableSetDesktopBg;
data.context.targetAsCPOW = targetAsCPOW;
mainWin.setContextMenuContentData(data);
}
this.mm.sendAsyncMessage("contextmenu", data, {
targetAsCPOW,
});
}
/**

Просмотреть файл

@ -124,8 +124,7 @@ XPCOMUtils.defineLazyScriptGetter(this, "gSync",
"chrome://browser/content/browser-sync.js");
XPCOMUtils.defineLazyScriptGetter(this, "gBrowserThumbnails",
"chrome://browser/content/browser-thumbnails.js");
XPCOMUtils.defineLazyScriptGetter(this, ["setContextMenuContentData",
"openContextMenu", "nsContextMenu"],
XPCOMUtils.defineLazyScriptGetter(this, ["openContextMenu", "nsContextMenu"],
"chrome://browser/content/nsContextMenu.js");
XPCOMUtils.defineLazyScriptGetter(this, ["DownloadsPanel",
"DownloadsOverlayLoader",

Просмотреть файл

@ -27,10 +27,6 @@ XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
var gContextMenuContentData = null;
function setContextMenuContentData(data) {
gContextMenuContentData = data;
}
function openContextMenu(aMessage) {
let data = aMessage.data;
let browser = aMessage.target;
@ -58,7 +54,6 @@ function openContextMenu(aMessage) {
}
gContextMenuContentData = { context: data.context,
isRemote: data.isRemote,
popupNodeSelectors: data.popupNodeSelectors,
browser,
editFlags: data.editFlags,
@ -74,7 +69,7 @@ function openContextMenu(aMessage) {
contentDisposition: data.contentDisposition,
frameOuterWindowID: data.frameOuterWindowID,
selectionInfo: data.selectionInfo,
disableSetDesktopBackground: data.disableSetDesktopBg,
disableSetDesktopBackground: data.disableSetDesktopBackground,
loginFillInfo: data.loginFillInfo,
parentAllowsMixedContent: data.parentAllowsMixedContent,
userContextId: data.userContextId,
@ -90,7 +85,6 @@ function openContextMenu(aMessage) {
var newEvent = document.createEvent("MouseEvent");
newEvent.initNSMouseEvent("contextmenu", true, true, null, 0, context.screenX, context.screenY,
0, 0, false, false, false, false, 0, null, 0, context.mozInputSource);
popup.openPopupAtScreen(newEvent.screenX, newEvent.screenY, true, newEvent);
}
@ -111,13 +105,9 @@ nsContextMenu.prototype = {
this.hasPageMenu = false;
this.isContentSelected = !this.selectionInfo.docSelectionIsCollapsed;
if (!aIsShift) {
if (this.isRemote) {
this.hasPageMenu =
PageMenuParent.addToPopup(gContextMenuContentData.customMenuItems,
this.browser, aXulMenu);
} else {
this.hasPageMenu = PageMenuParent.buildAndAddToPopup(this.target, aXulMenu);
}
this.hasPageMenu =
PageMenuParent.addToPopup(gContextMenuContentData.customMenuItems,
this.browser, aXulMenu);
let tab = gBrowser && gBrowser.getTabForBrowser ?
gBrowser.getTabForBrowser(this.browser) : undefined;
@ -175,12 +165,10 @@ nsContextMenu.prototype = {
setContext() {
let context = Object.create(null);
this.isRemote = false;
if (gContextMenuContentData) {
context = gContextMenuContentData.context;
gContextMenuContentData.context = null;
this.isRemote = gContextMenuContentData.isRemote;
}
this.shouldDisplay = context.shouldDisplay;
@ -231,7 +219,7 @@ nsContextMenu.prototype = {
this.onTextInput = context.onTextInput;
this.onVideo = context.onVideo;
this.target = this.isRemote ? context.target : document.popupNode;
this.target = context.target;
this.targetAsCPOW = context.targetAsCPOW;
this.principal = context.principal;
@ -252,13 +240,8 @@ nsContextMenu.prototype = {
? gContextMenuContentData.popupNodeSelectors
: [];
if (this.isRemote) {
this.browser = gContextMenuContentData.browser;
this.selectionInfo = gContextMenuContentData.selectionInfo;
} else {
this.browser = this.ownerDoc.defaultView.docShell.chromeEventHandler;
this.selectionInfo = BrowserUtils.getSelectionDetails(window);
}
this.browser = gContextMenuContentData.browser;
this.selectionInfo = gContextMenuContentData.selectionInfo;
const {gBrowser} = this.browser.ownerGlobal;
@ -270,27 +253,11 @@ nsContextMenu.prototype = {
!!gBrowser.getTabForBrowser(this.browser) : false;
if (context.shouldInitInlineSpellCheckerUINoChildren) {
if (this.isRemote) {
InlineSpellCheckerUI.initFromRemote(gContextMenuContentData.spellInfo);
} else {
InlineSpellCheckerUI.init(this.target.editor);
InlineSpellCheckerUI.initFromEvent(document.popupRangeParent,
document.popupRangeOffset);
}
InlineSpellCheckerUI.initFromRemote(gContextMenuContentData.spellInfo);
}
if (context.shouldInitInlineSpellCheckerUIWithChildren) {
if (this.isRemote) {
InlineSpellCheckerUI.initFromRemote(gContextMenuContentData.spellInfo);
} else {
var targetWin = this.ownerDoc.defaultView;
var {editingSession} = targetWin.docShell;
InlineSpellCheckerUI.init(editingSession.getEditorForWindow(targetWin));
InlineSpellCheckerUI.initFromEvent(document.popupRangeParent,
document.popupRangeOffset);
}
InlineSpellCheckerUI.initFromRemote(gContextMenuContentData.spellInfo);
let canSpell = InlineSpellCheckerUI.canSpellCheck && this.canSpellCheck;
this.showItem("spell-check-enabled", canSpell);
this.showItem("spell-separator", canSpell);
@ -804,12 +771,6 @@ nsContextMenu.prototype = {
params[p] = extra[p];
}
if (!this.isRemote) {
// Propagate the frameOuterWindowID value saved when
// the context menu has been opened.
params.frameOuterWindowID = this.frameOuterWindowID;
}
let referrerInfo = gContextMenuContentData.referrerInfo;
// If we want to change userContextId, we must be sure that we don't
// propagate the referrer.
@ -1266,7 +1227,7 @@ nsContextMenu.prototype = {
// Save URL of clicked-on link.
saveLink() {
let isContentWindowPrivate = this.isRemote ? this.ownerDoc.isPrivate : undefined;
let isContentWindowPrivate = this.ownerDoc.isPrivate;
this.saveHelper(this.linkURL, this.linkTextStr, null, true, this.ownerDoc,
gContextMenuContentData.documentURIObject,
this.frameOuterWindowID,
@ -1283,7 +1244,7 @@ nsContextMenu.prototype = {
// Save URL of the clicked upon image, video, or audio.
saveMedia() {
let doc = this.ownerDoc;
let isContentWindowPrivate = this.isRemote ? this.ownerDoc.isPrivate : undefined;
let isContentWindowPrivate = this.ownerDoc.isPrivate;
let referrerURI = gContextMenuContentData.documentURIObject;
let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(this.browser);
if (this.onCanvas) {

Просмотреть файл

@ -42,9 +42,11 @@ window._gBrowser = {
}
let messageManager = window.getGroupMessageManager("browsers");
window.messageManager.addMessageListener("contextmenu", this);
if (gMultiProcessBrowser) {
messageManager.addMessageListener("DOMTitleChanged", this);
window.messageManager.addMessageListener("contextmenu", this);
messageManager.addMessageListener("DOMWindowClose", this);
messageManager.addMessageListener("Browser:Init", this);
} else {
this._outerWindowIDBrowserMap.set(this.selectedBrowser.outerWindowID,

Просмотреть файл

@ -244,26 +244,8 @@ function PageMenuParent() {
PageMenuParent.prototype = {
__proto__: PageMenu.prototype,
/*
* Given a target node and popup, add the context menu to the popup. This is
* intended to be called when a single process is used. This is equivalent to
* calling PageMenuChild.build and PageMenuParent.addToPopup in sequence.
*
* Returns true if custom menu items were present.
*/
buildAndAddToPopup(aTarget, aPopup) {
let menuObject = this.maybeBuild(aTarget);
if (!menuObject) {
return false;
}
return this.buildAndAttachMenuWithObject(menuObject, null, aPopup);
},
/*
* Given a JSON menu object and popup, add the context menu to the popup. This
* is intended to be called when the child page is in a different process.
* Given a JSON menu object and popup, add the context menu to the popup.
* aBrowser should be the browser containing the page the context menu is
* displayed for, which may be null.
*