зеркало из https://github.com/mozilla/gecko-dev.git
Bug 908191 - Use xpcom-interface caller to do interaction between Inter-App Communication API and run-time prompt. r=gene,fabrice
This commit is contained in:
Родитель
01a275f2cb
Коммит
c4e8fe69ed
|
@ -692,15 +692,6 @@ Services.obs.addObserver(function onSystemMessageOpenApp(subject, topic, data) {
|
|||
shell.openAppForSystemMessage(msg);
|
||||
}, 'system-messages-open-app', false);
|
||||
|
||||
Services.obs.addObserver(function onInterAppCommConnect(subject, topic, data) {
|
||||
data = JSON.parse(data);
|
||||
shell.sendChromeEvent({ type: "inter-app-comm-permission",
|
||||
chromeEventID: data.callerID,
|
||||
manifestURL: data.manifestURL,
|
||||
keyword: data.keyword,
|
||||
peers: data.appsToSelect });
|
||||
}, 'inter-app-comm-select-app', false);
|
||||
|
||||
Services.obs.addObserver(function onFullscreenOriginChange(subject, topic, data) {
|
||||
shell.sendChromeEvent({ type: "fullscreenoriginchange",
|
||||
fullscreenorigin: data });
|
||||
|
@ -768,13 +759,6 @@ var CustomEventManager = {
|
|||
case 'captive-portal-login-cancel':
|
||||
CaptivePortalLoginHelper.handleEvent(detail);
|
||||
break;
|
||||
case 'inter-app-comm-permission':
|
||||
Services.obs.notifyObservers(null, 'inter-app-comm-select-app-result',
|
||||
JSON.stringify({ callerID: detail.chromeEventID,
|
||||
keyword: detail.keyword,
|
||||
manifestURL: detail.manifestURL,
|
||||
selectedApps: detail.peers }));
|
||||
break;
|
||||
case 'inputmethod-update-layouts':
|
||||
KeyboardHelper.handleEvent(detail);
|
||||
break;
|
||||
|
|
|
@ -24,6 +24,10 @@ category xpcom-directory-providers b2g-directory-provider @mozilla.org/b2g/direc
|
|||
component {3a54788b-48cc-4ab4-93d6-0d6a8ef74f8e} ActivitiesGlue.js
|
||||
contract @mozilla.org/dom/activities/ui-glue;1 {3a54788b-48cc-4ab4-93d6-0d6a8ef74f8e}
|
||||
|
||||
# InterAppCommUIGlue.js
|
||||
component {879ee66c-e246-11e3-9910-74d02b97e723} InterAppCommUIGlue.js
|
||||
contract @mozilla.org/dom/apps/inter-app-comm-ui-glue;1 {879ee66c-e246-11e3-9910-74d02b97e723}
|
||||
|
||||
# ProcessGlobal.js
|
||||
component {1a94c87a-5ece-4d11-91e1-d29c29f21b28} ProcessGlobal.js
|
||||
contract @mozilla.org/b2g-process-global;1 {1a94c87a-5ece-4d11-91e1-d29c29f21b28}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict"
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
||||
"resource://gre/modules/SystemAppProxy.jsm");
|
||||
|
||||
const DEBUG = false;
|
||||
function debug(aMsg) {
|
||||
dump("-- InterAppCommUIGlue: " + Date.now() + ": " + aMsg + "\n");
|
||||
}
|
||||
|
||||
function InterAppCommUIGlue() {
|
||||
// This matrix is to store the callerID (a random UUID) / deferral binding.
|
||||
// An example of the object literal is shown below:
|
||||
//
|
||||
// {
|
||||
// "callerID1" : deferred1,
|
||||
// "callerID2" : deferred2
|
||||
// }
|
||||
this._deferreds = {};
|
||||
|
||||
// Listen to the result of selected apps from front-end.
|
||||
SystemAppProxy.addEventListener ("mozIACContentEvent", function (aEvent) {
|
||||
let detail = aEvent.detail;
|
||||
if (detail.type != "inter-app-comm-permission") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
debug("mozIACContentEvent: " + JSON.stringify(detail));
|
||||
}
|
||||
|
||||
let callerID = detail.chromeEventID;
|
||||
let deferred = this._deferreds[callerID];
|
||||
if (!deferred) {
|
||||
if (DEBUG) {
|
||||
debug("Error! Cannot find the deferred for callerID: " + callerID);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
delete this._deferreds[callerID];
|
||||
deferred.resolve({ callerID: callerID,
|
||||
keyword: detail.keyword,
|
||||
manifestURL: detail.manifestURL,
|
||||
selectedApps: detail.peers });
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
InterAppCommUIGlue.prototype = {
|
||||
selectApps: function(aCallerID, aPubAppManifestURL, aKeyword, aAppsToSelect) {
|
||||
let deferred = Promise.defer();
|
||||
this._deferreds[aCallerID] = deferred;
|
||||
|
||||
SystemAppProxy._sendCustomEvent("mozIACChromeEvent",
|
||||
{ type: "inter-app-comm-permission",
|
||||
chromeEventID: aCallerID,
|
||||
manifestURL: aPubAppManifestURL,
|
||||
keyword: aKeyword,
|
||||
peers: aAppsToSelect });
|
||||
|
||||
// TODO Bug 897169 Simulate the return of the app-selected result by
|
||||
// the prompt, which always allows the connection. This dummy codes
|
||||
// will be removed when the UX/UI for the prompt is ready.
|
||||
SystemAppProxy._sendCustomEvent("mozIACContentEvent",
|
||||
{ type: "inter-app-comm-permission",
|
||||
chromeEventID: aCallerID,
|
||||
manifestURL: aPubAppManifestURL,
|
||||
keyword: aKeyword,
|
||||
peers: aAppsToSelect });
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
classID: Components.ID("{879ee66c-e246-11e3-9910-74d02b97e723}"),
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterAppCommUIGlue])
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([InterAppCommUIGlue]);
|
|
@ -13,6 +13,7 @@ EXTRA_COMPONENTS += [
|
|||
'ContentPermissionPrompt.js',
|
||||
'FilePicker.js',
|
||||
'HelperAppDialog.js',
|
||||
'InterAppCommUIGlue.js',
|
||||
'MailtoProtocolHandler.js',
|
||||
'PaymentGlue.js',
|
||||
'ProcessGlobal.js',
|
||||
|
|
|
@ -792,6 +792,7 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
|
|||
@BINPATH@/components/FilePicker.js
|
||||
@BINPATH@/components/HelperAppDialog.js
|
||||
@BINPATH@/components/DownloadsUI.js
|
||||
@BINPATH@/components/InterAppCommUIGlue.js
|
||||
|
||||
#ifndef MOZ_WIDGET_GONK
|
||||
@BINPATH@/components/SimulatorScreen.js
|
||||
|
|
|
@ -52,7 +52,6 @@ const kMessages =["Webapps:Connect",
|
|||
this.InterAppCommService = {
|
||||
init: function() {
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
Services.obs.addObserver(this, "inter-app-comm-select-app-result", false);
|
||||
|
||||
kMessages.forEach(function(aMsg) {
|
||||
ppmm.addMessageListener(aMsg, this);
|
||||
|
@ -544,30 +543,36 @@ this.InterAppCommService = {
|
|||
target: aTarget
|
||||
};
|
||||
|
||||
// TODO Bug 897169 Temporarily disable the notification for popping up
|
||||
// the prompt until the UX/UI for the prompt is confirmed.
|
||||
//
|
||||
// TODO Bug 908191 We need to change the way of interaction between API and
|
||||
// run-time prompt from observer notification to xpcom-interface caller.
|
||||
//
|
||||
/*
|
||||
if (DEBUG) debug("appsToSelect: " + appsToSelect);
|
||||
Services.obs.notifyObservers(null, "inter-app-comm-select-app",
|
||||
JSON.stringify({ callerID: callerID,
|
||||
manifestURL: pubAppManifestURL,
|
||||
keyword: keyword,
|
||||
appsToSelect: appsToSelect }));
|
||||
*/
|
||||
let glue = Cc["@mozilla.org/dom/apps/inter-app-comm-ui-glue;1"]
|
||||
.createInstance(Ci.nsIInterAppCommUIGlue);
|
||||
if (glue) {
|
||||
glue.selectApps(callerID, pubAppManifestURL, keyword, appsToSelect).then(
|
||||
function(aData) {
|
||||
this._handleSelectedApps(aData);
|
||||
}.bind(this),
|
||||
function(aError) {
|
||||
if (DEBUG) {
|
||||
debug("Error occurred in the UI glue component. " + aError)
|
||||
}
|
||||
|
||||
// TODO Bug 897169 Simulate the return of the app-selected result by
|
||||
// the prompt, which always allows the connection. This dummy codes
|
||||
// will be removed when the UX/UI for the prompt is ready.
|
||||
if (DEBUG) debug("appsToSelect: " + appsToSelect);
|
||||
Services.obs.notifyObservers(null, 'inter-app-comm-select-app-result',
|
||||
JSON.stringify({ callerID: callerID,
|
||||
manifestURL: pubAppManifestURL,
|
||||
keyword: keyword,
|
||||
selectedApps: appsToSelect }));
|
||||
// Resolve the caller as if there were no selected apps.
|
||||
this._handleSelectedApps({ callerID: callerID,
|
||||
keyword: keyword,
|
||||
manifestURL: pubAppManifestURL,
|
||||
selectedApps: [] });
|
||||
}.bind(this)
|
||||
);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
debug("Error! The UI glue component is not implemented.")
|
||||
}
|
||||
|
||||
// Resolve the caller as if there were no selected apps.
|
||||
this._handleSelectedApps({ callerID: callerID,
|
||||
keyword: keyword,
|
||||
manifestURL: pubAppManifestURL,
|
||||
selectedApps: [] });
|
||||
}
|
||||
},
|
||||
|
||||
_getConnections: function(aMessage, aTarget) {
|
||||
|
@ -780,7 +785,7 @@ this.InterAppCommService = {
|
|||
message: message });
|
||||
},
|
||||
|
||||
_handleSelectcedApps: function(aData) {
|
||||
_handleSelectedApps: function(aData) {
|
||||
let callerID = aData.callerID;
|
||||
let caller = this._promptUICallers[callerID];
|
||||
if (!caller) {
|
||||
|
@ -877,16 +882,11 @@ this.InterAppCommService = {
|
|||
switch (aTopic) {
|
||||
case "xpcom-shutdown":
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
Services.obs.removeObserver(this, "inter-app-comm-select-app-result");
|
||||
kMessages.forEach(function(aMsg) {
|
||||
ppmm.removeMessageListener(aMsg, this);
|
||||
}, this);
|
||||
ppmm = null;
|
||||
break;
|
||||
case "inter-app-comm-select-app-result":
|
||||
if (DEBUG) debug("inter-app-comm-select-app-result: " + aData);
|
||||
this._handleSelectcedApps(JSON.parse(aData));
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ XPIDL_SOURCES += [
|
|||
'nsIDOMApplicationRegistry2.idl',
|
||||
'nsIDOMMozApplicationEvent.idl',
|
||||
'nsIInterAppCommService.idl',
|
||||
'nsIInterAppCommUIGlue.idl'
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom_apps'
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* To be implemented by @mozilla.org/dom/apps/inter-app-comm-ui-glue;1
|
||||
*/
|
||||
[scriptable, uuid(634555c6-e246-11e3-b427-74d02b97e723)]
|
||||
interface nsIInterAppCommUIGlue : nsISupports
|
||||
{
|
||||
/**
|
||||
* This method is to notify the prompt to let the user select some of the
|
||||
* IAC-eligible apps.
|
||||
*
|
||||
* @param callerID The generated UUID to identify the caller and
|
||||
* should be unique for each call.
|
||||
* @param pubAppManifestURL The manifest URL of the publisher.
|
||||
* @param keyword The IAC keyword.
|
||||
* @param appsToSelect The IAC-eligible apps for selection.
|
||||
*
|
||||
* Returns a promise.
|
||||
*/
|
||||
jsval selectApps(in AString callerID,
|
||||
in AString pubAppManifestURL,
|
||||
in AString keyword,
|
||||
in jsval appsToSelect);
|
||||
};
|
Загрузка…
Ссылка в новой задаче