| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 } | 254 } |
| 255 | 255 |
| 256 updatePageFrameStructure(details.frameId, details.tabId, details.url, | 256 updatePageFrameStructure(details.frameId, details.tabId, details.url, |
| 257 details.parentFrameId); | 257 details.parentFrameId); |
| 258 }, | 258 }, |
| 259 {types: ["main_frame", "sub_frame"], urls: ["http://*/*", "https://*/*"]}, | 259 {types: ["main_frame", "sub_frame"], urls: ["http://*/*", "https://*/*"]}, |
| 260 ["responseHeaders"]); | 260 ["responseHeaders"]); |
| 261 | 261 |
| 262 browser.webNavigation.onBeforeNavigate.addListener(details => | 262 browser.webNavigation.onBeforeNavigate.addListener(details => |
| 263 { | 263 { |
| 264 // Since we can only listen for HTTP(S) responses using | 264 // Requests can be made by about:blank frames before the frame's |
| 265 // webRequest.onHeadersReceived we must update the page structure here for | 265 // onCommitted event has fired, so we update the frame structure |
| 266 // other navigations. | 266 // for those now. |
| 267 let {url} = details; | 267 if (details.url == "about:blank") |
| 268 if (!(url.startsWith("http:") || | 268 { |
|
Sebastian Noack
2018/05/29 16:48:48
Wouldn't checking for "about:blank" be sufficient
kzar
2018/05/29 17:28:12
Yep, seems to work. Done.
| |
| 269 url.startsWith("https:") && | 269 updatePageFrameStructure(details.frameId, details.tabId, details.url, |
| 270 // Chrome doesn't dispatch webRequest.onHeadersReceived | |
| 271 // for Web Store URLs. | |
| 272 // https://crrev.com/76882bf/extensions/common/extension_urls.cc#33 | |
| 273 !url.startsWith("https://chrome.google.com/webstore/"))) | |
| 274 { | |
| 275 updatePageFrameStructure(details.frameId, details.tabId, url, | |
| 276 details.parentFrameId); | 270 details.parentFrameId); |
| 277 } | 271 } |
| 278 }); | 272 }); |
| 279 | 273 |
| 280 browser.webNavigation.onCommitted.addListener(details => | 274 browser.webNavigation.onCommitted.addListener(details => |
| 281 { | 275 { |
| 282 // For navigations which the previous two listeners missed - | 276 // We have to update the frame structure for documents that weren't |
| 283 // including documents cached by Service Workers - we must now | 277 // loaded over HTTP (including documents cached by Service Workers), |
| 284 // update the frame structure. However, since this event fires | 278 // when the navigation occurs. However, we must be careful to not |
| 285 // last we must be careful to not update the state of the same | 279 // update the state of the same document twice, otherewise the number |
| 286 // document twice, otherwise the number of any ads blocked already | 280 // of any ads blocked already and any recorded sitekey could get lost. |
| 287 // and any recorded sitekey could get lost. | |
| 288 let frame = ext.getFrame(details.tabId, details.frameId); | 281 let frame = ext.getFrame(details.tabId, details.frameId); |
| 289 if (!frame || frame.url.href != details.url) | 282 if (!frame || frame.url.href != details.url) |
| 290 { | 283 { |
| 291 updatePageFrameStructure(details.frameId, details.tabId, details.url, | 284 updatePageFrameStructure(details.frameId, details.tabId, details.url, |
| 292 details.parentFrameId); | 285 details.parentFrameId); |
| 293 } | 286 } |
| 294 }); | 287 }); |
| 295 | 288 |
| 296 function forgetTab(tabId) | 289 function forgetTab(tabId) |
| 297 { | 290 { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 return frames.get(0) || null; | 582 return frames.get(0) || null; |
| 590 } | 583 } |
| 591 }; | 584 }; |
| 592 } | 585 } |
| 593 | 586 |
| 594 return ext.onMessage._dispatch( | 587 return ext.onMessage._dispatch( |
| 595 message, sender, sendResponse | 588 message, sender, sendResponse |
| 596 ).includes(true); | 589 ).includes(true); |
| 597 }); | 590 }); |
| 598 } | 591 } |
| LEFT | RIGHT |