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-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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return frame; | 123 return frame; |
124 } | 124 } |
125 | 125 |
126 chrome.webNavigation.onBeforeNavigate.addListener(function(details) | 126 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
127 { | 127 { |
128 // Capture parent frame here because onCommitted doesn't get this info. | 128 // Capture parent frame here because onCommitted doesn't get this info. |
129 var frame = createFrame(details.tabId, details.frameId); | 129 var frame = createFrame(details.tabId, details.frameId); |
130 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; | 130 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; |
131 }); | 131 }); |
132 | 132 |
133 chrome.webNavigation.onCommitted.addListener(function(details) | 133 var eagerlyUpdatedPages = new ext.PageMap(); |
| 134 |
| 135 ext._updatePageFrameStructure = function(frameId, tabId, url, eager) |
134 { | 136 { |
135 if (details.frameId == 0) | 137 if (frameId == 0) |
136 { | 138 { |
137 ext._removeFromAllPageMaps(details.tabId); | 139 let page = new Page({id: tabId, url: url}); |
138 | 140 |
139 chrome.tabs.get(details.tabId, function() | 141 if (eagerlyUpdatedPages.get(page) != url) |
140 { | 142 { |
141 // If the tab is prerendered, chrome.tabs.get() sets | 143 ext._removeFromAllPageMaps(tabId); |
142 // chrome.runtime.lastError and we have to dispatch the onLoading event, | 144 |
143 // since the onUpdated event isn't dispatched for prerendered tabs. | 145 // When a sitekey header is received we must immediately update the page |
144 // However, we have to keep relying on the unUpdated event for tabs that | 146 // structure in order to record and use the key. We want to avoid |
145 // are already visible. Otherwise browser action changes get overridden | 147 // trashing the page structure if the onCommitted event is then fired |
146 // when Chrome automatically resets them on navigation. | 148 // for the page. |
147 if (chrome.runtime.lastError) | 149 if (eager) |
| 150 eagerlyUpdatedPages.set(page, url); |
| 151 |
| 152 chrome.tabs.get(tabId, function() |
148 { | 153 { |
149 ext.pages.onLoading._dispatch( | 154 // If the tab is prerendered, chrome.tabs.get() sets |
150 new Page({ | 155 // chrome.runtime.lastError and we have to dispatch the onLoading even
t, |
151 id: details.tabId, | 156 // since the onUpdated event isn't dispatched for prerendered tabs. |
152 url: details.url | 157 // However, we have to keep relying on the unUpdated event for tabs th
at |
153 }) | 158 // are already visible. Otherwise browser action changes get overridde
n |
154 ); | 159 // when Chrome automatically resets them on navigation. |
155 } | 160 if (chrome.runtime.lastError) |
156 }); | 161 ext.pages.onLoading._dispatch(page); |
| 162 }); |
| 163 } |
157 } | 164 } |
158 | 165 |
159 // Update frame URL in frame structure | 166 // Update frame URL in frame structure |
160 var frame = createFrame(details.tabId, details.frameId); | 167 var frame = createFrame(tabId, frameId); |
161 frame.url = new URL(details.url); | 168 frame.url = new URL(url); |
| 169 }; |
| 170 |
| 171 chrome.webNavigation.onCommitted.addListener(function(details) |
| 172 { |
| 173 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); |
162 }); | 174 }); |
163 | 175 |
164 function forgetTab(tabId) | 176 function forgetTab(tabId) |
165 { | 177 { |
166 ext.pages.onRemoved._dispatch(tabId); | 178 ext.pages.onRemoved._dispatch(tabId); |
167 | 179 |
168 ext._removeFromAllPageMaps(tabId); | 180 ext._removeFromAllPageMaps(tabId); |
169 delete framesOfTabs[tabId]; | 181 delete framesOfTabs[tabId]; |
170 } | 182 } |
171 | 183 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 ext.windows = { | 639 ext.windows = { |
628 create: function(createData, callback) | 640 create: function(createData, callback) |
629 { | 641 { |
630 chrome.windows.create(createData, function(createdWindow) | 642 chrome.windows.create(createData, function(createdWindow) |
631 { | 643 { |
632 afterTabLoaded(callback)(createdWindow.tabs[0]); | 644 afterTabLoaded(callback)(createdWindow.tabs[0]); |
633 }); | 645 }); |
634 } | 646 } |
635 }; | 647 }; |
636 })(); | 648 })(); |
OLD | NEW |