OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 let request = new XMLHttpRequest(); | 277 let request = new XMLHttpRequest(); |
278 request.mozBackgroundRequest = true; | 278 request.mozBackgroundRequest = true; |
279 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul"); | 279 request.open("GET", "chrome://adblockplus/content/ui/overlay.xul"); |
280 request.addEventListener("load", function(event) | 280 request.addEventListener("load", function(event) |
281 { | 281 { |
282 if (onShutdown.done) | 282 if (onShutdown.done) |
283 return; | 283 return; |
284 | 284 |
285 this.processOverlay(request.responseXML.documentElement); | 285 this.processOverlay(request.responseXML.documentElement); |
286 | 286 |
| 287 // Don't wait for the rest of the startup sequence, add icon already |
| 288 this.addToolbarButton(); |
| 289 |
287 overlayLoaded = true; | 290 overlayLoaded = true; |
288 if (overlayLoaded && filtersLoaded && sessionRestored) | 291 if (overlayLoaded && filtersLoaded && sessionRestored) |
289 this.initDone(); | 292 this.initDone(); |
290 }.bind(this), false); | 293 }.bind(this), false); |
291 request.send(null); | 294 request.send(null); |
292 | 295 |
293 // Wait for filters to load | 296 // Wait for filters to load |
294 if (FilterStorage._loading) | 297 if (FilterStorage._loading) |
295 { | 298 { |
296 let listener = function(action) | 299 let listener = function(action) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true
), "abp-menuitem")); | 392 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true
), "abp-menuitem")); |
390 } | 393 } |
391 }, | 394 }, |
392 | 395 |
393 /** | 396 /** |
394 * Gets called once the initialization is finished and Adblock Plus elements | 397 * Gets called once the initialization is finished and Adblock Plus elements |
395 * can be added to the UI. | 398 * can be added to the UI. |
396 */ | 399 */ |
397 initDone: function() | 400 initDone: function() |
398 { | 401 { |
399 let {WindowObserver} = require("windowObserver"); | 402 // The icon might be added already, make sure its state is correct |
400 new WindowObserver(this); | 403 this.updateState(); |
401 | |
402 // Add toolbar icon | |
403 let {defaultToolbarPosition} = require("appSupport"); | |
404 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) | |
405 { | |
406 try | |
407 { | |
408 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm",
null); | |
409 } | |
410 catch (e) | |
411 { | |
412 // No built-in CustomizableUI API, use our own implementation. | |
413 ({CustomizableUI}) = require("customizableUI"); | |
414 } | |
415 | |
416 CustomizableUI.createWidget({ | |
417 id: "abp-toolbarbutton", | |
418 type: "custom", | |
419 positionAttribute: "abp-iconposition", // For emulation only | |
420 defaultArea: defaultToolbarPosition.parent, | |
421 defaultBefore: defaultToolbarPosition.before, // For emulation only | |
422 defaultAfter: defaultToolbarPosition.after, // For emulation only | |
423 removable: true, | |
424 onBuild: function(document) | |
425 { | |
426 let node = document.importNode(this.overlay["abp-toolbarbutton"], true
); | |
427 node.addEventListener("click", this.onIconClick, false); | |
428 node.addEventListener("command", this.onIconClick, false); | |
429 this.updateIconState(document.defaultView, node); | |
430 return node; | |
431 }.bind(this), | |
432 onAdded: function(node) | |
433 { | |
434 // For emulation only, this callback isn't part of the official | |
435 // CustomizableUI API. | |
436 this.updateIconState(node.ownerDocument.defaultView, node); | |
437 }.bind(this), | |
438 }); | |
439 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool
barbutton")); | |
440 } | |
441 | 404 |
442 // Listen for pref and filters changes | 405 // Listen for pref and filters changes |
443 Prefs.addListener(function(name) | 406 Prefs.addListener(function(name) |
444 { | 407 { |
445 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul
tstatusbaraction") | 408 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul
tstatusbaraction") |
446 this.updateState(); | 409 this.updateState(); |
447 else if (name == "showinstatusbar") | 410 else if (name == "showinstatusbar") |
448 { | 411 { |
449 for (let window in this.applicationWindows) | 412 for (let window in this.applicationWindows) |
450 this.updateStatusbarIcon(window); | 413 this.updateStatusbarIcon(window); |
(...skipping 20 matching lines...) Expand all Loading... |
471 return; | 434 return; |
472 | 435 |
473 this.showNextNotification(subject.location.href); | 436 this.showNextNotification(subject.location.href); |
474 }.bind(UI) | 437 }.bind(UI) |
475 }; | 438 }; |
476 Services.obs.addObserver(documentCreationObserver, "content-document-global-
created", false); | 439 Services.obs.addObserver(documentCreationObserver, "content-document-global-
created", false); |
477 onShutdown.add(function() | 440 onShutdown.add(function() |
478 { | 441 { |
479 Services.obs.removeObserver(documentCreationObserver, "content-document-gl
obal-created", false); | 442 Services.obs.removeObserver(documentCreationObserver, "content-document-gl
obal-created", false); |
480 }); | 443 }); |
| 444 |
| 445 // Execute first-run actions if a window is open already, otherwise it |
| 446 // will happen in applyToWindow() when a window is opened. |
| 447 this.firstRunActions(this.currentWindow); |
| 448 }, |
| 449 |
| 450 addToolbarButton: function() |
| 451 { |
| 452 let {WindowObserver} = require("windowObserver"); |
| 453 new WindowObserver(this); |
| 454 |
| 455 let {defaultToolbarPosition} = require("appSupport"); |
| 456 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) |
| 457 { |
| 458 try |
| 459 { |
| 460 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm",
null); |
| 461 } |
| 462 catch (e) |
| 463 { |
| 464 // No built-in CustomizableUI API, use our own implementation. |
| 465 ({CustomizableUI}) = require("customizableUI"); |
| 466 } |
| 467 |
| 468 CustomizableUI.createWidget({ |
| 469 id: "abp-toolbarbutton", |
| 470 type: "custom", |
| 471 positionAttribute: "abp-iconposition", // For emulation only |
| 472 defaultArea: defaultToolbarPosition.parent, |
| 473 defaultBefore: defaultToolbarPosition.before, // For emulation only |
| 474 defaultAfter: defaultToolbarPosition.after, // For emulation only |
| 475 removable: true, |
| 476 onBuild: function(document) |
| 477 { |
| 478 let node = document.importNode(this.overlay["abp-toolbarbutton"], true
); |
| 479 node.addEventListener("click", this.onIconClick, false); |
| 480 node.addEventListener("command", this.onIconClick, false); |
| 481 this.updateIconState(document.defaultView, node); |
| 482 return node; |
| 483 }.bind(this), |
| 484 onAdded: function(node) |
| 485 { |
| 486 // For emulation only, this callback isn't part of the official |
| 487 // CustomizableUI API. |
| 488 this.updateIconState(node.ownerDocument.defaultView, node); |
| 489 }.bind(this), |
| 490 }); |
| 491 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool
barbutton")); |
| 492 } |
| 493 }, |
| 494 |
| 495 firstRunActions: function(window) |
| 496 { |
| 497 if (this.firstRunDone || !window || FilterStorage._loading) |
| 498 return; |
| 499 |
| 500 this.firstRunDone = true; |
| 501 |
| 502 let {addonVersion} = require("info"); |
| 503 let prevVersion = Prefs.currentVersion; |
| 504 if (prevVersion != addonVersion) |
| 505 { |
| 506 Prefs.currentVersion = addonVersion; |
| 507 this.addSubscription(window, prevVersion); |
| 508 } |
481 }, | 509 }, |
482 | 510 |
483 /** | 511 /** |
484 * Will be set to true after the check whether first-run actions should run | 512 * Will be set to true after the check whether first-run actions should run |
485 * has been performed. | 513 * has been performed. |
486 * @type Boolean | 514 * @type Boolean |
487 */ | 515 */ |
488 firstRunDone: false, | 516 firstRunDone: false, |
489 | 517 |
490 /** | 518 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 this.updateIconState(window, window.document.getElementById("abp-toolbarbu
tton")); | 572 this.updateIconState(window, window.document.getElementById("abp-toolbarbu
tton")); |
545 }.bind(this)); | 573 }.bind(this)); |
546 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); | 574 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); |
547 | 575 |
548 window.document.getElementById("abp-notification-close").addEventListener("c
ommand", function(event) | 576 window.document.getElementById("abp-notification-close").addEventListener("c
ommand", function(event) |
549 { | 577 { |
550 window.document.getElementById("abp-notification").hidePopup(); | 578 window.document.getElementById("abp-notification").hidePopup(); |
551 }, false); | 579 }, false); |
552 | 580 |
553 // First-run actions? | 581 // First-run actions? |
554 if (!this.firstRunDone) | 582 this.firstRunActions(window); |
555 { | |
556 this.firstRunDone = true; | |
557 | |
558 let {addonVersion} = require("info"); | |
559 let prevVersion = Prefs.currentVersion; | |
560 if (prevVersion != addonVersion) | |
561 { | |
562 Prefs.currentVersion = addonVersion; | |
563 this.addSubscription(window, prevVersion); | |
564 } | |
565 } | |
566 | 583 |
567 // Some people actually switch off browser.frames.enabled and are surprised | 584 // Some people actually switch off browser.frames.enabled and are surprised |
568 // that things stop working... | 585 // that things stop working... |
569 window.QueryInterface(Ci.nsIInterfaceRequestor) | 586 window.QueryInterface(Ci.nsIInterfaceRequestor) |
570 .getInterface(Ci.nsIWebNavigation) | 587 .getInterface(Ci.nsIWebNavigation) |
571 .QueryInterface(Ci.nsIDocShell) | 588 .QueryInterface(Ci.nsIDocShell) |
572 .allowSubframes = true; | 589 .allowSubframes = true; |
573 }, | 590 }, |
574 | 591 |
575 /** | 592 /** |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 if (!icon) | 1086 if (!icon) |
1070 return; | 1087 return; |
1071 | 1088 |
1072 let state = (Prefs.enabled ? "active" : "disabled"); | 1089 let state = (Prefs.enabled ? "active" : "disabled"); |
1073 if (state == "active") | 1090 if (state == "active") |
1074 { | 1091 { |
1075 let location = this.getCurrentLocation(window); | 1092 let location = this.getCurrentLocation(window); |
1076 if (location && Policy.isWhitelisted(location.spec)) | 1093 if (location && Policy.isWhitelisted(location.spec)) |
1077 state = "whitelisted"; | 1094 state = "whitelisted"; |
1078 } | 1095 } |
1079 | 1096 |
1080 let popupId = "abp-status-popup"; | 1097 let popupId = "abp-status-popup"; |
1081 if (icon.localName == "statusbarpanel") | 1098 if (icon.localName == "statusbarpanel") |
1082 { | 1099 { |
1083 if (Prefs.defaultstatusbaraction == 0) | 1100 if (Prefs.defaultstatusbaraction == 0) |
1084 { | 1101 { |
1085 icon.setAttribute("popup", popupId); | 1102 icon.setAttribute("popup", popupId); |
1086 icon.removeAttribute("context"); | 1103 icon.removeAttribute("context"); |
1087 } | 1104 } |
1088 else | 1105 else |
1089 { | 1106 { |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], | 1950 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], |
1934 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] | 1951 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] |
1935 ]; | 1952 ]; |
1936 | 1953 |
1937 onShutdown.add(function() | 1954 onShutdown.add(function() |
1938 { | 1955 { |
1939 for (let window in UI.applicationWindows) | 1956 for (let window in UI.applicationWindows) |
1940 if (UI.isBottombarOpen(window)) | 1957 if (UI.isBottombarOpen(window)) |
1941 UI.toggleBottombar(window); | 1958 UI.toggleBottombar(window); |
1942 }); | 1959 }); |
OLD | NEW |