Left: | ||
Right: |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 else | 231 else |
232 return browser.windows.get(window.id, {populate: true}); | 232 return browser.windows.get(window.id, {populate: true}); |
233 }).then(window => | 233 }).then(window => |
234 { | 234 { |
235 let popupPageId = window.tabs[0].id; | 235 let popupPageId = window.tabs[0].id; |
236 | 236 |
237 let doInitAttempt = 0; | 237 let doInitAttempt = 0; |
238 let doInit = () => | 238 let doInit = () => |
239 { | 239 { |
240 doInitAttempt += 1; | 240 doInitAttempt += 1; |
241 if (doInitAttempt > 3) | 241 if (doInitAttempt > 30) |
kzar
2017/12/07 13:28:33
With other versions of Firefox e.g. 57 I found tha
| |
242 return; | 242 return; |
243 | 243 |
244 browser.tabs.sendMessage(popupPageId, { | 244 browser.tabs.sendMessage(popupPageId, { |
245 type: "composer.dialog.init", | 245 type: "composer.dialog.init", |
246 sender: sender.page.id, | 246 sender: sender.page.id, |
247 filters: message.filters | 247 filters: message.filters |
248 }).then(response => | |
249 { | |
250 // Sometimes sendMessage incorrectly reports a success on Firefox, so | |
251 // we must check the response too. | |
252 if (typeof response == "undefined") | |
Wladimir Palant
2017/12/12 12:14:52
Nit: why not `if (!response)`?
kzar
2017/12/12 12:33:14
Done.
| |
253 throw new Error(); | |
248 }).catch(e => | 254 }).catch(e => |
249 { | 255 { |
250 // Firefox sometimes sets the status for a window to "complete" before | 256 // Firefox sometimes sets the status for a window to "complete" before |
251 // it is ready to receive messages[1]. As a workaround we'll try again a | 257 // it is ready to receive messages[1]. As a workaround we'll try again a |
252 // few times with a second delay. | 258 // few times with a second delay. |
253 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1418655 | 259 // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1418655 |
254 setTimeout(doInit, 1000); | 260 setTimeout(doInit, 100); |
255 }); | 261 }); |
256 }; | 262 }; |
257 if (window.tabs[0].status != "complete") | 263 if (window.tabs[0].status != "complete") |
258 { | 264 { |
259 let updateListener = (tabId, changeInfo, tab) => | 265 let updateListener = (tabId, changeInfo, tab) => |
260 { | 266 { |
261 if (tabId == popupPageId && changeInfo.status == "complete") | 267 if (tabId == popupPageId && changeInfo.status == "complete") |
262 { | 268 { |
263 browser.tabs.onUpdated.removeListener(updateListener); | 269 browser.tabs.onUpdated.removeListener(updateListener); |
264 doInit(); | 270 doInit(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 { | 318 { |
313 return quoteCSS(message.CSS); | 319 return quoteCSS(message.CSS); |
314 }); | 320 }); |
315 | 321 |
316 ext.pages.onLoading.addListener(page => | 322 ext.pages.onLoading.addListener(page => |
317 { | 323 { |
318 // A newly opened tab that is still loading has its URL set to about:blank | 324 // A newly opened tab that is still loading has its URL set to about:blank |
319 if (/^https?:/.test(page.url.protocol)) | 325 if (/^https?:/.test(page.url.protocol)) |
320 page.sendMessage({type: "composer.content.finished"}); | 326 page.sendMessage({type: "composer.content.finished"}); |
321 }); | 327 }); |
OLD | NEW |