mobile/android/modules/Accounts.jsm

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 this.EXPORTED_SYMBOLS = ["Accounts"];
michael@0 8
michael@0 9 const { utils: Cu } = Components;
michael@0 10
michael@0 11 Cu.import("resource://gre/modules/Messaging.jsm");
michael@0 12 Cu.import("resource://gre/modules/Services.jsm");
michael@0 13 Cu.import("resource://gre/modules/Promise.jsm");
michael@0 14
michael@0 15 /**
michael@0 16 * A promise-based API for querying the existence of Sync accounts,
michael@0 17 * and accessing the Sync setup wizard.
michael@0 18 *
michael@0 19 * Usage:
michael@0 20 *
michael@0 21 * Cu.import("resource://gre/modules/Accounts.jsm");
michael@0 22 * Accounts.anySyncAccountsExist().then(
michael@0 23 * (exist) => {
michael@0 24 * console.log("Accounts exist? " + exist);
michael@0 25 * if (!exist) {
michael@0 26 * Accounts.launchSetup();
michael@0 27 * }
michael@0 28 * },
michael@0 29 * (err) => {
michael@0 30 * console.log("We failed so hard.");
michael@0 31 * }
michael@0 32 * );
michael@0 33 */
michael@0 34 let Accounts = Object.freeze({
michael@0 35 _accountsExist: function (kind) {
michael@0 36 let deferred = Promise.defer();
michael@0 37
michael@0 38 sendMessageToJava({
michael@0 39 type: "Accounts:Exist",
michael@0 40 kind: kind,
michael@0 41 }, (data, error) => {
michael@0 42 if (error) {
michael@0 43 deferred.reject(error);
michael@0 44 } else {
michael@0 45 deferred.resolve(data.exists);
michael@0 46 }
michael@0 47 });
michael@0 48
michael@0 49 return deferred.promise;
michael@0 50 },
michael@0 51
michael@0 52 firefoxAccountsExist: function () {
michael@0 53 return this._accountsExist("fxa");
michael@0 54 },
michael@0 55
michael@0 56 syncAccountsExist: function () {
michael@0 57 return this._accountsExist("sync11");
michael@0 58 },
michael@0 59
michael@0 60 anySyncAccountsExist: function () {
michael@0 61 return this._accountsExist("any");
michael@0 62 },
michael@0 63
michael@0 64 /**
michael@0 65 * Fire-and-forget: open the Firefox accounts activity, which
michael@0 66 * will be the Getting Started screen if FxA isn't yet set up.
michael@0 67 *
michael@0 68 * There is no return value from this method.
michael@0 69 */
michael@0 70 launchSetup: function () {
michael@0 71 sendMessageToJava({
michael@0 72 type: "Accounts:Create",
michael@0 73 });
michael@0 74 },
michael@0 75 });
michael@0 76

mercurial