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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 {
402 // The icon might be added already, make sure its state is correct
403 this.updateState();
404
405 // Listen for pref and filters changes
406 Prefs.addListener(function(name)
407 {
408 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction")
409 this.updateState();
410 else if (name == "showinstatusbar")
411 {
412 for (let window in this.applicationWindows)
413 this.updateStatusbarIcon(window);
414 }
415 }.bind(this));
416 FilterNotifier.addListener(function(action)
417 {
418 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load")
419 this.updateState();
420 }.bind(this));
421
422 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
423 notificationTimer.initWithCallback(this.showNextNotification.bind(this),
424 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ;
425 onShutdown.add(function() notificationTimer.cancel());
426
427 // Add "anti-adblock messages" notification
428 initAntiAdblockNotification();
429
430 let documentCreationObserver = {
431 observe: function(subject, topic, data)
432 {
433 if (!(subject instanceof Ci.nsIDOMWindow))
434 return;
435
436 this.showNextNotification(subject.location.href);
437 }.bind(UI)
438 };
439 Services.obs.addObserver(documentCreationObserver, "content-document-global- created", false);
440 onShutdown.add(function()
441 {
442 Services.obs.removeObserver(documentCreationObserver, "content-document-gl obal-created", false);
443 });
444 },
445
446 addToolbarButton: function()
447 {
399 let {WindowObserver} = require("windowObserver"); 448 let {WindowObserver} = require("windowObserver");
400 new WindowObserver(this); 449 new WindowObserver(this);
401 450
402 // Add toolbar icon
403 let {defaultToolbarPosition} = require("appSupport"); 451 let {defaultToolbarPosition} = require("appSupport");
404 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) 452 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
405 { 453 {
406 try 454 try
407 { 455 {
408 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null); 456 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null);
409 } 457 }
410 catch (e) 458 catch (e)
411 { 459 {
412 // No built-in CustomizableUI API, use our own implementation. 460 // No built-in CustomizableUI API, use our own implementation.
(...skipping 20 matching lines...) Expand all
433 }.bind(this), 481 }.bind(this),
434 onAdded: function(node) 482 onAdded: function(node)
435 { 483 {
436 // For emulation only, this callback isn't part of the official 484 // For emulation only, this callback isn't part of the official
437 // CustomizableUI API. 485 // CustomizableUI API.
438 this.updateIconState(node.ownerDocument.defaultView, node); 486 this.updateIconState(node.ownerDocument.defaultView, node);
439 }.bind(this), 487 }.bind(this),
440 }); 488 });
441 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); 489 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton"));
442 } 490 }
443
444 // Listen for pref and filters changes
445 Prefs.addListener(function(name)
446 {
447 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction")
448 this.updateState();
449 else if (name == "showinstatusbar")
450 {
451 for (let window in this.applicationWindows)
452 this.updateStatusbarIcon(window);
453 }
454 }.bind(this));
455 FilterNotifier.addListener(function(action)
456 {
457 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load")
458 this.updateState();
459 }.bind(this));
460
461 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
462 notificationTimer.initWithCallback(this.showNextNotification.bind(this),
463 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ;
464 onShutdown.add(function() notificationTimer.cancel());
465
466 // Add "anti-adblock messages" notification
467 initAntiAdblockNotification();
468
469 let documentCreationObserver = {
470 observe: function(subject, topic, data)
471 {
472 if (!(subject instanceof Ci.nsIDOMWindow))
473 return;
474
475 this.showNextNotification(subject.location.href);
476 }.bind(UI)
477 };
478 Services.obs.addObserver(documentCreationObserver, "content-document-global- created", false);
479 onShutdown.add(function()
480 {
481 Services.obs.removeObserver(documentCreationObserver, "content-document-gl obal-created", false);
482 });
483 }, 491 },
484 492
485 /** 493 /**
486 * Will be set to true after the check whether first-run actions should run 494 * Will be set to true after the check whether first-run actions should run
487 * has been performed. 495 * has been performed.
488 * @type Boolean 496 * @type Boolean
489 */ 497 */
490 firstRunDone: false, 498 firstRunDone: false,
491 499
492 /** 500 /**
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 }, 1279 },
1272 1280
1273 /** 1281 /**
1274 * Handles click on toolbar and status bar icons. 1282 * Handles click on toolbar and status bar icons.
1275 */ 1283 */
1276 onIconClick: function(/**Event*/ event) 1284 onIconClick: function(/**Event*/ event)
1277 { 1285 {
1278 if (event.eventPhase != event.AT_TARGET) 1286 if (event.eventPhase != event.AT_TARGET)
1279 return; 1287 return;
1280 1288
1289 if (FilterStorage._loading)
1290 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
1281 let isToolbar = (event.target.localName != "statusbarpanel"); 1292 let isToolbar = (event.target.localName != "statusbarpanel");
1282 let action = 0; 1293 let action = 0;
1283 if ((isToolbar && event.type == "command") || (!isToolbar && event.button == 0)) 1294 if ((isToolbar && event.type == "command") || (!isToolbar && event.button == 0))
1284 action = (isToolbar ? Prefs.defaulttoolbaraction : Prefs.defaultstatusbara ction); 1295 action = (isToolbar ? Prefs.defaulttoolbaraction : Prefs.defaultstatusbara ction);
1285 else if (event.button == 1) 1296 else if (event.button == 1)
1286 action = 3; 1297 action = 3;
1287 1298
1288 let window = event.target.ownerDocument.defaultView; 1299 let window = event.target.ownerDocument.defaultView;
1289 if (action == 1) 1300 if (action == 1)
1290 this.toggleBottombar(window); 1301 this.toggleBottombar(window);
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1933 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1923 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1934 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1924 ]; 1935 ];
1925 1936
1926 onShutdown.add(function() 1937 onShutdown.add(function()
1927 { 1938 {
1928 for (let window in UI.applicationWindows) 1939 for (let window in UI.applicationWindows)
1929 if (UI.isBottombarOpen(window)) 1940 if (UI.isBottombarOpen(window))
1930 UI.toggleBottombar(window); 1941 UI.toggleBottombar(window);
1931 }); 1942 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld