Left: | ||
Right: |
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({ |
Sebastian Noack
2016/10/18 13:20:10
Nit: This doesn't need to be wrapped.
kzar
2016/10/19 12:36:58
Done.
| |
140 id: tabId, | |
141 url: url | |
142 }); | |
138 | 143 |
139 chrome.tabs.get(details.tabId, function() | 144 if (eagerlyUpdatedPages.get(page) != url) |
140 { | 145 { |
141 // If the tab is prerendered, chrome.tabs.get() sets | 146 ext._removeFromAllPageMaps(tabId); |
142 // chrome.runtime.lastError and we have to dispatch the onLoading event, | 147 |
143 // since the onUpdated event isn't dispatched for prerendered tabs. | 148 // 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 | 149 // structure in order to record and use the key. We want to avoid |
145 // are already visible. Otherwise browser action changes get overridden | 150 // trashing the page structure if the onCommitted event is then fired |
146 // when Chrome automatically resets them on navigation. | 151 // for the page. |
147 if (chrome.runtime.lastError) | 152 if (eager) |
153 eagerlyUpdatedPages.set(page, url); | |
154 | |
155 chrome.tabs.get(tabId, function() | |
148 { | 156 { |
149 ext.pages.onLoading._dispatch( | 157 // If the tab is prerendered, chrome.tabs.get() sets |
150 new Page({ | 158 // chrome.runtime.lastError and we have to dispatch the onLoading even t, |
151 id: details.tabId, | 159 // since the onUpdated event isn't dispatched for prerendered tabs. |
152 url: details.url | 160 // However, we have to keep relying on the unUpdated event for tabs th at |
153 }) | 161 // are already visible. Otherwise browser action changes get overridde n |
154 ); | 162 // when Chrome automatically resets them on navigation. |
155 } | 163 if (chrome.runtime.lastError) |
156 }); | 164 ext.pages.onLoading._dispatch(page); |
165 }); | |
166 } | |
157 } | 167 } |
158 | 168 |
159 // Update frame URL in frame structure | 169 // Update frame URL in frame structure |
160 var frame = createFrame(details.tabId, details.frameId); | 170 var frame = createFrame(tabId, frameId); |
161 frame.url = new URL(details.url); | 171 frame.url = new URL(url); |
172 }; | |
173 | |
174 chrome.webNavigation.onCommitted.addListener(function(details) | |
175 { | |
176 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); | |
162 }); | 177 }); |
163 | 178 |
164 function forgetTab(tabId) | 179 function forgetTab(tabId) |
165 { | 180 { |
166 ext.pages.onRemoved._dispatch(tabId); | 181 ext.pages.onRemoved._dispatch(tabId); |
167 | 182 |
168 ext._removeFromAllPageMaps(tabId); | 183 ext._removeFromAllPageMaps(tabId); |
169 delete framesOfTabs[tabId]; | 184 delete framesOfTabs[tabId]; |
170 } | 185 } |
171 | 186 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 ext.windows = { | 642 ext.windows = { |
628 create: function(createData, callback) | 643 create: function(createData, callback) |
629 { | 644 { |
630 chrome.windows.create(createData, function(createdWindow) | 645 chrome.windows.create(createData, function(createdWindow) |
631 { | 646 { |
632 afterTabLoaded(callback)(createdWindow.tabs[0]); | 647 afterTabLoaded(callback)(createdWindow.tabs[0]); |
633 }); | 648 }); |
634 } | 649 } |
635 }; | 650 }; |
636 })(); | 651 })(); |
OLD | NEW |