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: Created June 7, 2016, 4:21 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 promises = [];
Thomas Greiner 2016/06/08 15:47:32 Detail: That variable name is not very descriptive
Wladimir Palant 2016/06/08 20:51:30 Done.
282 let filtersLoaded = false;
283 let sessionRestored = false;
284 282
285 // Start loading overlay 283 // Start loading overlay
286 let request = new XMLHttpRequest(); 284 promises.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;
Thomas Greiner 2016/06/08 15:47:32 Instead of returning I'd suggest to resolve or rej
Wladimir Palant 2016/06/08 20:51:30 We don't really want to do anything with that prom
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 request.send(null);
303 }.bind(this), false); 303 }));
304 request.send(null);
305 304
306 // Wait for filters to load 305 // Wait for filters to load
307 if (FilterStorage._loading) 306 if (FilterStorage._loading)
307 promises.push(FilterNotifier.once("load"));
308
309 // Wait for session to be restored
310 promises.push(new Promise((resolve, reject) =>
308 { 311 {
309 let listener = function(action) 312 let window = this.currentWindow;
313 if (!window && "nsISessionStore" in Ci)
310 { 314 {
311 if (action != "load") 315 // No application windows yet, the application must be starting up. Wait
312 return; 316 // for session to be restored before initializing our UI.
317 new SessionRestoreObserver(resolve);
318 }
319 else
320 resolve();
321 }));
313 322
314 FilterNotifier.removeListener(listener); 323 Promise.all(promises).then(() => this.initDone());
315 filtersLoaded = true;
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 }, 324 },
340 325
341 /** 326 /**
342 * Provesses overlay document data and initializes overlay property. 327 * Provesses overlay document data and initializes overlay property.
343 */ 328 */
344 processOverlay: function(/**Element*/ root) 329 processOverlay: function(/**Element*/ root)
345 { 330 {
346 Utils.splitAllLabels(root); 331 Utils.splitAllLabels(root);
347 332
348 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true}; 333 let specialElements = {"abp-status-popup": true, "abp-status": true, "abp-to olbarbutton": true, "abp-menuitem": true, "abp-bottombar-container": true};
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], 1877 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)],
1893 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] 1878 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)]
1894 ]; 1879 ];
1895 1880
1896 onShutdown.add(function() 1881 onShutdown.add(function()
1897 { 1882 {
1898 for (let window of UI.applicationWindows) 1883 for (let window of UI.applicationWindows)
1899 if (UI.isBottombarOpen(window)) 1884 if (UI.isBottombarOpen(window))
1900 UI.toggleBottombar(window); 1885 UI.toggleBottombar(window);
1901 }); 1886 });
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