| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 * @param {HTMLElement} parentNode Node to be parent for this dialog. | 8 * @param {HTMLElement} parentNode Node to be parent for this dialog. |
| 9 * @constructor | 9 * @constructor |
| 10 * @extends {cr.ui.dialogs.BaseDialog} | 10 * @extends {FileManagerDialogBase} |
| 11 * @implements {ShareClient.Observer} | 11 * @implements {ShareClient.Observer} |
| 12 */ | 12 */ |
| 13 function ShareDialog(parentNode) { | 13 function ShareDialog(parentNode) { |
| 14 this.queue_ = new AsyncUtil.Queue(); | 14 this.queue_ = new AsyncUtil.Queue(); |
| 15 this.onQueueTaskFinished_ = null; | 15 this.onQueueTaskFinished_ = null; |
| 16 this.shareClient_ = null; | 16 this.shareClient_ = null; |
| 17 this.spinner_ = null; | 17 this.spinner_ = null; |
| 18 this.spinnerWrapper_ = null; | 18 this.spinnerWrapper_ = null; |
| 19 this.webViewWrapper_ = null; | 19 this.webViewWrapper_ = null; |
| 20 this.webView_ = null; | 20 this.webView_ = null; |
| 21 this.failureTimeout_ = null; | 21 this.failureTimeout_ = null; |
| 22 this.callback_ = null; | 22 this.callback_ = null; |
| 23 | 23 |
| 24 cr.ui.dialogs.BaseDialog.call(this, parentNode); | 24 FileManagerDialogBase.call(this, parentNode); |
| 25 } | 25 } |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Timeout for loading the share dialog before giving up. | 28 * Timeout for loading the share dialog before giving up. |
| 29 * @type {number} | 29 * @type {number} |
| 30 * @const | 30 * @const |
| 31 */ | 31 */ |
| 32 ShareDialog.FAILURE_TIMEOUT = 5000; | 32 ShareDialog.FAILURE_TIMEOUT = 5000; |
| 33 | 33 |
| 34 /** | 34 /** |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 */ | 104 */ |
| 105 ShareDialog.WebViewAuthorizer.prototype.authorizeRequest_ = function(e) { | 105 ShareDialog.WebViewAuthorizer.prototype.authorizeRequest_ = function(e) { |
| 106 e.requestHeaders.push({ | 106 e.requestHeaders.push({ |
| 107 name: 'Authorization', | 107 name: 'Authorization', |
| 108 value: 'Bearer ' + this.accessToken_ | 108 value: 'Bearer ' + this.accessToken_ |
| 109 }); | 109 }); |
| 110 return {requestHeaders: e.requestHeaders}; | 110 return {requestHeaders: e.requestHeaders}; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 ShareDialog.prototype = { | 113 ShareDialog.prototype = { |
| 114 __proto__: cr.ui.dialogs.BaseDialog.prototype | 114 __proto__: FileManagerDialogBase.prototype |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * One-time initialization of DOM. | 118 * One-time initialization of DOM. |
| 119 * @private | 119 * @private |
| 120 */ | 120 */ |
| 121 ShareDialog.prototype.initDom_ = function() { | 121 ShareDialog.prototype.initDom_ = function() { |
| 122 cr.ui.dialogs.BaseDialog.prototype.initDom_.call(this); | 122 FileManagerDialogBase.prototype.initDom_.call(this); |
| 123 this.frame_.classList.add('share-dialog-frame'); | 123 this.frame_.classList.add('share-dialog-frame'); |
| 124 | 124 |
| 125 this.spinnerWrapper_ = this.document_.createElement('div'); | 125 this.spinnerWrapper_ = this.document_.createElement('div'); |
| 126 this.spinnerWrapper_.className = 'spinner-container'; | 126 this.spinnerWrapper_.className = 'spinner-container'; |
| 127 this.frame_.appendChild(this.spinnerWrapper_); | 127 this.frame_.appendChild(this.spinnerWrapper_); |
| 128 | 128 |
| 129 this.spinner_ = this.document_.createElement('div'); | 129 this.spinner_ = this.document_.createElement('div'); |
| 130 this.spinner_.className = 'spinner'; | 130 this.spinner_.className = 'spinner'; |
| 131 this.spinnerWrapper_.appendChild(this.spinner_); | 131 this.spinnerWrapper_.appendChild(this.spinner_); |
| 132 | 132 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return; | 197 return; |
| 198 if (this.shareClient_) { | 198 if (this.shareClient_) { |
| 199 this.shareClient_.dispose(); | 199 this.shareClient_.dispose(); |
| 200 this.shareClient_ = null; | 200 this.shareClient_ = null; |
| 201 } | 201 } |
| 202 this.webViewWrapper_.textContent = ''; | 202 this.webViewWrapper_.textContent = ''; |
| 203 if (this.failureTimeout_) { | 203 if (this.failureTimeout_) { |
| 204 clearTimeout(this.failureTimeout_); | 204 clearTimeout(this.failureTimeout_); |
| 205 this.failureTimeout_ = null; | 205 this.failureTimeout_ = null; |
| 206 } | 206 } |
| 207 cr.ui.dialogs.BaseDialog.prototype.hide.call( | 207 FileManagerDialogBase.prototype.hide.call( |
| 208 this, | 208 this, |
| 209 function() { | 209 function() { |
| 210 if (opt_onHide) | 210 if (opt_onHide) |
| 211 opt_onHide(); | 211 opt_onHide(); |
| 212 this.callback_(result); | 212 this.callback_(result); |
| 213 this.callback_ = null; | 213 this.callback_ = null; |
| 214 }.bind(this)); | 214 }.bind(this)); |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 /** | 217 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 247 this.webView_.setAttribute('tabIndex', '-1'); | 247 this.webView_.setAttribute('tabIndex', '-1'); |
| 248 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( | 248 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( |
| 249 !window.IN_TEST ? (ShareClient.SHARE_TARGET + '/*') : '<all_urls>', | 249 !window.IN_TEST ? (ShareClient.SHARE_TARGET + '/*') : '<all_urls>', |
| 250 this.webView_); | 250 this.webView_); |
| 251 this.webView_.addEventListener('newwindow', function(e) { | 251 this.webView_.addEventListener('newwindow', function(e) { |
| 252 // Discard the window object and reopen in an external window. | 252 // Discard the window object and reopen in an external window. |
| 253 e.window.discard(); | 253 e.window.discard(); |
| 254 util.visitURL(e.targetUrl); | 254 util.visitURL(e.targetUrl); |
| 255 e.preventDefault(); | 255 e.preventDefault(); |
| 256 }); | 256 }); |
| 257 cr.ui.dialogs.BaseDialog.prototype.show.call(this, '', null, null, null); | 257 var show = FileManagerDialogBase.prototype.showBlankDialog.call(this); |
| 258 if (!show) { |
| 259 // The code shoundn't get here, since already-showing was handled before. |
| 260 console.error('ShareDialog can\'t be shown.'); |
| 261 return; |
| 262 } |
| 258 | 263 |
| 259 // Initialize and authorize the Web View tag asynchronously. | 264 // Initialize and authorize the Web View tag asynchronously. |
| 260 var group = new AsyncUtil.Group(); | 265 var group = new AsyncUtil.Group(); |
| 261 | 266 |
| 262 // Fetches an url to the sharing dialog. | 267 // Fetches an url to the sharing dialog. |
| 263 var shareUrl; | 268 var shareUrl; |
| 264 group.add(function(inCallback) { | 269 group.add(function(inCallback) { |
| 265 chrome.fileBrowserPrivate.getShareUrl( | 270 chrome.fileBrowserPrivate.getShareUrl( |
| 266 entry.toURL(), | 271 entry.toURL(), |
| 267 function(inShareUrl) { | 272 function(inShareUrl) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 292 | 297 |
| 293 /** | 298 /** |
| 294 * Tells whether the share dialog is showing or not. | 299 * Tells whether the share dialog is showing or not. |
| 295 * | 300 * |
| 296 * @return {boolean} True since the show method is called and until the closing | 301 * @return {boolean} True since the show method is called and until the closing |
| 297 * callback is invoked. | 302 * callback is invoked. |
| 298 */ | 303 */ |
| 299 ShareDialog.prototype.isShowing = function() { | 304 ShareDialog.prototype.isShowing = function() { |
| 300 return !!this.callback_; | 305 return !!this.callback_; |
| 301 }; | 306 }; |
| OLD | NEW |