Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 const { interfaces: Ci, utils: Cu } = Components;
9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
10 Cu.import("resource://gre/modules/Services.jsm");
11 Cu.import("resource://gre/modules/Promise.jsm");
12 Cu.import("resource://gre/modules/FxAccountsCommon.js");
14 XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
15 "@mozilla.org/uuid-generator;1",
16 "nsIUUIDGenerator");
18 XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
19 "resource://gre/modules/SystemAppProxy.jsm");
21 function FxAccountsUIGlue() {
22 }
24 FxAccountsUIGlue.prototype = {
26 _contentRequest: function(aEventName, aData) {
27 let deferred = Promise.defer();
29 let id = uuidgen.generateUUID().toString();
31 SystemAppProxy.addEventListener("mozFxAccountsRPContentEvent",
32 function onContentEvent(result) {
33 let msg = result.detail;
34 if (!msg || !msg.id || msg.id != id) {
35 deferred.reject("InternalErrorWrongContentEvent");
36 SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
37 onContentEvent);
38 return;
39 }
41 log.debug("Got content event " + JSON.stringify(msg));
43 if (msg.error) {
44 deferred.reject(msg);
45 } else {
46 deferred.resolve(msg.result);
47 }
48 SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
49 onContentEvent);
50 });
52 let detail = {
53 eventName: aEventName,
54 id: id,
55 data: aData
56 };
57 log.debug("Send chrome event " + JSON.stringify(detail));
58 SystemAppProxy._sendCustomEvent("mozFxAccountsUnsolChromeEvent", detail);
60 return deferred.promise;
61 },
63 signInFlow: function() {
64 return this._contentRequest("openFlow");
65 },
67 refreshAuthentication: function(aAccountId) {
68 return this._contentRequest("refreshAuthentication", {
69 accountId: aAccountId
70 });
71 },
73 classID: Components.ID("{51875c14-91d7-4b8c-b65d-3549e101228c}"),
75 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFxAccountsUIGlue])
76 };
78 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FxAccountsUIGlue]);