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
3 // found in the LICENSE file.
5 // Note: the native-side handler for this is ResetProfileSettingsHandler.
7 cr.define('options', function() {
8 /** @const */ var OptionsPage = options.OptionsPage;
11 * ResetProfileSettingsBanner class
12 * Provides encapsulated handling of the Reset Profile Settings banner.
15 function ResetProfileSettingsBanner() {}
17 cr.addSingletonGetter(ResetProfileSettingsBanner);
19 ResetProfileSettingsBanner.prototype = {
21 * Whether or not the banner has already been dismissed.
23 * This is needed because of the surprising ordering of asynchronous
24 * JS<->native calls when the settings page is opened with specifying a
25 * given sub-page, e.g. chrome://settings/resetProfileSettings.
27 * In such a case, ResetProfileSettingsOverlay's didShowPage(), which calls
28 * our dismiss() method, would be called before the native Handlers'
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
31 * dismissed, then shown. We want to prevent this.
36 hadBeenDismissed_: false,
39 * Initializes the banner's event handlers.
41 initialize: function() {
42 $('reset-profile-settings-banner-close').onclick = function(event) {
43 chrome.send('metricsHandler:recordAction',
44 ['AutomaticReset_WebUIBanner_ManuallyClosed']);
45 ResetProfileSettingsBanner.dismiss();
47 $('reset-profile-settings-banner-activate').onclick = function(event) {
48 chrome.send('metricsHandler:recordAction',
49 ['AutomaticReset_WebUIBanner_ResetClicked']);
50 OptionsPage.navigateToPage('resetProfileSettings');
55 * Called by the native code to show the banner if needed.
59 if (!this.hadBeenDismissed_) {
60 chrome.send('metricsHandler:recordAction',
61 ['AutomaticReset_WebUIBanner_BannerShown']);
62 this.setVisibility_(true);
67 * 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
69 * the confirmation dialog for the profile settings reset feature is opened.
72 dismiss_: function() {
73 chrome.send('onDismissedResetProfileSettingsBanner');
74 this.hadBeenDismissed_ = true;
75 this.setVisibility_(false);
79 * Sets whether or not the reset profile settings banner shall be visible.
80 * @param {boolean} show Whether or not to show the banner.
83 setVisibility_: function(show) {
84 $('reset-profile-settings-banner').hidden = !show;
88 // Forward public APIs to private implementations.
92 ].forEach(function(name) {
93 ResetProfileSettingsBanner[name] = function() {
94 var instance = ResetProfileSettingsBanner.getInstance();
95 return instance[name + '_'].apply(instance, arguments);
101 ResetProfileSettingsBanner: ResetProfileSettingsBanner