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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 onActivated: new ext._EventTarget(), | 103 onActivated: new ext._EventTarget(), |
104 onRemoved: new ext._EventTarget() | 104 onRemoved: new ext._EventTarget() |
105 }; | 105 }; |
106 | 106 |
107 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) | 107 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
108 { | 108 { |
109 if (changeInfo.status == "loading") | 109 if (changeInfo.status == "loading") |
110 ext.pages.onLoading._dispatch(new Page(tab)); | 110 ext.pages.onLoading._dispatch(new Page(tab)); |
111 }); | 111 }); |
112 | 112 |
| 113 function createFrame(tabId, frameId) |
| 114 { |
| 115 var frames = framesOfTabs[tabId]; |
| 116 if (!frames) |
| 117 frames = framesOfTabs[tabId] = Object.create(null); |
| 118 |
| 119 var frame = frames[frameId]; |
| 120 if (!frame) |
| 121 frame = frames[frameId] = {}; |
| 122 |
| 123 return frame; |
| 124 } |
| 125 |
113 chrome.webNavigation.onBeforeNavigate.addListener(function(details) | 126 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
| 127 { |
| 128 // Capture parent frame here because onCommitted doesn't get this info. |
| 129 var frame = createFrame(details.tabId, details.frameId); |
| 130 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; |
| 131 }); |
| 132 |
| 133 chrome.webNavigation.onCommitted.addListener(function(details) |
114 { | 134 { |
115 if (details.frameId == 0) | 135 if (details.frameId == 0) |
116 { | 136 { |
117 ext._removeFromAllPageMaps(details.tabId); | 137 ext._removeFromAllPageMaps(details.tabId); |
118 | 138 |
119 chrome.tabs.get(details.tabId, function() | 139 chrome.tabs.get(details.tabId, function() |
120 { | 140 { |
121 // If the tab is prerendered, chrome.tabs.get() sets | 141 // If the tab is prerendered, chrome.tabs.get() sets |
122 // chrome.runtime.lastError and we have to dispatch the onLoading event, | 142 // chrome.runtime.lastError and we have to dispatch the onLoading event, |
123 // since the onUpdated event isn't dispatched for prerendered tabs. | 143 // since the onUpdated event isn't dispatched for prerendered tabs. |
124 // However, we have to keep relying on the unUpdated event for tabs that | 144 // However, we have to keep relying on the unUpdated event for tabs that |
125 // are already visible. Otherwise browser action changes get overridden | 145 // are already visible. Otherwise browser action changes get overridden |
126 // when Chrome automatically resets them on navigation. | 146 // when Chrome automatically resets them on navigation. |
127 if (chrome.runtime.lastError) | 147 if (chrome.runtime.lastError) |
128 { | 148 { |
129 ext.pages.onLoading._dispatch( | 149 ext.pages.onLoading._dispatch( |
130 new Page({ | 150 new Page({ |
131 id: details.tabId, | 151 id: details.tabId, |
132 url: details.url | 152 url: details.url |
133 }) | 153 }) |
134 ); | 154 ); |
135 } | 155 } |
136 }); | 156 }); |
137 } | 157 } |
138 | 158 |
139 // Add or update frame in frame structure | 159 // Update frame URL in frame structure |
140 var frames = framesOfTabs[details.tabId]; | 160 var frame = createFrame(details.tabId, details.frameId); |
141 if (!frames) | 161 frame.url = new URL(details.url); |
142 frames = framesOfTabs[details.tabId] = Object.create(null); | |
143 | |
144 frames[details.frameId] = { | |
145 parent: frames[details.parentFrameId] || null, | |
146 url: new URL(details.url) | |
147 }; | |
148 }); | 162 }); |
149 | 163 |
150 function forgetTab(tabId) | 164 function forgetTab(tabId) |
151 { | 165 { |
152 ext.pages.onRemoved._dispatch(tabId); | 166 ext.pages.onRemoved._dispatch(tabId); |
153 | 167 |
154 ext._removeFromAllPageMaps(tabId); | 168 ext._removeFromAllPageMaps(tabId); |
155 delete framesOfTabs[tabId]; | 169 delete framesOfTabs[tabId]; |
156 } | 170 } |
157 | 171 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 if (parentFrameId != -1) | 476 if (parentFrameId != -1) |
463 frames[details[i].frameId].parent = frames[parentFrameId]; | 477 frames[details[i].frameId].parent = frames[parentFrameId]; |
464 } | 478 } |
465 } | 479 } |
466 }); | 480 }); |
467 }); | 481 }); |
468 }); | 482 }); |
469 | 483 |
470 chrome.webRequest.onBeforeRequest.addListener(function(details) | 484 chrome.webRequest.onBeforeRequest.addListener(function(details) |
471 { | 485 { |
472 // the high-level code isn't interested in requests that aren't | 486 // The high-level code isn't interested in requests that aren't |
473 // related to a tab or requests loading a top-level document, | 487 // related to a tab or requests loading a top-level document, |
474 // those should never be blocked | 488 // those should never be blocked. |
475 if (details.tabId == -1 || details.type == "main_frame") | 489 if (details.tabId == -1 || details.type == "main_frame") |
476 return; | 490 return; |
477 | 491 |
478 // we are looking for the frame that contains the element that | 492 // We are looking for the frame that contains the element which |
479 // is about to load, however if a frame is loading the surrounding | 493 // has triggered this request. For most requests (e.g. images) we |
480 // frame is indicated by parentFrameId instead of frameId | 494 // can just use the request's frame ID, but for subdocument requests |
| 495 // (e.g. iframes) we must instead use the request's parent frame ID. |
481 var frameId; | 496 var frameId; |
482 var requestType; | 497 var requestType; |
483 if (details.type == "sub_frame") | 498 if (details.type == "sub_frame") |
484 { | 499 { |
485 frameId = details.parentFrameId; | 500 frameId = details.parentFrameId; |
486 requestType = "SUBDOCUMENT"; | 501 requestType = "SUBDOCUMENT"; |
487 } | 502 } |
488 else | 503 else |
489 { | 504 { |
490 frameId = details.frameId; | 505 frameId = details.frameId; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 ext.windows = { | 627 ext.windows = { |
613 create: function(createData, callback) | 628 create: function(createData, callback) |
614 { | 629 { |
615 chrome.windows.create(createData, function(createdWindow) | 630 chrome.windows.create(createData, function(createdWindow) |
616 { | 631 { |
617 afterTabLoaded(callback)(createdWindow.tabs[0]); | 632 afterTabLoaded(callback)(createdWindow.tabs[0]); |
618 }); | 633 }); |
619 } | 634 } |
620 }; | 635 }; |
621 })(); | 636 })(); |
LEFT | RIGHT |