"use strict";const{classes:Cc,interfaces:Ci,utils:Cu,results:Cr}=Components;Cu.import("resource://gre/modules/Services.jsm");Cu.import("resource://gre/modules/XPCOMUtils.jsm");Cu.import("resource://gre/modules/DOMRequestHelper.jsm");XPCOMUtils.defineLazyServiceGetter(this,"cpmm","@mozilla.org/childprocessmessagemanager;1","nsIMessageSender");XPCOMUtils.defineLazyServiceGetter(this,"appsService","@mozilla.org/AppsService;1","nsIAppsService");const DEBUG=false;function debug(aMsg){dump("-- InterAppConnection: "+Date.now()+": "+aMsg+"\n");}
function InterAppConnection(){if(DEBUG)debug("InterAppConnection()");this.keyword=null;this.publisher=null;this.subscriber=null;};InterAppConnection.prototype={__proto__:DOMRequestIpcHelper.prototype,classDescription:"MozInterAppConnection",classID:Components.ID("{9dbfa904-0718-11e3-8e77-0721a45514b8}"),contractID:"@mozilla.org/dom/inter-app-connection;1",QueryInterface:XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,Ci.nsISupportsWeakReference,Ci.nsIObserver]),__init:function(aKeyword,aPublisher,aSubscriber){if(DEBUG){debug("__init: aKeyword: "+aKeyword+" aPublisher: "+aPublisher+" aSubscriber: "+aSubscriber);}
this.keyword=aKeyword;this.publisher=aPublisher;this.subscriber=aSubscriber;},init:function(aWindow){if(DEBUG)debug("init");this.initDOMRequestHelper(aWindow,[]);let principal=aWindow.document.nodePrincipal;this._manifestURL=appsService.getManifestURLByLocalId(principal.appId);},cancel:function(){if(DEBUG)debug("cancel");cpmm.sendAsyncMessage("InterAppConnection:Cancel",{keyword:this.keyword,pubAppManifestURL:this.publisher,subAppManifestURL:this.subscriber,manifestURL:this._manifestURL});}};function InterAppConnectionRequest(){if(DEBUG)debug("InterAppConnectionRequest()");this.keyword=null;this.port=null;};InterAppConnectionRequest.prototype={classDescription:"MozInterAppConnectionRequest",classID:Components.ID("{6a77e9e0-0645-11e3-b90b-73bb7c78e06a}"),contractID:"@mozilla.org/dom/inter-app-connection-request;1",QueryInterface:XPCOMUtils.generateQI([Ci.nsISupports]),__init:function(aKeyword,aPort){if(DEBUG)debug("__init: aKeyword: "+aKeyword+" aPort: "+aPort);this.keyword=aKeyword;this.port=aPort;}};function InterAppConnectionRequestWrapper(){if(DEBUG)debug("InterAppConnectionRequestWrapper()");}
InterAppConnectionRequestWrapper.prototype={wrapMessage:function(aMessage,aWindow){if(DEBUG)debug("wrapMessage: "+JSON.stringify(aMessage));let port=new aWindow.MozInterAppMessagePort(aMessage.messagePortID);let connectionRequest=new aWindow.MozInterAppConnectionRequest(aMessage.keyword,port);return connectionRequest;},classDescription:"InterAppConnectionRequestWrapper",classID:Components.ID("{d7c7a466-f91d-11e2-812a-6fab12ece58e}"),contractID:"@mozilla.org/dom/system-messages/wrapper/connection;1",QueryInterface:XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])}
this.NSGetFactory=XPCOMUtils.generateNSGetFactory([InterAppConnection,InterAppConnectionRequest,InterAppConnectionRequestWrapper]);