OLD | NEW |
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 Loading... |
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) | 105 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
106 { | 106 { |
107 if (changeInfo.status == "loading") | 107 if (details.frameId == 0) |
108 ext.pages.onLoading._dispatch(new Page(tab)); | 108 { |
| 109 ext._removeFromAllPageMaps(details.tabId); |
| 110 |
| 111 chrome.tabs.get(details.tabId, function() |
| 112 { |
| 113 if (chrome.runtime.lastError) |
| 114 { |
| 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( |
| 121 new Page({ |
| 122 id: details.tabId, |
| 123 url: details.url |
| 124 }) |
| 125 ); |
| 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 } |
| 157 }); |
| 158 } |
109 }); | 159 }); |
110 | 160 |
111 function forgetTab(tabId) | 161 function forgetTab(tabId) |
112 { | 162 { |
113 ext._removeFromAllPageMaps(tabId); | 163 ext._removeFromAllPageMaps(tabId); |
114 delete framesOfTabs[tabId]; | 164 delete framesOfTabs[tabId]; |
115 } | 165 } |
116 | 166 |
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) | 167 chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) |
124 { | 168 { |
125 forgetTab(removedTabId); | 169 forgetTab(removedTabId); |
126 }); | 170 }); |
127 | 171 |
128 chrome.tabs.onRemoved.addListener(forgetTab); | 172 chrome.tabs.onRemoved.addListener(forgetTab); |
129 | 173 |
130 | 174 |
131 /* Browser actions */ | 175 /* Browser actions */ |
132 | 176 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 callback(new Page(tab)); | 536 callback(new Page(tab)); |
493 } | 537 } |
494 else | 538 else |
495 { | 539 { |
496 ext.pages.open(optionsUrl, callback); | 540 ext.pages.open(optionsUrl, callback); |
497 } | 541 } |
498 }); | 542 }); |
499 }); | 543 }); |
500 }; | 544 }; |
501 })(); | 545 })(); |
OLD | NEW |