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: Fixed first-run actions running too early Created May 23, 2014, 12:43 p.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 if (!this.firstRunDone)
446 {
447 // Execute first-run actions if a window is open already, otherwise it
448 // will happen in applyToWindow() when a window is opened.
449 let window = this.currentWindow;
450 if (window)
451 this.firstRunActions(window);
452 }
453 },
454
455 addToolbarButton: function()
456 {
399 let {WindowObserver} = require("windowObserver"); 457 let {WindowObserver} = require("windowObserver");
400 new WindowObserver(this); 458 new WindowObserver(this);
401 459
402 // Add toolbar icon
403 let {defaultToolbarPosition} = require("appSupport"); 460 let {defaultToolbarPosition} = require("appSupport");
404 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) 461 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
405 { 462 {
406 try 463 try
407 { 464 {
408 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null); 465 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null);
409 } 466 }
410 catch (e) 467 catch (e)
411 { 468 {
412 // No built-in CustomizableUI API, use our own implementation. 469 // No built-in CustomizableUI API, use our own implementation.
(...skipping 20 matching lines...) Expand all
433 }.bind(this), 490 }.bind(this),
434 onAdded: function(node) 491 onAdded: function(node)
435 { 492 {
436 // For emulation only, this callback isn't part of the official 493 // For emulation only, this callback isn't part of the official
437 // CustomizableUI API. 494 // CustomizableUI API.
438 this.updateIconState(node.ownerDocument.defaultView, node); 495 this.updateIconState(node.ownerDocument.defaultView, node);
439 }.bind(this), 496 }.bind(this),
440 }); 497 });
441 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); 498 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton"));
442 } 499 }
500 },
443 501
444 // Listen for pref and filters changes 502 firstRunActions: function(window)
Thomas Greiner 2014/05/23 16:10:31 Is there a case in which firstRunActions are / cou
Wladimir Palant 2014/05/26 11:16:52 This was pretty much premature optimization on my
445 Prefs.addListener(function(name) 503 {
504 if (FilterStorage._loading)
505 return;
506
507 this.firstRunDone = true;
508
509 let {addonVersion} = require("info");
510 let prevVersion = Prefs.currentVersion;
511 if (prevVersion != addonVersion)
446 { 512 {
447 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") 513 Prefs.currentVersion = addonVersion;
448 this.updateState(); 514 this.addSubscription(window, prevVersion);
449 else if (name == "showinstatusbar") 515 }
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 }, 516 },
484 517
485 /** 518 /**
486 * Will be set to true after the check whether first-run actions should run 519 * Will be set to true after the check whether first-run actions should run
487 * has been performed. 520 * has been performed.
488 * @type Boolean 521 * @type Boolean
489 */ 522 */
490 firstRunDone: false, 523 firstRunDone: false,
491 524
492 /** 525 /**
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 }.bind(this)); 580 }.bind(this));
548 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); 581 addBrowserClickListener(window, this.onBrowserClick.bind(this, window));
549 582
550 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) 583 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event)
551 { 584 {
552 window.document.getElementById("abp-notification").hidePopup(); 585 window.document.getElementById("abp-notification").hidePopup();
553 }, false); 586 }, false);
554 587
555 // First-run actions? 588 // First-run actions?
556 if (!this.firstRunDone) 589 if (!this.firstRunDone)
557 { 590 this.firstRunActions(window);
558 this.firstRunDone = true;
559
560 let {addonVersion} = require("info");
561 let prevVersion = Prefs.currentVersion;
562 if (prevVersion != addonVersion)
563 {
564 Prefs.currentVersion = addonVersion;
565 this.addSubscription(window, prevVersion);
566 }
567 }
568 591
569 // Some people actually switch off browser.frames.enabled and are surprised 592 // Some people actually switch off browser.frames.enabled and are surprised
570 // that things stop working... 593 // that things stop working...
571 window.QueryInterface(Ci.nsIInterfaceRequestor) 594 window.QueryInterface(Ci.nsIInterfaceRequestor)
572 .getInterface(Ci.nsIWebNavigation) 595 .getInterface(Ci.nsIWebNavigation)
573 .QueryInterface(Ci.nsIDocShell) 596 .QueryInterface(Ci.nsIDocShell)
574 .allowSubframes = true; 597 .allowSubframes = true;
575 }, 598 },
576 599
577 /** 600 /**
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1945 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1923 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1946 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1924 ]; 1947 ];
1925 1948
1926 onShutdown.add(function() 1949 onShutdown.add(function()
1927 { 1950 {
1928 for (let window in UI.applicationWindows) 1951 for (let window in UI.applicationWindows)
1929 if (UI.isBottombarOpen(window)) 1952 if (UI.isBottombarOpen(window))
1930 UI.toggleBottombar(window); 1953 UI.toggleBottombar(window);
1931 }); 1954 });
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