Bug 1299371 - Show context menu in WebExtension popups; r?kmag draft
authorMartin Giger <martin@humanoids.be>
Sun, 19 Feb 2017 11:02:14 +0100
changeset 486704 0bcf0066786c58da0c16d0f7d6f5fe04de4dd86b
parent 484626 ec3ef9f77a52693e9732ca480df16017af0d9504
child 546297 35f006068b5bdc33334b826c1b9f007274c48a72
push id46038
push userbmo:martin@humanoids.be
push dateSun, 19 Feb 2017 10:13:21 +0000
reviewerskmag
bugs1299371
milestone54.0a1
Bug 1299371 - Show context menu in WebExtension popups; r?kmag MozReview-Commit-ID: 5bty8uurFns
browser/base/content/nsContextMenu.js
browser/components/extensions/ExtensionPopups.jsm
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -170,17 +170,17 @@ nsContextMenu.prototype = {
     this.showItem("context-openlinkinusercontext-menu", shouldShow && !isWindowPrivate && showContainers);
     this.showItem("context-openlinkincurrent", this.onPlainTextLink);
     this.showItem("context-sep-open", shouldShow);
   },
 
   initNavigationItems: function CM_initNavigationItems() {
     var shouldShow = !(this.isContentSelected || this.onLink || this.onImage ||
                        this.onCanvas || this.onVideo || this.onAudio ||
-                       this.onTextInput || this.onSocial);
+                       this.onTextInput || this.onSocial || this.onWebExtPopup);
     this.showItem("context-navigation", shouldShow);
     this.showItem("context-sep-navigation", shouldShow);
 
     let stopped = XULBrowserWindow.stopCommand.getAttribute("disabled") == "true";
 
     let stopReloadItem = "";
     if (shouldShow || this.onSocial) {
       stopReloadItem = (stopped || this.onSocial) ? "reload" : "stop";
@@ -245,19 +245,19 @@ nsContextMenu.prototype = {
                   this.isContentSelected);
     this.showItem("context-viewpartialsource-mathml",
                   this.onMathML && !this.isContentSelected);
 
     var shouldShow = !(this.isContentSelected ||
                        this.onImage || this.onCanvas ||
                        this.onVideo || this.onAudio ||
                        this.onLink || this.onTextInput);
-    var showInspect = !this.onSocial && gPrefService.getBoolPref("devtools.inspector.enabled");
+    var showInspect = !this.onSocial && gPrefService.getBoolPref("devtools.inspector.enabled") && !this.onWebExtPopup;
     this.showItem("context-viewsource", shouldShow);
-    this.showItem("context-viewinfo", shouldShow);
+    this.showItem("context-viewinfo", shouldShow && !this.onWebExtPopup);
     this.showItem("inspect-separator", showInspect);
     this.showItem("context-inspect", showInspect);
 
     this.showItem("context-sep-viewsource", shouldShow);
 
     // Set as Desktop background depends on whether an image was clicked on,
     // and only works if we have a shell service.
     var haveSetDesktopBackground = false;
@@ -624,16 +624,17 @@ nsContextMenu.prototype = {
     this.inSyntheticDoc    = false;
     this.hasBGImage        = false;
     this.bgImageURL        = "";
     this.onEditableArea    = false;
     this.isDesignMode      = false;
     this.onCTPPlugin       = false;
     this.canSpellCheck     = false;
     this.onPassword        = false;
+    this.onWebExtPopup     = false;
 
     if (this.isRemote) {
       this.selectionInfo = gContextMenuContentData.selectionInfo;
     } else {
       this.selectionInfo = BrowserUtils.getSelectionDetails(window);
     }
 
     this.textSelected      = this.selectionInfo.text;
@@ -660,16 +661,17 @@ nsContextMenu.prototype = {
                              .chromeEventHandler;
       this.principal = ownerDoc.nodePrincipal;
       this.frameOuterWindowID = ownerDoc.defaultView
                                         .QueryInterface(Ci.nsIInterfaceRequestor)
                                         .getInterface(Ci.nsIDOMWindowUtils)
                                         .outerWindowID;
     }
     this.onSocial = !!this.browser.getAttribute("origin");
+    this.onWebExtPopup = this.browser.getAttribute("webextension-view-type") === "popup";
 
     // Check if we are in a synthetic document (stand alone image, video, etc.).
     this.inSyntheticDoc = ownerDoc.mozSyntheticDocument;
     // First, do checks for nodes that never have children.
     if (this.target.nodeType == Node.ELEMENT_NODE) {
       // See if the user clicked on an image. This check mirrors
       // nsDocumentViewer::GetInImage. Make sure to update both if this is
       // changed.
--- a/browser/components/extensions/ExtensionPopups.jsm
+++ b/browser/components/extensions/ExtensionPopups.jsm
@@ -224,16 +224,17 @@ class BasePopup {
     let document = viewNode.ownerDocument;
     let browser = document.createElementNS(XUL_NS, "browser");
     browser.setAttribute("type", "content");
     browser.setAttribute("disableglobalhistory", "true");
     browser.setAttribute("transparent", "true");
     browser.setAttribute("class", "webextension-popup-browser");
     browser.setAttribute("webextension-view-type", "popup");
     browser.setAttribute("tooltip", "aHTMLTooltip");
+    browser.setAttribute("contextmenu", "contentAreaContextMenu");
 
     if (this.extension.remote) {
       browser.setAttribute("remote", "true");
       browser.setAttribute("remoteType", E10SUtils.EXTENSION_REMOTE_TYPE);
     }
 
     // We only need flex sizing for the sake of the slide-in sub-views of the
     // main menu panel, so that the browser occupies the full width of the view,
@@ -260,16 +261,19 @@ class BasePopup {
 
     let setupBrowser = browser => {
       let mm = browser.messageManager;
       mm.addMessageListener("DOMTitleChanged", this);
       mm.addMessageListener("Extension:BrowserBackgroundChanged", this);
       mm.addMessageListener("Extension:BrowserContentLoaded", this);
       mm.addMessageListener("Extension:BrowserResized", this);
       mm.addMessageListener("Extension:DOMWindowClose", this, true);
+
+      // Sets the context information for context menus.
+      mm.loadFrameScript("chrome://browser/content/content.js", true);
       return browser;
     };
 
     if (!popupURL) {
       // For remote browsers, we can't do any setup until the frame loader is
       // created. Non-remote browsers get a message manager immediately, so
       // there's no need to wait for the load event.
       if (this.extension.remote) {