| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 have to wait for multiple events before running start-up actions | 280 // We have to wait for multiple events before running start-up actions |
| 281 let promises = []; | 281 let prerequisites = []; |
|
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 | 282 |
| 283 // Start loading overlay | 283 // Start loading overlay |
| 284 promises.push(new Promise((resolve, reject) => | 284 prerequisites.push(new Promise((resolve, reject) => |
| 285 { | 285 { |
| 286 let request = new XMLHttpRequest(); | 286 let request = new XMLHttpRequest(); |
| 287 request.mozBackgroundRequest = true; | 287 request.mozBackgroundRequest = true; |
| 288 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul"); | 288 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul"); |
| 289 request.channel.owner = Utils.systemPrincipal; | 289 request.channel.owner = Utils.systemPrincipal; |
| 290 request.addEventListener("load", event => | 290 request.addEventListener("load", event => |
| 291 { | 291 { |
| 292 if (onShutdown.done) | 292 if (onShutdown.done) |
| 293 return; | 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 resolve(); | 300 resolve(); |
| 301 }, false); | 301 }, false); |
| 302 | |
| 303 request.addEventListener("error", event => | |
| 304 { | |
| 305 reject(new Error("Unexpected: Failed to load overlay.xul")); | |
| 306 }); | |
| 307 | |
| 302 request.send(null); | 308 request.send(null); |
| 303 })); | 309 })); |
| 304 | 310 |
| 305 // Wait for filters to load | 311 // Wait for filters to load |
| 306 if (FilterStorage._loading) | 312 if (FilterStorage._loading) |
| 307 promises.push(FilterNotifier.once("load")); | 313 prerequisites.push(FilterNotifier.once("load")); |
| 308 | 314 |
| 309 // Wait for session to be restored | 315 // Wait for session to be restored |
| 310 promises.push(new Promise((resolve, reject) => | 316 prerequisites.push(new Promise((resolve, reject) => |
| 311 { | 317 { |
| 312 let window = this.currentWindow; | 318 let window = this.currentWindow; |
| 313 if (!window && "nsISessionStore" in Ci) | 319 if (!window && "nsISessionStore" in Ci) |
| 314 { | 320 { |
| 315 // No application windows yet, the application must be starting up. Wait | 321 // No application windows yet, the application must be starting up. Wait |
| 316 // for session to be restored before initializing our UI. | 322 // for session to be restored before initializing our UI. |
| 317 new SessionRestoreObserver(resolve); | 323 new SessionRestoreObserver(resolve); |
| 318 } | 324 } |
| 319 else | 325 else |
| 320 resolve(); | 326 resolve(); |
| 321 })); | 327 })); |
| 322 | 328 |
| 323 Promise.all(promises).then(() => this.initDone()); | 329 Promise.all(prerequisites).then(() => this.initDone()) |
| 330 .catch(e => Cu.reportError(e)); | |
| 324 }, | 331 }, |
| 325 | 332 |
| 326 /** | 333 /** |
| 327 * Provesses overlay document data and initializes overlay property. | 334 * Provesses overlay document data and initializes overlay property. |
| 328 */ | 335 */ |
| 329 processOverlay: function(/**Element*/ root) | 336 processOverlay: function(/**Element*/ root) |
| 330 { | 337 { |
| 331 Utils.splitAllLabels(root); | 338 Utils.splitAllLabels(root); |
| 332 | 339 |
| 333 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 /** | 398 /** |
| 392 * Gets called once the initialization is finished and Adblock Plus elements | 399 * Gets called once the initialization is finished and Adblock Plus elements |
| 393 * can be added to the UI. | 400 * can be added to the UI. |
| 394 */ | 401 */ |
| 395 initDone: function() | 402 initDone: function() |
| 396 { | 403 { |
| 397 // The icon might be added already, make sure its state is correct | 404 // The icon might be added already, make sure its state is correct |
| 398 this.updateState(); | 405 this.updateState(); |
| 399 | 406 |
| 400 // Listen for pref and filters changes | 407 // Listen for pref and filters changes |
| 401 Prefs.addListener(function(name) | 408 Prefs.addListener(name => |
| 402 { | 409 { |
| 403 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") | 410 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") |
| 404 this.updateState(); | 411 this.updateState(); |
| 405 else if (name == "showinstatusbar") | 412 else if (name == "showinstatusbar") |
| 406 { | 413 { |
| 407 for (let window of this.applicationWindows) | 414 for (let window of this.applicationWindows) |
| 408 this.updateStatusbarIcon(window); | 415 this.updateStatusbarIcon(window); |
| 409 } | 416 } |
| 410 }.bind(this)); | 417 }); |
| 411 FilterNotifier.addListener(function(action) | 418 |
| 412 { | 419 for (let eventName of [ |
| 413 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load") | 420 "filter.added", "filter.removed", "filter.disabled", |
| 414 this.updateState(); | 421 "subscription.added", "subscription.removed", "subscription.disabled", |
| 415 }.bind(this)); | 422 "subscription.updated", "load" |
| 423 ]) | |
| 424 { | |
| 425 FilterNotifier.on(eventName, () => this.updateState()); | |
| 426 } | |
| 416 | 427 |
| 417 Notification.addShowListener(notification => | 428 Notification.addShowListener(notification => |
| 418 { | 429 { |
| 419 let window = this.currentWindow; | 430 let window = this.currentWindow; |
| 420 if (!window) | 431 if (!window) |
| 421 return; | 432 return; |
| 422 | 433 |
| 423 let button = window.document.getElementById("abp-toolbarbutton") | 434 let button = window.document.getElementById("abp-toolbarbutton") |
| 424 || window.document.getElementById("abp-status"); | 435 || window.document.getElementById("abp-status"); |
| 425 if (!button) | 436 if (!button) |
| (...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1877 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], | 1888 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], |
| 1878 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] | 1889 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] |
| 1879 ]; | 1890 ]; |
| 1880 | 1891 |
| 1881 onShutdown.add(function() | 1892 onShutdown.add(function() |
| 1882 { | 1893 { |
| 1883 for (let window of UI.applicationWindows) | 1894 for (let window of UI.applicationWindows) |
| 1884 if (UI.isBottombarOpen(window)) | 1895 if (UI.isBottombarOpen(window)) |
| 1885 UI.toggleBottombar(window); | 1896 UI.toggleBottombar(window); |
| 1886 }); | 1897 }); |
| LEFT | RIGHT |