Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/ext/background.js

Issue 29357576: Issue 4483 - Update page structure when sitekey is received (Closed)
Patch Set: Create page on one line Created Oct. 19, 2016, 12:36 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/whitelisting.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld