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

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

Issue 5735785512828928: Remove tabs from TabMap onLoading instead of onBeforeNavigate on Safari (Closed)
Patch Set: Addressed comments Created Jan. 23, 2014, 1:50 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 | safari/ext/background.js » ('j') | 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-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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 }; 238 };
239 239
240 Tab = function(tab) 240 Tab = function(tab)
241 { 241 {
242 this._id = tab.id; 242 this._id = tab.id;
243 this._url = tab.url; 243 this._url = tab.url;
244 244
245 this.browserAction = new BrowserAction(tab.id); 245 this.browserAction = new BrowserAction(tab.id);
246 246
247 this.onBeforeNavigate = ext.tabs.onBeforeNavigate._bindToTab(this);
248 this.onLoading = ext.tabs.onLoading._bindToTab(this); 247 this.onLoading = ext.tabs.onLoading._bindToTab(this);
249 this.onCompleted = ext.tabs.onCompleted._bindToTab(this); 248 this.onCompleted = ext.tabs.onCompleted._bindToTab(this);
250 this.onActivated = ext.tabs.onActivated._bindToTab(this); 249 this.onActivated = ext.tabs.onActivated._bindToTab(this);
251 this.onRemoved = ext.tabs.onRemoved._bindToTab(this); 250 this.onRemoved = ext.tabs.onRemoved._bindToTab(this);
251
252 // the "beforeNavigate" event in Safari isn't dispatched when a new URL
253 // was entered into the address bar. So we can only use it only on Chrome,
254 // but we have to hide it from the browser-independent high level code.
255 this._onBeforeNavigate = ext.tabs._onBeforeNavigate._bindToTab(this);
252 }; 256 };
253 Tab.prototype = { 257 Tab.prototype = {
254 get url() 258 get url()
255 { 259 {
256 // usually our Tab objects are created from chrome Tab objects, which 260 // usually our Tab objects are created from chrome Tab objects, which
257 // provide the url. So we can return the url given in the constructor. 261 // provide the url. So we can return the url given in the constructor.
258 if (this._url != null) 262 if (this._url != null)
259 return this._url; 263 return this._url;
260 264
261 // but sometimes we only have the id when we create a Tab object. 265 // but sometimes we only have the id when we create a Tab object.
(...skipping 14 matching lines...) Expand all
276 activate: function() 280 activate: function()
277 { 281 {
278 chrome.tabs.update(this._id, {selected: true}); 282 chrome.tabs.update(this._id, {selected: true});
279 }, 283 },
280 sendMessage: function(message, responseCallback) 284 sendMessage: function(message, responseCallback)
281 { 285 {
282 sendMessage(this._id, message, responseCallback); 286 sendMessage(this._id, message, responseCallback);
283 } 287 }
284 }; 288 };
285 289
286 TabMap = function(deleteTabOnBeforeNavigate) 290 TabMap = function(deleteOnPageUnload)
287 { 291 {
288 this._map = {}; 292 this._map = {};
289 293
290 this._delete = this._delete.bind(this); 294 this._delete = this._delete.bind(this);
291 this._deleteTabOnBeforeNavigate = deleteTabOnBeforeNavigate; 295 this._deleteOnPageUnload = deleteOnPageUnload;
292 }; 296 };
293 TabMap.prototype = { 297 TabMap.prototype = {
294 get: function(tab) 298 get: function(tab)
295 { 299 {
296 return (this._map[tab._id] || {}).value; 300 return (this._map[tab._id] || {}).value;
297 }, 301 },
298 set: function(tab, value) 302 set: function(tab, value)
299 { 303 {
300 if (!(tab._id in this._map)) 304 if (!(tab._id in this._map))
301 { 305 {
302 tab.onRemoved.addListener(this._delete); 306 tab.onRemoved.addListener(this._delete);
303 if (this._deleteTabOnBeforeNavigate) 307 if (this._deleteOnPageUnload)
304 tab.onBeforeNavigate.addListener(this._delete); 308 tab._onBeforeNavigate.addListener(this._delete);
305 } 309 }
306 310
307 this._map[tab._id] = {tab: tab, value: value}; 311 this._map[tab._id] = {tab: tab, value: value};
308 }, 312 },
309 has: function(tab) 313 has: function(tab)
310 { 314 {
311 return tab._id in this._map; 315 return tab._id in this._map;
312 }, 316 },
313 clear: function() 317 clear: function()
314 { 318 {
315 for (var id in this._map) 319 for (var id in this._map)
316 this.delete(this._map[id].tab); 320 this.delete(this._map[id].tab);
317 }, 321 },
318 _delete: function(tab) 322 _delete: function(tab)
319 { 323 {
320 // delay so that other event handlers can still lookup this tab 324 // delay so that other event handlers can still lookup this tab
321 setTimeout(this.delete.bind(this, tab), 0); 325 setTimeout(this.delete.bind(this, tab), 0);
322 } 326 }
323 }; 327 };
324 TabMap.prototype["delete"] = function(tab) 328 TabMap.prototype["delete"] = function(tab)
325 { 329 {
326 delete this._map[tab._id]; 330 delete this._map[tab._id];
327 331
328 tab.onRemoved.removeListener(this._delete); 332 tab.onRemoved.removeListener(this._delete);
329 tab.onBeforeNavigate.removeListener(this._delete); 333 tab._onBeforeNavigate.removeListener(this._delete);
330 }; 334 };
331 335
332 336
333 /* Windows */ 337 /* Windows */
334 338
335 Window = function(win) 339 Window = function(win)
336 { 340 {
337 this._id = win.id; 341 this._id = win.id;
338 this.visible = win.status != "minimized"; 342 this.visible = win.status != "minimized";
339 }; 343 };
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 getLastFocused: function(callback) 510 getLastFocused: function(callback)
507 { 511 {
508 chrome.windows.getLastFocused(function(win) 512 chrome.windows.getLastFocused(function(win)
509 { 513 {
510 callback(new Window(win)); 514 callback(new Window(win));
511 }); 515 });
512 } 516 }
513 }; 517 };
514 518
515 ext.tabs = { 519 ext.tabs = {
516 onBeforeNavigate: new BeforeNavigateTabEventTarget(),
517 onLoading: new LoadingTabEventTarget(), 520 onLoading: new LoadingTabEventTarget(),
518 onCompleted: new CompletedTabEventTarget(), 521 onCompleted: new CompletedTabEventTarget(),
519 onActivated: new ActivatedTabEventTarget(), 522 onActivated: new ActivatedTabEventTarget(),
520 onRemoved: new RemovedTabEventTarget() 523 onRemoved: new RemovedTabEventTarget(),
524
525 // the "beforeNavigate" event in Safari isn't dispatched when a new URL
526 // was entered into the address bar. So we can only use it only on Chrome,
527 // but we have to hide it from the browser-independent high level code.
528 _onBeforeNavigate: new BeforeNavigateTabEventTarget()
521 }; 529 };
522 530
523 ext.webRequest = { 531 ext.webRequest = {
524 onBeforeRequest: new SimpleEventTarget(), 532 onBeforeRequest: new SimpleEventTarget(),
525 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged 533 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged
526 }; 534 };
527 535
528 var contextMenuItems = []; 536 var contextMenuItems = [];
529 var isContextMenuHidden = true; 537 var isContextMenuHidden = true;
530 ext.contextMenus = { 538 ext.contextMenus = {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (isContextMenuHidden) 577 if (isContextMenuHidden)
570 return; 578 return;
571 579
572 chrome.contextMenus.removeAll(); 580 chrome.contextMenus.removeAll();
573 isContextMenuHidden = true; 581 isContextMenuHidden = true;
574 } 582 }
575 }; 583 };
576 584
577 ext.onMessage = new BackgroundMessageEventTarget(); 585 ext.onMessage = new BackgroundMessageEventTarget();
578 })(); 586 })();
OLDNEW
« no previous file with comments | « no previous file | safari/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld