1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/modules/Accounts.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +this.EXPORTED_SYMBOLS = ["Accounts"]; 1.11 + 1.12 +const { utils: Cu } = Components; 1.13 + 1.14 +Cu.import("resource://gre/modules/Messaging.jsm"); 1.15 +Cu.import("resource://gre/modules/Services.jsm"); 1.16 +Cu.import("resource://gre/modules/Promise.jsm"); 1.17 + 1.18 +/** 1.19 + * A promise-based API for querying the existence of Sync accounts, 1.20 + * and accessing the Sync setup wizard. 1.21 + * 1.22 + * Usage: 1.23 + * 1.24 + * Cu.import("resource://gre/modules/Accounts.jsm"); 1.25 + * Accounts.anySyncAccountsExist().then( 1.26 + * (exist) => { 1.27 + * console.log("Accounts exist? " + exist); 1.28 + * if (!exist) { 1.29 + * Accounts.launchSetup(); 1.30 + * } 1.31 + * }, 1.32 + * (err) => { 1.33 + * console.log("We failed so hard."); 1.34 + * } 1.35 + * ); 1.36 + */ 1.37 +let Accounts = Object.freeze({ 1.38 + _accountsExist: function (kind) { 1.39 + let deferred = Promise.defer(); 1.40 + 1.41 + sendMessageToJava({ 1.42 + type: "Accounts:Exist", 1.43 + kind: kind, 1.44 + }, (data, error) => { 1.45 + if (error) { 1.46 + deferred.reject(error); 1.47 + } else { 1.48 + deferred.resolve(data.exists); 1.49 + } 1.50 + }); 1.51 + 1.52 + return deferred.promise; 1.53 + }, 1.54 + 1.55 + firefoxAccountsExist: function () { 1.56 + return this._accountsExist("fxa"); 1.57 + }, 1.58 + 1.59 + syncAccountsExist: function () { 1.60 + return this._accountsExist("sync11"); 1.61 + }, 1.62 + 1.63 + anySyncAccountsExist: function () { 1.64 + return this._accountsExist("any"); 1.65 + }, 1.66 + 1.67 + /** 1.68 + * Fire-and-forget: open the Firefox accounts activity, which 1.69 + * will be the Getting Started screen if FxA isn't yet set up. 1.70 + * 1.71 + * There is no return value from this method. 1.72 + */ 1.73 + launchSetup: function () { 1.74 + sendMessageToJava({ 1.75 + type: "Accounts:Create", 1.76 + }); 1.77 + }, 1.78 +}); 1.79 +