| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * SuggestAppsDialog contains a list box to select an app to be opened the file | 8 * SuggestAppsDialog contains a list box to select an app to be opened the file |
| 9 * with. This dialog should be used as action picker for file operations. | 9 * with. This dialog should be used as action picker for file operations. |
| 10 */ | 10 */ |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * Retrieves the authorize token. This method should be called in | 222 * Retrieves the authorize token. This method should be called in |
| 223 * initialization of the dialog. | 223 * initialization of the dialog. |
| 224 * | 224 * |
| 225 * @param {function()} callback Called when the token is retrieved. | 225 * @param {function()} callback Called when the token is retrieved. |
| 226 * @private | 226 * @private |
| 227 */ | 227 */ |
| 228 SuggestAppsDialog.prototype.retrieveAuthorizeToken_ = function(callback) { | 228 SuggestAppsDialog.prototype.retrieveAuthorizeToken_ = function(callback) { |
| 229 // TODO(yoshiki): Share the access token with ShareDialog. | |
| 230 if (this.accessToken_) { | 229 if (this.accessToken_) { |
| 231 callback(); | 230 callback(); |
| 232 return; | 231 return; |
| 233 } | 232 } |
| 234 | 233 |
| 235 // Fetch or update the access token. | 234 // Fetch or update the access token. |
| 236 chrome.fileBrowserPrivate.requestAccessToken( | 235 chrome.fileBrowserPrivate.requestWebStoreAccessToken( |
| 237 false, // force_refresh | 236 function(accessToken) { |
| 238 function(inAccessToken) { | 237 // In case of error, this.accessToken_ will be set to null. |
| 239 this.accessToken_ = inAccessToken; | 238 this.accessToken_ = accessToken; |
| 240 callback(); | 239 callback(); |
| 241 }.bind(this)); | 240 }.bind(this)); |
| 242 }; | 241 }; |
| 243 | 242 |
| 244 /** | 243 /** |
| 245 * Shows dialog. | 244 * Shows dialog. |
| 246 * | 245 * |
| 247 * @param {string} extension Extension of the file. | 246 * @param {string} extension Extension of the file. |
| 248 * @param {string} mime Mime of the file. | 247 * @param {string} mime Mime of the file. |
| 249 * @param {function(boolean)} onDialogClosed Called when the dialog is closed. | 248 * @param {function(boolean)} onDialogClosed Called when the dialog is closed. |
| 250 * The argument is the result of installation: true if an app is installed, | 249 * The argument is the result of installation: true if an app is installed, |
| 251 * false otherwise. | 250 * false otherwise. |
| 252 */ | 251 */ |
| 253 SuggestAppsDialog.prototype.show = function(extension, mime, onDialogClosed) { | 252 SuggestAppsDialog.prototype.show = function(extension, mime, onDialogClosed) { |
| 254 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) { | 253 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) { |
| 255 console.error('Invalid state.'); | 254 console.error('Invalid state.'); |
| 256 return; | 255 return; |
| 257 } | 256 } |
| 258 | 257 |
| 259 this.extension_ = extension; | 258 this.extension_ = extension; |
| 260 this.mimeType_ = mime; | 259 this.mimeType_ = mime; |
| 261 this.onDialogClosed_ = onDialogClosed; | 260 this.onDialogClosed_ = onDialogClosed; |
| 262 this.state_ = SuggestAppsDialog.State.INITIALIZING; | 261 this.state_ = SuggestAppsDialog.State.INITIALIZING; |
| 263 | 262 |
| 264 // Makes it sure that the initialization is completed. | 263 // Makes it sure that the initialization is completed. |
| 265 this.initializationTask_.run(function() { | 264 this.initializationTask_.run(function() { |
| 265 if (!this.accessToken_) { |
| 266 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; |
| 267 this.onHide_(); |
| 268 return; |
| 269 } |
| 270 |
| 266 var title = str('SUGGEST_DIALOG_TITLE'); | 271 var title = str('SUGGEST_DIALOG_TITLE'); |
| 267 | 272 |
| 268 // TODO(yoshiki): Remove this before ShareDialog launches. | 273 // TODO(yoshiki): Remove this before ShareDialog launches. |
| 269 if (this.urlOverrided_) | 274 if (this.urlOverrided_) |
| 270 title += ' [OVERRIDED]'; | 275 title += ' [OVERRIDED]'; |
| 271 | 276 |
| 272 cr.ui.dialogs.BaseDialog.prototype.showWithTitle.apply( | 277 cr.ui.dialogs.BaseDialog.prototype.showWithTitle.apply( |
| 273 this, [title, '', function() {}, null, null]); | 278 this, [title, '', function() {}, null, null]); |
| 274 | 279 |
| 275 this.webviewContainer_.innerHTML = | 280 this.webviewContainer_.innerHTML = |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 result = SuggestAppsDialog.Result.USER_CANCELL; | 465 result = SuggestAppsDialog.Result.USER_CANCELL; |
| 461 break; | 466 break; |
| 462 default: | 467 default: |
| 463 result = SuggestAppsDialog.Result.USER_CANCELL; | 468 result = SuggestAppsDialog.Result.USER_CANCELL; |
| 464 console.error('Invalid state.'); | 469 console.error('Invalid state.'); |
| 465 } | 470 } |
| 466 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; | 471 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; |
| 467 | 472 |
| 468 this.onDialogClosed_(result); | 473 this.onDialogClosed_(result); |
| 469 }; | 474 }; |
| OLD | NEW |