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

Side by Side Diff: ext/content.js

Issue 29715759: Issue 6440 - Use long-lived connections to listen to extension events (Closed)
Patch Set: Added message passing mock for ports Created March 7, 2018, 7:10 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
« ext/common.js ('K') | « ext/common.js ('k') | firstRun.js » ('j') | 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-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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ext.backgroundPage = { 52 ext.backgroundPage = {
53 _sendRawMessage(message) 53 _sendRawMessage(message)
54 { 54 {
55 if (messageQueue) 55 if (messageQueue)
56 messageQueue.push(message); 56 messageQueue.push(message);
57 else 57 else
58 backgroundFrame.contentWindow.postMessage(message, "*"); 58 backgroundFrame.contentWindow.postMessage(message, "*");
59 } 59 }
60 }; 60 };
61 61
62 /* Polyfills */ 62 /* Message passing */
63 63
64 if (!("runtime" in browser)) 64 if (!("runtime" in browser))
65 browser.runtime = {}; 65 browser.runtime = {};
66 66
67 browser.runtime.sendMessage = (message, responseCallback) => 67 browser.runtime.sendMessage = (message, responseCallback) =>
68 { 68 {
69 let messageId = ++maxMessageId; 69 let messageId = ++maxMessageId;
70 70
71 ext.backgroundPage._sendRawMessage({ 71 ext.backgroundPage._sendRawMessage({
72 type: "message", 72 type: "message",
(...skipping 16 matching lines...) Expand all
89 resolvePromise = responseCallback; 89 resolvePromise = responseCallback;
90 } 90 }
91 else 91 else
92 { 92 {
93 return new Promise((resolve, reject) => 93 return new Promise((resolve, reject) =>
94 { 94 {
95 resolvePromise = resolve; 95 resolvePromise = resolve;
96 }); 96 });
97 } 97 }
98 }; 98 };
99
100 function postMessage(msg)
101 {
102 ext.backgroundPage._sendRawMessage({
103 type: "port",
104 name: this._name,
105 payload: msg
106 });
107 }
108 ext._Port.prototype.postMessage = postMessage;
109
110 function connect({name})
111 {
112 ext.backgroundPage._sendRawMessage({type: "connect", name});
113 return new ext._Port(name);
114 }
115 browser.runtime.connect = connect;
99 }()); 116 }());
OLDNEW
« ext/common.js ('K') | « ext/common.js ('k') | firstRun.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld