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

Delta Between Two Patch Sets: lib/ui.js

Issue 5634514093080576: Issue 293 - AdBlock button is slow to appear on toolbar after launching Firefox (Closed)
Left Patch Set: Fixed first-run actions running too early Created May 23, 2014, 12:43 p.m.
Right Patch Set: Fixed nit Created May 26, 2014, 11:15 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 444
445 if (!this.firstRunDone) 445 // Execute first-run actions if a window is open already, otherwise it
446 { 446 // will happen in applyToWindow() when a window is opened.
447 // Execute first-run actions if a window is open already, otherwise it 447 this.firstRunActions(this.currentWindow);
448 // will happen in applyToWindow() when a window is opened.
449 let window = this.currentWindow;
450 if (window)
451 this.firstRunActions(window);
452 }
453 }, 448 },
454 449
455 addToolbarButton: function() 450 addToolbarButton: function()
456 { 451 {
457 let {WindowObserver} = require("windowObserver"); 452 let {WindowObserver} = require("windowObserver");
458 new WindowObserver(this); 453 new WindowObserver(this);
459 454
460 let {defaultToolbarPosition} = require("appSupport"); 455 let {defaultToolbarPosition} = require("appSupport");
461 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) 456 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
462 { 457 {
(...skipping 13 matching lines...) Expand all
476 positionAttribute: "abp-iconposition", // For emulation only 471 positionAttribute: "abp-iconposition", // For emulation only
477 defaultArea: defaultToolbarPosition.parent, 472 defaultArea: defaultToolbarPosition.parent,
478 defaultBefore: defaultToolbarPosition.before, // For emulation only 473 defaultBefore: defaultToolbarPosition.before, // For emulation only
479 defaultAfter: defaultToolbarPosition.after, // For emulation only 474 defaultAfter: defaultToolbarPosition.after, // For emulation only
480 removable: true, 475 removable: true,
481 onBuild: function(document) 476 onBuild: function(document)
482 { 477 {
483 let node = document.importNode(this.overlay["abp-toolbarbutton"], true ); 478 let node = document.importNode(this.overlay["abp-toolbarbutton"], true );
484 node.addEventListener("click", this.onIconClick, false); 479 node.addEventListener("click", this.onIconClick, false);
485 node.addEventListener("command", this.onIconClick, false); 480 node.addEventListener("command", this.onIconClick, false);
486 if ("addClass" in defaultToolbarPosition)
487 node.classList.add(defaultToolbarPosition.addClass);
488 this.updateIconState(document.defaultView, node); 481 this.updateIconState(document.defaultView, node);
489 return node; 482 return node;
490 }.bind(this), 483 }.bind(this),
491 onAdded: function(node) 484 onAdded: function(node)
492 { 485 {
493 // For emulation only, this callback isn't part of the official 486 // For emulation only, this callback isn't part of the official
494 // CustomizableUI API. 487 // CustomizableUI API.
495 this.updateIconState(node.ownerDocument.defaultView, node); 488 this.updateIconState(node.ownerDocument.defaultView, node);
496 }.bind(this), 489 }.bind(this),
497 }); 490 });
498 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton")); 491 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton"));
499 } 492 }
500 }, 493 },
501 494
502 firstRunActions: function(window) 495 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
503 { 496 {
504 if (FilterStorage._loading) 497 if (this.firstRunDone || !window || FilterStorage._loading)
505 return; 498 return;
506 499
507 this.firstRunDone = true; 500 this.firstRunDone = true;
508 501
509 let {addonVersion} = require("info"); 502 let {addonVersion} = require("info");
510 let prevVersion = Prefs.currentVersion; 503 let prevVersion = Prefs.currentVersion;
511 if (prevVersion != addonVersion) 504 if (prevVersion != addonVersion)
512 { 505 {
513 Prefs.currentVersion = addonVersion; 506 Prefs.currentVersion = addonVersion;
514 this.addSubscription(window, prevVersion); 507 this.addSubscription(window, prevVersion);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); 572 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton"));
580 }.bind(this)); 573 }.bind(this));
581 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); 574 addBrowserClickListener(window, this.onBrowserClick.bind(this, window));
582 575
583 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) 576 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event)
584 { 577 {
585 window.document.getElementById("abp-notification").hidePopup(); 578 window.document.getElementById("abp-notification").hidePopup();
586 }, false); 579 }, false);
587 580
588 // First-run actions? 581 // First-run actions?
589 if (!this.firstRunDone) 582 this.firstRunActions(window);
590 this.firstRunActions(window);
591 583
592 // Some people actually switch off browser.frames.enabled and are surprised 584 // Some people actually switch off browser.frames.enabled and are surprised
593 // that things stop working... 585 // that things stop working...
594 window.QueryInterface(Ci.nsIInterfaceRequestor) 586 window.QueryInterface(Ci.nsIInterfaceRequestor)
595 .getInterface(Ci.nsIWebNavigation) 587 .getInterface(Ci.nsIWebNavigation)
596 .QueryInterface(Ci.nsIDocShell) 588 .QueryInterface(Ci.nsIDocShell)
597 .allowSubframes = true; 589 .allowSubframes = true;
598 }, 590 },
599 591
600 /** 592 /**
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 return; 1087 return;
1096 1088
1097 let state = (Prefs.enabled ? "active" : "disabled"); 1089 let state = (Prefs.enabled ? "active" : "disabled");
1098 if (state == "active") 1090 if (state == "active")
1099 { 1091 {
1100 let location = this.getCurrentLocation(window); 1092 let location = this.getCurrentLocation(window);
1101 if (location && Policy.isWhitelisted(location.spec)) 1093 if (location && Policy.isWhitelisted(location.spec))
1102 state = "whitelisted"; 1094 state = "whitelisted";
1103 } 1095 }
1104 1096
1097 let popupId = "abp-status-popup";
1105 if (icon.localName == "statusbarpanel") 1098 if (icon.localName == "statusbarpanel")
1106 { 1099 {
1107 if (Prefs.defaultstatusbaraction == 0) 1100 if (Prefs.defaultstatusbaraction == 0)
1108 icon.setAttribute("popup", icon.getAttribute("context")); 1101 {
1102 icon.setAttribute("popup", popupId);
1103 icon.removeAttribute("context");
1104 }
1109 else 1105 else
1106 {
1110 icon.removeAttribute("popup"); 1107 icon.removeAttribute("popup");
1108 icon.setAttribute("context", popupId);
1109 }
1111 } 1110 }
1112 else 1111 else
1113 { 1112 {
1114 if (Prefs.defaulttoolbaraction == 0) 1113 if (Prefs.defaulttoolbaraction == 0)
1114 {
1115 icon.setAttribute("type", "menu"); 1115 icon.setAttribute("type", "menu");
1116 icon.removeAttribute("context");
1117 }
1116 else 1118 else
1119 {
1117 icon.setAttribute("type", "menu-button"); 1120 icon.setAttribute("type", "menu-button");
1121 icon.setAttribute("context", popupId);
1122 }
1118 } 1123 }
1119 1124
1120 icon.setAttribute("abpstate", state); 1125 icon.setAttribute("abpstate", state);
1121 }, 1126 },
1122 1127
1123 /** 1128 /**
1124 * 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.
1125 */ 1130 */
1126 updateStatusbarIcon: function(/**Window*/ window) 1131 updateStatusbarIcon: function(/**Window*/ window)
1127 { 1132 {
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1950 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1946 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1951 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1947 ]; 1952 ];
1948 1953
1949 onShutdown.add(function() 1954 onShutdown.add(function()
1950 { 1955 {
1951 for (let window in UI.applicationWindows) 1956 for (let window in UI.applicationWindows)
1952 if (UI.isBottombarOpen(window)) 1957 if (UI.isBottombarOpen(window))
1953 UI.toggleBottombar(window); 1958 UI.toggleBottombar(window);
1954 }); 1959 });
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld