mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 721413 - [New Tab Page] Load links lazily when opening a new tab; r=mak
This commit is contained in:
parent
a94af4f75b
commit
19c86cbf99
@ -174,9 +174,6 @@ XPCOMUtils.defineLazyGetter(this, "PopupNotifications", function () {
|
||||
}
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
|
||||
"resource:///modules/NewTabUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "InspectorUI", function() {
|
||||
let tmp = {};
|
||||
Cu.import("resource:///modules/inspector.jsm", tmp);
|
||||
@ -1711,7 +1708,6 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) {
|
||||
#endif
|
||||
|
||||
gBrowserThumbnails.init();
|
||||
NewTabUtils.init();
|
||||
TabView.init();
|
||||
|
||||
setUrlAndSearchBarWidthForConditionalForwardButton();
|
||||
|
@ -77,21 +77,21 @@ let gPage = {
|
||||
|
||||
this._initialized = true;
|
||||
|
||||
let self = this;
|
||||
gLinks.populateCache(function () {
|
||||
// Check if the grid is modified.
|
||||
this.updateModifiedFlag();
|
||||
|
||||
// Check if the grid is modified.
|
||||
this.updateModifiedFlag();
|
||||
// Initialize and render the grid.
|
||||
gGrid.init(this._gridSelector);
|
||||
|
||||
// Initialize and render the grid.
|
||||
gGrid.init(this._gridSelector);
|
||||
// Initialize the drop target shim.
|
||||
gDropTargetShim.init();
|
||||
|
||||
// Initialize the drop target shim.
|
||||
gDropTargetShim.init();
|
||||
|
||||
// Workaround to prevent a delay on MacOSX due to a slow drop animation.
|
||||
let doc = document.documentElement;
|
||||
doc.addEventListener("dragover", this.onDragOver, false);
|
||||
doc.addEventListener("drop", this.onDrop, false);
|
||||
// Workaround to prevent a delay on MacOSX due to a slow drop animation.
|
||||
let doc = document.documentElement;
|
||||
doc.addEventListener("dragover", this.onDragOver, false);
|
||||
doc.addEventListener("drop", this.onDrop, false);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ let gToolbar = {
|
||||
|
||||
// Without the setTimeout() we have a strange flicker.
|
||||
setTimeout(function () gTransformation.fadeNodeIn(node, aCallback));
|
||||
});
|
||||
}, true);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -126,10 +126,15 @@ function addNewTabPageTab() {
|
||||
|
||||
cw = browser.contentWindow;
|
||||
|
||||
if (NewTabUtils.allPages.enabled)
|
||||
if (NewTabUtils.allPages.enabled) {
|
||||
cells = cw.gGrid.cells;
|
||||
|
||||
TestRunner.next();
|
||||
// Continue when the link cache has been populated.
|
||||
NewTabUtils.links.populateCache(TestRunner.next);
|
||||
} else {
|
||||
TestRunner.next();
|
||||
}
|
||||
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
@ -464,24 +464,55 @@ let Links = {
|
||||
/**
|
||||
* The links cache.
|
||||
*/
|
||||
_links: [],
|
||||
_links: null,
|
||||
|
||||
/**
|
||||
* The default provider for links.
|
||||
*/
|
||||
_provider: PlacesProvider,
|
||||
|
||||
/**
|
||||
* List of callbacks waiting for the cache to be populated.
|
||||
*/
|
||||
_populateCallbacks: [],
|
||||
|
||||
/**
|
||||
* Populates the cache with fresh links from the current provider.
|
||||
* @param aCallback The callback to call when finished (optional).
|
||||
* @param aForce When true, populates the cache even when it's already filled.
|
||||
*/
|
||||
populateCache: function Links_populateCache(aCallback) {
|
||||
let self = this;
|
||||
populateCache: function Links_populateCache(aCallback, aForce) {
|
||||
let callbacks = this._populateCallbacks;
|
||||
|
||||
this._provider.getLinks(function (aLinks) {
|
||||
self._links = aLinks;
|
||||
aCallback && aCallback();
|
||||
});
|
||||
// Enqueue the current callback.
|
||||
callbacks.push(aCallback);
|
||||
|
||||
// There was a callback waiting already, thus the cache has not yet been
|
||||
// populated.
|
||||
if (callbacks.length > 1)
|
||||
return;
|
||||
|
||||
function executeCallbacks() {
|
||||
while (callbacks.length) {
|
||||
let callback = callbacks.shift();
|
||||
if (callback) {
|
||||
try {
|
||||
callback();
|
||||
} catch (e) {
|
||||
// We want to proceed even if a callback fails.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._links && !aForce) {
|
||||
executeCallbacks();
|
||||
} else {
|
||||
this._provider.getLinks(function (aLinks) {
|
||||
this._links = aLinks;
|
||||
executeCallbacks();
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -520,20 +551,6 @@ let Links = {
|
||||
* Singleton that provides the public API of this JSM.
|
||||
*/
|
||||
let NewTabUtils = {
|
||||
_initialized: false,
|
||||
|
||||
/**
|
||||
* Initializes and prepares the NewTabUtils module.
|
||||
*/
|
||||
init: function NewTabUtils_init() {
|
||||
if (!this._initialized) {
|
||||
// Prefetch the links.
|
||||
Links.populateCache();
|
||||
|
||||
this._initialized = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the NewTabUtils module, its links and its storage.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user