Index: toolkit/components/extensions/ext-c-runtime.js |
=================================================================== |
--- a/toolkit/components/extensions/ext-c-runtime.js |
+++ b/toolkit/components/extensions/ext-c-runtime.js |
@@ -1,16 +1,38 @@ |
"use strict"; |
+Components.utils.import("resource://gre/modules/Messaging.jsm"); |
+ |
this.runtime = class extends ExtensionAPI { |
getAPI(context) { |
let {extension} = context; |
return { |
runtime: { |
+ |
+ // Added functions in order to make possible the communication between |
+ // the Android part and the extension. |
+ // See https://issues.adblockplus.org/ticket/6865 |
+ registerAbbMessageListener: function(listener) { |
+ EventDispatcher.instance.registerListener((event, data, callback) => |
+ { |
+ let result = context.runSafe(listener, data); |
+ if (result["success"]) { |
+ callback.onSuccess(result); |
+ } else { |
+ let errorMsg = result["error"] ? result["error"] : "An error has ocurred"; |
+ callback.onError(errorMsg); |
+ } |
+ }, "Abb:Api"); |
+ }, |
+ sendAbbMessage: function(type) { |
+ EventDispatcher.instance.sendRequest({"type": "Abb:" + type}); |
+ }, |
+ |
onConnect: context.messenger.onConnect("runtime.onConnect"), |
onMessage: context.messenger.onMessage("runtime.onMessage"), |
onConnectExternal: context.messenger.onConnectExternal("runtime.onConnectExternal"), |
onMessageExternal: context.messenger.onMessageExternal("runtime.onMessageExternal"), |