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 SettingsBannerBase = options.SettingsBannerBase; | 8 /** @const */ var SettingsBannerBase = options.SettingsBannerBase; |
9 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 9 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
10 | 10 |
11 /** | 11 /** |
12 * AutomaticSettingsResetBanner class | 12 * AutomaticSettingsResetBanner class |
13 * Provides encapsulated handling of the Reset Profile Settings banner. | 13 * Provides encapsulated handling of the Reset Profile Settings banner. |
14 * @constructor | 14 * @constructor |
15 * @extends {options.SettingsBannerBase} | 15 * @extends {options.SettingsBannerBase} |
16 */ | 16 */ |
17 function AutomaticSettingsResetBanner() {} | 17 function AutomaticSettingsResetBanner() {} |
18 | 18 |
19 cr.addSingletonGetter(AutomaticSettingsResetBanner); | 19 cr.addSingletonGetter(AutomaticSettingsResetBanner); |
20 | 20 |
21 AutomaticSettingsResetBanner.prototype = { | 21 AutomaticSettingsResetBanner.prototype = { |
22 __proto__: SettingsBannerBase.prototype, | 22 __proto__: SettingsBannerBase.prototype, |
23 | 23 |
24 /** | 24 /** |
25 * Initializes the banner's event handlers. | 25 * Initializes the banner's event handlers. |
26 */ | 26 */ |
27 initialize: function() { | 27 initialize: function() { |
28 this.showMetricName_ = 'AutomaticSettingsReset_WebUIBanner_BannerShown'; | 28 this.showMetricName = 'AutomaticSettingsReset_WebUIBanner_BannerShown'; |
29 | 29 |
30 this.dismissNativeCallbackName_ = | 30 this.dismissNativeCallbackName = |
31 'onDismissedAutomaticSettingsResetBanner'; | 31 'onDismissedAutomaticSettingsResetBanner'; |
32 | 32 |
33 this.setVisibilibyDomElement_ = $('automatic-settings-reset-banner'); | 33 this.visibilityDomElement = $('automatic-settings-reset-banner'); |
34 | 34 |
35 $('automatic-settings-reset-banner-close').onclick = function(event) { | 35 $('automatic-settings-reset-banner-close').onclick = function(event) { |
36 chrome.send('metricsHandler:recordAction', | 36 chrome.send('metricsHandler:recordAction', |
37 ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']); | 37 ['AutomaticSettingsReset_WebUIBanner_ManuallyClosed']); |
38 AutomaticSettingsResetBanner.dismiss(); | 38 AutomaticSettingsResetBanner.dismiss(); |
39 }; | 39 }; |
40 $('automatic-settings-reset-learn-more').onclick = function(event) { | 40 $('automatic-settings-reset-learn-more').onclick = function(event) { |
41 chrome.send('metricsHandler:recordAction', | 41 chrome.send('metricsHandler:recordAction', |
42 ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']); | 42 ['AutomaticSettingsReset_WebUIBanner_LearnMoreClicked']); |
43 }; | 43 }; |
44 $('automatic-settings-reset-banner-activate-reset').onclick = | 44 $('automatic-settings-reset-banner-activate-reset').onclick = |
45 function(event) { | 45 function(event) { |
46 chrome.send('metricsHandler:recordAction', | 46 chrome.send('metricsHandler:recordAction', |
47 ['AutomaticSettingsReset_WebUIBanner_ResetClicked']); | 47 ['AutomaticSettingsReset_WebUIBanner_ResetClicked']); |
48 PageManager.showPageByName('resetProfileSettings'); | 48 PageManager.showPageByName('resetProfileSettings'); |
49 }; | 49 }; |
50 }, | 50 }, |
51 | |
52 /** | |
53 * Called by the native code to show the banner if needed. | |
54 * @private | |
55 */ | |
56 show_: function() { | |
57 if (!this.hadBeenDismissed_) { | |
58 chrome.send('metricsHandler:recordAction', [this.showMetricName_]); | |
59 this.setVisibility(true); | |
60 } | |
61 }, | |
62 | |
63 /** | |
64 * Called when the banner should be closed as a result of something taking | |
65 * place on the WebUI page, i.e. when its close button is pressed, or when | |
66 * the confirmation dialog for the profile settings reset feature is opened. | |
67 * @private | |
68 */ | |
69 dismiss_: function() { | |
70 chrome.send(this.dismissNativeCallbackName_); | |
71 this.hadBeenDismissed_ = true; | |
72 this.setVisibility(false); | |
73 }, | |
74 }; | 51 }; |
75 | 52 |
76 // Forward public APIs to private implementations. | 53 // Forward public APIs to protected implementations. |
77 cr.makePublic(AutomaticSettingsResetBanner, [ | 54 [ |
78 'show', | 55 'show', |
79 'dismiss', | 56 'dismiss', |
80 ]); | 57 ].forEach(function(name) { |
| 58 AutomaticSettingsResetBanner[name] = function() { |
| 59 var instance = AutomaticSettingsResetBanner.getInstance(); |
| 60 return instance[name].apply(instance, arguments); |
| 61 }; |
| 62 }); |
81 | 63 |
82 // Export | 64 // Export |
83 return { | 65 return { |
84 AutomaticSettingsResetBanner: AutomaticSettingsResetBanner | 66 AutomaticSettingsResetBanner: AutomaticSettingsResetBanner |
85 }; | 67 }; |
86 }); | 68 }); |
OLD | NEW |