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.

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

mercurial