Chromium Code Reviews| 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 /** @suppress {duplicate} */ | 9 /** @suppress {duplicate} */ |
| 10 var remoting = remoting || {}; | 10 var remoting = remoting || {}; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 181 } |
| 182 | 182 |
| 183 // If not, pass an error back to the callback(s) if we've already prompted the | 183 // If not, pass an error back to the callback(s) if we've already prompted the |
| 184 // user for permission. | 184 // user for permission. |
| 185 if (this.interactive_) { | 185 if (this.interactive_) { |
| 186 var error_message = | 186 var error_message = |
| 187 chrome.runtime.lastError ? chrome.runtime.lastError.message | 187 chrome.runtime.lastError ? chrome.runtime.lastError.message |
| 188 : 'Unknown error.'; | 188 : 'Unknown error.'; |
| 189 console.error(error_message); | 189 console.error(error_message); |
| 190 var error = (error_message == USER_CANCELLED) ? | 190 var error = (error_message == USER_CANCELLED) ? |
| 191 remoting.Error.Tag.CANCELLED : remoting.Error.Tag.NOT_AUTHENTICATED; | 191 new remoting.Error(remoting.Error.Tag.CANCELLED) : |
| 192 new remoting.Error(remoting.Error.Tag.NOT_AUTHENTICATED); | |
|
Jamie
2015/03/16 22:52:15
getToken is documented as passing a remoting.Error
| |
| 192 authTokenDeferred.reject(error); | 193 authTokenDeferred.reject(error); |
| 193 this.authTokenDeferred_ = null; | 194 this.authTokenDeferred_ = null; |
| 194 return; | 195 return; |
| 195 } | 196 } |
| 196 | 197 |
| 197 // If there's no token, but we haven't yet prompted for permission, do so | 198 // If there's no token, but we haven't yet prompted for permission, do so |
| 198 // now. | 199 // now. |
| 199 var that = this; | 200 var that = this; |
| 200 var showConsentDialog = | 201 var showConsentDialog = |
| 201 (this.consentDialog_) ? this.consentDialog_.show() : Promise.resolve(); | 202 (this.consentDialog_) ? this.consentDialog_.show() : Promise.resolve(); |
| 202 showConsentDialog.then(function() { | 203 showConsentDialog.then(function() { |
| 203 that.interactive_ = true; | 204 that.interactive_ = true; |
| 204 chrome.identity.getAuthToken({'interactive': that.interactive_}, | 205 chrome.identity.getAuthToken({'interactive': that.interactive_}, |
| 205 that.onAuthComplete_.bind(that)); | 206 that.onAuthComplete_.bind(that)); |
| 206 }); | 207 }); |
| 207 }; | 208 }; |
| 208 | 209 |
| 209 /** | 210 /** |
| 210 * Returns whether the web app has authenticated with the Google services. | 211 * Returns whether the web app has authenticated with the Google services. |
| 211 * | 212 * |
| 212 * @return {boolean} | 213 * @return {boolean} |
| 213 */ | 214 */ |
| 214 remoting.Identity.prototype.isAuthenticated = function() { | 215 remoting.Identity.prototype.isAuthenticated = function() { |
| 215 return remoting.identity.email_ !== ''; | 216 return remoting.identity.email_ !== ''; |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 })(); | 219 })(); |
| OLD | NEW |