Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/ui.js

Issue 5634514093080576: Issue 293 - AdBlock button is slow to appear on toolbar after launching Firefox (Closed)
Patch Set: Fixed nit Created May 26, 2014, 11:15 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/ui.js
===================================================================
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -279,16 +279,19 @@ let UI = exports.UI =
request.open("GET", "chrome://adblockplus/content/ui/overlay.xul");
request.addEventListener("load", function(event)
{
if (onShutdown.done)
return;
this.processOverlay(request.responseXML.documentElement);
+ // Don't wait for the rest of the startup sequence, add icon already
+ this.addToolbarButton();
+
overlayLoaded = true;
if (overlayLoaded && filtersLoaded && sessionRestored)
this.initDone();
}.bind(this), false);
request.send(null);
// Wait for filters to load
if (FilterStorage._loading)
@@ -391,58 +394,18 @@ let UI = exports.UI =
},
/**
* Gets called once the initialization is finished and Adblock Plus elements
* can be added to the UI.
*/
initDone: function()
{
- let {WindowObserver} = require("windowObserver");
- new WindowObserver(this);
-
- // Add toolbar icon
- let {defaultToolbarPosition} = require("appSupport");
- if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
- {
- try
- {
- ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null);
- }
- catch (e)
- {
- // No built-in CustomizableUI API, use our own implementation.
- ({CustomizableUI}) = require("customizableUI");
- }
-
- CustomizableUI.createWidget({
- id: "abp-toolbarbutton",
- type: "custom",
- positionAttribute: "abp-iconposition", // For emulation only
- defaultArea: defaultToolbarPosition.parent,
- defaultBefore: defaultToolbarPosition.before, // For emulation only
- defaultAfter: defaultToolbarPosition.after, // For emulation only
- removable: true,
- onBuild: function(document)
- {
- let node = document.importNode(this.overlay["abp-toolbarbutton"], true);
- node.addEventListener("click", this.onIconClick, false);
- node.addEventListener("command", this.onIconClick, false);
- this.updateIconState(document.defaultView, node);
- return node;
- }.bind(this),
- onAdded: function(node)
- {
- // For emulation only, this callback isn't part of the official
- // CustomizableUI API.
- this.updateIconState(node.ownerDocument.defaultView, node);
- }.bind(this),
- });
- onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-toolbarbutton"));
- }
+ // The icon might be added already, make sure its state is correct
+ this.updateState();
// Listen for pref and filters changes
Prefs.addListener(function(name)
{
if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaultstatusbaraction")
this.updateState();
else if (name == "showinstatusbar")
{
@@ -473,16 +436,81 @@ let UI = exports.UI =
this.showNextNotification(subject.location.href);
}.bind(UI)
};
Services.obs.addObserver(documentCreationObserver, "content-document-global-created", false);
onShutdown.add(function()
{
Services.obs.removeObserver(documentCreationObserver, "content-document-global-created", false);
});
+
+ // Execute first-run actions if a window is open already, otherwise it
+ // will happen in applyToWindow() when a window is opened.
+ this.firstRunActions(this.currentWindow);
+ },
+
+ addToolbarButton: function()
+ {
+ let {WindowObserver} = require("windowObserver");
+ new WindowObserver(this);
+
+ let {defaultToolbarPosition} = require("appSupport");
+ if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
+ {
+ try
+ {
+ ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null);
+ }
+ catch (e)
+ {
+ // No built-in CustomizableUI API, use our own implementation.
+ ({CustomizableUI}) = require("customizableUI");
+ }
+
+ CustomizableUI.createWidget({
+ id: "abp-toolbarbutton",
+ type: "custom",
+ positionAttribute: "abp-iconposition", // For emulation only
+ defaultArea: defaultToolbarPosition.parent,
+ defaultBefore: defaultToolbarPosition.before, // For emulation only
+ defaultAfter: defaultToolbarPosition.after, // For emulation only
+ removable: true,
+ onBuild: function(document)
+ {
+ let node = document.importNode(this.overlay["abp-toolbarbutton"], true);
+ node.addEventListener("click", this.onIconClick, false);
+ node.addEventListener("command", this.onIconClick, false);
+ this.updateIconState(document.defaultView, node);
+ return node;
+ }.bind(this),
+ onAdded: function(node)
+ {
+ // For emulation only, this callback isn't part of the official
+ // CustomizableUI API.
+ this.updateIconState(node.ownerDocument.defaultView, node);
+ }.bind(this),
+ });
+ onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-toolbarbutton"));
+ }
+ },
+
+ firstRunActions: function(window)
+ {
+ if (this.firstRunDone || !window || FilterStorage._loading)
+ return;
+
+ this.firstRunDone = true;
+
+ let {addonVersion} = require("info");
+ let prevVersion = Prefs.currentVersion;
+ if (prevVersion != addonVersion)
+ {
+ Prefs.currentVersion = addonVersion;
+ this.addSubscription(window, prevVersion);
+ }
},
/**
* Will be set to true after the check whether first-run actions should run
* has been performed.
* @type Boolean
*/
firstRunDone: false,
@@ -546,28 +574,17 @@ let UI = exports.UI =
addBrowserClickListener(window, this.onBrowserClick.bind(this, window));
window.document.getElementById("abp-notification-close").addEventListener("command", function(event)
{
window.document.getElementById("abp-notification").hidePopup();
}, false);
// First-run actions?
- if (!this.firstRunDone)
- {
- this.firstRunDone = true;
-
- let {addonVersion} = require("info");
- let prevVersion = Prefs.currentVersion;
- if (prevVersion != addonVersion)
- {
- Prefs.currentVersion = addonVersion;
- this.addSubscription(window, prevVersion);
- }
- }
+ this.firstRunActions(window);
// Some people actually switch off browser.frames.enabled and are surprised
// that things stop working...
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.allowSubframes = true;
},
@@ -1071,17 +1088,17 @@ let UI = exports.UI =
let state = (Prefs.enabled ? "active" : "disabled");
if (state == "active")
{
let location = this.getCurrentLocation(window);
if (location && Policy.isWhitelisted(location.spec))
state = "whitelisted";
}
-
+
let popupId = "abp-status-popup";
if (icon.localName == "statusbarpanel")
{
if (Prefs.defaultstatusbaraction == 0)
{
icon.setAttribute("popup", popupId);
icon.removeAttribute("context");
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld