Chromium Code Reviews| 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} ext File extension. | 9 * @param {string} ext File extension. |
| 10 * @param {string} mime File mime type. | 10 * @param {string} mime File mime type. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 * @param {Event} event Message event. | 40 * @param {Event} event Message event. |
| 41 * @private | 41 * @private |
| 42 */ | 42 */ |
| 43 CWSContainerClient.prototype.onMessage_ = function(event) { | 43 CWSContainerClient.prototype.onMessage_ = function(event) { |
| 44 if (event.origin != this.target_) | 44 if (event.origin != this.target_) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 var data = event.data; | 47 var data = event.data; |
| 48 switch (data['message']) { | 48 switch (data['message']) { |
| 49 case 'widget_loaded': | 49 case 'widget_loaded': |
| 50 // Do nothing. Waits for user action and next message. | 50 this.onWidgetLoaded_(); |
| 51 break; | |
| 52 case 'widget_load_failed': | |
| 53 this.onWidgetLoadFailed_(); | |
| 51 break; | 54 break; |
| 52 case 'before_install': | 55 case 'before_install': |
| 53 this.sendInstallRequest_(data['item_id']); | 56 this.sendInstallRequest_(data['item_id']); |
| 54 break; | 57 break; |
| 55 default: | 58 default: |
| 56 console.error('Unexpected message: ' + data['message'], data); | 59 console.error('Unexpected message: ' + data['message'], data); |
| 57 } | 60 } |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 /** | 63 /** |
| 61 * Called when receiving 'loadstop' event from the <wevview>. | 64 * Called when receiving 'loadstop' event from the <wevview>. |
| 62 * @param {Event} event Message event. | 65 * @param {Event} event Message event. |
| 63 * @private | 66 * @private |
| 64 */ | 67 */ |
| 65 CWSContainerClient.prototype.onLoadStop_ = function(event) { | 68 CWSContainerClient.prototype.onLoadStop_ = function(event) { |
| 66 if (this.url_ == this.webView_.src && !this.loaded_) { | 69 if (this.url_ == this.webView_.src && !this.loaded_) { |
| 67 this.loaded_ = true; | 70 this.loaded_ = true; |
| 68 this.postInitializeMessage_(); | 71 this.postInitializeMessage_(); |
| 69 } | 72 } |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 /** | 75 /** |
| 76 * Called when the widget is loaded successfully. | |
| 77 * @private | |
| 78 */ | |
| 79 CWSContainerClient.prototype.onWidgetLoaded_ = function() { | |
| 80 this.dispatchEvent(new cr.Event('loaded')); | |
|
hirono
2013/08/30 09:06:19
Can we make the event names enum values?
To do thi
yoshiki
2013/08/30 09:16:03
Done.
| |
| 81 }; | |
| 82 | |
| 83 /** | |
| 84 * Called when the widget is failed to load. | |
| 85 * @private | |
| 86 */ | |
| 87 CWSContainerClient.prototype.onWidgetLoadFailed_ = function() { | |
| 88 this.sendWidgetLoadFailed_(); | |
| 89 }; | |
| 90 | |
| 91 /** | |
| 73 * Called when receiving the 'loadabort' event from <webview>. | 92 * Called when receiving the 'loadabort' event from <webview>. |
| 74 * @param {Event} event Message event. | 93 * @param {Event} event Message event. |
| 75 * @private | 94 * @private |
| 76 */ | 95 */ |
| 77 CWSContainerClient.prototype.onLoadAbort_ = function(event) { | 96 CWSContainerClient.prototype.onLoadAbort_ = function(event) { |
| 78 this.sendWebviewLoadAbort_(); | 97 this.sendWidgetLoadFailed_(); |
| 79 }; | 98 }; |
| 80 | 99 |
| 81 /** | 100 /** |
| 82 * Called when the installation is completed from the suggest-app dialog. | 101 * Called when the installation is completed from the suggest-app dialog. |
| 83 * | 102 * |
| 84 * @param {boolean} result True if the installation is success, false if failed. | 103 * @param {boolean} result True if the installation is success, false if failed. |
| 85 * @param {string} itemId Item id to be installed. | 104 * @param {string} itemId Item id to be installed. |
| 86 */ | 105 */ |
| 87 CWSContainerClient.prototype.onInstallCompleted = function(result, itemId) { | 106 CWSContainerClient.prototype.onInstallCompleted = function(result, itemId) { |
| 88 if (result) | 107 if (result) |
| 89 this.postInstallSuccessMessage_(itemId); | 108 this.postInstallSuccessMessage_(itemId); |
| 90 else | 109 else |
| 91 this.postInstallFailureMessage_(itemId); | 110 this.postInstallFailureMessage_(itemId); |
| 92 }; | 111 }; |
| 93 | 112 |
| 94 /** | 113 /** |
| 95 * Send the abort event to the suggest-app dialog. | 114 * Send the fail message to the suggest-app dialog. |
| 96 * @private | 115 * @private |
| 97 */ | 116 */ |
| 98 CWSContainerClient.prototype.sendWebviewLoadAbort_ = function() { | 117 CWSContainerClient.prototype.sendWidgetLoadFailed_ = function() { |
| 99 this.dispatchEvent(new cr.Event('webview-load-abort')); | 118 this.dispatchEvent(new cr.Event('load-failed')); |
| 100 }; | 119 }; |
| 101 | 120 |
| 102 /** | 121 /** |
| 103 * Send the install request to the suggest-app dialog. | 122 * Send the install request to the suggest-app dialog. |
| 104 * | 123 * |
| 105 * @param {string} itemId Item id to be installed. | 124 * @param {string} itemId Item id to be installed. |
| 106 * @private | 125 * @private |
| 107 */ | 126 */ |
| 108 CWSContainerClient.prototype.sendInstallRequest_ = function(itemId) { | 127 CWSContainerClient.prototype.sendInstallRequest_ = function(itemId) { |
| 109 var event = new cr.Event('install-request'); | 128 var event = new cr.Event('install-request'); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 this.webView_.stop(); | 220 this.webView_.stop(); |
| 202 }; | 221 }; |
| 203 | 222 |
| 204 /** | 223 /** |
| 205 * Cleans the dialog by removing all handlers. | 224 * Cleans the dialog by removing all handlers. |
| 206 */ | 225 */ |
| 207 CWSContainerClient.prototype.dispose = function() { | 226 CWSContainerClient.prototype.dispose = function() { |
| 208 this.abort(); | 227 this.abort(); |
| 209 }; | 228 }; |
| 210 | 229 |
| OLD | NEW |