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

Side by Side Diff: chrome/ext/background.js

Issue 29317030: Issue 2689 - Logic problem in BrowserAction._addChange (Closed)
Patch Set: Created June 17, 2015, 11:11 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 }); 147 });
148 148
149 chrome.tabs.onRemoved.addListener(forgetTab); 149 chrome.tabs.onRemoved.addListener(forgetTab);
150 150
151 151
152 /* Browser actions */ 152 /* Browser actions */
153 153
154 var BrowserAction = function(tabId) 154 var BrowserAction = function(tabId)
155 { 155 {
156 this._tabId = tabId; 156 this._tabId = tabId;
157 this._changes = null; 157 this._changes = {};
158 }; 158 };
159 BrowserAction.prototype = { 159 BrowserAction.prototype = {
160 _applyChanges: function() 160 _applyChanges: function()
161 { 161 {
162 if ("iconPath" in this._changes) 162 if ("iconPath" in this._changes)
163 { 163 {
164 chrome.browserAction.setIcon({ 164 chrome.browserAction.setIcon({
165 tabId: this._tabId, 165 tabId: this._tabId,
166 path: { 166 path: {
167 19: this._changes.iconPath.replace("$size", "19"), 167 19: this._changes.iconPath.replace("$size", "19"),
(...skipping 11 matching lines...) Expand all
179 } 179 }
180 180
181 if ("badgeColor" in this._changes) 181 if ("badgeColor" in this._changes)
182 { 182 {
183 chrome.browserAction.setBadgeBackgroundColor({ 183 chrome.browserAction.setBadgeBackgroundColor({
184 tabId: this._tabId, 184 tabId: this._tabId,
185 color: this._changes.badgeColor 185 color: this._changes.badgeColor
186 }); 186 });
187 } 187 }
188 188
189 this._changes = null; 189 this._changes = {};
190 }, 190 },
191 _queueChanges: function() 191 _queueChanges: function()
192 { 192 {
193 chrome.tabs.get(this._tabId, function() 193 chrome.tabs.get(this._tabId, function()
194 { 194 {
195 // If the tab is prerendered, chrome.tabs.get() sets 195 // If the tab is prerendered, chrome.tabs.get() sets
196 // chrome.runtime.lastError and we have to delay our changes 196 // chrome.runtime.lastError and we have to delay our changes
197 // until the currently visible tab is replaced with the 197 // until the currently visible tab is replaced with the
198 // prerendered tab. Otherwise chrome.browserAction.set* fails. 198 // prerendered tab. Otherwise chrome.browserAction.set* fails.
199 if (chrome.runtime.lastError) 199 if (chrome.runtime.lastError)
200 { 200 {
201 var onReplaced = function(addedTabId, removedTabId) 201 var onReplaced = function(addedTabId, removedTabId)
202 { 202 {
203 if (addedTabId == this._tabId) 203 if (addedTabId == this._tabId)
204 { 204 {
205 chrome.tabs.onReplaced.removeListener(onReplaced); 205 chrome.tabs.onReplaced.removeListener(onReplaced);
206 this._applyChanges(); 206 this._applyChanges();
207 } 207 }
208 }.bind(this); 208 }.bind(this);
209 chrome.tabs.onReplaced.addListener(onReplaced); 209 chrome.tabs.onReplaced.addListener(onReplaced);
210 } 210 }
211 else 211 else
212 { 212 {
213 this._applyChanges(); 213 this._applyChanges();
214 } 214 }
215 }.bind(this)); 215 }.bind(this));
216 }, 216 },
217 _addChange: function(name, value) 217 _addChange: function(name, value)
218 { 218 {
219 if (!this._changes)
220 {
221 this._changes = {};
222 this._queueChanges();
223 }
224
225 this._changes[name] = value; 219 this._changes[name] = value;
220 this._queueChanges();
Sebastian Noack 2015/06/23 09:46:36 This will call chrome.tabs.get() redundantly if mu
226 }, 221 },
227 setIcon: function(path) 222 setIcon: function(path)
228 { 223 {
229 this._addChange("iconPath", path); 224 this._addChange("iconPath", path);
230 }, 225 },
231 setBadge: function(badge) 226 setBadge: function(badge)
232 { 227 {
233 if (!badge) 228 if (!badge)
234 { 229 {
235 this._addChange("badgeText", ""); 230 this._addChange("badgeText", "");
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 callback(new Page(tab)); 639 callback(new Page(tab));
645 } 640 }
646 else 641 else
647 { 642 {
648 ext.pages.open(optionsUrl, callback); 643 ext.pages.open(optionsUrl, callback);
649 } 644 }
650 }); 645 });
651 }); 646 });
652 }; 647 };
653 })(); 648 })();
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