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[internal].dispatchEvent(ext.pages.onLoading, 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[internal].dispatchEvent(ext.pages.onLoading, 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[internal].dispatchEvent(ext.pages.onRemoved, 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[internal].dispatchEvent(ext.pages.onActivated, |
| 305 new Page({id: details.tabId})); |
296 }); | 306 }); |
297 | 307 |
298 | 308 |
299 /* Browser actions */ | 309 /* Browser actions */ |
300 | 310 |
301 let BrowserAction = function(tabId) | 311 let BrowserAction = function(tabId) |
302 { | 312 { |
303 this._tabId = tabId; | 313 defineNamespace(this, internal); |
304 this._changes = null; | 314 |
| 315 this[internal].tabId = tabId; |
| 316 this[internal].changes = null; |
305 }; | 317 }; |
306 BrowserAction.prototype = { | 318 BrowserAction.prototype = { |
307 _applyChanges() | |
308 { | |
309 if ("iconPath" in this._changes) | |
310 { | |
311 // Firefox for Android displays the browser action not as an icon but | |
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 { | |
317 let path = { | |
318 16: this._changes.iconPath.replace("$size", "16"), | |
319 19: this._changes.iconPath.replace("$size", "19"), | |
320 20: this._changes.iconPath.replace("$size", "20"), | |
321 32: this._changes.iconPath.replace("$size", "32"), | |
322 38: this._changes.iconPath.replace("$size", "38"), | |
323 40: this._changes.iconPath.replace("$size", "40") | |
324 }; | |
325 try | |
326 { | |
327 browser.browserAction.setIcon({tabId: this._tabId, path}); | |
328 } | |
329 catch (e) | |
330 { | |
331 // Edge throws if passed icon sizes different than 19,20,38,40px. | |
332 delete path[16]; | |
333 delete path[32]; | |
334 browser.browserAction.setIcon({tabId: this._tabId, path}); | |
335 } | |
336 } | |
337 } | |
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 }, | |
403 setIcon(path) | 319 setIcon(path) |
404 { | 320 { |
405 this._addChange("iconPath", path); | 321 addBrowserActionChange(this, "iconPath", path); |
406 }, | 322 }, |
407 setBadge(badge) | 323 setBadge(badge) |
408 { | 324 { |
409 if (!badge) | 325 if (!badge) |
410 { | 326 { |
411 this._addChange("badgeText", ""); | 327 addBrowserActionChange(this, "badgeText", ""); |
412 } | 328 } |
413 else | 329 else |
414 { | 330 { |
415 if ("number" in badge) | 331 if ("number" in badge) |
416 this._addChange("badgeText", badge.number.toString()); | 332 addBrowserActionChange(this, "badgeText", badge.number.toString()); |
417 | 333 |
418 if ("color" in badge) | 334 if ("color" in badge) |
419 this._addChange("badgeColor", badge.color); | 335 addBrowserActionChange(this, "badgeColor", badge.color); |
420 } | 336 } |
421 } | 337 } |
422 }; | 338 }; |
423 | 339 |
| 340 function queueBrowserActionChanges(browserAction) |
| 341 { |
| 342 browser.tabs.get(browserAction[internal].tabId, () => |
| 343 { |
| 344 // If the tab is prerendered, browser.tabs.get() sets |
| 345 // browser.runtime.lastError and we have to delay our changes |
| 346 // until the currently visible tab is replaced with the |
| 347 // prerendered tab. Otherwise browser.browserAction.set* fails. |
| 348 if (browser.runtime.lastError) |
| 349 { |
| 350 let onReplaced = (addedTabId, removedTabId) => |
| 351 { |
| 352 if (addedTabId == browserAction[internal].tabId) |
| 353 { |
| 354 browser.tabs.onReplaced.removeListener(onReplaced); |
| 355 applyBrowserActionChanges(browserAction); |
| 356 } |
| 357 }; |
| 358 browser.tabs.onReplaced.addListener(onReplaced); |
| 359 } |
| 360 else |
| 361 { |
| 362 applyBrowserActionChanges(browserAction); |
| 363 } |
| 364 }); |
| 365 } |
| 366 |
| 367 function applyBrowserActionChanges(browserAction) |
| 368 { |
| 369 if ("iconPath" in browserAction[internal].changes) |
| 370 { |
| 371 // Firefox for Android displays the browser action not as an icon but |
| 372 // as a menu item. There is no icon, but such an option may be added in |
| 373 // the future. |
| 374 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 |
| 375 if ("setIcon" in browser.browserAction) |
| 376 { |
| 377 let path = { |
| 378 16: browserAction[internal].changes.iconPath.replace("$size", "16"), |
| 379 19: browserAction[internal].changes.iconPath.replace("$size", "19"), |
| 380 20: browserAction[internal].changes.iconPath.replace("$size", "20"), |
| 381 32: browserAction[internal].changes.iconPath.replace("$size", "32"), |
| 382 38: browserAction[internal].changes.iconPath.replace("$size", "38"), |
| 383 40: browserAction[internal].changes.iconPath.replace("$size", "40") |
| 384 }; |
| 385 try |
| 386 { |
| 387 browser.browserAction.setIcon({ |
| 388 tabId: browserAction[internal].tabId, |
| 389 path |
| 390 }); |
| 391 } |
| 392 catch (e) |
| 393 { |
| 394 // Edge throws if passed icon sizes different than 19,20,38,40px. |
| 395 delete path[16]; |
| 396 delete path[32]; |
| 397 browser.browserAction.setIcon({ |
| 398 tabId: browserAction[internal].tabId, |
| 399 path |
| 400 }); |
| 401 } |
| 402 } |
| 403 } |
| 404 |
| 405 if ("badgeText" in browserAction[internal].changes) |
| 406 { |
| 407 // There is no badge on Firefox for Android; the browser action is |
| 408 // simply a menu item. |
| 409 if ("setBadgeText" in browser.browserAction) |
| 410 { |
| 411 browser.browserAction.setBadgeText({ |
| 412 tabId: browserAction[internal].tabId, |
| 413 text: browserAction[internal].changes.badgeText |
| 414 }); |
| 415 } |
| 416 } |
| 417 |
| 418 if ("badgeColor" in browserAction[internal].changes) |
| 419 { |
| 420 // There is no badge on Firefox for Android; the browser action is |
| 421 // simply a menu item. |
| 422 if ("setBadgeBackgroundColor" in browser.browserAction) |
| 423 { |
| 424 browser.browserAction.setBadgeBackgroundColor({ |
| 425 tabId: browserAction[internal].tabId, |
| 426 color: browserAction[internal].changes.badgeColor |
| 427 }); |
| 428 } |
| 429 } |
| 430 |
| 431 browserAction[internal].changes = null; |
| 432 } |
| 433 |
| 434 function addBrowserActionChange(browserAction, name, value) |
| 435 { |
| 436 if (!browserAction[internal].changes) |
| 437 { |
| 438 browserAction[internal].changes = {}; |
| 439 queueBrowserActionChanges(browserAction); |
| 440 } |
| 441 |
| 442 browserAction[internal].changes[name] = value; |
| 443 } |
| 444 |
424 | 445 |
425 /* Context menus */ | 446 /* Context menus */ |
426 | 447 |
427 let contextMenuItems = new ext.PageMap(); | 448 let contextMenuItems = new ext.PageMap(); |
428 let contextMenuUpdating = false; | 449 let contextMenuUpdating = false; |
429 | 450 |
430 let updateContextMenu = () => | 451 let updateContextMenu = () => |
431 { | 452 { |
432 // Firefox for Android does not support context menus. | 453 // Firefox for Android does not support context menus. |
433 // https://bugzilla.mozilla.org/show_bug.cgi?id=1269062 | 454 // https://bugzilla.mozilla.org/show_bug.cgi?id=1269062 |
(...skipping 26 matching lines...) Expand all Loading... |
460 item.onclick(new Page(tab)); | 481 item.onclick(new Page(tab)); |
461 } | 482 } |
462 }); | 483 }); |
463 }); | 484 }); |
464 }); | 485 }); |
465 }); | 486 }); |
466 }; | 487 }; |
467 | 488 |
468 let ContextMenus = function(page) | 489 let ContextMenus = function(page) |
469 { | 490 { |
470 this._page = page; | 491 defineNamespace(this, internal); |
| 492 |
| 493 this[internal].page = page; |
471 }; | 494 }; |
472 ContextMenus.prototype = { | 495 ContextMenus.prototype = { |
473 create(item) | 496 create(item) |
474 { | 497 { |
475 let items = contextMenuItems.get(this._page); | 498 let items = contextMenuItems.get(this[internal].page); |
476 if (!items) | 499 if (!items) |
477 contextMenuItems.set(this._page, items = []); | 500 contextMenuItems.set(this[internal].page, items = []); |
478 | 501 |
479 items.push(item); | 502 items.push(item); |
480 updateContextMenu(); | 503 updateContextMenu(); |
481 }, | 504 }, |
482 remove(item) | 505 remove(item) |
483 { | 506 { |
484 let items = contextMenuItems.get(this._page); | 507 let items = contextMenuItems.get(this[internal].page); |
485 if (items) | 508 if (items) |
486 { | 509 { |
487 let index = items.indexOf(item); | 510 let index = items.indexOf(item); |
488 if (index != -1) | 511 if (index != -1) |
489 { | 512 { |
490 items.splice(index, 1); | 513 items.splice(index, 1); |
491 updateContextMenu(); | 514 updateContextMenu(); |
492 } | 515 } |
493 } | 516 } |
494 } | 517 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 propagateHandlerBehaviorChange | 553 propagateHandlerBehaviorChange |
531 ); | 554 ); |
532 browser.webRequest.handlerBehaviorChanged(); | 555 browser.webRequest.handlerBehaviorChanged(); |
533 | 556 |
534 handlerBehaviorChangedQuota--; | 557 handlerBehaviorChangedQuota--; |
535 setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); | 558 setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); |
536 } | 559 } |
537 } | 560 } |
538 | 561 |
539 ext.webRequest = { | 562 ext.webRequest = { |
540 onBeforeRequest: new ext._EventTarget(), | 563 onBeforeRequest: new ext[internal].EventTarget(), |
541 handlerBehaviorChanged() | 564 handlerBehaviorChanged() |
542 { | 565 { |
543 // Defer handlerBehaviorChanged() until navigation occurs. | 566 // Defer handlerBehaviorChanged() until navigation occurs. |
544 // There wouldn't be any visible effect when calling it earlier, | 567 // 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 | 568 // but it's an expensive operation and that way we avoid to call |
546 // it multiple times, if multiple filters are added/removed. | 569 // it multiple times, if multiple filters are added/removed. |
547 let {onBeforeNavigate} = browser.webNavigation; | 570 let {onBeforeNavigate} = browser.webNavigation; |
548 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) | 571 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) |
549 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); | 572 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); |
550 } | 573 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 // Sometimes requests are not associated with a browser tab and | 638 // 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. | 639 // in this case we want to still be able to view the url being called. |
617 let frame = null; | 640 let frame = null; |
618 let page = null; | 641 let page = null; |
619 if (details.tabId != -1) | 642 if (details.tabId != -1) |
620 { | 643 { |
621 frame = ext.getFrame(details.tabId, frameId); | 644 frame = ext.getFrame(details.tabId, frameId); |
622 page = new Page({id: details.tabId}); | 645 page = new Page({id: details.tabId}); |
623 } | 646 } |
624 | 647 |
625 if (ext.webRequest.onBeforeRequest._dispatch( | 648 if (ext[internal].dispatchEvent(ext.webRequest.onBeforeRequest, |
626 url, type, page, frame).includes(false)) | 649 url, type, page, frame).includes(false)) |
| 650 { |
627 return {cancel: true}; | 651 return {cancel: true}; |
| 652 } |
628 }, {urls: ["<all_urls>"]}, ["blocking"]); | 653 }, {urls: ["<all_urls>"]}, ["blocking"]); |
629 | 654 |
630 | 655 |
631 /* Message passing */ | 656 /* Message passing */ |
632 | 657 |
633 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) => | 658 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) => |
634 { | 659 { |
635 let sender = {}; | 660 let sender = {}; |
636 | 661 |
637 // Add "page" and "frame" if the message was sent by a content script. | 662 // Add "page" and "frame" if the message was sent by a content script. |
(...skipping 15 matching lines...) Expand all Loading... |
653 | 678 |
654 let frame = frames.get(rawSender.frameId); | 679 let frame = frames.get(rawSender.frameId); |
655 if (frame) | 680 if (frame) |
656 return frame.parent || null; | 681 return frame.parent || null; |
657 | 682 |
658 return frames.get(0) || null; | 683 return frames.get(0) || null; |
659 } | 684 } |
660 }; | 685 }; |
661 } | 686 } |
662 | 687 |
663 return ext.onMessage._dispatch( | 688 return ext[internal].dispatchEvent( |
| 689 ext.onMessage, |
664 message, sender, sendResponse | 690 message, sender, sendResponse |
665 ).includes(true); | 691 ).includes(true); |
666 }); | 692 }); |
667 | 693 |
668 | 694 |
669 /* Storage */ | 695 /* Storage */ |
670 | 696 |
671 ext.storage = { | 697 ext.storage = { |
672 get(keys, callback) | 698 get(keys, callback) |
673 { | 699 { |
(...skipping 16 matching lines...) Expand all Loading... |
690 ext.windows = { | 716 ext.windows = { |
691 create(createData, callback) | 717 create(createData, callback) |
692 { | 718 { |
693 browser.windows.create(createData, createdWindow => | 719 browser.windows.create(createData, createdWindow => |
694 { | 720 { |
695 afterTabLoaded(callback)(createdWindow.tabs[0]); | 721 afterTabLoaded(callback)(createdWindow.tabs[0]); |
696 }); | 722 }); |
697 } | 723 } |
698 }; | 724 }; |
699 } | 725 } |
OLD | NEW |