OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Wrapper class for Chrome's identity API. | 7 * Wrapper class for Chrome's identity API. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * | 44 * |
45 * @param {function(string):void} onOk Function to invoke with access token if | 45 * @param {function(string):void} onOk Function to invoke with access token if |
46 * an access token was successfully retrieved. | 46 * an access token was successfully retrieved. |
47 * @param {function(remoting.Error):void} onError Function to invoke with an | 47 * @param {function(remoting.Error):void} onError Function to invoke with an |
48 * error code on failure. | 48 * error code on failure. |
49 * @return {void} Nothing. | 49 * @return {void} Nothing. |
50 */ | 50 */ |
51 remoting.Identity.prototype.callWithToken = function(onOk, onError) { | 51 remoting.Identity.prototype.callWithToken = function(onOk, onError) { |
52 this.pendingCallbacks_.push(new remoting.Identity.Callbacks(onOk, onError)); | 52 this.pendingCallbacks_.push(new remoting.Identity.Callbacks(onOk, onError)); |
53 if (this.pendingCallbacks_.length == 1) { | 53 if (this.pendingCallbacks_.length == 1) { |
54 chrome.experimental.identity.getAuthToken( | 54 chrome.identity.getAuthToken( |
55 { 'interactive': false }, | 55 { 'interactive': false }, |
56 this.onAuthComplete_.bind(this, false)); | 56 this.onAuthComplete_.bind(this, false)); |
57 } | 57 } |
58 }; | 58 }; |
59 | 59 |
60 /** | 60 /** |
61 * Get the user's email address. | 61 * Get the user's email address. |
62 * | 62 * |
63 * @param {function(string):void} onOk Callback invoked when the email | 63 * @param {function(string):void} onOk Callback invoked when the email |
64 * address is available. | 64 * address is available. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // now. The consent callback is responsible for continuing the auth flow. | 125 // now. The consent callback is responsible for continuing the auth flow. |
126 this.consentCallback_(this.onAuthContinue_.bind(this)); | 126 this.consentCallback_(this.onAuthContinue_.bind(this)); |
127 }; | 127 }; |
128 | 128 |
129 /** | 129 /** |
130 * Called in response to the user signing in to the web-app. | 130 * Called in response to the user signing in to the web-app. |
131 * | 131 * |
132 * @private | 132 * @private |
133 */ | 133 */ |
134 remoting.Identity.prototype.onAuthContinue_ = function() { | 134 remoting.Identity.prototype.onAuthContinue_ = function() { |
135 chrome.experimental.identity.getAuthToken( | 135 chrome.identity.getAuthToken( |
136 { 'interactive': true }, | 136 { 'interactive': true }, |
137 this.onAuthComplete_.bind(this, true)); | 137 this.onAuthComplete_.bind(this, true)); |
138 }; | 138 }; |
139 | 139 |
140 /** | 140 /** |
141 * Internal representation for pair of callWithToken callbacks. | 141 * Internal representation for pair of callWithToken callbacks. |
142 * | 142 * |
143 * @param {function(string):void} onOk | 143 * @param {function(string):void} onOk |
144 * @param {function(remoting.Error):void} onError | 144 * @param {function(remoting.Error):void} onError |
145 * @constructor | 145 * @constructor |
146 * @private | 146 * @private |
147 */ | 147 */ |
148 remoting.Identity.Callbacks = function(onOk, onError) { | 148 remoting.Identity.Callbacks = function(onOk, onError) { |
149 /** @type {function(string):void} */ | 149 /** @type {function(string):void} */ |
150 this.onOk = onOk; | 150 this.onOk = onOk; |
151 /** @type {function(remoting.Error):void} */ | 151 /** @type {function(remoting.Error):void} */ |
152 this.onError = onError; | 152 this.onError = onError; |
153 }; | 153 }; |
OLD | NEW |