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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 29357576: Issue 4483 - Update page structure when sitekey is received (Closed)
Left Patch Set: Created Oct. 17, 2016, 10:16 a.m.
Right Patch Set: Create page on one line Created Oct. 19, 2016, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/whitelisting.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 ext._updatePageFrameStructure = function(frameId, tabId, url) 133 var eagerlyUpdatedPages = new ext.PageMap();
134
135 ext._updatePageFrameStructure = function(frameId, tabId, url, eager)
134 { 136 {
135 if (frameId == 0) 137 if (frameId == 0)
136 { 138 {
137 ext._removeFromAllPageMaps(tabId); 139 let page = new Page({id: tabId, url: url});
138 140
139 chrome.tabs.get(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)
148 { 150 eagerlyUpdatedPages.set(page, url);
149 ext.pages.onLoading._dispatch( 151
150 new Page({ 152 chrome.tabs.get(tabId, function()
151 id: tabId, 153 {
152 url: url 154 // If the tab is prerendered, chrome.tabs.get() sets
153 }) 155 // chrome.runtime.lastError and we have to dispatch the onLoading even t,
154 ); 156 // since the onUpdated event isn't dispatched for prerendered tabs.
155 } 157 // However, we have to keep relying on the unUpdated event for tabs th at
156 }); 158 // are already visible. Otherwise browser action changes get overridde n
159 // when Chrome automatically resets them on navigation.
160 if (chrome.runtime.lastError)
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(tabId, frameId); 167 var frame = createFrame(tabId, frameId);
161 frame.url = new URL(url); 168 frame.url = new URL(url);
162 }; 169 };
163 170
164 chrome.webNavigation.onCommitted.addListener(function(details) 171 chrome.webNavigation.onCommitted.addListener(function(details)
165 { 172 {
166 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); 173 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ext.windows = { 639 ext.windows = {
633 create: function(createData, callback) 640 create: function(createData, callback)
634 { 641 {
635 chrome.windows.create(createData, function(createdWindow) 642 chrome.windows.create(createData, function(createdWindow)
636 { 643 {
637 afterTabLoaded(callback)(createdWindow.tabs[0]); 644 afterTabLoaded(callback)(createdWindow.tabs[0]);
638 }); 645 });
639 } 646 }
640 }; 647 };
641 })(); 648 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld