From 06c91b453ad085481844d53b343414dfe522a3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Mon, 28 Jul 2014 11:06:00 -0700 Subject: [PATCH] Bug 1037662 - Grant Firefox Accounts (FxA) access to web payment providers r=ferjm --- dom/payment/Payment.jsm | 30 +++++++++++++++++++++++++++++- dom/payment/moz.build | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dom/payment/Payment.jsm b/dom/payment/Payment.jsm index d9e981e4c0bd..1a0d519d9f22 100644 --- a/dom/payment/Payment.jsm +++ b/dom/payment/Payment.jsm @@ -198,6 +198,18 @@ let PaymentManager = { } } +#ifdef MOZ_B2G + let appsService = Cc["@mozilla.org/AppsService;1"] + .getService(Ci.nsIAppsService); + let systemAppId = Ci.nsIScriptSecurityManager.NO_APP_ID; + + try { + let manifestURL = Services.prefs.getCharPref("b2g.system_manifest_url"); + systemAppId = appsService.getAppLocalIdByManifestURL(manifestURL); + this.LOG("System app id=" + systemAppId); + } catch(e) {} +#endif + // Now register the payment providers. for (let i in nums) { let branch = prefService @@ -211,12 +223,28 @@ let PaymentManager = { if (type in this.registeredProviders) { continue; } - this.registeredProviders[type] = { + let provider = this.registeredProviders[type] = { name: branch.getCharPref("name"), uri: branch.getCharPref("uri"), description: branch.getCharPref("description"), requestMethod: branch.getCharPref("requestMethod") }; + +#ifdef MOZ_B2G + // Let this payment provider access the firefox-accounts API when + // it's loaded in the trusted UI. + if (systemAppId != Ci.nsIScriptSecurityManager.NO_APP_ID) { + this.LOG("Granting firefox-accounts permission to " + provider.uri); + let uri = Services.io.newURI(provider.uri, null, null); + let principal = Services.scriptSecurityManager + .getAppCodebasePrincipal(uri, systemAppId, true); + + Services.perms.addFromPrincipal(principal, "firefox-accounts", + Ci.nsIPermissionManager.ALLOW_ACTION, + Ci.nsIPermissionManager.EXPIRE_SESSION); + } +#endif + if (this._debug) { this.LOG("Registered Payment Providers: " + JSON.stringify(this.registeredProviders[type])); diff --git a/dom/payment/moz.build b/dom/payment/moz.build index c697d97fc0d7..82399c403c04 100644 --- a/dom/payment/moz.build +++ b/dom/payment/moz.build @@ -6,7 +6,7 @@ PARALLEL_DIRS += ['interfaces'] -EXTRA_JS_MODULES += [ +EXTRA_PP_JS_MODULES += [ 'Payment.jsm', ]