OLD | NEW |
1 // Copyright 2013 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 ResetProfileSettingsHandler. | 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 OptionsPage = options.OptionsPage; | 8 /** @const */ var OptionsPage = options.OptionsPage; |
9 | 9 |
10 /** | 10 /** |
11 * ResetProfileSettingsBanner 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 */ | 14 */ |
15 function ResetProfileSettingsBanner() {} | 15 function AutomaticSettingsResetBanner() {} |
16 | 16 |
17 cr.addSingletonGetter(ResetProfileSettingsBanner); | 17 cr.addSingletonGetter(AutomaticSettingsResetBanner); |
18 | 18 |
19 ResetProfileSettingsBanner.prototype = { | 19 AutomaticSettingsResetBanner.prototype = { |
20 /** | 20 /** |
21 * Whether or not the banner has already been dismissed. | 21 * Whether or not the banner has already been dismissed. |
22 * | 22 * |
23 * This is needed because of the surprising ordering of asynchronous | 23 * This is needed because of the surprising ordering of asynchronous |
24 * 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 |
25 * given sub-page, e.g. chrome://settings/resetProfileSettings. | 25 * given sub-page, e.g. chrome://settings/AutomaticSettingsReset. |
26 * | 26 * |
27 * In such a case, ResetProfileSettingsOverlay's didShowPage(), which calls | 27 * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which |
28 * our dismiss() method, would be called before the native Handlers' | 28 * calls our dismiss() method, would be called before the native Handlers' |
29 * InitalizePage() methods have an effect in the JS, which includes calling | 29 * InitalizePage() methods have an effect in the JS, which includes calling |
30 * 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 |
31 * dismissed, then shown. We want to prevent this. | 31 * dismissed, then shown. We want to prevent this. |
32 * | 32 * |
33 * @type {boolean} | 33 * @type {boolean} |
34 * @private | 34 * @private |
35 */ | 35 */ |
36 hadBeenDismissed_: false, | 36 hadBeenDismissed_: false, |
37 | 37 |
38 /** | 38 /** |
39 * Initializes the banner's event handlers. | 39 * Initializes the banner's event handlers. |
40 */ | 40 */ |
41 initialize: function() { | 41 initialize: function() { |
42 $('reset-profile-settings-banner-close').onclick = function(event) { | 42 $('automatic-settings-reset-banner-close').onclick = function(event) { |
43 chrome.send('metricsHandler:recordAction', | 43 chrome.send('metricsHandler:recordAction', |
44 ['AutomaticReset_WebUIBanner_ManuallyClosed']); | 44 ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']); |
45 ResetProfileSettingsBanner.dismiss(); | 45 AutomaticSettingsResetBanner.dismiss(); |
46 }; | 46 }; |
47 $('reset-profile-settings-banner-activate').onclick = function(event) { | 47 $('automatic-settings-reset-learn-more').onclick = function(event) { |
48 chrome.send('metricsHandler:recordAction', | 48 chrome.send('metricsHandler:recordAction', |
49 ['AutomaticReset_WebUIBanner_ResetClicked']); | 49 ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']); |
50 OptionsPage.navigateToPage('resetProfileSettings'); | |
51 }; | 50 }; |
52 }, | 51 }, |
53 | 52 |
54 /** | 53 /** |
55 * Called by the native code to show the banner if needed. | 54 * Called by the native code to show the banner if needed. |
56 * @private | 55 * @private |
57 */ | 56 */ |
58 show_: function() { | 57 show_: function() { |
59 if (!this.hadBeenDismissed_) { | 58 if (!this.hadBeenDismissed_) { |
60 chrome.send('metricsHandler:recordAction', | 59 chrome.send('metricsHandler:recordAction', |
61 ['AutomaticReset_WebUIBanner_BannerShown']); | 60 ['AutomaticSettingsReset_WebUIBanner_BannerShown']); |
62 this.setVisibility_(true); | 61 this.setVisibility_(true); |
63 } | 62 } |
64 }, | 63 }, |
65 | 64 |
66 /** | 65 /** |
67 * Called when the banner should be closed as a result of something taking | 66 * Called when the banner should be closed as a result of something taking |
68 * place on the WebUI page, i.e. when its close button is pressed, or when | 67 * place on the WebUI page, i.e. when its close button is pressed, or when |
69 * the confirmation dialog for the profile settings reset feature is opened. | 68 * the confirmation dialog for the profile settings reset feature is opened. |
70 * @private | 69 * @private |
71 */ | 70 */ |
72 dismiss_: function() { | 71 dismiss_: function() { |
73 chrome.send('onDismissedResetProfileSettingsBanner'); | 72 chrome.send('onDismissedAutomaticSettingsResetBanner'); |
74 this.hadBeenDismissed_ = true; | 73 this.hadBeenDismissed_ = true; |
75 this.setVisibility_(false); | 74 this.setVisibility_(false); |
76 }, | 75 }, |
77 | 76 |
78 /** | 77 /** |
79 * Sets whether or not the reset profile settings banner shall be visible. | 78 * Sets whether or not the reset profile settings banner shall be visible. |
80 * @param {boolean} show Whether or not to show the banner. | 79 * @param {boolean} show Whether or not to show the banner. |
81 * @private | 80 * @private |
82 */ | 81 */ |
83 setVisibility_: function(show) { | 82 setVisibility_: function(show) { |
84 $('reset-profile-settings-banner').hidden = !show; | 83 $('automatic-settings-reset-banner').hidden = !show; |
85 } | 84 } |
86 }; | 85 }; |
87 | 86 |
88 // Forward public APIs to private implementations. | 87 // Forward public APIs to private implementations. |
89 [ | 88 [ |
90 'show', | 89 'show', |
91 'dismiss', | 90 'dismiss', |
92 ].forEach(function(name) { | 91 ].forEach(function(name) { |
93 ResetProfileSettingsBanner[name] = function() { | 92 AutomaticSettingsResetBanner[name] = function() { |
94 var instance = ResetProfileSettingsBanner.getInstance(); | 93 var instance = AutomaticSettingsResetBanner.getInstance(); |
95 return instance[name + '_'].apply(instance, arguments); | 94 return instance[name + '_'].apply(instance, arguments); |
96 }; | 95 }; |
97 }); | 96 }); |
98 | 97 |
99 // Export | 98 // Export |
100 return { | 99 return { |
101 ResetProfileSettingsBanner: ResetProfileSettingsBanner | 100 AutomaticSettingsResetBanner: AutomaticSettingsResetBanner |
102 }; | 101 }; |
103 }); | 102 }); |
OLD | NEW |