| 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 {WebView} webView Web View tag. | 8 * @param {WebView} webView Web View tag. |
| 9 * @param {string} url Share Url for an entry. | 9 * @param {string} url Share Url for an entry. |
| 10 * @param {ShareClient.Observer} observer Observer instance. | 10 * @param {ShareClient.Observer} observer Observer instance. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 */ | 70 */ |
| 71 ShareClient.Observer.prototype.onClosed = function() { | 71 ShareClient.Observer.prototype.onClosed = function() { |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Handles messages from the embedded dialog. | 75 * Handles messages from the embedded dialog. |
| 76 * @param {Event} e Message event. | 76 * @param {Event} e Message event. |
| 77 * @private | 77 * @private |
| 78 */ | 78 */ |
| 79 ShareClient.prototype.onMessage_ = function(e) { | 79 ShareClient.prototype.onMessage_ = function(e) { |
| 80 if (e.origin != ShareClient.SHARE_TARGET) | 80 if (e.origin != ShareClient.SHARE_TARGET && !window.IN_TEST) |
| 81 return; | 81 return; |
| 82 |
| 82 var data = JSON.parse(e.data); | 83 var data = JSON.parse(e.data); |
| 83 switch (data.type) { | 84 switch (data.type) { |
| 84 case 'resize': | 85 case 'resize': |
| 85 this.observer_.onResized(data.args.width, | 86 this.observer_.onResized(data.args.width, |
| 86 data.args.height, | 87 data.args.height, |
| 87 this.postMessage_.bind(this, 'resizeComplete')); | 88 this.postMessage_.bind(this, 'resizeComplete')); |
| 88 break; | 89 break; |
| 89 case 'prepareForVisible': | 90 case 'prepareForVisible': |
| 90 this.postMessage_('prepareComplete'); | 91 this.postMessage_('prepareComplete'); |
| 91 if (!this.loaded_) { | 92 if (!this.loaded_) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 * @param {string} type Message type. | 125 * @param {string} type Message type. |
| 125 * @param {Object=} opt_args Optional arguments. | 126 * @param {Object=} opt_args Optional arguments. |
| 126 * @private | 127 * @private |
| 127 */ | 128 */ |
| 128 ShareClient.prototype.postMessage_ = function(type, opt_args) { | 129 ShareClient.prototype.postMessage_ = function(type, opt_args) { |
| 129 var message = { | 130 var message = { |
| 130 type: type, | 131 type: type, |
| 131 args: opt_args | 132 args: opt_args |
| 132 }; | 133 }; |
| 133 this.webView_.contentWindow.postMessage( | 134 this.webView_.contentWindow.postMessage( |
| 134 JSON.stringify(message), ShareClient.SHARE_TARGET); | 135 JSON.stringify(message), |
| 136 !window.IN_TEST ? ShareClient.SHARE_TARGET : '*'); |
| 135 }; | 137 }; |
| 136 | 138 |
| 137 /** | 139 /** |
| 138 * Loads the embedded dialog. Can be called only one. | 140 * Loads the embedded dialog. Can be called only one. |
| 139 */ | 141 */ |
| 140 ShareClient.prototype.load = function() { | 142 ShareClient.prototype.load = function() { |
| 141 if (this.loading_ || this.loaded_) | 143 if (this.loading_ || this.loaded_) |
| 142 throw new Error('Already loaded.'); | 144 throw new Error('Already loaded.'); |
| 143 this.loading_ = true; | 145 this.loading_ = true; |
| 144 | 146 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 158 'loadabort', this.onLoadAbortBound_); | 160 'loadabort', this.onLoadAbortBound_); |
| 159 this.webView_.stop(); | 161 this.webView_.stop(); |
| 160 }; | 162 }; |
| 161 | 163 |
| 162 /** | 164 /** |
| 163 * Cleans the dialog by removing all handlers. | 165 * Cleans the dialog by removing all handlers. |
| 164 */ | 166 */ |
| 165 ShareClient.prototype.dispose = function() { | 167 ShareClient.prototype.dispose = function() { |
| 166 this.abort(); | 168 this.abort(); |
| 167 }; | 169 }; |
| OLD | NEW |