Bug 949526 - FxAccountsManager and B2G implementation. Part 2: UI Glue r=fabrice
authorFernando Jiménez <ferjmoreno@gmail.com>
Fri, 13 Dec 2013 12:25:26 +0100
changeset 160322 cc7892e78f65ac2c56cb642b8ac65a9b76808f03
parent 160321 bcc13b8db10c9a3ec2ea3153ba737af7d4af149b
child 160323 be0847f85ca9679d0a15769b1f8c8e631ffdfedb
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersfabrice
bugs949526
milestone29.0a1
Bug 949526 - FxAccountsManager and B2G implementation. Part 2: UI Glue r=fabrice
b2g/components/B2GComponents.manifest
b2g/components/FxAccountsUIGlue.js
b2g/components/moz.build
b2g/installer/package-manifest.in
services/fxaccounts/interfaces/moz.build
services/fxaccounts/interfaces/nsIFxAccountsUIGlue.idl
services/fxaccounts/moz.build
--- a/b2g/components/B2GComponents.manifest
+++ b/b2g/components/B2GComponents.manifest
@@ -67,11 +67,15 @@ contract @mozilla.org/network/protocol/a
 component {436ff8f9-0acc-4b11-8ec7-e293efba3141} FilePicker.js
 contract @mozilla.org/filepicker;1 {436ff8f9-0acc-4b11-8ec7-e293efba3141}
 
 # WebappsUpdateTimer.js
 component {637b0f77-2429-49a0-915f-abf5d0db8b9a} WebappsUpdateTimer.js
 contract @mozilla.org/b2g/webapps-update-timer;1 {637b0f77-2429-49a0-915f-abf5d0db8b9a}
 category update-timer WebappsUpdateTimer @mozilla.org/b2g/webapps-update-timer;1,getService,background-update-timer,webapps.update.interval,86400
 
+# FxAccountsUIGlue.js
+component {51875c14-91d7-4b8c-b65d-3549e101228c} FxAccountsUIGlue.js
+contract @mozilla.org/fxaccounts/fxaccounts-ui-glue;1 {51875c14-91d7-4b8c-b65d-3549e101228c}
+
 # HelperAppDialog.js
 component {710322af-e6ae-4b0c-b2c9-1474a87b077e} HelperAppDialog.js
 contract @mozilla.org/helperapplauncherdialog;1 {710322af-e6ae-4b0c-b2c9-1474a87b077e}
new file mode 100644
--- /dev/null
+++ b/b2g/components/FxAccountsUIGlue.js
@@ -0,0 +1,68 @@
+/* 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 { interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/ObjectWrapper.jsm");
+Cu.import("resource://gre/modules/Promise.jsm");
+
+XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
+                                   "@mozilla.org/uuid-generator;1",
+                                   "nsIUUIDGenerator");
+
+function FxAccountsUIGlue() {
+}
+
+FxAccountsUIGlue.prototype = {
+
+  _browser: Services.wm.getMostRecentWindow("navigator:browser"),
+
+  signInFlow: function() {
+    let deferred = Promise.defer();
+
+    let content = this._browser.getContentWindow();
+    if (!content) {
+      deferred.reject("InternalErrorNoContent");
+      return;
+    }
+
+    let id = uuidgen.generateUUID().toString();
+
+    content.addEventListener("mozFxAccountsRPContentEvent",
+                             function onContentEvent(result) {
+      let msg = result.detail;
+      if (!msg || !msg.id || msg.id != id) {
+        deferred.reject("InternalErrorWrongContentEvent");
+        content.removeEventListener("mozFxAccountsRPContentEvent",
+                                    onContentEvent);
+        return;
+      }
+
+      if (msg.error) {
+        deferred.reject(msg);
+      } else {
+        deferred.resolve(msg.result);
+      }
+      content.removeEventListener("mozFxAccountsRPContentEvent",
+                                  onContentEvent);
+    });
+
+    this._browser.shell.sendCustomEvent("mozFxAccountsRPChromeEvent", {
+      method: "openFlow",
+      id: id
+    });
+
+    return deferred.promise;
+  },
+
+  classID: Components.ID("{51875c14-91d7-4b8c-b65d-3549e101228c}"),
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFxAccountsUIGlue])
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FxAccountsUIGlue]);
--- a/b2g/components/moz.build
+++ b/b2g/components/moz.build
@@ -8,16 +8,17 @@ TEST_DIRS += ['test']
 
 EXTRA_COMPONENTS += [
     'ActivitiesGlue.js',
     'AlertsService.js',
     'B2GAboutRedirector.js',
     'ContentHandler.js',
     'ContentPermissionPrompt.js',
     'FilePicker.js',
+    'FxAccountsUIGlue.js',
     'HelperAppDialog.js',
     'MailtoProtocolHandler.js',
     'PaymentGlue.js',
     'ProcessGlobal.js',
     'SmsProtocolHandler.js',
     'TelProtocolHandler.js',
     'WebappsUpdateTimer.js',
     'YoutubeProtocolHandler.js',
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -784,23 +784,26 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DL
 @BINPATH@/components/PaymentGlue.js
 @BINPATH@/components/YoutubeProtocolHandler.js
 @BINPATH@/components/RecoveryService.js
 @BINPATH@/components/MailtoProtocolHandler.js
 @BINPATH@/components/SmsProtocolHandler.js
 @BINPATH@/components/TelProtocolHandler.js
 @BINPATH@/components/B2GAboutRedirector.js
 @BINPATH@/components/FilePicker.js
+@BINPATH@/components/FxAccountsUIGlue.js
 @BINPATH@/components/HelperAppDialog.js
 @BINPATH@/components/DownloadsUI.js
 
 @BINPATH@/components/DataStore.manifest
 @BINPATH@/components/DataStoreService.js
 @BINPATH@/components/dom_datastore.xpt
 
+@BINPATH@/components/services_fxaccounts.xpt
+
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
 #ifdef XP_MACOSX
 @BINPATH@/@DLL_PREFIX@plugin_child_interpose@DLL_SUFFIX@
 #endif
 
new file mode 100644
--- /dev/null
+++ b/services/fxaccounts/interfaces/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+XPIDL_SOURCES += [
+    'nsIFxAccountsUIGlue.idl'
+]
+
+XPIDL_MODULE = 'services_fxaccounts'
new file mode 100644
--- /dev/null
+++ b/services/fxaccounts/interfaces/nsIFxAccountsUIGlue.idl
@@ -0,0 +1,12 @@
+/* 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"
+
+[scriptable, uuid(5805ac8b-7cbe-4fbd-97ad-d3ae8cd29f79)]
+interface nsIFxAccountsUIGlue : nsISupports
+{
+  // Returns a Promise.
+  jsval signInFlow();
+};
--- a/services/fxaccounts/moz.build
+++ b/services/fxaccounts/moz.build
@@ -1,14 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
+PARALLEL_DIRS += ['interfaces']
+
 TEST_DIRS += ['tests']
 
 EXTRA_JS_MODULES += [
   'FxAccounts.jsm',
   'FxAccountsClient.jsm',
   'FxAccountsConsts.js'
 ]