| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 return; | 434 return; |
| 435 | 435 |
| 436 this.showNextNotification(subject.location.href); | 436 this.showNextNotification(subject.location.href); |
| 437 }.bind(UI) | 437 }.bind(UI) |
| 438 }; | 438 }; |
| 439 Services.obs.addObserver(documentCreationObserver, "content-document-global- created", false); | 439 Services.obs.addObserver(documentCreationObserver, "content-document-global- created", false); |
| 440 onShutdown.add(function() | 440 onShutdown.add(function() |
| 441 { | 441 { |
| 442 Services.obs.removeObserver(documentCreationObserver, "content-document-gl obal-created", false); | 442 Services.obs.removeObserver(documentCreationObserver, "content-document-gl obal-created", false); |
| 443 }); | 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); | |
| 444 }, | 448 }, |
| 445 | 449 |
| 446 addToolbarButton: function() | 450 addToolbarButton: function() |
| 447 { | 451 { |
| 448 let {WindowObserver} = require("windowObserver"); | 452 let {WindowObserver} = require("windowObserver"); |
| 449 new WindowObserver(this); | 453 new WindowObserver(this); |
| 450 | 454 |
| 451 let {defaultToolbarPosition} = require("appSupport"); | 455 let {defaultToolbarPosition} = require("appSupport"); |
| 452 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) | 456 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) |
| 453 { | 457 { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 467 positionAttribute: "abp-iconposition", // For emulation only | 471 positionAttribute: "abp-iconposition", // For emulation only |
| 468 defaultArea: defaultToolbarPosition.parent, | 472 defaultArea: defaultToolbarPosition.parent, |
| 469 defaultBefore: defaultToolbarPosition.before, // For emulation only | 473 defaultBefore: defaultToolbarPosition.before, // For emulation only |
| 470 defaultAfter: defaultToolbarPosition.after, // For emulation only | 474 defaultAfter: defaultToolbarPosition.after, // For emulation only |
| 471 removable: true, | 475 removable: true, |
| 472 onBuild: function(document) | 476 onBuild: function(document) |
| 473 { | 477 { |
| 474 let node = document.importNode(this.overlay["abp-toolbarbutton"], true ); | 478 let node = document.importNode(this.overlay["abp-toolbarbutton"], true ); |
| 475 node.addEventListener("click", this.onIconClick, false); | 479 node.addEventListener("click", this.onIconClick, false); |
| 476 node.addEventListener("command", this.onIconClick, false); | 480 node.addEventListener("command", this.onIconClick, false); |
| 477 if ("addClass" in defaultToolbarPosition) | |
| 478 node.classList.add(defaultToolbarPosition.addClass); | |
| 479 this.updateIconState(document.defaultView, node); | 481 this.updateIconState(document.defaultView, node); |
| 480 return node; | 482 return node; |
| 481 }.bind(this), | 483 }.bind(this), |
| 482 onAdded: function(node) | 484 onAdded: function(node) |
| 483 { | 485 { |
| 484 // For emulation only, this callback isn't part of the official | 486 // For emulation only, this callback isn't part of the official |
| 485 // CustomizableUI API. | 487 // CustomizableUI API. |
| 486 this.updateIconState(node.ownerDocument.defaultView, node); | 488 this.updateIconState(node.ownerDocument.defaultView, node); |
| 487 }.bind(this), | 489 }.bind(this), |
| 488 }); | 490 }); |
| 489 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); | 491 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); |
| 490 } | 492 } |
| 491 }, | 493 }, |
| 492 | 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 } | |
| 509 }, | |
| 510 | |
| 493 /** | 511 /** |
| 494 * 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 |
| 495 * has been performed. | 513 * has been performed. |
| 496 * @type Boolean | 514 * @type Boolean |
| 497 */ | 515 */ |
| 498 firstRunDone: false, | 516 firstRunDone: false, |
| 499 | 517 |
| 500 /** | 518 /** |
| 501 * Initializes Adblock Plus UI in a window. | 519 * Initializes Adblock Plus UI in a window. |
| 502 */ | 520 */ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); | 572 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); |
| 555 }.bind(this)); | 573 }.bind(this)); |
| 556 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); | 574 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); |
| 557 | 575 |
| 558 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) | 576 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) |
| 559 { | 577 { |
| 560 window.document.getElementById("abp-notification").hidePopup(); | 578 window.document.getElementById("abp-notification").hidePopup(); |
| 561 }, false); | 579 }, false); |
| 562 | 580 |
| 563 // First-run actions? | 581 // First-run actions? |
| 564 if (!this.firstRunDone) | 582 this.firstRunActions(window); |
| 565 { | |
| 566 this.firstRunDone = true; | |
| 567 | |
| 568 let {addonVersion} = require("info"); | |
| 569 let prevVersion = Prefs.currentVersion; | |
| 570 if (prevVersion != addonVersion) | |
| 571 { | |
| 572 Prefs.currentVersion = addonVersion; | |
| 573 this.addSubscription(window, prevVersion); | |
| 574 } | |
| 575 } | |
| 576 | 583 |
| 577 // Some people actually switch off browser.frames.enabled and are surprised | 584 // Some people actually switch off browser.frames.enabled and are surprised |
| 578 // that things stop working... | 585 // that things stop working... |
| 579 window.QueryInterface(Ci.nsIInterfaceRequestor) | 586 window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 580 .getInterface(Ci.nsIWebNavigation) | 587 .getInterface(Ci.nsIWebNavigation) |
| 581 .QueryInterface(Ci.nsIDocShell) | 588 .QueryInterface(Ci.nsIDocShell) |
| 582 .allowSubframes = true; | 589 .allowSubframes = true; |
| 583 }, | 590 }, |
| 584 | 591 |
| 585 /** | 592 /** |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 return; | 1087 return; |
| 1081 | 1088 |
| 1082 let state = (Prefs.enabled ? "active" : "disabled"); | 1089 let state = (Prefs.enabled ? "active" : "disabled"); |
| 1083 if (state == "active") | 1090 if (state == "active") |
| 1084 { | 1091 { |
| 1085 let location = this.getCurrentLocation(window); | 1092 let location = this.getCurrentLocation(window); |
| 1086 if (location && Policy.isWhitelisted(location.spec)) | 1093 if (location && Policy.isWhitelisted(location.spec)) |
| 1087 state = "whitelisted"; | 1094 state = "whitelisted"; |
| 1088 } | 1095 } |
| 1089 | 1096 |
| 1097 let popupId = "abp-status-popup"; | |
| 1090 if (icon.localName == "statusbarpanel") | 1098 if (icon.localName == "statusbarpanel") |
| 1091 { | 1099 { |
| 1092 if (Prefs.defaultstatusbaraction == 0) | 1100 if (Prefs.defaultstatusbaraction == 0) |
| 1093 icon.setAttribute("popup", icon.getAttribute("context")); | 1101 { |
| 1102 icon.setAttribute("popup", popupId); | |
| 1103 icon.removeAttribute("context"); | |
| 1104 } | |
| 1094 else | 1105 else |
| 1106 { | |
| 1095 icon.removeAttribute("popup"); | 1107 icon.removeAttribute("popup"); |
| 1108 icon.setAttribute("context", popupId); | |
| 1109 } | |
| 1096 } | 1110 } |
| 1097 else | 1111 else |
| 1098 { | 1112 { |
| 1099 if (Prefs.defaulttoolbaraction == 0) | 1113 if (Prefs.defaulttoolbaraction == 0) |
| 1114 { | |
| 1100 icon.setAttribute("type", "menu"); | 1115 icon.setAttribute("type", "menu"); |
| 1116 icon.removeAttribute("context"); | |
| 1117 } | |
| 1101 else | 1118 else |
| 1119 { | |
| 1102 icon.setAttribute("type", "menu-button"); | 1120 icon.setAttribute("type", "menu-button"); |
| 1121 icon.setAttribute("context", popupId); | |
| 1122 } | |
| 1103 } | 1123 } |
| 1104 | 1124 |
| 1105 icon.setAttribute("abpstate", state); | 1125 icon.setAttribute("abpstate", state); |
| 1106 }, | 1126 }, |
| 1107 | 1127 |
| 1108 /** | 1128 /** |
| 1109 * Shows or hides status bar icons in all windows, according to pref. | 1129 * Shows or hides status bar icons in all windows, according to pref. |
| 1110 */ | 1130 */ |
| 1111 updateStatusbarIcon: function(/**Window*/ window) | 1131 updateStatusbarIcon: function(/**Window*/ window) |
| 1112 { | 1132 { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1277 this.fillIconMenu(event, popup.ownerDocument.defaultView, match[1]); | 1297 this.fillIconMenu(event, popup.ownerDocument.defaultView, match[1]); |
| 1278 } | 1298 } |
| 1279 }, | 1299 }, |
| 1280 | 1300 |
| 1281 /** | 1301 /** |
| 1282 * Handles click on toolbar and status bar icons. | 1302 * Handles click on toolbar and status bar icons. |
| 1283 */ | 1303 */ |
| 1284 onIconClick: function(/**Event*/ event) | 1304 onIconClick: function(/**Event*/ event) |
| 1285 { | 1305 { |
| 1286 if (event.eventPhase != event.AT_TARGET) | 1306 if (event.eventPhase != event.AT_TARGET) |
| 1287 return; | |
| 1288 | |
| 1289 if (FilterStorage._loading) | |
| 1290 return; | 1307 return; |
|
Wladimir Palant
2014/05/23 11:50:50
I guess I could just as well remove that failsafe
Thomas Greiner
2014/05/23 16:10:31
Doesn't seem to affect the upcoming changes to the
| |
| 1291 | 1308 |
| 1292 let isToolbar = (event.target.localName != "statusbarpanel"); | 1309 let isToolbar = (event.target.localName != "statusbarpanel"); |
| 1293 let action = 0; | 1310 let action = 0; |
| 1294 if ((isToolbar && event.type == "command") || (!isToolbar && event.button == 0)) | 1311 if ((isToolbar && event.type == "command") || (!isToolbar && event.button == 0)) |
| 1295 action = (isToolbar ? Prefs.defaulttoolbaraction : Prefs.defaultstatusbara ction); | 1312 action = (isToolbar ? Prefs.defaulttoolbaraction : Prefs.defaultstatusbara ction); |
| 1296 else if (event.button == 1) | 1313 else if (event.button == 1) |
| 1297 action = 3; | 1314 action = 3; |
| 1298 | 1315 |
| 1299 let window = event.target.ownerDocument.defaultView; | 1316 let window = event.target.ownerDocument.defaultView; |
| 1300 if (action == 1) | 1317 if (action == 1) |
| (...skipping 632 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 }); |
| LEFT | RIGHT |