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

Delta Between Two Patch Sets: ext/background.js

Issue 29445648: Issue 5264 - Return page objects instead of page IDs (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created May 22, 2017, 3:50 p.m.
Right Patch Set: Return page objects instead of page IDs Created May 22, 2017, 5:08 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 | « 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 (function() 20 (function()
21 { 21 {
22 let nonEmptyPageMaps = new Set(); 22 let nonEmptyPageMaps = new Set();
23 23
24 let PageMap = ext.PageMap = function() 24 let PageMap = ext.PageMap = function()
25 { 25 {
26 this._map = new Map(); 26 this._map = new Map();
27 }; 27 };
28 PageMap.prototype = { 28 PageMap.prototype = {
29 _deleteByPageId(id) 29 _delete(id)
30 { 30 {
31 for (let page of this.keys().filter(page => page.id == id)) 31 this._map.delete(id);
32 this.delete(page); 32
33 if (this._map.size == 0)
34 nonEmptyPageMaps.delete(this);
33 }, 35 },
34 keys() 36 keys()
35 { 37 {
36 return Array.from(this._map.keys()); 38 return Array.from(this._map.keys()).map(ext.getPage);
kzar 2017/05/23 11:47:59 I wonder if you could do `return Array.prototype.m
Sebastian Noack 2017/05/23 12:16:54 Please don't. Array generics are non-standard and
Manish Jethani 2017/05/23 12:32:27 I think Dave meant Array.prototype.map rather than
Sebastian Noack 2017/05/23 15:09:18 Sorry, you are right, I mixed things up, calling a
kzar 2017/05/23 16:15:04 Acknowledged.
37 }, 39 },
38 get(page) 40 get(page)
39 { 41 {
40 return this._map.get(page); 42 return this._map.get(page.id);
41 }, 43 },
42 set(page, value) 44 set(page, value)
43 { 45 {
44 this._map.set(page, value); 46 this._map.set(page.id, value);
45 nonEmptyPageMaps.add(this); 47 nonEmptyPageMaps.add(this);
46 }, 48 },
47 has(page) 49 has(page)
48 { 50 {
49 return this._map.has(page); 51 return this._map.has(page.id);
50 }, 52 },
51 clear() 53 clear()
52 { 54 {
53 this._map.clear(); 55 this._map.clear();
54 nonEmptyPageMaps.delete(this); 56 nonEmptyPageMaps.delete(this);
55 }, 57 },
56 delete(page) 58 delete(page)
57 { 59 {
58 this._map.delete(page); 60 this._delete(page.id);
59
60 if (this._map.size == 0)
61 nonEmptyPageMaps.delete(this);
62 } 61 }
63 }; 62 };
64 63
65 ext._removeFromAllPageMaps = pageId => 64 ext._removeFromAllPageMaps = pageId =>
66 { 65 {
67 for (let pageMap of nonEmptyPageMaps) 66 for (let pageMap of nonEmptyPageMaps)
68 pageMap._deleteByPageId(pageId); 67 pageMap._delete(pageId);
69 }; 68 };
70 69
71 /* Pages */ 70 /* Pages */
72 71
73 let Page = ext.Page = function(tab) 72 let Page = ext.Page = function(tab)
74 { 73 {
75 this.id = tab.id; 74 this.id = tab.id;
76 this._url = tab.url && new URL(tab.url); 75 this._url = tab.url && new URL(tab.url);
77 76
78 this.browserAction = new BrowserAction(tab.id); 77 this.browserAction = new BrowserAction(tab.id);
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 ext.windows = { 730 ext.windows = {
732 create(createData, callback) 731 create(createData, callback)
733 { 732 {
734 chrome.windows.create(createData, createdWindow => 733 chrome.windows.create(createData, createdWindow =>
735 { 734 {
736 afterTabLoaded(callback)(createdWindow.tabs[0]); 735 afterTabLoaded(callback)(createdWindow.tabs[0]);
737 }); 736 });
738 } 737 }
739 }; 738 };
740 }()); 739 }());
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