OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Note: the native-side handler for this is AutomaticSettingsResetHandler. | 5 // Note: the native-side handler for this is AutomaticSettingsResetHandler. |
6 | 6 |
7 cr.define('options', function() { | 7 cr.define('options', function() { |
8 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 8 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
9 | 9 |
10 /** | 10 /** |
11 * AutomaticSettingsResetBanner class | 11 * AutomaticSettingsResetBanner class |
12 * Provides encapsulated handling of the Reset Profile Settings banner. | 12 * Provides encapsulated handling of the Reset Profile Settings banner. |
13 * @constructor | 13 * @constructor |
14 * @extends {options.SettingsBannerBase} | |
15 */ | 14 */ |
16 function AutomaticSettingsResetBanner() {} | 15 function AutomaticSettingsResetBanner() {} |
17 | 16 |
18 cr.addSingletonGetter(AutomaticSettingsResetBanner); | 17 cr.addSingletonGetter(AutomaticSettingsResetBanner); |
19 | 18 |
20 AutomaticSettingsResetBanner.prototype = { | 19 AutomaticSettingsResetBanner.prototype = { |
21 /** | 20 /** |
22 * Whether or not the banner has already been dismissed. | 21 * Whether or not the banner has already been dismissed. |
23 * | 22 * |
24 * This is needed because of the surprising ordering of asynchronous | 23 * This is needed because of the surprising ordering of asynchronous |
25 * JS<->native calls when the settings page is opened with specifying a | 24 * JS<->native calls when the settings page is opened with specifying a |
26 * given sub-page, e.g. chrome://settings/AutomaticSettingsReset. | 25 * given sub-page, e.g. chrome://settings/AutomaticSettingsReset. |
27 * | 26 * |
28 * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which | 27 * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which |
29 * calls our dismiss() method, would be called before the native Handlers' | 28 * calls our dismiss() method, would be called before the native Handlers' |
30 * InitalizePage() methods have an effect in the JS, which includes calling | 29 * InitalizePage() methods have an effect in the JS, which includes calling |
31 * our show() method. This would mean that the banner would be first | 30 * our show() method. This would mean that the banner would be first |
32 * dismissed, then shown. We want to prevent this. | 31 * dismissed, then shown. We want to prevent this. |
33 * | 32 * |
34 * @type {boolean} | 33 * @private {boolean} |
35 * @private | |
36 */ | 34 */ |
37 hadBeenDismissed_: false, | 35 wasDismissed_: false, |
38 | 36 |
39 /** | 37 /** |
40 * Metric name to send when a show event occurs. | 38 * Metric name to send when a show event occurs. |
39 * @private {string} | |
41 */ | 40 */ |
42 showMetricName_: '', | 41 showMetricName_: '', |
43 | 42 |
44 /** | 43 /** |
45 * Name of the native callback invoked when the banner is dismised. | 44 * Name of the native callback invoked when the banner is dismised. |
46 */ | 45 */ |
47 dismissNativeCallbackName_: '', | 46 dismissNativeCallbackName_: '', |
48 | 47 |
49 /** | 48 /** |
50 * DOM element whose visibility is set when setVisibility_ is called. | 49 * DOM element whose visibility is set when setVisibility_ is called. |
50 * @private {HTMLElement} | |
Dan Beam
2015/11/18 17:38:22
nit: ?HTMLElement
robertshield
2015/11/19 00:04:45
Done.
| |
51 */ | 51 */ |
52 setVisibilibyDomElement_: null, | 52 visibleElement_: null, |
53 | 53 |
54 /** | 54 /** |
55 * Initializes the banner's event handlers. | 55 * Initializes the banner's event handlers. |
56 * @suppress {checkTypes} | 56 * @suppress {checkTypes} |
57 * TODO(vitalyp): remove the suppression. Suppression is needed because | 57 * TODO(vitalyp): remove the suppression. Suppression is needed because |
58 * method dismiss() is attached to AutomaticSettingsResetBanner at run-time | 58 * method dismiss() is attached to AutomaticSettingsResetBanner at run-time |
59 * via "Forward public APIs to protected implementations" pattern (see | 59 * via "Forward public APIs to protected implementations" pattern (see |
60 * below). Currently the compiler pass and cr.js handles only forwarding to | 60 * below). Currently the compiler pass and cr.js handles only forwarding to |
61 * private implementations using cr.makePublic(). | 61 * private implementations using cr.makePublic(). |
62 */ | 62 */ |
63 initialize: function() { | 63 initialize: function() { |
64 this.showMetricName_ = 'AutomaticSettingsReset_WebUIBanner_BannerShown'; | 64 this.showMetricName_ = 'AutomaticSettingsReset_WebUIBanner_BannerShown'; |
65 | 65 |
66 this.dismissNativeCallbackName_ = | 66 this.dismissNativeCallbackName_ = |
67 'onDismissedAutomaticSettingsResetBanner'; | 67 'onDismissedAutomaticSettingsResetBanner'; |
68 | 68 |
69 this.setVisibilibyDomElement_ = $('automatic-settings-reset-banner'); | 69 this.visibleElement_ = $('automatic-settings-reset-banner'); |
Dan Beam
2015/11/18 17:38:22
nit:
this.visibleElement_ = getRequiredElement('a
robertshield
2015/11/19 00:04:44
Done.
| |
70 | 70 |
71 $('automatic-settings-reset-banner-close').onclick = function(event) { | 71 $('automatic-settings-reset-banner-close').onclick = function(event) { |
72 chrome.send('metricsHandler:recordAction', | 72 chrome.send('metricsHandler:recordAction', |
73 ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']); | 73 ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']); |
74 AutomaticSettingsResetBanner.dismiss(); | 74 AutomaticSettingsResetBanner.dismiss(); |
75 }; | 75 }; |
76 $('automatic-settings-reset-learn-more').onclick = function(event) { | 76 $('automatic-settings-reset-learn-more').onclick = function(event) { |
77 chrome.send('metricsHandler:recordAction', | 77 chrome.send('metricsHandler:recordAction', |
78 ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']); | 78 ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']); |
79 }; | 79 }; |
80 $('automatic-settings-reset-banner-activate-reset').onclick = | 80 $('automatic-settings-reset-banner-activate-reset').onclick = |
81 function(event) { | 81 function(event) { |
82 chrome.send('metricsHandler:recordAction', | 82 chrome.send('metricsHandler:recordAction', |
83 ['AutomaticSettingsReset_WebUIBanner_ResetClicked']); | 83 ['AutomaticSettingsReset_WebUIBanner_ResetClicked']); |
84 PageManager.showPageByName('resetProfileSettings'); | 84 PageManager.showPageByName('resetProfileSettings'); |
85 }; | 85 }; |
86 }, | 86 }, |
87 | 87 |
88 /** | 88 /** |
89 * Sets whether or not the reset profile settings banner shall be visible. | 89 * Sets whether or not the reset profile settings banner shall be visible. |
90 * @param {boolean} show Whether or not to show the banner. | 90 * @param {boolean} show Whether or not to show the banner. |
91 * @protected | 91 * @protected |
92 */ | 92 */ |
93 setVisibility: function(show) { | 93 setVisibility: function(show) { |
94 this.setVisibilibyDomElement_.hidden = !show; | 94 this.visibleElement_.hidden = !show; |
95 }, | 95 }, |
96 | 96 |
97 /** | 97 /** |
98 * Called by the native code to show the banner if needed. | 98 * Called by the native code to show the banner if needed. |
99 * @private | 99 * @private |
100 */ | 100 */ |
101 show_: function() { | 101 show_: function() { |
102 if (!this.hadBeenDismissed_) { | 102 if (!this.wasDismissed_) { |
103 chrome.send('metricsHandler:recordAction', [this.showMetricName_]); | 103 chrome.send('metricsHandler:recordAction', [this.showMetricName_]); |
104 this.setVisibility(true); | 104 this.setVisibility(true); |
105 } | 105 } |
106 }, | 106 }, |
107 | 107 |
108 /** | 108 /** |
109 * Called when the banner should be closed as a result of something taking | 109 * Called when the banner should be closed as a result of something taking |
110 * place on the WebUI page, i.e. when its close button is pressed, or when | 110 * place on the WebUI page, i.e. when its close button is pressed, or when |
111 * the confirmation dialog for the profile settings reset feature is opened. | 111 * the confirmation dialog for the profile settings reset feature is opened. |
112 * @private | 112 * @private |
113 */ | 113 */ |
114 dismiss_: function() { | 114 dismiss_: function() { |
115 assert(this.dismissNativeCallbackName_); | |
115 chrome.send(this.dismissNativeCallbackName_); | 116 chrome.send(this.dismissNativeCallbackName_); |
Dan Beam
2015/11/18 17:38:22
nit: chrome.send(assert(this.dismissNativeCallback
robertshield
2015/11/19 00:04:45
Done.
| |
116 this.hadBeenDismissed_ = true; | 117 this.wasDismissed_ = true; |
117 this.setVisibility(false); | 118 this.setVisibility(false); |
118 }, | 119 }, |
119 }; | 120 }; |
120 | 121 |
121 // Forward public APIs to private implementations. | 122 // Forward public APIs to private implementations. |
122 cr.makePublic(AutomaticSettingsResetBanner, [ | 123 cr.makePublic(AutomaticSettingsResetBanner, [ |
123 'show', | 124 'show', |
124 'dismiss', | 125 'dismiss', |
125 ]); | 126 ]); |
126 | 127 |
127 // Export | 128 // Export |
128 return { | 129 return { |
129 AutomaticSettingsResetBanner: AutomaticSettingsResetBanner | 130 AutomaticSettingsResetBanner: AutomaticSettingsResetBanner |
130 }; | 131 }; |
131 }); | 132 }); |
OLD | NEW |