Index: chrome/ext/background.js |
diff --git a/chrome/ext/background.js b/chrome/ext/background.js |
index 0baea123e912d64275646f377d42391f494fa50e..0c8bdfc289fc8276fa7a8c6b5f171ad41e729328 100644 |
--- a/chrome/ext/background.js |
+++ b/chrome/ext/background.js |
@@ -130,35 +130,47 @@ |
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({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) |