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

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

Issue 5943816674607104: Issue 1983 - Dispatch onLoading event for prerendered pages (Closed)
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:
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-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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 105 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
106 { 106 {
107 if (changeInfo.status == "loading") 107 if (changeInfo.status == "loading")
108 ext.pages.onLoading._dispatch(new Page(tab)); 108 ext.pages.onLoading._dispatch(new Page(tab));
109 }); 109 });
110 110
111 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
112 {
113 if (details.frameId == 0)
114 {
115 ext._removeFromAllPageMaps(details.tabId);
116
117 chrome.tabs.get(details.tabId, function()
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.
125 if (chrome.runtime.lastError)
126 {
127 ext.pages.onLoading._dispatch(
128 new Page({
129 id: details.tabId,
130 url: details.url
131 })
132 );
133 }
134 });
135 }
136 });
137
111 function forgetTab(tabId) 138 function forgetTab(tabId)
112 { 139 {
113 ext._removeFromAllPageMaps(tabId); 140 ext._removeFromAllPageMaps(tabId);
114 delete framesOfTabs[tabId]; 141 delete framesOfTabs[tabId];
115 } 142 }
116 143
117 chrome.webNavigation.onBeforeNavigate.addListener(function(details)
118 {
119 if (details.frameId == 0)
120 forgetTab(details.tabId);
121 });
122
123 chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) 144 chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId)
124 { 145 {
125 forgetTab(removedTabId); 146 forgetTab(removedTabId);
126 }); 147 });
127 148
128 chrome.tabs.onRemoved.addListener(forgetTab); 149 chrome.tabs.onRemoved.addListener(forgetTab);
129 150
130 151
131 /* Browser actions */ 152 /* Browser actions */
132 153
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 callback(new Page(tab)); 513 callback(new Page(tab));
493 } 514 }
494 else 515 else
495 { 516 {
496 ext.pages.open(optionsUrl, callback); 517 ext.pages.open(optionsUrl, callback);
497 } 518 }
498 }); 519 });
499 }); 520 });
500 }; 521 };
501 })(); 522 })();
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