| OLD | NEW |
| 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 _delete(id) | 29 _deleteByPageId(id) |
| 30 { | 30 { |
| 31 this._map.delete(id); | 31 for (let page of this.keys().filter(page => page.id == id)) |
| 32 | 32 this.delete(page); |
| 33 if (this._map.size == 0) | |
| 34 nonEmptyPageMaps.delete(this); | |
| 35 }, | 33 }, |
| 36 keys() | 34 keys() |
| 37 { | 35 { |
| 38 return this._map.keys(); | 36 return Array.from(this._map.keys()); |
| 39 }, | 37 }, |
| 40 get(page) | 38 get(page) |
| 41 { | 39 { |
| 42 return this._map.get(page.id); | 40 return this._map.get(page); |
| 43 }, | 41 }, |
| 44 set(page, value) | 42 set(page, value) |
| 45 { | 43 { |
| 46 this._map.set(page.id, value); | 44 this._map.set(page, value); |
| 47 nonEmptyPageMaps.add(this); | 45 nonEmptyPageMaps.add(this); |
| 48 }, | 46 }, |
| 49 has(page) | 47 has(page) |
| 50 { | 48 { |
| 51 return this._map.has(page.id); | 49 return this._map.has(page); |
| 52 }, | 50 }, |
| 53 clear() | 51 clear() |
| 54 { | 52 { |
| 55 this._map.clear(); | 53 this._map.clear(); |
| 56 nonEmptyPageMaps.delete(this); | 54 nonEmptyPageMaps.delete(this); |
| 57 }, | 55 }, |
| 58 delete(page) | 56 delete(page) |
| 59 { | 57 { |
| 60 this._delete(page.id); | 58 this._map.delete(page); |
| 59 |
| 60 if (this._map.size == 0) |
| 61 nonEmptyPageMaps.delete(this); |
| 61 } | 62 } |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 ext._removeFromAllPageMaps = pageId => | 65 ext._removeFromAllPageMaps = pageId => |
| 65 { | 66 { |
| 66 for (let pageMap of nonEmptyPageMaps) | 67 for (let pageMap of nonEmptyPageMaps) |
| 67 pageMap._delete(pageId); | 68 pageMap._deleteByPageId(pageId); |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 /* Pages */ | 71 /* Pages */ |
| 71 | 72 |
| 72 let Page = ext.Page = function(tab) | 73 let Page = ext.Page = function(tab) |
| 73 { | 74 { |
| 74 this.id = tab.id; | 75 this.id = tab.id; |
| 75 this._url = tab.url && new URL(tab.url); | 76 this._url = tab.url && new URL(tab.url); |
| 76 | 77 |
| 77 this.browserAction = new BrowserAction(tab.id); | 78 this.browserAction = new BrowserAction(tab.id); |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 ext.windows = { | 731 ext.windows = { |
| 731 create(createData, callback) | 732 create(createData, callback) |
| 732 { | 733 { |
| 733 chrome.windows.create(createData, createdWindow => | 734 chrome.windows.create(createData, createdWindow => |
| 734 { | 735 { |
| 735 afterTabLoaded(callback)(createdWindow.tabs[0]); | 736 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 736 }); | 737 }); |
| 737 } | 738 } |
| 738 }; | 739 }; |
| 739 }()); | 740 }()); |
| OLD | NEW |