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

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

Issue 5943816674607104: Issue 1983 - Dispatch onLoading event for prerendered pages (Closed)
Left Patch Set: Consider that Chrome resets browser actions on navigation Created Feb. 10, 2015, 4:56 p.m.
Right Patch Set: Simplified changes Created Feb. 10, 2015, 5:14 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 | no next file » | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 { 95 {
96 callback(tabs.map(function(tab) 96 callback(tabs.map(function(tab)
97 { 97 {
98 return new Page(tab); 98 return new Page(tab);
99 })); 99 }));
100 }); 100 });
101 }, 101 },
102 onLoading: new ext._EventTarget() 102 onLoading: new ext._EventTarget()
103 }; 103 };
104 104
105 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
106 {
107 if (changeInfo.status == "loading")
108 ext.pages.onLoading._dispatch(new Page(tab));
109 });
110
105 chrome.webNavigation.onBeforeNavigate.addListener(function(details) 111 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
106 { 112 {
107 if (details.frameId == 0) 113 if (details.frameId == 0)
108 { 114 {
109 ext._removeFromAllPageMaps(details.tabId); 115 ext._removeFromAllPageMaps(details.tabId);
110 116
111 chrome.tabs.get(details.tabId, function() 117 chrome.tabs.get(details.tabId, function()
112 { 118 {
119 // If the tab is prerendered, chrome.tabs.get() sets
120 // chrome.runtime.lastError and we have to dispatch the onLoading event,
121 // since the onUpdated event isn't dispatched for prerendered tabs.
122 // However, we have to keep relying on the unUpdated event for tabs that
123 // are already visible. Otherwise browser action changes get overridden
124 // when Chrome automatically resets them on navigation.
113 if (chrome.runtime.lastError) 125 if (chrome.runtime.lastError)
114 { 126 {
115 // If the tab is prerendered, chrome.tabs.get() sets
116 // chrome.runtime.lastError and we have to immediately dispatch the
117 // "onLoading" event, since "onUpdated" events aren't dispatched for
118 // prerendered tabs. The browserAction object (see above) then take
119 // care to delay changes until the tab becomes visible.
120 ext.pages.onLoading._dispatch( 127 ext.pages.onLoading._dispatch(
121 new Page({ 128 new Page({
122 id: details.tabId, 129 id: details.tabId,
123 url: details.url 130 url: details.url
124 }) 131 })
125 ); 132 );
126 }
127 else
128 {
129 // If the tab is already visible, we have to delay the "onLoading"
130 // event until the tab actually switches to "loading" status.
131 // Otherwise browser action changes get overridden when Chrome
132 // automatically resets them for the new page.
133 function onUpdated(tabId, changeInfo, tab)
134 {
135 if (tabId == details.tabId && changeInfo.status == "loading")
136 {
137 chrome.tabs.onUpdated.removeListener(onUpdated);
138 chrome.tabs.onRemoved.removeListener(onRemoved);
139
140 ext.pages.onLoading._dispatch(new Page(tab));
141 }
142 }
143 chrome.tabs.onUpdated.addListener(onUpdated);
144
145 // Make sure to not leak any callbacks, in case the tab
146 // is removed before its status changes to "loading".
147 function onRemoved(tabId)
148 {
149 if (tabId == details.tabId)
150 {
151 chrome.tabs.onUpdated.removeListener(onUpdated);
152 chrome.tabs.onRemoved.removeListener(onRemoved);
153 }
154 }
155 chrome.tabs.onRemoved.addListener(onRemoved);
156 } 133 }
157 }); 134 });
158 } 135 }
159 }); 136 });
160 137
161 function forgetTab(tabId) 138 function forgetTab(tabId)
162 { 139 {
163 ext._removeFromAllPageMaps(tabId); 140 ext._removeFromAllPageMaps(tabId);
164 delete framesOfTabs[tabId]; 141 delete framesOfTabs[tabId];
165 } 142 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 callback(new Page(tab)); 513 callback(new Page(tab));
537 } 514 }
538 else 515 else
539 { 516 {
540 ext.pages.open(optionsUrl, callback); 517 ext.pages.open(optionsUrl, callback);
541 } 518 }
542 }); 519 });
543 }); 520 });
544 }; 521 };
545 })(); 522 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld