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

Side by Side Diff: chrome/ext/background.js

Issue 29362203: Issue 4599 - Update the page structure more eagerly (Closed)
Patch Set: Created Nov. 10, 2016, 3:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/whitelisting.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if (!frames) 116 if (!frames)
117 frames = framesOfTabs[tabId] = Object.create(null); 117 frames = framesOfTabs[tabId] = Object.create(null);
118 118
119 var frame = frames[frameId]; 119 var frame = frames[frameId];
120 if (!frame) 120 if (!frame)
121 frame = frames[frameId] = {}; 121 frame = frames[frameId] = {};
122 122
123 return frame; 123 return frame;
124 } 124 }
125 125
126 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
127 {
128 // Capture parent frame here because onCommitted doesn't get this info.
129 var frame = createFrame(details.tabId, details.frameId);
130 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null;
131 });
132
133 var eagerlyUpdatedPages = new ext.PageMap(); 126 var eagerlyUpdatedPages = new ext.PageMap();
134 127
135 ext._updatePageFrameStructure = function(frameId, tabId, url, eager) 128 ext._updatePageFrameStructure = function(frameId, tabId, url, eager,
129 parentFrameId)
136 { 130 {
137 if (frameId == 0) 131 if (frameId == 0)
138 { 132 {
139 let page = new Page({id: tabId, url: url}); 133 let page = new Page({id: tabId, url: url});
140 134
141 if (eagerlyUpdatedPages.get(page) != url) 135 if (eagerlyUpdatedPages.get(page) != url)
142 { 136 {
143 ext._removeFromAllPageMaps(tabId); 137 ext._removeFromAllPageMaps(tabId);
144 138
145 // When a sitekey header is received we must immediately update the page 139 // When a sitekey header is received we must immediately update the page
(...skipping 13 matching lines...) Expand all
159 // when Chrome automatically resets them on navigation. 153 // when Chrome automatically resets them on navigation.
160 if (chrome.runtime.lastError) 154 if (chrome.runtime.lastError)
161 ext.pages.onLoading._dispatch(page); 155 ext.pages.onLoading._dispatch(page);
162 }); 156 });
163 } 157 }
164 } 158 }
165 159
166 // Update frame URL in frame structure 160 // Update frame URL in frame structure
167 var frame = createFrame(tabId, frameId); 161 var frame = createFrame(tabId, frameId);
168 frame.url = new URL(url); 162 frame.url = new URL(url);
163
164 // We only get the parentFrameId for onBeforeNavigate, not for onCommitted
165 if (typeof parentFrameId != "undefined")
166 frame.parent = framesOfTabs[tabId][parentFrameId] || null;
169 }; 167 };
170 168
169 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
170 {
171 // Since requests can be fired from a page before its navigation has been
172 // confirmed we have to also update the page structure here. Otherwise those
173 // requests will be using the old structure, meaning first party requests
174 // might be considered third party. (We also need to listen for this event
175 // in order to get the parentFrameId which onCommitted doesn't provide.)
176 ext._updatePageFrameStructure(details.frameId, details.tabId,
177 details.url, false, details.parentFrameId);
178 });
179
171 chrome.webNavigation.onCommitted.addListener(function(details) 180 chrome.webNavigation.onCommitted.addListener(function(details)
172 { 181 {
173 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); 182 ext._updatePageFrameStructure(details.frameId, details.tabId,
183 details.url, false);
174 }); 184 });
175 185
176 function forgetTab(tabId) 186 function forgetTab(tabId)
177 { 187 {
178 ext.pages.onRemoved._dispatch(tabId); 188 ext.pages.onRemoved._dispatch(tabId);
179 189
180 ext._removeFromAllPageMaps(tabId); 190 ext._removeFromAllPageMaps(tabId);
181 delete framesOfTabs[tabId]; 191 delete framesOfTabs[tabId];
182 } 192 }
183 193
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 ext.windows = { 649 ext.windows = {
640 create: function(createData, callback) 650 create: function(createData, callback)
641 { 651 {
642 chrome.windows.create(createData, function(createdWindow) 652 chrome.windows.create(createData, function(createdWindow)
643 { 653 {
644 afterTabLoaded(callback)(createdWindow.tabs[0]); 654 afterTabLoaded(callback)(createdWindow.tabs[0]);
645 }); 655 });
646 } 656 }
647 }; 657 };
648 })(); 658 })();
OLDNEW
« 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