| 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 {cr.ui.dialogs.BaseDialog} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Timeout for loading the share dialog before giving up. | 27 * Timeout for loading the share dialog before giving up. |
| 28 * @type {number} | 28 * @type {number} |
| 29 * @const | 29 * @const |
| 30 */ | 30 */ |
| 31 ShareDialog.FAILURE_TIMEOUT = 5000; | 31 ShareDialog.FAILURE_TIMEOUT = 5000; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Wraps a Web View element and adds authorization headers to it. | 34 * Wraps a Web View element and adds authorization headers to it. |
| 35 * @param {origin} origin Origin to be authorized. | 35 * @param {string} urlPattern Pattern of urls to be authorized. |
| 36 * @param {WebView} webView Web View element to be wrapped. | 36 * @param {WebView} webView Web View element to be wrapped. |
| 37 * @constructor | 37 * @constructor |
| 38 */ | 38 */ |
| 39 ShareDialog.WebViewAuthorizer = function(origin, webView) { | 39 ShareDialog.WebViewAuthorizer = function(urlPattern, webView) { |
| 40 this.origin_ = origin; | 40 this.urlPattern_ = urlPattern; |
| 41 this.webView_ = webView; | 41 this.webView_ = webView; |
| 42 this.initialized_ = false; | 42 this.initialized_ = false; |
| 43 this.accessToken_ = null; | 43 this.accessToken_ = null; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Initializes the web view by installing hooks injecting the authorization | 47 * Initializes the web view by installing hooks injecting the authorization |
| 48 * headers. | 48 * headers. |
| 49 * @param {function()} callback Completion callback. | 49 * @param {function()} callback Completion callback. |
| 50 */ | 50 */ |
| 51 ShareDialog.WebViewAuthorizer.prototype.initialize = function(callback) { | 51 ShareDialog.WebViewAuthorizer.prototype.initialize = function(callback) { |
| 52 if (this.initialized_) { | 52 if (this.initialized_) { |
| 53 callback(); | 53 callback(); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 var registerInjectionHooks = function() { | 57 var registerInjectionHooks = function() { |
| 58 this.webView_.removeEventListener('loadstop', registerInjectionHooks); | 58 this.webView_.removeEventListener('loadstop', registerInjectionHooks); |
| 59 this.webView_.onBeforeSendHeaders.addListener( | 59 this.webView_.onBeforeSendHeaders.addListener( |
| 60 this.authorizeRequest_.bind(this), | 60 this.authorizeRequest_.bind(this), |
| 61 {urls: [this.origin_ + '/*']}, | 61 {urls: [this.urlPattern_]}, |
| 62 ['blocking', 'requestHeaders']); | 62 ['blocking', 'requestHeaders']); |
| 63 this.initialized_ = true; | 63 this.initialized_ = true; |
| 64 callback(); | 64 callback(); |
| 65 }.bind(this); | 65 }.bind(this); |
| 66 | 66 |
| 67 this.webView_.addEventListener('loadstop', registerInjectionHooks); | 67 this.webView_.addEventListener('loadstop', registerInjectionHooks); |
| 68 this.webView_.setAttribute('src', 'data:text/html,'); | 68 this.webView_.setAttribute('src', 'data:text/html,'); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 /** | 71 /** |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 this.failureTimeout_ = setTimeout(function() { | 211 this.failureTimeout_ = setTimeout(function() { |
| 212 onError(); | 212 onError(); |
| 213 }, ShareDialog.FAILURE_TIMEOUT); | 213 }, ShareDialog.FAILURE_TIMEOUT); |
| 214 | 214 |
| 215 // TODO(mtomasz): Move to initDom_() once and reuse <webview> once it gets | 215 // TODO(mtomasz): Move to initDom_() once and reuse <webview> once it gets |
| 216 // fixed. See: crbug.com/260622. | 216 // fixed. See: crbug.com/260622. |
| 217 this.webView_ = util.createChild( | 217 this.webView_ = util.createChild( |
| 218 this.webViewWrapper_, 'share-dialog-webview', 'webview'); | 218 this.webViewWrapper_, 'share-dialog-webview', 'webview'); |
| 219 this.webView_.setAttribute('tabIndex', '-1'); | 219 this.webView_.setAttribute('tabIndex', '-1'); |
| 220 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( | 220 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( |
| 221 ShareClient.SHARE_TARGET, this.webView_); | 221 !window.IN_TEST ? (ShareClient.SHARE_TARGET + '/*') : '<all_urls>', |
| 222 this.webView_); |
| 222 this.webView_.addEventListener('newwindow', function(e) { | 223 this.webView_.addEventListener('newwindow', function(e) { |
| 223 // Discard the window object and reopen in an external window. | 224 // Discard the window object and reopen in an external window. |
| 224 e.window.discard(); | 225 e.window.discard(); |
| 225 chrome.windows.create({url: e.targetUrl}); | 226 chrome.windows.create({url: e.targetUrl}); |
| 226 e.preventDefault(); | 227 e.preventDefault(); |
| 227 }); | 228 }); |
| 228 | |
| 229 cr.ui.dialogs.BaseDialog.prototype.show.call(this, '', null, null, null); | 229 cr.ui.dialogs.BaseDialog.prototype.show.call(this, '', null, null, null); |
| 230 | 230 |
| 231 // Initialize and authorize the Web View tag asynchronously. | 231 // Initialize and authorize the Web View tag asynchronously. |
| 232 var group = new AsyncUtil.Group(); | 232 var group = new AsyncUtil.Group(); |
| 233 | 233 |
| 234 // Fetches an url to the sharing dialog. | 234 // Fetches an url to the sharing dialog. |
| 235 var shareUrl; | 235 var shareUrl; |
| 236 var getShareUrlClosure = function(callback) { | 236 var getShareUrlClosure = function(callback) { |
| 237 chrome.fileBrowserPrivate.getShareUrl( | 237 chrome.fileBrowserPrivate.getShareUrl( |
| 238 entry.toURL(), | 238 entry.toURL(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 264 }.bind(this)); | 264 }.bind(this)); |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 /** | 267 /** |
| 268 * Tells whether the share dialog is being shown or not. | 268 * Tells whether the share dialog is being shown or not. |
| 269 * @return {boolean} True if shown, false otherwise. | 269 * @return {boolean} True if shown, false otherwise. |
| 270 */ | 270 */ |
| 271 ShareDialog.prototype.isShowing = function() { | 271 ShareDialog.prototype.isShowing = function() { |
| 272 return this.container_.classList.contains('shown'); | 272 return this.container_.classList.contains('shown'); |
| 273 }; | 273 }; |
| OLD | NEW |