update readme
[dotfiles/.git] / .config / BraveSoftware / Brave-Browser / Default / Extensions / cimiefiiaegbelhefglklhhakcgmhkai / 1.7.6_0 / content-utils.js
1 /*
2     Copyright (C) 2017, 2019 Kai Uwe Broulik <kde@privat.broulik.de>
3     Copyright (C) 2018 David Edmundson <davidedmundson@kde.org>
4
5     This program is free software; you can redistribute it and/or
6     modify it under the terms of the GNU General Public License as
7     published by the Free Software Foundation; either version 3 of
8     the License, or (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 function sendMessage(subsystem, action, payload) {
20     let data = {
21         subsystem: subsystem,
22         action: action,
23         payload: payload
24     };
25
26     if (chrome.extension && chrome.extension.sendMessage) {
27         return new Promise((resolve, reject) => {
28             chrome.extension.sendMessage(data, (reply) => {
29                 if (chrome.runtime.lastError) {
30                     if (chrome.runtime.lastError.message === "The message port closed before a response was received.") {
31                         resolve();
32                     } else {
33                         reject(chrome.runtime.lastError);
34                     }
35                     return;
36                 }
37
38                 if (reply && reply.rejected) {
39                     reject(reply);
40                 } else {
41                     resolve(reply);
42                 }
43             });
44         });
45     }
46
47     return browser.runtime.sendMessage(data);
48 }