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-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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 | 118 |
119 var frame = frames[frameId]; | 119 var frame = frames[frameId]; |
120 if (!frame) | 120 if (!frame) |
121 frame = frames[frameId] = {}; | 121 frame = frames[frameId] = {}; |
122 | 122 |
123 return frame; | 123 return frame; |
124 } | 124 } |
125 | 125 |
126 var eagerlyUpdatedPages = new ext.PageMap(); | 126 var eagerlyUpdatedPages = new ext.PageMap(); |
127 | 127 |
128 ext._updatePageFrameStructure = function(frameId, tabId, url, eager, | 128 ext._updatePageFrameStructure = function(frameId, tabId, url, eager) |
129 parentFrameId) | |
130 { | 129 { |
131 if (frameId == 0) | 130 if (frameId == 0) |
132 { | 131 { |
133 let page = new Page({id: tabId, url: url}); | 132 let page = new Page({id: tabId, url: url}); |
134 | 133 |
135 if (eagerlyUpdatedPages.get(page) != url) | 134 if (eagerlyUpdatedPages.get(page) != url) |
136 { | 135 { |
137 ext._removeFromAllPageMaps(tabId); | 136 ext._removeFromAllPageMaps(tabId); |
138 | 137 |
139 // When a sitekey header is received we must immediately update the page | 138 // When a sitekey header is received we must immediately update the page |
(...skipping 13 matching lines...) Expand all Loading... | |
153 // when Chrome automatically resets them on navigation. | 152 // when Chrome automatically resets them on navigation. |
154 if (chrome.runtime.lastError) | 153 if (chrome.runtime.lastError) |
155 ext.pages.onLoading._dispatch(page); | 154 ext.pages.onLoading._dispatch(page); |
156 }); | 155 }); |
157 } | 156 } |
158 } | 157 } |
159 | 158 |
160 // Update frame URL in frame structure | 159 // Update frame URL in frame structure |
161 var frame = createFrame(tabId, frameId); | 160 var frame = createFrame(tabId, frameId); |
162 frame.url = new URL(url); | 161 frame.url = new URL(url); |
163 | |
164 // We only get the parentFrameId for onBeforeNavigate, not for onCommitted | |
165 if (typeof parentFrameId != "undefined") | |
166 frame.parent = framesOfTabs[tabId][parentFrameId] || null; | |
167 }; | 162 }; |
168 | 163 |
169 chrome.webNavigation.onBeforeNavigate.addListener(function(details) | 164 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
170 { | 165 { |
171 // Since requests can be fired from a page before its navigation has been | 166 // Capture parent frame here because onCommitted doesn't get this info. |
172 // confirmed we have to also update the page structure here. Otherwise those | 167 var frame = createFrame(details.tabId, details.frameId); |
173 // requests will be using the old structure, meaning first party requests | 168 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; |
174 // might be considered third party. (We also need to listen for this event | 169 |
175 // in order to get the parentFrameId which onCommitted doesn't provide.) | 170 // Chrome will sometimes perform requests for pre-rendered pages before |
176 ext._updatePageFrameStructure(details.frameId, details.tabId, | 171 // navigation was confirmed and the onComitted event was fired. Those |
177 details.url, false, details.parentFrameId); | 172 // requests will often wrongly be considered to be third party, since we |
173 // don't know the correct document domain for requests until after we've | |
174 // updated the page structure. As a work around we update the page | |
175 // structure eagerly for new tabs (which includes pre-rendered pages). | |
176 if (!(details.tabId in framesOfTabs)) | |
Wladimir Palant
2016/11/14 15:56:29
While this is probably not wrong, I think that you
kzar
2016/11/15 12:19:28
Well so far the issue only described a problem wit
| |
177 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url) ; | |
178 }); | 178 }); |
179 | 179 |
180 chrome.webNavigation.onCommitted.addListener(function(details) | 180 chrome.webNavigation.onCommitted.addListener(function(details) |
181 { | 181 { |
182 ext._updatePageFrameStructure(details.frameId, details.tabId, | 182 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); |
183 details.url, false); | |
184 }); | 183 }); |
185 | 184 |
186 function forgetTab(tabId) | 185 function forgetTab(tabId) |
187 { | 186 { |
188 ext.pages.onRemoved._dispatch(tabId); | 187 ext.pages.onRemoved._dispatch(tabId); |
189 | 188 |
190 ext._removeFromAllPageMaps(tabId); | 189 ext._removeFromAllPageMaps(tabId); |
191 delete framesOfTabs[tabId]; | 190 delete framesOfTabs[tabId]; |
192 } | 191 } |
193 | 192 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 ext.windows = { | 648 ext.windows = { |
650 create: function(createData, callback) | 649 create: function(createData, callback) |
651 { | 650 { |
652 chrome.windows.create(createData, function(createdWindow) | 651 chrome.windows.create(createData, function(createdWindow) |
653 { | 652 { |
654 afterTabLoaded(callback)(createdWindow.tabs[0]); | 653 afterTabLoaded(callback)(createdWindow.tabs[0]); |
655 }); | 654 }); |
656 } | 655 } |
657 }; | 656 }; |
658 })(); | 657 })(); |
LEFT | RIGHT |