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

Delta Between Two Patch Sets: safari/ext/background.js

Issue 5099207639695360: Made browser actions per tab on Safari (Closed)
Left Patch Set: Created Dec. 27, 2013, 7:22 p.m.
Right Patch Set: Forgot to set tab in BrowserAction constructor Created Jan. 17, 2014, 2:19 p.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 | « background.js ('k') | 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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 onLoading: new LoadingTabEventTarget(safari.application), 182 onLoading: new LoadingTabEventTarget(safari.application),
183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue), 183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue),
184 onCompleted: new TabEventTarget(safari.application, "navigate", true), 184 onCompleted: new TabEventTarget(safari.application, "navigate", true),
185 onActivated: new TabEventTarget(safari.application, "activate", true), 185 onActivated: new TabEventTarget(safari.application, "activate", true),
186 onRemoved: new TabEventTarget(safari.application, "close", true) 186 onRemoved: new TabEventTarget(safari.application, "close", true)
187 }; 187 };
188 188
189 189
190 /* Browser actions */ 190 /* Browser actions */
191 191
192 var globalTooltipItemProperties = {} 192 var toolbarItemProperties = {};
193 var tooltipItemPropertiesPerTab = new TabMap(); 193
Wladimir Palant 2014/01/15 15:24:47 You meant toolbarItem, not tooltipItem, right?
Sebastian Noack 2014/01/15 19:25:47 It is gone now.
194 var getToolbarItemProperty = function(name)
195 {
196 var property = toolbarItemProperties[name];
197 if (!property)
198 {
199 property = {tabs: new TabMap()};
200 toolbarItemProperties[name] = property;
201 }
202 return property;
203 };
194 204
195 var getToolbarItemForWindow = function(win) 205 var getToolbarItemForWindow = function(win)
196 { 206 {
197 for (var i = 0; i < safari.extension.toolbarItems.length; i++) 207 for (var i = 0; i < safari.extension.toolbarItems.length; i++)
198 { 208 {
199 var toolbarItem = safari.extension.toolbarItems[i]; 209 var toolbarItem = safari.extension.toolbarItems[i];
200 210
201 if (toolbarItem.browserWindow == win) 211 if (toolbarItem.browserWindow == win)
202 return toolbarItem; 212 return toolbarItem;
203 } 213 }
Wladimir Palant 2014/01/15 15:24:47 This should return something if no toolbar item is
Sebastian Noack 2014/01/15 19:25:47 Done. Even though I think that it is a bug when th
214
215 return null;
204 }; 216 };
205 217
206 var BrowserAction = function(tab) 218 var BrowserAction = function(tab)
207 { 219 {
208 this._tab = tab; 220 this._tab = tab;
209 }; 221 };
210 BrowserAction.prototype = { 222 BrowserAction.prototype = {
211 _set: function(property, value) 223 _set: function(name, value)
212 { 224 {
213 var currentWindow = this._tab._tab.browserWindow; 225 var currentWindow = this._tab._tab.browserWindow;
214 var toolbarItem = getToolbarItemForWindow(currentWindow); 226 var toolbarItem = getToolbarItemForWindow(currentWindow);
215 227
216 if (!(property in globalTooltipItemProperties)) 228 if (toolbarItem)
217 globalTooltipItemProperties[property] = toolbarItem[property]; 229 {
218 230 var property = getToolbarItemProperty(name);
219 if (this._tab._tab == currentWindow.activeTab) 231 property.tabs.set(this._tab, value);
220 toolbarItem[property] = value; 232
221 233 if (!("global" in property))
222 var props = tooltipItemPropertiesPerTab.get(this._tab); 234 property.global = toolbarItem[name];
223 if (!props) 235
224 { 236 if (this._tab._tab == currentWindow.activeTab)
225 props = {}; 237 toolbarItem[name] = value;
226 tooltipItemPropertiesPerTab.set(this._tab, props); 238 }
227 }
228 props[property] = value;
229 }, 239 },
230 setIcon: function(path) 240 setIcon: function(path)
231 { 241 {
232 this._set("image", safari.extension.baseURI + path); 242 this._set("image", safari.extension.baseURI + path);
233 }, 243 },
234 setTitle: function(title) 244 setTitle: function(title)
235 { 245 {
246 this._set("label", title);
236 this._set("toolTip", title); 247 this._set("toolTip", title);
237 }, 248 },
238 setBadge: function(badge) 249 setBadge: function(badge)
239 { 250 {
240 if (!badge) 251 if (!badge)
241 this._set("badge", 0); 252 this._set("badge", 0);
242 else if ("number" in badge) 253 else if ("number" in badge)
243 this._set("badge", badge.number); 254 this._set("badge", badge.number);
244 } 255 }
245 }; 256 };
246 257
247 ext.tabs.onActivated.addListener(function(tab) 258 ext.tabs.onActivated.addListener(function(tab)
248 { 259 {
249 var props = tooltipItemPropertiesPerTab.get(tab);
250 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); 260 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow);
251 261
252 for (var property in globalTooltipItemProperties) 262 if (!toolbarItem)
253 { 263 return;
254 if (props && property in props) 264
255 toolbarItem[property] = props[property]; 265 for (var name in toolbarItemProperties)
266 {
267 var property = toolbarItemProperties[name];
268
269 if (property.tabs.has(tab))
270 toolbarItem[name] = property.tabs.get(tab);
256 else 271 else
257 toolbarItem[property] = globalTooltipItemProperties[property]; 272 toolbarItem[name] = property.global;
258 } 273 }
Wladimir Palant 2014/01/15 15:24:47 What's the point of globalTooltipItemProperties? I
Sebastian Noack 2014/01/15 19:25:47 This approach just emulates the behavior we alread
259 }); 274 });
260 275
261 276
262 /* Windows */ 277 /* Windows */
263 278
264 Window = function(win) 279 Window = function(win)
265 { 280 {
266 this._win = win; 281 this._win = win;
267 } 282 }
268 Window.prototype = { 283 Window.prototype = {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 }; 626 };
612 627
613 ext.onMessage = new BackgroundMessageEventTarget(); 628 ext.onMessage = new BackgroundMessageEventTarget();
614 629
615 // TODO: Implement context menu 630 // TODO: Implement context menu
616 ext.contextMenus = { 631 ext.contextMenus = {
617 create: function(title, contexts, onclick) {}, 632 create: function(title, contexts, onclick) {},
618 removeAll: function(callback) {} 633 removeAll: function(callback) {}
619 }; 634 };
620 })(); 635 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld