Index: chrome/ext/background.js |
diff --git a/chrome/ext/background.js b/chrome/ext/background.js |
index 0baea123e912d64275646f377d42391f494fa50e..8e8170eb4e94141e8a2acbe578853110f6dcb805 100644 |
--- a/chrome/ext/background.js |
+++ b/chrome/ext/background.js |
@@ -130,35 +130,50 @@ |
frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; |
}); |
- chrome.webNavigation.onCommitted.addListener(function(details) |
+ var eagerlyUpdatedPages = new ext.PageMap(); |
+ |
+ ext._updatePageFrameStructure = function(frameId, tabId, url, eager) |
{ |
- if (details.frameId == 0) |
+ if (frameId == 0) |
{ |
- ext._removeFromAllPageMaps(details.tabId); |
+ 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.
|
+ id: tabId, |
+ url: url |
+ }); |
- chrome.tabs.get(details.tabId, function() |
+ if (eagerlyUpdatedPages.get(page) != url) |
{ |
- // If the tab is prerendered, chrome.tabs.get() sets |
- // chrome.runtime.lastError and we have to dispatch the onLoading event, |
- // since the onUpdated event isn't dispatched for prerendered tabs. |
- // However, we have to keep relying on the unUpdated event for tabs that |
- // are already visible. Otherwise browser action changes get overridden |
- // when Chrome automatically resets them on navigation. |
- if (chrome.runtime.lastError) |
+ ext._removeFromAllPageMaps(tabId); |
+ |
+ // When a sitekey header is received we must immediately update the page |
+ // structure in order to record and use the key. We want to avoid |
+ // trashing the page structure if the onCommitted event is then fired |
+ // for the page. |
+ if (eager) |
+ eagerlyUpdatedPages.set(page, url); |
+ |
+ chrome.tabs.get(tabId, function() |
{ |
- ext.pages.onLoading._dispatch( |
- new Page({ |
- id: details.tabId, |
- url: details.url |
- }) |
- ); |
- } |
- }); |
+ // If the tab is prerendered, chrome.tabs.get() sets |
+ // chrome.runtime.lastError and we have to dispatch the onLoading event, |
+ // since the onUpdated event isn't dispatched for prerendered tabs. |
+ // However, we have to keep relying on the unUpdated event for tabs that |
+ // are already visible. Otherwise browser action changes get overridden |
+ // when Chrome automatically resets them on navigation. |
+ if (chrome.runtime.lastError) |
+ ext.pages.onLoading._dispatch(page); |
+ }); |
+ } |
} |
// Update frame URL in frame structure |
- var frame = createFrame(details.tabId, details.frameId); |
- frame.url = new URL(details.url); |
+ var frame = createFrame(tabId, frameId); |
+ frame.url = new URL(url); |
+ }; |
+ |
+ chrome.webNavigation.onCommitted.addListener(function(details) |
+ { |
+ ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); |
}); |
function forgetTab(tabId) |