Bug 1164942 - do not load pocket's jsm or other scripts until used, r=jaws
☠☠ backed out by 162c7e7a8a9b ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 15 May 2015 14:25:57 +0100
changeset 244215 5f81902ee93e5bb5c76d511954dc30eae4e214f8
parent 244208 35918b0441b4ea614185fe2df5e8de4db9fb28d9
child 244216 162c7e7a8a9bc9180f616628375008a3e568f818
push id28772
push usercbook@mozilla.com
push dateMon, 18 May 2015 11:29:34 +0000
treeherdermozilla-central@433f1e00ae3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1164942
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1164942 - do not load pocket's jsm or other scripts until used, r=jaws
browser/base/content/browser.js
browser/base/content/browser.xul
browser/components/customizableui/CustomizableWidgets.jsm
browser/components/customizableui/content/panelUI.js
browser/components/pocket/Pocket.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -50,16 +50,39 @@ XPCOMUtils.defineLazyServiceGetter(this,
 XPCOMUtils.defineLazyServiceGetter(this, "gDNSService",
                                    "@mozilla.org/network/dns-service;1",
                                    "nsIDNSService");
 XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
                                   "resource://gre/modules/LightweightThemeManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Pocket",
                                   "resource:///modules/Pocket.jsm");
 
+// Can't use XPCOMUtils for these because the scripts try to define the variables
+// on window, and so the defineProperty inside defineLazyGetter fails.
+Object.defineProperty(window, "pktApi", {
+  get: function() {
+    // Avoid this getter running again:
+    delete window.pktApi;
+    Services.scriptloader.loadSubScript("chrome://browser/content/pocket/pktApi.js", window);
+    return window.pktApi;
+  },
+  configurable: true,
+  enumerable: true
+});
+Object.defineProperty(window, "pktUI", {
+  get: function() {
+    // Avoid this getter running again:
+    delete window.pktUI;
+    Services.scriptloader.loadSubScript("chrome://browser/content/pocket/main.js", window);
+    return window.pktUI;
+  },
+  configurable: true,
+  enumerable: true
+});
+
 const nsIWebNavigation = Ci.nsIWebNavigation;
 
 var gLastBrowserCharset = null;
 var gProxyFavIcon = null;
 var gLastValidURLStr = "";
 var gInPrintPreviewMode = false;
 var gContextMenu = null; // nsContextMenu instance
 var gMultiProcessBrowser =
@@ -4166,17 +4189,16 @@ var XULBrowserWindow = {
       }
 
       if (gURLBar) {
         URLBarSetURI(aLocationURI);
 
         BookmarkingUI.onLocationChange();
         SocialUI.updateState(location);
         UITour.onLocationChange(location);
-        Pocket.onLocationChange(browser, aLocationURI);
       }
 
       // Utility functions for disabling find
       var shouldDisableFind = function shouldDisableFind(aDocument) {
         let docElt = aDocument.documentElement;
         return docElt && docElt.getAttribute("disablefastfind") == "true";
       }
 
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -1302,12 +1302,9 @@
   </svg:svg>
 
 </vbox>
 # <iframe id="tab-view"> is dynamically appended as the 2nd child of #tab-view-deck.
 #     Introducing the iframe dynamically, as needed, was found to be better than
 #     starting with an empty iframe here in browser.xul from a Ts standpoint.
 </deck>
 
-<script type="application/javascript" src="chrome://browser/content/pocket/pktApi.js"/>
-<script type="application/javascript" src="chrome://browser/content/pocket/main.js"/>
-
 </window>
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -1101,18 +1101,23 @@ if (Services.prefs.getBoolPref("browser.
     let pocketButton = {
       id: "pocket-button",
       defaultArea: CustomizableUI.AREA_NAVBAR,
       introducedInVersion: "pref",
       type: "view",
       viewId: "PanelUI-pocketView",
       label: label,
       tooltiptext: tooltiptext,
-      onViewShowing: Pocket.onPanelViewShowing,
-      onViewHiding: Pocket.onPanelViewHiding,
+      // Use forwarding functions here to avoid loading Pocket.jsm on startup:
+      onViewShowing: function() {
+        return Pocket.onPanelViewShowing.apply(this, arguments);
+      },
+      onViewHiding: function() {
+        return Pocket.onPanelViewHiding.apply(this, arguments);
+      },
 
       // If the user has the "classic" Pocket add-on installed, use that instead
       // and destroy the widget.
       conditionalDestroyPromise: new Promise(resolve => {
         AddonManager.getAddonByID("isreaditlater@ideashower.com", addon => {
           resolve(addon && addon.isActive);
         });
       }),
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -1,18 +1,16 @@
 /* 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/. */
 
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
                                   "resource:///modules/CustomizableUI.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ScrollbarSampler",
                                   "resource:///modules/ScrollbarSampler.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Pocket",
-                                  "resource:///modules/Pocket.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
                                   "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
                                   "resource://gre/modules/ShortcutUtils.jsm");
 
 /**
  * Maintains the state and dispatches events for the main menu panel.
  */
--- a/browser/components/pocket/Pocket.jsm
+++ b/browser/components/pocket/Pocket.jsm
@@ -61,40 +61,16 @@ let Pocket = {
     window.pktUI.pocketPanelDidShow();
   },
 
   onPanelViewHiding(event) {
     let window = event.target.ownerDocument.defaultView;
     window.pktUI.pocketPanelDidHide(event);
   },
 
-  // Called on tab/urlbar/location changes and after customization. Update
-  // anything that is tab specific.
-  onLocationChange(browser, locationURI) {
-    if (!locationURI) {
-      return;
-    }
-    let widget = CustomizableUI.getWidget("pocket-button");
-    for (let instance of widget.instances) {
-      let node = instance.node;
-      if (!node ||
-          node.ownerDocument != browser.ownerDocument) {
-        continue;
-      }
-      if (node) {
-        let win = browser.ownerDocument.defaultView;
-        node.disabled = win.pktApi.isUserLoggedIn() &&
-                        !locationURI.schemeIs("http") &&
-                        !locationURI.schemeIs("https") &&
-                        !(locationURI.schemeIs("about") &&
-                          locationURI.spec.toLowerCase().startsWith("about:reader?url="));
-      }
-    }
-  },
-
   _urlToSave: null,
   _titleToSave: null,
   savePage(browser, url, title) {
     let document = browser.ownerDocument;
     let pocketWidget = document.getElementById("pocket-button");
     let placement = CustomizableUI.getPlacementOfWidget("pocket-button");
     if (!placement)
       return;