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

Side by Side Diff: js/desktop-options.js

Issue 29715759: Issue 6440 - Use long-lived connections to listen to extension events (Closed)
Patch Set: Created March 6, 2018, 6:35 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
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-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 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 tooltip.setAttribute("role", "tooltip"); 1412 tooltip.setAttribute("role", "tooltip");
1413 1413
1414 let paragraph = document.createElement("p"); 1414 let paragraph = document.createElement("p");
1415 paragraph.textContent = getMessage(id); 1415 paragraph.textContent = getMessage(id);
1416 tooltip.appendChild(paragraph); 1416 tooltip.appendChild(paragraph);
1417 1417
1418 wrapper.appendChild(tooltip); 1418 wrapper.appendChild(tooltip);
1419 } 1419 }
1420 } 1420 }
1421 1421
1422 ext.onMessage.addListener((message) => 1422 let port = browser.runtime.connect({name: "ui"});
1423
1424 port.onMessage.addListener((message) =>
1423 { 1425 {
1424 switch (message.type) 1426 switch (message.type)
1425 { 1427 {
1426 case "app.respond": 1428 case "app.respond":
1427 switch (message.action) 1429 switch (message.action)
1428 { 1430 {
1429 case "addSubscription": 1431 case "addSubscription":
1430 let subscription = message.args[0]; 1432 let subscription = message.args[0];
1431 let dialog = E("dialog-content-predefined"); 1433 let dialog = E("dialog-content-predefined");
1432 dialog.querySelector("h3").textContent = subscription.title || ""; 1434 dialog.querySelector("h3").textContent = subscription.title || "";
(...skipping 10 matching lines...) Expand all
1443 break; 1445 break;
1444 case "prefs.respond": 1446 case "prefs.respond":
1445 onPrefMessage(message.action, message.args[0], false); 1447 onPrefMessage(message.action, message.args[0], false);
1446 break; 1448 break;
1447 case "subscriptions.respond": 1449 case "subscriptions.respond":
1448 onSubscriptionMessage(message.action, message.args[0]); 1450 onSubscriptionMessage(message.action, message.args[0]);
1449 break; 1451 break;
1450 } 1452 }
1451 }); 1453 });
1452 1454
1453 browser.runtime.sendMessage({ 1455 port.postMessage({
1454 type: "app.listen", 1456 type: "app.listen",
1455 filter: ["addSubscription", "focusSection"] 1457 filter: ["addSubscription", "focusSection"]
1456 }); 1458 });
1457 browser.runtime.sendMessage({ 1459 port.postMessage({
1458 type: "filters.listen", 1460 type: "filters.listen",
1459 filter: ["added", "loaded", "removed"] 1461 filter: ["added", "loaded", "removed"]
1460 }); 1462 });
1461 browser.runtime.sendMessage({ 1463 port.postMessage({
1462 type: "prefs.listen", 1464 type: "prefs.listen",
1463 filter: ["notifications_ignoredcategories", "notifications_showui", 1465 filter: ["notifications_ignoredcategories", "notifications_showui",
1464 "show_devtools_panel", "shouldShowBlockElementMenu", 1466 "show_devtools_panel", "shouldShowBlockElementMenu",
1465 "ui_warn_tracking"] 1467 "ui_warn_tracking"]
1466 }); 1468 });
1467 browser.runtime.sendMessage({ 1469 port.postMessage({
1468 type: "subscriptions.listen", 1470 type: "subscriptions.listen",
1469 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1471 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1470 "title", "downloadStatus", "downloading"] 1472 "title", "downloadStatus", "downloading"]
1471 }); 1473 });
1472 1474
1473 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1475 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1474 window.addEventListener("hashchange", onHashChange, false); 1476 window.addEventListener("hashchange", onHashChange, false);
OLDNEW
« no previous file with comments | « firstRun.js ('k') | messageResponder.js » ('j') | messageResponder.js » ('J')

Powered by Google App Engine
This is Rietveld