OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
6 * CWSWidgetContainer contains a Chrome Web Store widget that displays list of | 6 * CWSWidgetContainer contains a Chrome Web Store widget that displays list of |
7 * apps that satisfy certain constraints (e.g. fileHandler apps that can handle | 7 * apps that satisfy certain constraints (e.g. fileHandler apps that can handle |
8 * files with specific file extension or MIME type) and enables the user to | 8 * files with specific file extension or MIME type) and enables the user to |
9 * install apps directly from it. | 9 * install apps directly from it. |
10 * CWSWidgetContainer implements client side of the widget, which handles | 10 * CWSWidgetContainer implements client side of the widget, which handles |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 * The element containing the widget webview. | 60 * The element containing the widget webview. |
61 * @type {!Element} | 61 * @type {!Element} |
62 * @private | 62 * @private |
63 */ | 63 */ |
64 this.webviewContainer_ = document.createElement('div'); | 64 this.webviewContainer_ = document.createElement('div'); |
65 this.webviewContainer_.classList.add('cws-widget-webview-container'); | 65 this.webviewContainer_.classList.add('cws-widget-webview-container'); |
66 this.webviewContainer_.style.width = WEBVIEW_WIDTH + 'px'; | 66 this.webviewContainer_.style.width = WEBVIEW_WIDTH + 'px'; |
67 this.webviewContainer_.style.height = WEBVIEW_HEIGHT + 'px'; | 67 this.webviewContainer_.style.height = WEBVIEW_HEIGHT + 'px'; |
68 parentNode.appendChild(this.webviewContainer_); | 68 parentNode.appendChild(this.webviewContainer_); |
69 | 69 |
| 70 parentNode.classList.add('cws-widget-container-root'); |
| 71 |
70 /** | 72 /** |
71 * Element showing spinner layout in place of Web Store widget. | 73 * Element showing spinner layout in place of Web Store widget. |
72 * @type {!Element} | 74 * @type {!Element} |
73 */ | 75 */ |
74 var spinnerLayer = document.createElement('div'); | 76 var spinnerLayer = document.createElement('div'); |
75 spinnerLayer.className = 'cws-widget-spinner-layer'; | 77 spinnerLayer.className = 'cws-widget-spinner-layer'; |
76 this.webviewContainer_.appendChild(spinnerLayer); | 78 this.webviewContainer_.appendChild(spinnerLayer); |
77 | 79 |
78 /** | 80 /** |
79 * The widget container's button strip. | 81 * The widget container's button strip. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 * @private | 185 * @private |
184 */ | 186 */ |
185 this.resolveStart_ = null; | 187 this.resolveStart_ = null; |
186 | 188 |
187 /** | 189 /** |
188 * Promise for retriving {@code this.accessToken_}. | 190 * Promise for retriving {@code this.accessToken_}. |
189 * @type {Promise.<string>} | 191 * @type {Promise.<string>} |
190 * @private | 192 * @private |
191 */ | 193 */ |
192 this.tokenGetter_ = this.createTokenGetter_(); | 194 this.tokenGetter_ = this.createTokenGetter_(); |
| 195 |
| 196 /** |
| 197 * Dialog to be shown when an installation attempt fails. |
| 198 * @type {CWSWidgetContainerErrorDialog} |
| 199 * @private |
| 200 */ |
| 201 this.errorDialog_ = new CWSWidgetContainerErrorDialog(parentNode); |
193 } | 202 } |
194 | 203 |
195 /** | 204 /** |
196 * @enum {string} | 205 * @enum {string} |
197 * @private | 206 * @private |
198 */ | 207 */ |
199 CWSWidgetContainer.State = { | 208 CWSWidgetContainer.State = { |
200 UNINITIALIZED: 'CWSWidgetContainer.State.UNINITIALIZED', | 209 UNINITIALIZED: 'CWSWidgetContainer.State.UNINITIALIZED', |
201 GETTING_ACCESS_TOKEN: 'CWSWidgetContainer.State.GETTING_ACCESS_TOKEN', | 210 GETTING_ACCESS_TOKEN: 'CWSWidgetContainer.State.GETTING_ACCESS_TOKEN', |
202 ACCESS_TOKEN_READY: 'CWSWidgetContainer.State.ACCESS_TOKEN_READY', | 211 ACCESS_TOKEN_READY: 'CWSWidgetContainer.State.ACCESS_TOKEN_READY', |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // Wait for the widget webview container to dispatch INSTALL_DONE. | 521 // Wait for the widget webview container to dispatch INSTALL_DONE. |
513 break; | 522 break; |
514 case AppInstaller.Result.CANCELLED: | 523 case AppInstaller.Result.CANCELLED: |
515 CWSWidgetContainer.Metrics.recordInstall( | 524 CWSWidgetContainer.Metrics.recordInstall( |
516 CWSWidgetContainer.Metrics.INSTALL.CANCELLED); | 525 CWSWidgetContainer.Metrics.INSTALL.CANCELLED); |
517 // User cancelled the installation. Do nothing. | 526 // User cancelled the installation. Do nothing. |
518 break; | 527 break; |
519 case AppInstaller.Result.ERROR: | 528 case AppInstaller.Result.ERROR: |
520 CWSWidgetContainer.Metrics.recordInstall( | 529 CWSWidgetContainer.Metrics.recordInstall( |
521 CWSWidgetContainer.Metrics.INSTALL.FAILED); | 530 CWSWidgetContainer.Metrics.INSTALL.FAILED); |
522 // TODO(tbarzic): Remove dialog showing call from this class. | 531 this.errorDialog_.show( |
523 fileManager.ui.errorDialog.show( | |
524 str('SUGGEST_DIALOG_INSTALLATION_FAILED'), | 532 str('SUGGEST_DIALOG_INSTALLATION_FAILED'), |
525 null, | 533 null, |
526 null, | 534 null, |
527 null); | 535 null); |
528 break; | 536 break; |
529 } | 537 } |
530 }; | 538 }; |
531 | 539 |
532 /** | 540 /** |
533 * Resolves the promise returned by {@code this.start} when widget is done with | 541 * Resolves the promise returned by {@code this.start} when widget is done with |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 this.webviewClient_ = null; | 645 this.webviewClient_ = null; |
638 } | 646 } |
639 | 647 |
640 if (this.webview_) | 648 if (this.webview_) |
641 this.webviewContainer_.removeChild(this.webview_); | 649 this.webviewContainer_.removeChild(this.webview_); |
642 | 650 |
643 if (this.appInstaller_) | 651 if (this.appInstaller_) |
644 this.appInstaller_.cancel(); | 652 this.appInstaller_.cancel(); |
645 | 653 |
646 this.options_ = null; | 654 this.options_ = null; |
| 655 |
| 656 if (this.errorDialog_.shown()) |
| 657 this.errorDialog_.hide(); |
647 }; | 658 }; |
648 | 659 |
649 /** | 660 /** |
650 * Utility methods and constants to record histograms. | 661 * Utility methods and constants to record histograms. |
651 */ | 662 */ |
652 CWSWidgetContainer.Metrics = {}; | 663 CWSWidgetContainer.Metrics = {}; |
653 | 664 |
654 /** | 665 /** |
655 * @enum {number} | 666 * @enum {number} |
656 * @const | 667 * @const |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 metrics.recordUserAction('SuggestApps.ShowDialog'); | 724 metrics.recordUserAction('SuggestApps.ShowDialog'); |
714 }; | 725 }; |
715 | 726 |
716 CWSWidgetContainer.Metrics.startLoad = function() { | 727 CWSWidgetContainer.Metrics.startLoad = function() { |
717 metrics.startInterval('SuggestApps.LoadTime'); | 728 metrics.startInterval('SuggestApps.LoadTime'); |
718 }; | 729 }; |
719 | 730 |
720 CWSWidgetContainer.Metrics.finishLoad = function() { | 731 CWSWidgetContainer.Metrics.finishLoad = function() { |
721 metrics.recordInterval('SuggestApps.LoadTime'); | 732 metrics.recordInterval('SuggestApps.LoadTime'); |
722 }; | 733 }; |
OLD | NEW |