Left: | ||
Right: |
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 13 matching lines...) Expand all Loading... | |
24 let {FilterListener} = require("filterListener"); | 24 let {FilterListener} = require("filterListener"); |
25 let {FilterStorage} = require("filterStorage"); | 25 let {FilterStorage} = require("filterStorage"); |
26 let {FilterNotifier} = require("filterNotifier"); | 26 let {FilterNotifier} = require("filterNotifier"); |
27 let {RequestNotifier} = require("requestNotifier"); | 27 let {RequestNotifier} = require("requestNotifier"); |
28 let {Filter} = require("filterClasses"); | 28 let {Filter} = require("filterClasses"); |
29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses"); | 29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses"); |
30 let {Synchronizer} = require("synchronizer"); | 30 let {Synchronizer} = require("synchronizer"); |
31 let {KeySelector} = require("keySelector"); | 31 let {KeySelector} = require("keySelector"); |
32 let {Notification} = require("notification"); | 32 let {Notification} = require("notification"); |
33 | 33 |
34 let CustomizableUI; | |
35 try | |
36 { | |
37 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null) ; | |
38 } | |
39 catch (e) | |
40 { | |
41 // No built-in CustomizableUI API, use our own implementation. | |
42 ({CustomizableUI}) = require("customizableUI"); | |
43 } | |
44 | |
34 /** | 45 /** |
35 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) . | 46 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) . |
36 * @type Filter | 47 * @type Filter |
37 */ | 48 */ |
38 let siteWhitelist = null; | 49 let siteWhitelist = null; |
39 /** | 50 /** |
40 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) . | 51 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) . |
41 * @type Filter | 52 * @type Filter |
42 */ | 53 */ |
43 let pageWhitelist = null; | 54 let pageWhitelist = null; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 | 101 |
91 Utils.splitAllLabels(doc); | 102 Utils.splitAllLabels(doc); |
92 | 103 |
93 addCommandHandler("adblockplus-filters", UI.openFiltersDialog.bind(UI)); | 104 addCommandHandler("adblockplus-filters", UI.openFiltersDialog.bind(UI)); |
94 | 105 |
95 let {Sync} = require("sync"); | 106 let {Sync} = require("sync"); |
96 let syncEngine = Sync.getEngine(); | 107 let syncEngine = Sync.getEngine(); |
97 hideElement("adblockplus-sync", !syncEngine); | 108 hideElement("adblockplus-sync", !syncEngine); |
98 | 109 |
99 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); | 110 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); |
100 let hasToolbar = defaultToolbarPosition && !defaultToolbarPosition.isAddonBa r; | 111 let hasToolbar = defaultToolbarPosition; |
101 let hasAddonBar = defaultToolbarPosition && defaultToolbarPosition.isAddonBa r; | |
102 let hasStatusBar = statusbarPosition; | 112 let hasStatusBar = statusbarPosition; |
103 | 113 |
104 hideElement("adblockplus-showinaddonbar", !hasAddonBar); | |
105 hideElement("adblockplus-showintoolbar", !hasToolbar); | 114 hideElement("adblockplus-showintoolbar", !hasToolbar); |
106 hideElement("adblockplus-showinstatusbar", !hasStatusBar); | 115 hideElement("adblockplus-showinstatusbar", !hasStatusBar); |
107 | 116 |
108 let checkbox = doc.querySelector("setting[type=bool]"); | 117 let checkbox = doc.querySelector("setting[type=bool]"); |
109 if (checkbox) | 118 if (checkbox) |
110 initCheckboxes(); | 119 initCheckboxes(); |
111 | 120 |
112 function initCheckboxes() | 121 function initCheckboxes() |
113 { | 122 { |
114 if (!("value" in checkbox)) | 123 if (!("value" in checkbox)) |
(...skipping 16 matching lines...) Expand all Loading... | |
131 { | 140 { |
132 this.value = UI.toggleAcceptableAds(); | 141 this.value = UI.toggleAcceptableAds(); |
133 }); | 142 }); |
134 | 143 |
135 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled); | 144 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled); |
136 addCommandHandler("adblockplus-sync", function() | 145 addCommandHandler("adblockplus-sync", function() |
137 { | 146 { |
138 this.value = UI.toggleSync(); | 147 this.value = UI.toggleSync(); |
139 }); | 148 }); |
140 | 149 |
141 let window = null; | 150 setChecked("adblockplus-showintoolbar", UI.isToolbarIconVisible()); |
142 for (window in UI.applicationWindows) | 151 addCommandHandler("adblockplus-showintoolbar", function() |
143 break; | |
144 | |
145 if (window) | |
146 { | 152 { |
147 setChecked("adblockplus-showinaddonbar", UI.isToolbarIconVisible(window) ); | 153 UI.toggleToolbarIcon(); |
148 setChecked("adblockplus-showintoolbar", UI.isToolbarIconVisible(window)) ; | 154 this.value = UI.isToolbarIconVisible(); |
149 | 155 }); |
150 let handler = function() | |
151 { | |
152 UI.toggleToolbarIcon(); | |
153 this.value = UI.isToolbarIconVisible(window); | |
154 }; | |
155 addCommandHandler("adblockplus-showinaddonbar", handler); | |
156 addCommandHandler("adblockplus-showintoolbar", handler); | |
157 } | |
158 | 156 |
159 let list = doc.getElementById("adblockplus-subscription-list"); | 157 let list = doc.getElementById("adblockplus-subscription-list"); |
160 if (list) | 158 if (list) |
161 { | 159 { |
162 // Load subscriptions data | 160 // Load subscriptions data |
163 let request = new XMLHttpRequest(); | 161 let request = new XMLHttpRequest(); |
164 request.mozBackgroundRequest = true; | 162 request.mozBackgroundRequest = true; |
165 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ; | 163 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ; |
166 request.addEventListener("load", function() | 164 request.addEventListener("load", function() |
167 { | 165 { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 filtersLoaded = true; | 310 filtersLoaded = true; |
313 if (overlayLoaded && filtersLoaded && sessionRestored) | 311 if (overlayLoaded && filtersLoaded && sessionRestored) |
314 this.initDone(); | 312 this.initDone(); |
315 }.bind(this); | 313 }.bind(this); |
316 FilterNotifier.addListener(listener); | 314 FilterNotifier.addListener(listener); |
317 } | 315 } |
318 else | 316 else |
319 filtersLoaded = true; | 317 filtersLoaded = true; |
320 | 318 |
321 // Initialize UI after the session is restored | 319 // Initialize UI after the session is restored |
322 let window = null; | 320 let window = this.currentWindow; |
323 for (window in this.applicationWindows) | |
324 break; | |
325 if (!window && "nsISessionStore" in Ci) | 321 if (!window && "nsISessionStore" in Ci) |
326 { | 322 { |
327 // No application windows yet, the application must be starting up. Wait | 323 // No application windows yet, the application must be starting up. Wait |
328 // for session to be restored before initializing our UI. | 324 // for session to be restored before initializing our UI. |
329 new SessionRestoreObserver(function() | 325 new SessionRestoreObserver(function() |
330 { | 326 { |
331 sessionRestored = true; | 327 sessionRestored = true; |
332 if (overlayLoaded && filtersLoaded && sessionRestored) | 328 if (overlayLoaded && filtersLoaded && sessionRestored) |
333 this.initDone(); | 329 this.initDone(); |
334 }.bind(this)); | 330 }.bind(this)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 400 |
405 /** | 401 /** |
406 * Gets called once the initialization is finished and Adblock Plus elements | 402 * Gets called once the initialization is finished and Adblock Plus elements |
407 * can be added to the UI. | 403 * can be added to the UI. |
408 */ | 404 */ |
409 initDone: function() | 405 initDone: function() |
410 { | 406 { |
411 let {WindowObserver} = require("windowObserver"); | 407 let {WindowObserver} = require("windowObserver"); |
412 new WindowObserver(this); | 408 new WindowObserver(this); |
413 | 409 |
410 // Add toolbar icon | |
411 let {defaultToolbarPosition} = require("appSupport"); | |
412 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) | |
413 { | |
414 CustomizableUI.createWidget({ | |
415 id: "abp-toolbarbutton", | |
416 type: "custom", | |
417 positionAttribute: "abp-iconposition", // For emulation only | |
418 defaultArea: defaultToolbarPosition.parent, | |
419 defaultBefore: defaultToolbarPosition.before, // For emulation only | |
420 defaultAfter: defaultToolbarPosition.after, // For emulation only | |
421 removable: true, | |
422 onBuild: function(document) | |
423 { | |
tschuster
2014/05/15 20:12:30
We can probably make these arrow functions when I
Wladimir Palant
2014/07/11 07:15:54
Don't think so, arrow functions are for trivial fu
| |
424 let node = document.importNode(this.overlay["abp-toolbarbutton"], true ); | |
425 this.updateIconState(document.defaultView, node); | |
426 return node; | |
427 }.bind(this), | |
428 onAdded: function(node) | |
429 { | |
430 // For emulation only, this callback isn't part of the official | |
431 // CustomizableUI API. | |
432 this.updateIconState(node.ownerDocument.defaultView, node); | |
433 }.bind(this), | |
434 onClick: this.onIconClick, | |
435 onCommand: this.onIconCommand | |
Wladimir Palant
2013/12/02 15:14:18
These two lines don't actually do anything, they a
| |
436 }); | |
437 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); | |
438 } | |
439 | |
414 // Listen for pref and filters changes | 440 // Listen for pref and filters changes |
415 Prefs.addListener(function(name) | 441 Prefs.addListener(function(name) |
416 { | 442 { |
417 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") | 443 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") |
418 this.updateState(); | 444 this.updateState(); |
419 else if (name == "showinstatusbar") | 445 else if (name == "showinstatusbar") |
420 { | 446 { |
421 for (let window in this.applicationWindows) | 447 for (let window in this.applicationWindows) |
422 this.updateStatusbarIcon(window); | 448 this.updateStatusbarIcon(window); |
423 } | 449 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 if (!noDelay && delayInitialization) | 488 if (!noDelay && delayInitialization) |
463 { | 489 { |
464 Utils.runAsync(this.applyToWindow.bind(this, window, true)); | 490 Utils.runAsync(this.applyToWindow.bind(this, window, true)); |
465 return; | 491 return; |
466 } | 492 } |
467 | 493 |
468 // Add general items to the document | 494 // Add general items to the document |
469 for (let i = 0; i < this.overlay.all.length; i++) | 495 for (let i = 0; i < this.overlay.all.length; i++) |
470 window.document.documentElement.appendChild(this.overlay.all[i].cloneNode( true)); | 496 window.document.documentElement.appendChild(this.overlay.all[i].cloneNode( true)); |
471 | 497 |
472 // Add toolbar icon | |
473 if ("abp-toolbarbutton" in this.overlay) | |
474 { | |
475 let toolbox = this.getToolbox(window); | |
476 if (toolbox) | |
477 { | |
478 // Insert toolbar button asynchronously, otherwise it will show up | |
479 // before our stylesheet loads | |
480 Utils.runAsync(function() | |
481 { | |
482 toolbox.addEventListener("aftercustomization", this.onToolbarCustomiza tion, false); | |
483 | |
484 let {defaultToolbarPosition} = require("appSupport"); | |
485 let icon = this.overlay["abp-toolbarbutton"].cloneNode(true); | |
486 if ("addClass" in defaultToolbarPosition) | |
487 icon.classList.add(defaultToolbarPosition.addClass); | |
488 this.restoreToolbarIcon(toolbox, icon); | |
489 }.bind(this)); | |
490 } | |
491 } | |
492 | |
493 // Add status bar icon | 498 // Add status bar icon |
494 this.updateStatusbarIcon(window); | 499 this.updateStatusbarIcon(window); |
495 | 500 |
496 // Add tools menu item | 501 // Add tools menu item |
497 if ("abp-menuitem" in this.overlay) | 502 if ("abp-menuitem" in this.overlay) |
498 { | 503 { |
499 let {toolsMenu} = require("appSupport"); | 504 let {toolsMenu} = require("appSupport"); |
500 let [parent, before] = this.resolveInsertionPoint(window, toolsMenu); | 505 let [parent, before] = this.resolveInsertionPoint(window, toolsMenu); |
501 if (parent) | 506 if (parent) |
502 parent.insertBefore(this.overlay["abp-menuitem"].cloneNode(true), before ); | 507 parent.insertBefore(this.overlay["abp-menuitem"].cloneNode(true), before ); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 } | 577 } |
573 } | 578 } |
574 else | 579 else |
575 { | 580 { |
576 let clone = window.document.getElementById(id); | 581 let clone = window.document.getElementById(id); |
577 if (clone) | 582 if (clone) |
578 clone.parentNode.removeChild(clone); | 583 clone.parentNode.removeChild(clone); |
579 } | 584 } |
580 } | 585 } |
581 | 586 |
582 if ("abp-toolbarbutton" in this.overlay) | |
583 { | |
584 let toolbox = this.getToolbox(window); | |
585 if (toolbox) | |
586 { | |
587 toolbox.removeEventListener("aftercustomization", this.onToolbarCustomiz ation, false); | |
588 | |
589 let paletteItem = this.getPaletteItem(toolbox); | |
590 if (paletteItem) | |
591 paletteItem.parentNode.removeChild(paletteItem); | |
592 } | |
593 } | |
594 | |
595 window.removeEventListener("popupshowing", this.onPopupShowing, false); | 587 window.removeEventListener("popupshowing", this.onPopupShowing, false); |
596 window.removeEventListener("keypress", this.onKeyPress, false); | 588 window.removeEventListener("keypress", this.onKeyPress, false); |
597 removeBrowserLocationListeners(window); | 589 removeBrowserLocationListeners(window); |
598 removeBrowserClickListeners(window); | 590 removeBrowserClickListeners(window); |
599 }, | 591 }, |
600 | 592 |
601 /** | 593 /** |
602 * The overlay information to be used when adding elements to the UI. | 594 * The overlay information to be used when adding elements to the UI. |
603 * @type Object | 595 * @type Object |
604 */ | 596 */ |
(...skipping 15 matching lines...) Expand all Loading... | |
620 } | 612 } |
621 while (enumerator.hasMoreElements()) | 613 while (enumerator.hasMoreElements()) |
622 { | 614 { |
623 let window = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow); | 615 let window = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow); |
624 if (isKnownWindow(window)) | 616 if (isKnownWindow(window)) |
625 yield window; | 617 yield window; |
626 } | 618 } |
627 }, | 619 }, |
628 | 620 |
629 /** | 621 /** |
622 * Returns the top-most application window or null if none exists. | |
623 * @type Window | |
624 */ | |
625 get currentWindow() | |
626 { | |
627 for (let window of this.applicationWindows) | |
628 return window; | |
629 return null; | |
630 }, | |
631 | |
632 /** | |
630 * Opens a URL in the browser window. If browser window isn't passed as parame ter, | 633 * Opens a URL in the browser window. If browser window isn't passed as parame ter, |
631 * this function attempts to find a browser window. If an event is passed in | 634 * this function attempts to find a browser window. If an event is passed in |
632 * it should be passed in to the browser if possible (will e.g. open a tab in | 635 * it should be passed in to the browser if possible (will e.g. open a tab in |
633 * background depending on modifiers keys). | 636 * background depending on modifiers keys). |
634 */ | 637 */ |
635 loadInBrowser: function(/**String*/ url, /**Window*/ currentWindow, /**Event*/ event) | 638 loadInBrowser: function(/**String*/ url, /**Window*/ currentWindow, /**Event*/ event) |
636 { | 639 { |
637 if (!currentWindow) | 640 if (!currentWindow) |
638 for (currentWindow in this.applicationWindows) | 641 currentWindow = this.currentWindow; |
639 break; | |
640 | 642 |
641 let {addTab} = require("appSupport"); | 643 let {addTab} = require("appSupport"); |
642 if (currentWindow && addTab) | 644 if (currentWindow && addTab) |
643 addTab(currentWindow, url, event); | 645 addTab(currentWindow, url, event); |
644 else | 646 else |
645 { | 647 { |
646 let protocolService = Cc["@mozilla.org/uriloader/external-protocol-service ;1"].getService(Ci.nsIExternalProtocolService); | 648 let protocolService = Cc["@mozilla.org/uriloader/external-protocol-service ;1"].getService(Ci.nsIExternalProtocolService); |
647 protocolService.loadURI(Services.io.newURI(url, null, null), null); | 649 protocolService.loadURI(Services.io.newURI(url, null, null), null); |
648 } | 650 } |
649 }, | 651 }, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 }, | 946 }, |
945 | 947 |
946 /** | 948 /** |
947 * Looks up an element with given ID in the window. If a list of IDs is given | 949 * Looks up an element with given ID in the window. If a list of IDs is given |
948 * will try all of them until an element exists. | 950 * will try all of them until an element exists. |
949 */ | 951 */ |
950 findElement: function(/**Window*/ window, /**String|String[]*/ id) /**Element* / | 952 findElement: function(/**Window*/ window, /**String|String[]*/ id) /**Element* / |
951 { | 953 { |
952 if (id instanceof Array) | 954 if (id instanceof Array) |
953 { | 955 { |
954 for (let i = 0; i < id.length; i++) | 956 for (let candidate of id) |
955 { | 957 { |
956 let result = window.document.getElementById(id[i]); | 958 let result = window.document.getElementById(candidate); |
957 if (result) | 959 if (result) |
958 return result; | 960 return result; |
959 } | 961 } |
960 return null; | 962 return null; |
961 } | 963 } |
962 else | 964 else |
963 return window.document.getElementById(id); | 965 return window.document.getElementById(id); |
964 }, | 966 }, |
965 | 967 |
966 /** | 968 /** |
(...skipping 20 matching lines...) Expand all Loading... | |
987 } | 989 } |
988 | 990 |
989 if (before && before.parentNode != parent) | 991 if (before && before.parentNode != parent) |
990 before = null; | 992 before = null; |
991 } | 993 } |
992 | 994 |
993 return [parent, before]; | 995 return [parent, before]; |
994 }, | 996 }, |
995 | 997 |
996 /** | 998 /** |
997 * Finds the toolbox element responsible for the toolbar where Adblock Plus | |
998 * icon should be placed. | |
999 */ | |
1000 getToolbox: function(/**Window*/ window) /**Element*/ | |
1001 { | |
1002 let {defaultToolbarPosition} = require("appSupport"); | |
1003 if (!defaultToolbarPosition || !defaultToolbarPosition.parent) | |
1004 return null; | |
1005 | |
1006 let toolbar = this.findElement(window, defaultToolbarPosition.parent); | |
1007 if (!toolbar) | |
1008 return null; | |
1009 | |
1010 let toolbox = toolbar.toolbox; | |
1011 if (toolbox && ("palette" in toolbox) && toolbox.palette) | |
1012 return toolbox; | |
1013 else | |
1014 return null; | |
1015 }, | |
1016 | |
1017 /** | |
1018 * Restores the Adblock Plus icon at its original position. | |
1019 */ | |
1020 restoreToolbarIcon: function(/**Element*/ toolbox, /**Element*/ icon) | |
1021 { | |
1022 // Insert into the palette first | |
1023 toolbox.palette.insertBefore(icon, toolbox.palette.firstChild); | |
1024 | |
1025 // Now find where we should put the icon | |
1026 let position = toolbox.getAttribute("abp-iconposition"); | |
1027 if (!/^\S*,\S*,\S*$/.test(position)) | |
1028 position = null; | |
1029 | |
1030 if (position == null) | |
1031 { | |
1032 // No explicitly saved position but maybe we can find it in a currentset | |
1033 // attribute somewhere. | |
1034 let toolbars = toolbox.externalToolbars.slice(); | |
1035 for (let child = toolbox.firstElementChild; child; child = child.nextEleme ntSibling) | |
1036 if (child.localName == "toolbar") | |
1037 toolbars.push(child); | |
1038 for (let i = 0; i < toolbars.length; i++) | |
1039 { | |
1040 let toolbar = toolbars[i]; | |
1041 let currentSet = toolbar.getAttribute("currentset"); | |
1042 if (currentSet) | |
1043 { | |
1044 let items = currentSet.split(","); | |
1045 let index = items.indexOf("abp-toolbarbutton"); | |
1046 if (index >= 0) | |
1047 { | |
1048 position = "visible," + toolbar.id + "," + (index + 1 < items.length ? items[index + 1] : ""); | |
1049 toolbox.setAttribute("abp-iconposition", position); | |
1050 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition"); | |
1051 break; | |
1052 } | |
1053 } | |
1054 } | |
1055 } | |
1056 | |
1057 this.showToolbarIcon(toolbox, position); | |
1058 }, | |
1059 | |
1060 /** | |
1061 * Finds the toolbar button in the toolbar palette. | |
1062 */ | |
1063 getPaletteItem: function(/**Element*/ toolbox) /**Element*/ | |
1064 { | |
1065 for (var child = toolbox.palette.firstElementChild; child; child = child.nex tElementSibling) | |
1066 if (child.id == "abp-toolbarbutton") | |
1067 return child; | |
1068 | |
1069 return null; | |
1070 }, | |
1071 | |
1072 /** | |
1073 * Called after toolbar customization, sets up our icon and remembers its | |
1074 * position. | |
1075 */ | |
1076 onToolbarCustomization: function(/**Event*/ event) | |
1077 { | |
1078 let toolbox = event.currentTarget; | |
1079 let icon = toolbox.ownerDocument.getElementById("abp-toolbarbutton"); | |
1080 | |
1081 let position = toolbox.getAttribute("abp-iconposition") || "hidden,,"; | |
1082 if (icon && icon.parentNode.localName == "toolbar") | |
1083 { | |
1084 this.updateIconState(icon.ownerDocument.defaultView, icon); | |
1085 icon.addEventListener("click", this.onIconClick, false); | |
1086 icon.addEventListener("command", this.onIconClick, false); | |
1087 position = "visible," + icon.parentNode.id + "," + (icon.nextSibling ? ico n.nextSibling.id : ""); | |
1088 } | |
1089 else | |
1090 position = position.replace(/^visible,/, "hidden,") | |
1091 | |
1092 toolbox.setAttribute("abp-iconposition", position); | |
1093 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition"); | |
1094 }, | |
1095 | |
1096 /** | |
1097 * Shows or hides toolbar icon based on a remembered position. | |
1098 */ | |
1099 showToolbarIcon: function(/**Element*/ toolbox, /**String*/ position) | |
1100 { | |
1101 let visible, parent, before; | |
1102 if (position) | |
1103 { | |
1104 [visible, parent, before] = position.split(",", 3); | |
1105 parent = toolbox.ownerDocument.getElementById(parent); | |
1106 if (before == "") | |
1107 before = null; | |
1108 else | |
1109 before = toolbox.ownerDocument.getElementById(before); | |
1110 if (before && before.parentNode != parent) | |
1111 before = null; | |
1112 } | |
1113 else | |
1114 { | |
1115 let {defaultToolbarPosition} = require("appSupport"); | |
1116 visible = "visible"; | |
1117 [parent, before] = this.resolveInsertionPoint(toolbox.ownerDocument.defaul tView, defaultToolbarPosition); | |
1118 | |
1119 if (parent && parent.collapsed) | |
1120 { | |
1121 // First time we insert the toolbar icon, make sure it is actually visib le | |
1122 parent.setAttribute("collapsed", "false"); | |
1123 toolbox.ownerDocument.persist(parent.id, "collapsed"); | |
1124 } | |
1125 } | |
1126 | |
1127 if (parent && parent.localName != "toolbar") | |
1128 parent = null; | |
1129 | |
1130 if (visible != "visible") | |
1131 { | |
1132 // Hide icon if it is currently visible | |
1133 let icon = toolbox.ownerDocument.getElementById("abp-toolbarbutton"); | |
1134 if (icon && icon.parentNode.localName == "toolbar") | |
1135 toolbox.palette.appendChild(icon); | |
1136 } | |
1137 else if (parent) | |
1138 { | |
1139 // Add the icon to the toolbar | |
1140 let items = parent.currentSet.split(","); | |
1141 let index = (before ? items.indexOf(before.id) : -1); | |
1142 if (index < 0) | |
1143 before = null; | |
1144 parent.insertItem("abp-toolbarbutton", before, null, false); | |
1145 } | |
1146 | |
1147 this.onToolbarCustomization({currentTarget: toolbox}); | |
1148 }, | |
1149 | |
1150 /** | |
1151 * Toggles visibility state of the toolbar icon. | 999 * Toggles visibility state of the toolbar icon. |
1152 */ | 1000 */ |
1153 toggleToolbarIcon: function() | 1001 toggleToolbarIcon: function() |
1154 { | 1002 { |
1155 for (let window in this.applicationWindows) | 1003 if (this.isToolbarIconVisible()) |
1004 CustomizableUI.removeWidgetFromArea("abp-toolbarbutton"); | |
1005 else | |
1156 { | 1006 { |
1157 let toolbox = this.getToolbox(window); | 1007 let {defaultToolbarPosition} = require("appSupport"); |
tschuster
2014/05/15 20:12:30
From the rest of the code it looks like this can b
Wladimir Palant
2014/07/11 07:15:54
No, it cannot - nothing would call toggleToolbarIc
| |
1158 if (!toolbox) | 1008 CustomizableUI.addWidgetToArea("abp-toolbarbutton", defaultToolbarPosition .parent); |
1159 continue; | |
1160 | |
1161 let position = toolbox.getAttribute("abp-iconposition"); | |
1162 if (position) | |
1163 { | |
1164 let parts = position.split(","); | |
1165 parts[0] = (parts[0] == "visible" ? "hidden" : "visible"); | |
1166 position = parts.join(","); | |
1167 } | |
1168 this.showToolbarIcon(toolbox, position); | |
1169 } | 1009 } |
1170 }, | 1010 }, |
1171 | 1011 |
1172 /** | 1012 /** |
1173 * Updates Adblock Plus icon state for all windows. | 1013 * Updates Adblock Plus icon state for all windows. |
1174 */ | 1014 */ |
1175 updateState: function() | 1015 updateState: function() |
1176 { | 1016 { |
1177 for (let window in this.applicationWindows) | 1017 for (let window in this.applicationWindows) |
1178 { | 1018 { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1363 | 1203 |
1364 /** | 1204 /** |
1365 * Called when some pop-up in the application window shows up, initializes | 1205 * Called when some pop-up in the application window shows up, initializes |
1366 * pop-ups related to Adblock Plus. | 1206 * pop-ups related to Adblock Plus. |
1367 */ | 1207 */ |
1368 onPopupShowing: function(/**Event*/ event) | 1208 onPopupShowing: function(/**Event*/ event) |
1369 { | 1209 { |
1370 if (event.defaultPrevented) | 1210 if (event.defaultPrevented) |
1371 return; | 1211 return; |
1372 | 1212 |
1373 let popup = event.target; | 1213 let popup = event.originalTarget; |
1374 | 1214 |
1375 let {contentContextMenu} = require("appSupport"); | 1215 let {contentContextMenu} = require("appSupport"); |
1376 if ((typeof contentContextMenu == "string" && popup.id == contentContextMenu ) || | 1216 if ((typeof contentContextMenu == "string" && popup.id == contentContextMenu ) || |
1377 (contentContextMenu instanceof Array && contentContextMenu.indexOf(popup .id) >= 0)) | 1217 (contentContextMenu instanceof Array && contentContextMenu.indexOf(popup .id) >= 0)) |
1378 { | 1218 { |
1379 this.fillContentContextMenu(popup); | 1219 this.fillContentContextMenu(popup); |
1380 } | 1220 } |
1381 else if (popup.id == "abp-tooltip") | 1221 else if (popup.id == "abp-tooltip") |
1382 this.fillIconTooltip(event, popup.ownerDocument.defaultView); | 1222 this.fillIconTooltip(event, popup.ownerDocument.defaultView); |
1383 else | 1223 else |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 } | 1461 } |
1622 | 1462 |
1623 setDisabled("abp-command-sendReport", !location || !Policy.isBlockableScheme (location) || location.scheme == "mailto"); | 1463 setDisabled("abp-command-sendReport", !location || !Policy.isBlockableScheme (location) || location.scheme == "mailto"); |
1624 | 1464 |
1625 setChecked(prefix + "disabled", !Prefs.enabled); | 1465 setChecked(prefix + "disabled", !Prefs.enabled); |
1626 setChecked(prefix + "frameobjects", Prefs.frameobjects); | 1466 setChecked(prefix + "frameobjects", Prefs.frameobjects); |
1627 setChecked(prefix + "slowcollapse", !Prefs.fastcollapse); | 1467 setChecked(prefix + "slowcollapse", !Prefs.fastcollapse); |
1628 setChecked(prefix + "savestats", Prefs.savestats); | 1468 setChecked(prefix + "savestats", Prefs.savestats); |
1629 | 1469 |
1630 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); | 1470 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); |
1631 let hasToolbar = defaultToolbarPosition && !defaultToolbarPosition.isAddonBa r; | 1471 let hasToolbar = defaultToolbarPosition; |
1632 let hasAddonBar = defaultToolbarPosition && defaultToolbarPosition.isAddonBa r; | |
1633 let hasStatusBar = statusbarPosition; | 1472 let hasStatusBar = statusbarPosition; |
1634 hideElement(prefix + "showinaddonbar", !hasAddonBar || prefix == "abp-toolba r-"); | |
1635 hideElement(prefix + "showintoolbar", !hasToolbar || prefix == "abp-toolbar- "); | 1473 hideElement(prefix + "showintoolbar", !hasToolbar || prefix == "abp-toolbar- "); |
1636 hideElement(prefix + "showinstatusbar", !hasStatusBar); | 1474 hideElement(prefix + "showinstatusbar", !hasStatusBar); |
1637 hideElement(prefix + "iconSettingsSeparator", (prefix == "abp-toolbar-" || ( !hasAddonBar && !hasToolbar)) && !hasStatusBar); | 1475 hideElement(prefix + "iconSettingsSeparator", (prefix == "abp-toolbar-" || ! hasToolbar) && !hasStatusBar); |
1638 | 1476 |
1639 setChecked(prefix + "showinaddonbar", this.isToolbarIconVisible(window)); | 1477 setChecked(prefix + "showintoolbar", this.isToolbarIconVisible()); |
1640 setChecked(prefix + "showintoolbar", this.isToolbarIconVisible(window)); | |
1641 setChecked(prefix + "showinstatusbar", Prefs.showinstatusbar); | 1478 setChecked(prefix + "showinstatusbar", Prefs.showinstatusbar); |
1642 | 1479 |
1643 let {Sync} = require("sync"); | 1480 let {Sync} = require("sync"); |
1644 let syncEngine = Sync.getEngine(); | 1481 let syncEngine = Sync.getEngine(); |
1645 hideElement(prefix + "sync", !syncEngine); | 1482 hideElement(prefix + "sync", !syncEngine); |
1646 setChecked(prefix + "sync", syncEngine && syncEngine.enabled); | 1483 setChecked(prefix + "sync", syncEngine && syncEngine.enabled); |
1647 | 1484 |
1648 let defAction = (!window.document.popupNode || window.document.popupNode.id == "abp-toolbarbutton" ? | 1485 let defAction = (!window.document.popupNode || window.document.popupNode.id == "abp-toolbarbutton" ? |
1649 Prefs.defaulttoolbaraction : | 1486 Prefs.defaulttoolbaraction : |
1650 Prefs.defaultstatusbaraction); | 1487 Prefs.defaultstatusbaraction); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1828 let command = event.currentTarget.document.getElementById("abp-command-" + key); | 1665 let command = event.currentTarget.document.getElementById("abp-command-" + key); |
1829 if (command) | 1666 if (command) |
1830 command.doCommand(); | 1667 command.doCommand(); |
1831 } | 1668 } |
1832 } | 1669 } |
1833 }, | 1670 }, |
1834 | 1671 |
1835 /** | 1672 /** |
1836 * Checks whether the toolbar icon is currently displayed. | 1673 * Checks whether the toolbar icon is currently displayed. |
1837 */ | 1674 */ |
1838 isToolbarIconVisible: function(/**Window*/ window) | 1675 isToolbarIconVisible: function() /**Boolean*/ |
1839 { | 1676 { |
1840 let button = window.document.getElementById("abp-toolbarbutton"); | 1677 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
1841 return (button && button.parentNode && button.parentNode.localName == "toolb ar" && !button.parentNode.collapsed); | 1678 return !!placement; |
1842 }, | 1679 }, |
1843 | 1680 |
1844 /** | 1681 /** |
1845 * Stores the selected hotkeys, initialized when the user presses a key. | 1682 * Stores the selected hotkeys, initialized when the user presses a key. |
1846 */ | 1683 */ |
1847 hotkeys: null, | 1684 hotkeys: null, |
1848 | 1685 |
1849 /** | 1686 /** |
1850 * Chooses shortcut keys that are available in the window according to | 1687 * Chooses shortcut keys that are available in the window according to |
1851 * preferences. | 1688 * preferences. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1921 Prefs.hideContributeButton = true; | 1758 Prefs.hideContributeButton = true; |
1922 | 1759 |
1923 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"]) | 1760 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"]) |
1924 { | 1761 { |
1925 let button = window.document.getElementById(id); | 1762 let button = window.document.getElementById(id); |
1926 if (button) | 1763 if (button) |
1927 button.hidden = true; | 1764 button.hidden = true; |
1928 } | 1765 } |
1929 }, | 1766 }, |
1930 | 1767 |
1931 _showNextNotification: function(notification) | 1768 _showNextNotification: function() |
1932 { | 1769 { |
1933 let window = null; | 1770 let window = this.currentWindow; |
1934 for (window in this.applicationWindows) | |
1935 break; | |
1936 | |
1937 if (!window) | 1771 if (!window) |
1938 return; | 1772 return; |
1939 | 1773 |
1940 let button = window.document.getElementById("abp-toolbarbutton") | 1774 let button = window.document.getElementById("abp-toolbarbutton") |
1941 || window.document.getElementById("abp-status"); | 1775 || window.document.getElementById("abp-status"); |
1942 if (!button) | 1776 if (!button) |
1943 return; | 1777 return; |
1944 | 1778 |
1945 let notification = Notification.getNextToShow(); | 1779 let notification = Notification.getNextToShow(); |
1946 if (!notification) | 1780 if (!notification) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1994 this.loadInBrowser(link.href, window); | 1828 this.loadInBrowser(link.href, window); |
1995 }.bind(this)); | 1829 }.bind(this)); |
1996 | 1830 |
1997 let panel = window.document.getElementById("abp-notification"); | 1831 let panel = window.document.getElementById("abp-notification"); |
1998 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); | 1832 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); |
1999 } | 1833 } |
2000 }; | 1834 }; |
2001 UI.onPopupShowing = UI.onPopupShowing.bind(UI); | 1835 UI.onPopupShowing = UI.onPopupShowing.bind(UI); |
2002 UI.onKeyPress = UI.onKeyPress.bind(UI); | 1836 UI.onKeyPress = UI.onKeyPress.bind(UI); |
2003 UI.onIconClick = UI.onIconClick.bind(UI); | 1837 UI.onIconClick = UI.onIconClick.bind(UI); |
2004 UI.onToolbarCustomization = UI.onToolbarCustomization.bind(UI); | |
2005 UI.init(); | 1838 UI.init(); |
2006 | 1839 |
2007 /** | 1840 /** |
2008 * List of event handers to be registered for each window. For each event | 1841 * List of event handers to be registered for each window. For each event |
2009 * handler the element ID, event and the actual event handler are listed. | 1842 * handler the element ID, event and the actual event handler are listed. |
2010 * @type Array | 1843 * @type Array |
2011 */ | 1844 */ |
2012 let eventHandlers = [ | 1845 let eventHandlers = [ |
2013 ["abp-command-sendReport", "command", UI.openReportDialog.bind(UI)], | 1846 ["abp-command-sendReport", "command", UI.openReportDialog.bind(UI)], |
2014 ["abp-command-filters", "command", UI.openFiltersDialog.bind(UI)], | 1847 ["abp-command-filters", "command", UI.openFiltersDialog.bind(UI)], |
(...skipping 10 matching lines...) Expand all Loading... | |
2025 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], | 1858 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], |
2026 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] | 1859 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] |
2027 ]; | 1860 ]; |
2028 | 1861 |
2029 onShutdown.add(function() | 1862 onShutdown.add(function() |
2030 { | 1863 { |
2031 for (let window in UI.applicationWindows) | 1864 for (let window in UI.applicationWindows) |
2032 if (UI.isBottombarOpen(window)) | 1865 if (UI.isBottombarOpen(window)) |
2033 UI.toggleBottombar(window); | 1866 UI.toggleBottombar(window); |
2034 }); | 1867 }); |
OLD | NEW |