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: Only eagerly update structure for new tabs Created Nov. 14, 2016, 2:53 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 | no next file » | 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)
136 { 129 {
137 if (frameId == 0) 130 if (frameId == 0)
138 { 131 {
139 let page = new Page({id: tabId, url: url}); 132 let page = new Page({id: tabId, url: url});
140 133
141 if (eagerlyUpdatedPages.get(page) != url) 134 if (eagerlyUpdatedPages.get(page) != url)
142 { 135 {
(...skipping 18 matching lines...) Expand all
161 ext.pages.onLoading._dispatch(page); 154 ext.pages.onLoading._dispatch(page);
162 }); 155 });
163 } 156 }
164 } 157 }
165 158
166 // Update frame URL in frame structure 159 // Update frame URL in frame structure
167 var frame = createFrame(tabId, frameId); 160 var frame = createFrame(tabId, frameId);
168 frame.url = new URL(url); 161 frame.url = new URL(url);
169 }; 162 };
170 163
164 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
165 {
166 // Capture parent frame here because onCommitted doesn't get this info.
167 var frame = createFrame(details.tabId, details.frameId);
168 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null;
169
170 // Chrome will sometimes perform requests for a pre-rendered page before
171 // navigation was confirmed and the onComitted event was fired. Those
172 // requests will often wrongly be considered as third party, since their
173 // page structure was not recorded. As a work around we update the page
174 // structure eagerly for new tabs (which includes pre-rendered pages).
175 if (!(details.tabId in framesOfTabs))
176 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url) ;
177 });
178
171 chrome.webNavigation.onCommitted.addListener(function(details) 179 chrome.webNavigation.onCommitted.addListener(function(details)
172 { 180 {
173 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); 181 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url);
174 }); 182 });
175 183
176 function forgetTab(tabId) 184 function forgetTab(tabId)
177 { 185 {
178 ext.pages.onRemoved._dispatch(tabId); 186 ext.pages.onRemoved._dispatch(tabId);
179 187
180 ext._removeFromAllPageMaps(tabId); 188 ext._removeFromAllPageMaps(tabId);
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 ext.windows = { 647 ext.windows = {
640 create: function(createData, callback) 648 create: function(createData, callback)
641 { 649 {
642 chrome.windows.create(createData, function(createdWindow) 650 chrome.windows.create(createData, function(createdWindow)
643 { 651 {
644 afterTabLoaded(callback)(createdWindow.tabs[0]); 652 afterTabLoaded(callback)(createdWindow.tabs[0]);
645 }); 653 });
646 } 654 }
647 }; 655 };
648 })(); 656 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld