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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 var pattern = (this.origin_ == '<all_urls>') ? this.origin_ : | |
60 this.origin_ + '/*'; | |
59 this.webView_.onBeforeSendHeaders.addListener( | 61 this.webView_.onBeforeSendHeaders.addListener( |
60 this.authorizeRequest_.bind(this), | 62 this.authorizeRequest_.bind(this), |
61 {urls: [this.origin_ + '/*']}, | 63 {urls: [pattern]}, |
62 ['blocking', 'requestHeaders']); | 64 ['blocking', 'requestHeaders']); |
63 this.initialized_ = true; | 65 this.initialized_ = true; |
64 callback(); | 66 callback(); |
65 }.bind(this); | 67 }.bind(this); |
66 | 68 |
67 this.webView_.addEventListener('loadstop', registerInjectionHooks); | 69 this.webView_.addEventListener('loadstop', registerInjectionHooks); |
68 this.webView_.setAttribute('src', 'data:text/html,'); | 70 this.webView_.setAttribute('src', 'data:text/html,'); |
69 }; | 71 }; |
70 | 72 |
71 /** | 73 /** |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 this.failureTimeout_ = setTimeout(function() { | 213 this.failureTimeout_ = setTimeout(function() { |
212 onError(); | 214 onError(); |
213 }, ShareDialog.FAILURE_TIMEOUT); | 215 }, ShareDialog.FAILURE_TIMEOUT); |
214 | 216 |
215 // TODO(mtomasz): Move to initDom_() once and reuse <webview> once it gets | 217 // TODO(mtomasz): Move to initDom_() once and reuse <webview> once it gets |
216 // fixed. See: crbug.com/260622. | 218 // fixed. See: crbug.com/260622. |
217 this.webView_ = util.createChild( | 219 this.webView_ = util.createChild( |
218 this.webViewWrapper_, 'share-dialog-webview', 'webview'); | 220 this.webViewWrapper_, 'share-dialog-webview', 'webview'); |
219 this.webView_.setAttribute('tabIndex', '-1'); | 221 this.webView_.setAttribute('tabIndex', '-1'); |
220 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( | 222 this.webViewAuthorizer_ = new ShareDialog.WebViewAuthorizer( |
221 ShareClient.SHARE_TARGET, this.webView_); | 223 !window.IN_TEST ? ShareClient.SHARE_TARGET : '<all_urls>', |
yoshiki
2013/08/06 01:17:01
ShareClient.SHARE_TARGET is an origin, but "<all_u
mtomasz
2013/08/06 02:02:35
Good idea! Done.
| |
224 this.webView_); | |
222 this.webView_.addEventListener('newwindow', function(e) { | 225 this.webView_.addEventListener('newwindow', function(e) { |
223 // Discard the window object and reopen in an external window. | 226 // Discard the window object and reopen in an external window. |
224 e.window.discard(); | 227 e.window.discard(); |
225 chrome.windows.create({url: e.targetUrl}); | 228 chrome.windows.create({url: e.targetUrl}); |
226 e.preventDefault(); | 229 e.preventDefault(); |
227 }); | 230 }); |
228 | |
229 cr.ui.dialogs.BaseDialog.prototype.show.call(this, '', null, null, null); | 231 cr.ui.dialogs.BaseDialog.prototype.show.call(this, '', null, null, null); |
230 | 232 |
231 // Initialize and authorize the Web View tag asynchronously. | 233 // Initialize and authorize the Web View tag asynchronously. |
232 var group = new AsyncUtil.Group(); | 234 var group = new AsyncUtil.Group(); |
233 | 235 |
234 // Fetches an url to the sharing dialog. | 236 // Fetches an url to the sharing dialog. |
235 var shareUrl; | 237 var shareUrl; |
236 var getShareUrlClosure = function(callback) { | 238 var getShareUrlClosure = function(callback) { |
237 chrome.fileBrowserPrivate.getShareUrl( | 239 chrome.fileBrowserPrivate.getShareUrl( |
238 entry.toURL(), | 240 entry.toURL(), |
(...skipping 25 matching lines...) Expand all Loading... | |
264 }.bind(this)); | 266 }.bind(this)); |
265 }; | 267 }; |
266 | 268 |
267 /** | 269 /** |
268 * Tells whether the share dialog is being shown or not. | 270 * Tells whether the share dialog is being shown or not. |
269 * @return {boolean} True if shown, false otherwise. | 271 * @return {boolean} True if shown, false otherwise. |
270 */ | 272 */ |
271 ShareDialog.prototype.isShowing = function() { | 273 ShareDialog.prototype.isShowing = function() { |
272 return this.container_.classList.contains('shown'); | 274 return this.container_.classList.contains('shown'); |
273 }; | 275 }; |
OLD | NEW |