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

Delta Between Two Patch Sets: options.js

Issue 29536764: Issue 5587, 5748 - Use mobile options page on Firefox for Android (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Queue up messages from background page and forward them later Created Sept. 15, 2017, 5:49 p.m.
Right Patch Set: Remove workaround for FOUC issue and update adblockplusui dependency Created Oct. 5, 2017, 1:24 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 | « options.html ('k') | popup.js » ('j') | 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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {require} = chrome.extension.getBackgroundPage();
21
22 let messageQueue = [];
Manish Jethani 2017/09/15 17:57:27 Let me explain this. Basically the top frame's lo
23
24 let iframe = document.getElementById("content"); 20 let iframe = document.getElementById("content");
25 21
26 function queueMessage(message, sender, sendResponse) 22 iframe.onload = () =>
27 { 23 {
28 // Ignore messages from anywhere but the background page. 24 document.title = iframe.contentDocument.title;
Manish Jethani 2017/09/15 17:57:28 We probably only need to ignore messages from the
29 if (sender.tab || 25 };
30 sender.url && sender.url != chrome.extension.getBackgroundPage().location)
31 {
32 return false;
33 }
34 26
35 messageQueue.push({message, sendResponse}); 27 chrome.runtime.sendMessage({
Oleksandr 2017/10/09 11:49:59 Edge does not support the 'chrome' namespace for e
Manish Jethani 2017/10/09 12:00:55 Thanks.
Sebastian Noack 2017/10/09 15:09:55 Note that we already do so in ext/common.js: https
36 28 type: "app.get",
37 // Return true to make the background page wait for the response. 29 what: "application"
Thomas Greiner 2017/09/19 17:51:21 The UI may or may not call `sendResponse()` so we
Manish Jethani 2017/09/19 19:42:05 OK, in that case queueMessage now doesn't return a
38 return true; 30 },
39 } 31 application =>
40
41 function handleContentLoad(event)
42 { 32 {
43 iframe.onload = null; 33 // Load the mobile version of the options page on Firefox for Android.
44 34 iframe.src = iframe.getAttribute("data-src-" + application) ||
45 chrome.runtime.onMessage.removeListener(queueMessage); 35 iframe.getAttribute("data-src");
46 36 });
47 // Make a local reference to the message queue and release the global
48 // reference to avoid any memory leaks.
49 let messageQueueLocalReference = messageQueue;
Manish Jethani 2017/09/15 17:57:28 This is just a safety measure just in case any err
50 messageQueue = null;
51
52 // Process message queue.
53 for (let {message, sendResponse} of messageQueueLocalReference)
54 iframe.contentWindow.ext.onMessage._dispatch(message, {}, sendResponse);
55 }
56
57 // Queue up messages from the background page until the content has finished
58 // loading.
59 chrome.runtime.onMessage.addListener(queueMessage);
60
61 // When the content has finished loading, stop listening for messages from the
62 // background page and forward all the queued up messages to the content
63 // document.
64 iframe.onload = handleContentLoad;
65
66 // Load the mobile version of the options page on Firefox for Android.
67 iframe.src = iframe.getAttribute("data-src-" + require("info").application) ||
68 iframe.getAttribute("data-src");
LEFTRIGHT

Powered by Google App Engine
This is Rietveld