Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/ui.js

Issue 29345630: Issue 4131 - Simplify UI initialization logic (Closed)
Patch Set: Addressed comments Created June 8, 2016, 8:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 */ 270 */
271 let notificationTimer = null; 271 let notificationTimer = null;
272 272
273 let UI = exports.UI = 273 let UI = exports.UI =
274 { 274 {
275 /** 275 /**
276 * Gets called on startup, initializes UI integration. 276 * Gets called on startup, initializes UI integration.
277 */ 277 */
278 init: function() 278 init: function()
279 { 279 {
280 // We should call initDone once both overlay and filters are loaded 280 // We have to wait for multiple events before running start-up actions
281 let overlayLoaded = false; 281 let prerequisites = [];
282 let filtersLoaded = false;
283 let sessionRestored = false;
284 282
285 // Start loading overlay 283 // Start loading overlay
286 let request = new XMLHttpRequest(); 284 prerequisites.push(new Promise((resolve, reject) =>
287 request.mozBackgroundRequest = true;
288 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul");
289 request.channel.owner = Utils.systemPrincipal;
290 request.addEventListener("load", function(event)
291 { 285 {
292 if (onShutdown.done) 286 let request = new XMLHttpRequest();
293 return; 287 request.mozBackgroundRequest = true;
288 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul");
289 request.channel.owner = Utils.systemPrincipal;
290 request.addEventListener("load", event =>
291 {
292 if (onShutdown.done)
293 return;
294 294
295 this.processOverlay(request.responseXML.documentElement); 295 this.processOverlay(request.responseXML.documentElement);
296 296
297 // Don't wait for the rest of the startup sequence, add icon already 297 // Don't wait for the rest of the startup sequence, add icon already
298 this.addToolbarButton(); 298 this.addToolbarButton();
299 299
300 overlayLoaded = true; 300 resolve();
301 if (overlayLoaded && filtersLoaded && sessionRestored) 301 }, false);
302 this.initDone(); 302
303 }.bind(this), false); 303 request.addEventListener("error", event =>
304 request.send(null); 304 {
305 reject(new Error("Unexpected: Failed to load overlay.xul"));
306 });
307
308 request.send(null);
309 }));
305 310
306 // Wait for filters to load 311 // Wait for filters to load
307 if (FilterStorage._loading) 312 if (FilterStorage._loading)
313 prerequisites.push(FilterNotifier.once("load"));
314
315 // Wait for session to be restored
316 prerequisites.push(new Promise((resolve, reject) =>
308 { 317 {
309 let listener = function(action) 318 let window = this.currentWindow;
319 if (!window && "nsISessionStore" in Ci)
310 { 320 {
311 if (action != "load") 321 // No application windows yet, the application must be starting up. Wait
312 return; 322 // for session to be restored before initializing our UI.
323 new SessionRestoreObserver(resolve);
324 }
325 else
326 resolve();
327 }));
313 328
314 FilterNotifier.removeListener(listener); 329 Promise.all(prerequisites).then(() => this.initDone())
315 filtersLoaded = true; 330 .catch(e => Cu.reportError(e));
316 if (overlayLoaded && filtersLoaded && sessionRestored)
317 this.initDone();
318 }.bind(this);
319 FilterNotifier.addListener(listener);
320 }
321 else
322 filtersLoaded = true;
323
324 // Initialize UI after the session is restored
325 let window = this.currentWindow;
326 if (!window && "nsISessionStore" in Ci)
327 {
328 // No application windows yet, the application must be starting up. Wait
329 // for session to be restored before initializing our UI.
330 new SessionRestoreObserver(function()
331 {
332 sessionRestored = true;
333 if (overlayLoaded && filtersLoaded && sessionRestored)
334 this.initDone();
335 }.bind(this));
336 }
337 else
338 sessionRestored = true;
339 }, 331 },
340 332
341 /** 333 /**
342 * Provesses overlay document data and initializes overlay property. 334 * Provesses overlay document data and initializes overlay property.
343 */ 335 */
344 processOverlay: function(/**Element*/ root) 336 processOverlay: function(/**Element*/ root)
345 { 337 {
346 Utils.splitAllLabels(root); 338 Utils.splitAllLabels(root);
347 339
348 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true}; 340 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true};
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], 1888 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)],
1897 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] 1889 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)]
1898 ]; 1890 ];
1899 1891
1900 onShutdown.add(function() 1892 onShutdown.add(function()
1901 { 1893 {
1902 for (let window of UI.applicationWindows) 1894 for (let window of UI.applicationWindows)
1903 if (UI.isBottombarOpen(window)) 1895 if (UI.isBottombarOpen(window))
1904 UI.toggleBottombar(window); 1896 UI.toggleBottombar(window);
1905 }); 1897 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld