| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 /* global internal, defineNamespace */ |
| 19 |
| 18 "use strict"; | 20 "use strict"; |
| 19 | 21 |
| 20 { | 22 { |
| 21 let nonEmptyPageMaps = new Set(); | 23 let nonEmptyPageMaps = new Set(); |
| 22 | 24 |
| 23 let PageMap = ext.PageMap = function() | 25 let PageMap = ext.PageMap = function() |
| 24 { | 26 { |
| 25 this._map = new Map(); | 27 defineNamespace(this, internal); |
| 28 |
| 29 this[internal].map = new Map(); |
| 26 }; | 30 }; |
| 27 PageMap.prototype = { | 31 PageMap.prototype = { |
| 28 _delete(id) | 32 [internal]: { |
| 29 { | 33 delete(pageId) |
| 30 this._map.delete(id); | 34 { |
| 35 this[internal].map.delete(pageId); |
| 31 | 36 |
| 32 if (this._map.size == 0) | 37 if (this[internal].map.size == 0) |
| 33 nonEmptyPageMaps.delete(this); | 38 nonEmptyPageMaps.delete(this); |
| 39 } |
| 34 }, | 40 }, |
| 35 keys() | 41 keys() |
| 36 { | 42 { |
| 37 return Array.from(this._map.keys()).map(ext.getPage); | 43 return Array.from(this[internal].map.keys()).map(ext.getPage); |
| 38 }, | 44 }, |
| 39 get(page) | 45 get(page) |
| 40 { | 46 { |
| 41 return this._map.get(page.id); | 47 return this[internal].map.get(page.id); |
| 42 }, | 48 }, |
| 43 set(page, value) | 49 set(page, value) |
| 44 { | 50 { |
| 45 this._map.set(page.id, value); | 51 this[internal].map.set(page.id, value); |
| 46 nonEmptyPageMaps.add(this); | 52 nonEmptyPageMaps.add(this); |
| 47 }, | 53 }, |
| 48 has(page) | 54 has(page) |
| 49 { | 55 { |
| 50 return this._map.has(page.id); | 56 return this[internal].map.has(page.id); |
| 51 }, | 57 }, |
| 52 clear() | 58 clear() |
| 53 { | 59 { |
| 54 this._map.clear(); | 60 this[internal].map.clear(); |
| 55 nonEmptyPageMaps.delete(this); | 61 nonEmptyPageMaps.delete(this); |
| 56 }, | 62 }, |
| 57 delete(page) | 63 delete(page) |
| 58 { | 64 { |
| 59 this._delete(page.id); | 65 this[internal].delete(page.id); |
| 60 } | 66 } |
| 61 }; | 67 }; |
| 62 | 68 |
| 63 ext._removeFromAllPageMaps = pageId => | 69 ext[internal].removeFromAllPageMaps = pageId => |
| 64 { | 70 { |
| 65 for (let pageMap of nonEmptyPageMaps) | 71 for (let pageMap of nonEmptyPageMaps) |
| 66 pageMap._delete(pageId); | 72 pageMap[internal].delete(pageId); |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 /* Pages */ | 75 /* Pages */ |
| 70 | 76 |
| 71 let Page = ext.Page = function(tab) | 77 let Page = ext.Page = function(tab) |
| 72 { | 78 { |
| 79 defineNamespace(this, internal); |
| 80 |
| 73 this.id = tab.id; | 81 this.id = tab.id; |
| 74 this._url = tab.url && new URL(tab.url); | 82 |
| 83 this[internal].url = tab.url && new URL(tab.url); |
| 75 | 84 |
| 76 this.browserAction = new BrowserAction(tab.id); | 85 this.browserAction = new BrowserAction(tab.id); |
| 77 this.contextMenus = new ContextMenus(this); | 86 this.contextMenus = new ContextMenus(this); |
| 78 }; | 87 }; |
| 79 Page.prototype = { | 88 Page.prototype = { |
| 80 get url() | 89 get url() |
| 81 { | 90 { |
| 82 // usually our Page objects are created from Chrome's Tab objects, which | 91 // usually our Page objects are created from Chrome's Tab objects, which |
| 83 // provide the url. So we can return the url given in the constructor. | 92 // provide the url. So we can return the url given in the constructor. |
| 84 if (this._url) | 93 if (this[internal].url) |
| 85 return this._url; | 94 return this[internal].url; |
| 86 | 95 |
| 87 // but sometimes we only have the tab id when we create a Page object. | 96 // but sometimes we only have the tab id when we create a Page object. |
| 88 // In that case we get the url from top frame of the tab, recorded by | 97 // In that case we get the url from top frame of the tab, recorded by |
| 89 // the onBeforeRequest handler. | 98 // the onBeforeRequest handler. |
| 90 let frames = framesOfTabs.get(this.id); | 99 let frames = framesOfTabs.get(this.id); |
| 91 if (frames) | 100 if (frames) |
| 92 { | 101 { |
| 93 let frame = frames.get(0); | 102 let frame = frames.get(0); |
| 94 if (frame) | 103 if (frame) |
| 95 return frame.url; | 104 return frame.url; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 113 { | 122 { |
| 114 browser.tabs.onUpdated.removeListener(onUpdated); | 123 browser.tabs.onUpdated.removeListener(onUpdated); |
| 115 callback(new Page(openedTab)); | 124 callback(new Page(openedTab)); |
| 116 } | 125 } |
| 117 }; | 126 }; |
| 118 browser.tabs.onUpdated.addListener(onUpdated); | 127 browser.tabs.onUpdated.addListener(onUpdated); |
| 119 }; | 128 }; |
| 120 } | 129 } |
| 121 | 130 |
| 122 ext.pages = { | 131 ext.pages = { |
| 123 onLoading: new ext._EventTarget(), | 132 onLoading: new ext[internal].EventTarget(), |
| 124 onActivated: new ext._EventTarget(), | 133 onActivated: new ext[internal].EventTarget(), |
| 125 onRemoved: new ext._EventTarget() | 134 onRemoved: new ext[internal].EventTarget() |
| 126 }; | 135 }; |
| 127 | 136 |
| 128 browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => | 137 browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => |
| 129 { | 138 { |
| 130 if (changeInfo.status == "loading") | 139 if (changeInfo.status == "loading") |
| 131 ext.pages.onLoading._dispatch(new Page(tab)); | 140 ext.pages.onLoading[internal].dispatch(new Page(tab)); |
| 132 }); | 141 }); |
| 133 | 142 |
| 134 function createFrame(tabId, frameId) | 143 function createFrame(tabId, frameId) |
| 135 { | 144 { |
| 136 let frames = framesOfTabs.get(tabId); | 145 let frames = framesOfTabs.get(tabId); |
| 137 if (!frames) | 146 if (!frames) |
| 138 { | 147 { |
| 139 frames = new Map(); | 148 frames = new Map(); |
| 140 framesOfTabs.set(tabId, frames); | 149 framesOfTabs.set(tabId, frames); |
| 141 } | 150 } |
| 142 | 151 |
| 143 let frame = frames.get(frameId); | 152 let frame = frames.get(frameId); |
| 144 if (!frame) | 153 if (!frame) |
| 145 { | 154 { |
| 146 frame = {}; | 155 frame = {}; |
| 147 frames.set(frameId, frame); | 156 frames.set(frameId, frame); |
| 148 } | 157 } |
| 149 | 158 |
| 150 return frame; | 159 return frame; |
| 151 } | 160 } |
| 152 | 161 |
| 153 function updatePageFrameStructure(frameId, tabId, url, parentFrameId) | 162 function updatePageFrameStructure(frameId, tabId, url, parentFrameId) |
| 154 { | 163 { |
| 155 if (frameId == 0) | 164 if (frameId == 0) |
| 156 { | 165 { |
| 157 let page = new Page({id: tabId, url}); | 166 let page = new Page({id: tabId, url}); |
| 158 | 167 |
| 159 ext._removeFromAllPageMaps(tabId); | 168 ext[internal].removeFromAllPageMaps(tabId); |
| 160 | 169 |
| 161 browser.tabs.get(tabId, () => | 170 browser.tabs.get(tabId, () => |
| 162 { | 171 { |
| 163 // If the tab is prerendered, browser.tabs.get() sets | 172 // If the tab is prerendered, browser.tabs.get() sets |
| 164 // browser.runtime.lastError and we have to dispatch the onLoading | 173 // browser.runtime.lastError and we have to dispatch the onLoading |
| 165 // event, since the onUpdated event isn't dispatched for prerendered | 174 // event, since the onUpdated event isn't dispatched for prerendered |
| 166 // tabs. However, we have to keep relying on the onUpdated event for | 175 // tabs. However, we have to keep relying on the onUpdated event for |
| 167 // tabs that are already visible. Otherwise browser action changes get | 176 // tabs that are already visible. Otherwise browser action changes get |
| 168 // overridden when Chrome automatically resets them on navigation. | 177 // overridden when Chrome automatically resets them on navigation. |
| 169 if (browser.runtime.lastError) | 178 if (browser.runtime.lastError) |
| 170 ext.pages.onLoading._dispatch(page); | 179 ext.pages.onLoading[internal].dispatch(page); |
| 171 }); | 180 }); |
| 172 } | 181 } |
| 173 | 182 |
| 174 // Update frame URL and parent in frame structure | 183 // Update frame URL and parent in frame structure |
| 175 let frame = createFrame(tabId, frameId); | 184 let frame = createFrame(tabId, frameId); |
| 176 frame.url = new URL(url); | 185 frame.url = new URL(url); |
| 177 | 186 |
| 178 let parentFrame = framesOfTabs.get(tabId).get(parentFrameId); | 187 let parentFrame = framesOfTabs.get(tabId).get(parentFrameId); |
| 179 if (parentFrame) | 188 if (parentFrame) |
| 180 frame.parent = parentFrame; | 189 frame.parent = parentFrame; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // for Web Store URLs. | 279 // for Web Store URLs. |
| 271 !url.startsWith("https://chrome.google.com/webstore/"))) | 280 !url.startsWith("https://chrome.google.com/webstore/"))) |
| 272 { | 281 { |
| 273 updatePageFrameStructure(details.frameId, details.tabId, url, | 282 updatePageFrameStructure(details.frameId, details.tabId, url, |
| 274 details.parentFrameId); | 283 details.parentFrameId); |
| 275 } | 284 } |
| 276 }); | 285 }); |
| 277 | 286 |
| 278 function forgetTab(tabId) | 287 function forgetTab(tabId) |
| 279 { | 288 { |
| 280 ext.pages.onRemoved._dispatch(tabId); | 289 ext.pages.onRemoved[internal].dispatch(tabId); |
| 281 | 290 |
| 282 ext._removeFromAllPageMaps(tabId); | 291 ext[internal].removeFromAllPageMaps(tabId); |
| 283 framesOfTabs.delete(tabId); | 292 framesOfTabs.delete(tabId); |
| 284 } | 293 } |
| 285 | 294 |
| 286 browser.tabs.onReplaced.addListener((addedTabId, removedTabId) => | 295 browser.tabs.onReplaced.addListener((addedTabId, removedTabId) => |
| 287 { | 296 { |
| 288 forgetTab(removedTabId); | 297 forgetTab(removedTabId); |
| 289 }); | 298 }); |
| 290 | 299 |
| 291 browser.tabs.onRemoved.addListener(forgetTab); | 300 browser.tabs.onRemoved.addListener(forgetTab); |
| 292 | 301 |
| 293 browser.tabs.onActivated.addListener(details => | 302 browser.tabs.onActivated.addListener(details => |
| 294 { | 303 { |
| 295 ext.pages.onActivated._dispatch(new Page({id: details.tabId})); | 304 ext.pages.onActivated[internal].dispatch(new Page({id: details.tabId})); |
| 296 }); | 305 }); |
| 297 | 306 |
| 298 | 307 |
| 299 /* Browser actions */ | 308 /* Browser actions */ |
| 300 | 309 |
| 301 let BrowserAction = function(tabId) | 310 let BrowserAction = function(tabId) |
| 302 { | 311 { |
| 303 this._tabId = tabId; | 312 defineNamespace(this, internal); |
| 304 this._changes = null; | 313 |
| 314 this[internal].tabId = tabId; |
| 315 this[internal].changes = null; |
| 305 }; | 316 }; |
| 306 BrowserAction.prototype = { | 317 BrowserAction.prototype = { |
| 307 _applyChanges() | 318 [internal]: { |
| 308 { | 319 applyChanges() |
| 309 if ("iconPath" in this._changes) | |
| 310 { | 320 { |
| 311 // Firefox for Android displays the browser action not as an icon but | 321 if ("iconPath" in this[internal].changes) |
| 312 // as a menu item. There is no icon, but such an option may be added in | |
| 313 // the future. | |
| 314 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 | |
| 315 if ("setIcon" in browser.browserAction) | |
| 316 { | 322 { |
| 317 let path = { | 323 // Firefox for Android displays the browser action not as an icon but |
| 318 16: this._changes.iconPath.replace("$size", "16"), | 324 // as a menu item. There is no icon, but such an option may be added |
| 319 19: this._changes.iconPath.replace("$size", "19"), | 325 // in the future. |
| 320 20: this._changes.iconPath.replace("$size", "20"), | 326 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 |
| 321 32: this._changes.iconPath.replace("$size", "32"), | 327 if ("setIcon" in browser.browserAction) |
| 322 38: this._changes.iconPath.replace("$size", "38"), | |
| 323 40: this._changes.iconPath.replace("$size", "40") | |
| 324 }; | |
| 325 try | |
| 326 { | 328 { |
| 327 browser.browserAction.setIcon({tabId: this._tabId, path}); | 329 let path = { |
| 328 } | 330 16: this[internal].changes.iconPath.replace("$size", "16"), |
| 329 catch (e) | 331 19: this[internal].changes.iconPath.replace("$size", "19"), |
| 330 { | 332 20: this[internal].changes.iconPath.replace("$size", "20"), |
| 331 // Edge throws if passed icon sizes different than 19,20,38,40px. | 333 32: this[internal].changes.iconPath.replace("$size", "32"), |
| 332 delete path[16]; | 334 38: this[internal].changes.iconPath.replace("$size", "38"), |
| 333 delete path[32]; | 335 40: this[internal].changes.iconPath.replace("$size", "40") |
| 334 browser.browserAction.setIcon({tabId: this._tabId, path}); | 336 }; |
| 337 try |
| 338 { |
| 339 browser.browserAction.setIcon({ |
| 340 tabId: this[internal].tabId, |
| 341 path |
| 342 }); |
| 343 } |
| 344 catch (e) |
| 345 { |
| 346 // Edge throws if passed icon sizes different than 19,20,38,40px. |
| 347 delete path[16]; |
| 348 delete path[32]; |
| 349 browser.browserAction.setIcon({ |
| 350 tabId: this[internal].tabId, |
| 351 path |
| 352 }); |
| 353 } |
| 335 } | 354 } |
| 336 } | 355 } |
| 356 |
| 357 if ("badgeText" in this[internal].changes) |
| 358 { |
| 359 // There is no badge on Firefox for Android; the browser action is |
| 360 // simply a menu item. |
| 361 if ("setBadgeText" in browser.browserAction) |
| 362 { |
| 363 browser.browserAction.setBadgeText({ |
| 364 tabId: this[internal].tabId, |
| 365 text: this[internal].changes.badgeText |
| 366 }); |
| 367 } |
| 368 } |
| 369 |
| 370 if ("badgeColor" in this[internal].changes) |
| 371 { |
| 372 // There is no badge on Firefox for Android; the browser action is |
| 373 // simply a menu item. |
| 374 if ("setBadgeBackgroundColor" in browser.browserAction) |
| 375 { |
| 376 browser.browserAction.setBadgeBackgroundColor({ |
| 377 tabId: this[internal].tabId, |
| 378 color: this[internal].changes.badgeColor |
| 379 }); |
| 380 } |
| 381 } |
| 382 |
| 383 this[internal].changes = null; |
| 384 }, |
| 385 queueChanges() |
| 386 { |
| 387 browser.tabs.get(this[internal].tabId, () => |
| 388 { |
| 389 // If the tab is prerendered, browser.tabs.get() sets |
| 390 // browser.runtime.lastError and we have to delay our changes |
| 391 // until the currently visible tab is replaced with the |
| 392 // prerendered tab. Otherwise browser.browserAction.set* fails. |
| 393 if (browser.runtime.lastError) |
| 394 { |
| 395 let onReplaced = (addedTabId, removedTabId) => |
| 396 { |
| 397 if (addedTabId == this[internal].tabId) |
| 398 { |
| 399 browser.tabs.onReplaced.removeListener(onReplaced); |
| 400 this[internal].applyChanges(); |
| 401 } |
| 402 }; |
| 403 browser.tabs.onReplaced.addListener(onReplaced); |
| 404 } |
| 405 else |
| 406 { |
| 407 this[internal].applyChanges(); |
| 408 } |
| 409 }); |
| 410 }, |
| 411 addChange(name, value) |
| 412 { |
| 413 if (!this[internal].changes) |
| 414 { |
| 415 this[internal].changes = {}; |
| 416 this[internal].queueChanges(); |
| 417 } |
| 418 |
| 419 this[internal].changes[name] = value; |
| 337 } | 420 } |
| 338 | |
| 339 if ("badgeText" in this._changes) | |
| 340 { | |
| 341 // There is no badge on Firefox for Android; the browser action is | |
| 342 // simply a menu item. | |
| 343 if ("setBadgeText" in browser.browserAction) | |
| 344 { | |
| 345 browser.browserAction.setBadgeText({ | |
| 346 tabId: this._tabId, | |
| 347 text: this._changes.badgeText | |
| 348 }); | |
| 349 } | |
| 350 } | |
| 351 | |
| 352 if ("badgeColor" in this._changes) | |
| 353 { | |
| 354 // There is no badge on Firefox for Android; the browser action is | |
| 355 // simply a menu item. | |
| 356 if ("setBadgeBackgroundColor" in browser.browserAction) | |
| 357 { | |
| 358 browser.browserAction.setBadgeBackgroundColor({ | |
| 359 tabId: this._tabId, | |
| 360 color: this._changes.badgeColor | |
| 361 }); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 this._changes = null; | |
| 366 }, | |
| 367 _queueChanges() | |
| 368 { | |
| 369 browser.tabs.get(this._tabId, () => | |
| 370 { | |
| 371 // If the tab is prerendered, browser.tabs.get() sets | |
| 372 // browser.runtime.lastError and we have to delay our changes | |
| 373 // until the currently visible tab is replaced with the | |
| 374 // prerendered tab. Otherwise browser.browserAction.set* fails. | |
| 375 if (browser.runtime.lastError) | |
| 376 { | |
| 377 let onReplaced = (addedTabId, removedTabId) => | |
| 378 { | |
| 379 if (addedTabId == this._tabId) | |
| 380 { | |
| 381 browser.tabs.onReplaced.removeListener(onReplaced); | |
| 382 this._applyChanges(); | |
| 383 } | |
| 384 }; | |
| 385 browser.tabs.onReplaced.addListener(onReplaced); | |
| 386 } | |
| 387 else | |
| 388 { | |
| 389 this._applyChanges(); | |
| 390 } | |
| 391 }); | |
| 392 }, | |
| 393 _addChange(name, value) | |
| 394 { | |
| 395 if (!this._changes) | |
| 396 { | |
| 397 this._changes = {}; | |
| 398 this._queueChanges(); | |
| 399 } | |
| 400 | |
| 401 this._changes[name] = value; | |
| 402 }, | 421 }, |
| 403 setIcon(path) | 422 setIcon(path) |
| 404 { | 423 { |
| 405 this._addChange("iconPath", path); | 424 this[internal].addChange("iconPath", path); |
| 406 }, | 425 }, |
| 407 setBadge(badge) | 426 setBadge(badge) |
| 408 { | 427 { |
| 409 if (!badge) | 428 if (!badge) |
| 410 { | 429 { |
| 411 this._addChange("badgeText", ""); | 430 this[internal].addChange("badgeText", ""); |
| 412 } | 431 } |
| 413 else | 432 else |
| 414 { | 433 { |
| 415 if ("number" in badge) | 434 if ("number" in badge) |
| 416 this._addChange("badgeText", badge.number.toString()); | 435 this[internal].addChange("badgeText", badge.number.toString()); |
| 417 | 436 |
| 418 if ("color" in badge) | 437 if ("color" in badge) |
| 419 this._addChange("badgeColor", badge.color); | 438 this[internal].addChange("badgeColor", badge.color); |
| 420 } | 439 } |
| 421 } | 440 } |
| 422 }; | 441 }; |
| 423 | 442 |
| 424 | 443 |
| 425 /* Context menus */ | 444 /* Context menus */ |
| 426 | 445 |
| 427 let contextMenuItems = new ext.PageMap(); | 446 let contextMenuItems = new ext.PageMap(); |
| 428 let contextMenuUpdating = false; | 447 let contextMenuUpdating = false; |
| 429 | 448 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 460 item.onclick(new Page(tab)); | 479 item.onclick(new Page(tab)); |
| 461 } | 480 } |
| 462 }); | 481 }); |
| 463 }); | 482 }); |
| 464 }); | 483 }); |
| 465 }); | 484 }); |
| 466 }; | 485 }; |
| 467 | 486 |
| 468 let ContextMenus = function(page) | 487 let ContextMenus = function(page) |
| 469 { | 488 { |
| 470 this._page = page; | 489 defineNamespace(this, internal); |
| 490 |
| 491 this[internal].page = page; |
| 471 }; | 492 }; |
| 472 ContextMenus.prototype = { | 493 ContextMenus.prototype = { |
| 473 create(item) | 494 create(item) |
| 474 { | 495 { |
| 475 let items = contextMenuItems.get(this._page); | 496 let items = contextMenuItems.get(this[internal].page); |
| 476 if (!items) | 497 if (!items) |
| 477 contextMenuItems.set(this._page, items = []); | 498 contextMenuItems.set(this[internal].page, items = []); |
| 478 | 499 |
| 479 items.push(item); | 500 items.push(item); |
| 480 updateContextMenu(); | 501 updateContextMenu(); |
| 481 }, | 502 }, |
| 482 remove(item) | 503 remove(item) |
| 483 { | 504 { |
| 484 let items = contextMenuItems.get(this._page); | 505 let items = contextMenuItems.get(this[internal].page); |
| 485 if (items) | 506 if (items) |
| 486 { | 507 { |
| 487 let index = items.indexOf(item); | 508 let index = items.indexOf(item); |
| 488 if (index != -1) | 509 if (index != -1) |
| 489 { | 510 { |
| 490 items.splice(index, 1); | 511 items.splice(index, 1); |
| 491 updateContextMenu(); | 512 updateContextMenu(); |
| 492 } | 513 } |
| 493 } | 514 } |
| 494 } | 515 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 propagateHandlerBehaviorChange | 551 propagateHandlerBehaviorChange |
| 531 ); | 552 ); |
| 532 browser.webRequest.handlerBehaviorChanged(); | 553 browser.webRequest.handlerBehaviorChanged(); |
| 533 | 554 |
| 534 handlerBehaviorChangedQuota--; | 555 handlerBehaviorChangedQuota--; |
| 535 setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); | 556 setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); |
| 536 } | 557 } |
| 537 } | 558 } |
| 538 | 559 |
| 539 ext.webRequest = { | 560 ext.webRequest = { |
| 540 onBeforeRequest: new ext._EventTarget(), | 561 onBeforeRequest: new ext[internal].EventTarget(), |
| 541 handlerBehaviorChanged() | 562 handlerBehaviorChanged() |
| 542 { | 563 { |
| 543 // Defer handlerBehaviorChanged() until navigation occurs. | 564 // Defer handlerBehaviorChanged() until navigation occurs. |
| 544 // There wouldn't be any visible effect when calling it earlier, | 565 // There wouldn't be any visible effect when calling it earlier, |
| 545 // but it's an expensive operation and that way we avoid to call | 566 // but it's an expensive operation and that way we avoid to call |
| 546 // it multiple times, if multiple filters are added/removed. | 567 // it multiple times, if multiple filters are added/removed. |
| 547 let {onBeforeNavigate} = browser.webNavigation; | 568 let {onBeforeNavigate} = browser.webNavigation; |
| 548 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) | 569 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) |
| 549 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); | 570 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); |
| 550 } | 571 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 // Sometimes requests are not associated with a browser tab and | 636 // Sometimes requests are not associated with a browser tab and |
| 616 // in this case we want to still be able to view the url being called. | 637 // in this case we want to still be able to view the url being called. |
| 617 let frame = null; | 638 let frame = null; |
| 618 let page = null; | 639 let page = null; |
| 619 if (details.tabId != -1) | 640 if (details.tabId != -1) |
| 620 { | 641 { |
| 621 frame = ext.getFrame(details.tabId, frameId); | 642 frame = ext.getFrame(details.tabId, frameId); |
| 622 page = new Page({id: details.tabId}); | 643 page = new Page({id: details.tabId}); |
| 623 } | 644 } |
| 624 | 645 |
| 625 if (ext.webRequest.onBeforeRequest._dispatch( | 646 if (ext.webRequest.onBeforeRequest[internal] |
| 626 url, type, page, frame).includes(false)) | 647 .dispatch(url, type, page, frame).includes(false)) |
| 648 { |
| 627 return {cancel: true}; | 649 return {cancel: true}; |
| 650 } |
| 628 }, {urls: ["<all_urls>"]}, ["blocking"]); | 651 }, {urls: ["<all_urls>"]}, ["blocking"]); |
| 629 | 652 |
| 630 | 653 |
| 631 /* Message passing */ | 654 /* Message passing */ |
| 632 | 655 |
| 633 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) => | 656 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) => |
| 634 { | 657 { |
| 635 let sender = {}; | 658 let sender = {}; |
| 636 | 659 |
| 637 // Add "page" and "frame" if the message was sent by a content script. | 660 // Add "page" and "frame" if the message was sent by a content script. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 653 | 676 |
| 654 let frame = frames.get(rawSender.frameId); | 677 let frame = frames.get(rawSender.frameId); |
| 655 if (frame) | 678 if (frame) |
| 656 return frame.parent || null; | 679 return frame.parent || null; |
| 657 | 680 |
| 658 return frames.get(0) || null; | 681 return frames.get(0) || null; |
| 659 } | 682 } |
| 660 }; | 683 }; |
| 661 } | 684 } |
| 662 | 685 |
| 663 return ext.onMessage._dispatch( | 686 return ext.onMessage[internal].dispatch( |
| 664 message, sender, sendResponse | 687 message, sender, sendResponse |
| 665 ).includes(true); | 688 ).includes(true); |
| 666 }); | 689 }); |
| 667 | 690 |
| 668 | 691 |
| 669 /* Storage */ | 692 /* Storage */ |
| 670 | 693 |
| 671 ext.storage = { | 694 ext.storage = { |
| 672 get(keys, callback) | 695 get(keys, callback) |
| 673 { | 696 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 690 ext.windows = { | 713 ext.windows = { |
| 691 create(createData, callback) | 714 create(createData, callback) |
| 692 { | 715 { |
| 693 browser.windows.create(createData, createdWindow => | 716 browser.windows.create(createData, createdWindow => |
| 694 { | 717 { |
| 695 afterTabLoaded(callback)(createdWindow.tabs[0]); | 718 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 696 }); | 719 }); |
| 697 } | 720 } |
| 698 }; | 721 }; |
| 699 } | 722 } |
| OLD | NEW |