Bug 1350298 - Stop preprocessing nsContextMenu.js - use AppConstants instead. r?jaws draft
authorMark Banner <standard8@mozilla.com>
Fri, 24 Mar 2017 11:33:48 +0000
changeset 504541 246156e4df71ed034fc7c0e95198784ea79ba6d1
parent 504149 01d1dedf400d4be413b1a0d48090dca7acf29637
child 504542 f929aa1d89d4ae76e55cb35e3e8a3a736f5d55ec
push id50821
push userbmo:standard8@mozilla.com
push dateFri, 24 Mar 2017 12:08:23 +0000
reviewersjaws
bugs1350298
milestone55.0a1
Bug 1350298 - Stop preprocessing nsContextMenu.js - use AppConstants instead. r?jaws MozReview-Commit-ID: LLz9bRu9Xxs
browser/base/content/nsContextMenu.js
browser/base/jar.mn
browser/base/moz.build
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1,13 +1,13 @@
 /* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
-# 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/.
+/* 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/. */
 
 Components.utils.import("resource://gre/modules/ContextualIdentityService.jsm");
 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
 Components.utils.import("resource://gre/modules/LoginManagerContextMenu.jsm");
 Components.utils.import("resource://gre/modules/BrowserUtils.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
@@ -256,22 +256,24 @@ nsContextMenu.prototype = {
     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;
-#ifdef HAVE_SHELL_SERVICE
-    // Only enable Set as Desktop Background if we can get the shell service.
-    var shell = getShellService();
-    if (shell)
-      haveSetDesktopBackground = shell.canSetDesktopBackground;
-#endif
+
+    if (AppConstants.HAVE_SHELL_SERVICE) {
+      // Only enable Set as Desktop Background if we can get the shell service.
+      var shell = getShellService();
+      if (shell)
+        haveSetDesktopBackground = shell.canSetDesktopBackground;
+    }
+
     this.showItem("context-setDesktopBackground",
                   haveSetDesktopBackground && this.onLoadedImage);
 
     if (haveSetDesktopBackground && this.onLoadedImage) {
       document.getElementById("context-setDesktopBackground")
               .disabled = gContextMenuContentData.disableSetDesktopBackground;
     }
 
@@ -442,20 +444,21 @@ nsContextMenu.prototype = {
     // Copy email link depends on whether we're on an email link.
     this.showItem("context-copyemail", this.onMailtoLink);
 
     // Copy link location depends on whether we're on a non-mailto link.
     this.showItem("context-copylink", this.onLink && !this.onMailtoLink);
     this.showItem("context-sep-copylink", this.onLink &&
                   (this.onImage || this.onVideo || this.onAudio));
 
-#ifdef CONTEXT_COPY_IMAGE_CONTENTS
     // Copy image contents depends on whether we're on an image.
+    // Note: the element doesn't exist on all platforms, but showItem() takes
+    // care of that by itself.
     this.showItem("context-copyimage-contents", this.onImage);
-#endif
+
     // Copy image location depends on whether we're on an image.
     this.showItem("context-copyimage", this.onImage);
     this.showItem("context-copyvideourl", this.onVideo);
     this.showItem("context-copyaudiourl", this.onAudio);
     this.setItemAttr("context-copyvideourl",  "disabled", !this.mediaURL);
     this.setItemAttr("context-copyaudiourl",  "disabled", !this.mediaURL);
     this.showItem("context-sep-copyimage", this.onImage ||
                   this.onVideo || this.onAudio);
@@ -1208,37 +1211,38 @@ nsContextMenu.prototype = {
         return;
 
       let image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
       image.src = message.data.dataUrl;
 
       // Confirm since it's annoying if you hit this accidentally.
       const kDesktopBackgroundURL =
                     "chrome://browser/content/setDesktopBackground.xul";
-#ifdef XP_MACOSX
-      // On Mac, the Set Desktop Background window is not modal.
-      // Don't open more than one Set Desktop Background window.
-      const wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-                 getService(Ci.nsIWindowMediator);
-      let dbWin = wm.getMostRecentWindow("Shell:SetDesktopBackground");
-      if (dbWin) {
-        dbWin.gSetBackground.init(image);
-        dbWin.focus();
-      }
-      else {
+
+      if (AppConstants.platform == "macosx") {
+        // On Mac, the Set Desktop Background window is not modal.
+        // Don't open more than one Set Desktop Background window.
+        const wm = Cc["@mozilla.org/appshell/window-mediator;1"].
+                   getService(Ci.nsIWindowMediator);
+        let dbWin = wm.getMostRecentWindow("Shell:SetDesktopBackground");
+        if (dbWin) {
+          dbWin.gSetBackground.init(image);
+          dbWin.focus();
+        }
+        else {
+          openDialog(kDesktopBackgroundURL, "",
+                     "centerscreen,chrome,dialog=no,dependent,resizable=no",
+                     image);
+        }
+      } else {
+        // On non-Mac platforms, the Set Wallpaper dialog is modal.
         openDialog(kDesktopBackgroundURL, "",
-                   "centerscreen,chrome,dialog=no,dependent,resizable=no",
+                   "centerscreen,chrome,dialog,modal,dependent",
                    image);
       }
-#else
-      // On non-Mac platforms, the Set Wallpaper dialog is modal.
-      openDialog(kDesktopBackgroundURL, "",
-                 "centerscreen,chrome,dialog,modal,dependent",
-                 image);
-#endif
     };
 
     mm.addMessageListener("ContextMenu:SetAsDesktopBackground:Result", onMessage);
   },
 
   // Save URL of clicked-on frame.
   saveFrame: function () {
     saveBrowser(this.browser, false, this.frameOuterWindowID);
@@ -1508,17 +1512,24 @@ nsContextMenu.prototype = {
                     getService(Ci.nsIClipboardHelper);
     clipboard.copyString(linkURL);
   },
 
   ///////////////
   // Utilities //
   ///////////////
 
-  // Show/hide one item (specified via name or the item element itself).
+  /**
+   * Show/hide one item (specified via name or the item element itself).
+   * If the element is not found, then this function finishes silently.
+   *
+   * @param {Element|String} aItemOrId The item element or the name of the element
+   *                                   to show.
+   * @param {Boolean} aShow Set to true to show the item, false to hide it.
+   */
   showItem: function(aItemOrId, aShow) {
     var item = aItemOrId.constructor == String ?
       document.getElementById(aItemOrId) : aItemOrId;
     if (item)
       item.hidden = !aShow;
   },
 
   // Set given attribute of specified context-menu item.  If the
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -152,17 +152,17 @@ browser.jar:
         content/browser/urlbarBindings.xml            (content/urlbarBindings.xml)
         content/browser/utilityOverlay.js             (content/utilityOverlay.js)
         content/browser/usercontext.svg               (content/usercontext.svg)
         content/browser/web-panels.js                 (content/web-panels.js)
 *       content/browser/web-panels.xul                (content/web-panels.xul)
         content/browser/webext-panels.js              (content/webext-panels.js)
 *       content/browser/webext-panels.xul             (content/webext-panels.xul)
 *       content/browser/baseMenuOverlay.xul           (content/baseMenuOverlay.xul)
-*       content/browser/nsContextMenu.js              (content/nsContextMenu.js)
+        content/browser/nsContextMenu.js              (content/nsContextMenu.js)
 # XXX: We should exclude this one as well (bug 71895)
 *       content/browser/hiddenWindow.xul              (content/hiddenWindow.xul)
 #ifdef XP_MACOSX
 *       content/browser/macBrowserOverlay.xul         (content/macBrowserOverlay.xul)
 *       content/browser/softwareUpdateOverlay.xul  (content/softwareUpdateOverlay.xul)
 #endif
 *       content/browser/viewSourceOverlay.xul         (content/viewSourceOverlay.xul)
 #ifndef XP_MACOSX
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -36,17 +36,16 @@ BROWSER_CHROME_MANIFESTS += [
 ]
 
 DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 DEFINES['MOZ_APP_VERSION_DISPLAY'] = CONFIG['MOZ_APP_VERSION_DISPLAY']
 
 DEFINES['APP_LICENSE_BLOCK'] = '%s/content/overrides/app-license.html' % SRCDIR
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3', 'cocoa'):
-    DEFINES['HAVE_SHELL_SERVICE'] = 1
     DEFINES['CONTEXT_COPY_IMAGE_CONTENTS'] = 1
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'cocoa'):
     DEFINES['CAN_DRAW_IN_TITLEBAR'] = 1
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3'):
     DEFINES['MENUBAR_CAN_AUTOHIDE'] = 1