Bug 1164942 - do not load pocket's jsm or other scripts until used with extra getter to satisfy tests, r=jaws

--HG--
extra : rebase_source : fc6d1273cc9c6dc355638033cd27705ab59747e7
This commit is contained in:
Gijs Kruitbosch 2015-05-15 14:25:57 +01:00
Родитель ac81fa3ddb
Коммит 6764c42a9e
5 изменённых файлов: 36 добавлений и 32 удалений

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

@ -55,6 +55,35 @@ XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
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
});
function pktUIGetter(prop) {
return {
get: function() {
// Avoid either of these getters running again:
delete window.pktUI;
delete window.pktUIMessaging;
Services.scriptloader.loadSubScript("chrome://browser/content/pocket/main.js", window);
return window[prop];
},
configurable: true,
enumerable: true
};
}
Object.defineProperty(window, "pktUI", pktUIGetter("pktUI"));
Object.defineProperty(window, "pktUIMessaging", pktUIGetter("pktUIMessaging"));
const nsIWebNavigation = Ci.nsIWebNavigation;
var gLastBrowserCharset = null;
@ -4171,7 +4200,6 @@ var XULBrowserWindow = {
BookmarkingUI.onLocationChange();
SocialUI.updateState(location);
UITour.onLocationChange(location);
Pocket.onLocationChange(browser, aLocationURI);
}
// Utility functions for disabling find

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

@ -1307,7 +1307,4 @@
# 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>

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

@ -1106,8 +1106,13 @@ if (Services.prefs.getBoolPref("browser.pocket.enabled")) {
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.

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

@ -6,8 +6,6 @@ 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",

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

@ -66,30 +66,6 @@ let Pocket = {
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) {