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: Created May 23, 2014, 11:30 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,20 +394,65 @@ let UI = exports.UI =
},
/**
* Gets called once the initialization is finished and Adblock Plus elements
* can be added to the UI.
*/
initDone: function()
{
+ // 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")
+ {
+ for (let window in this.applicationWindows)
+ this.updateStatusbarIcon(window);
+ }
+ }.bind(this));
+ FilterNotifier.addListener(function(action)
+ {
+ if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(action) || action == "load")
+ this.updateState();
+ }.bind(this));
+
+ notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ notificationTimer.initWithCallback(this.showNextNotification.bind(this),
+ 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
+ onShutdown.add(function() notificationTimer.cancel());
+
+ // Add "anti-adblock messages" notification
+ initAntiAdblockNotification();
+
+ let documentCreationObserver = {
+ observe: function(subject, topic, data)
+ {
+ if (!(subject instanceof Ci.nsIDOMWindow))
+ return;
+
+ 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);
+ });
+ },
+
+ addToolbarButton: 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)
@@ -435,56 +483,16 @@ let UI = exports.UI =
{
// 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"));
}
-
- // Listen for pref and filters changes
- Prefs.addListener(function(name)
- {
- if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaultstatusbaraction")
- this.updateState();
- else if (name == "showinstatusbar")
- {
- for (let window in this.applicationWindows)
- this.updateStatusbarIcon(window);
- }
- }.bind(this));
- FilterNotifier.addListener(function(action)
- {
- if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(action) || action == "load")
- this.updateState();
- }.bind(this));
-
- notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- notificationTimer.initWithCallback(this.showNextNotification.bind(this),
- 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
- onShutdown.add(function() notificationTimer.cancel());
-
- // Add "anti-adblock messages" notification
- initAntiAdblockNotification();
-
- let documentCreationObserver = {
- observe: function(subject, topic, data)
- {
- if (!(subject instanceof Ci.nsIDOMWindow))
- return;
-
- 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);
- });
},
/**
* Will be set to true after the check whether first-run actions should run
* has been performed.
* @type Boolean
*/
firstRunDone: false,
@@ -1273,16 +1281,19 @@ let UI = exports.UI =
/**
* Handles click on toolbar and status bar icons.
*/
onIconClick: function(/**Event*/ event)
{
if (event.eventPhase != event.AT_TARGET)
return;
+ if (FilterStorage._loading)
+ 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
+
let isToolbar = (event.target.localName != "statusbarpanel");
let action = 0;
if ((isToolbar && event.type == "command") || (!isToolbar && event.button == 0))
action = (isToolbar ? Prefs.defaulttoolbaraction : Prefs.defaultstatusbaraction);
else if (event.button == 1)
action = 3;
let window = event.target.ownerDocument.defaultView;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld