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
3 // found in the LICENSE file.
5 // TODO(engedy): AutomaticSettingsResetBanner is the sole class to derive from
6 // SettingsBannerBase. Refactor this into automatic_settings_reset_banner.js.
8 cr.define('options', function() {
11 * Base class for banners that appear at the top of the settings page.
13 function SettingsBannerBase() {}
15 cr.addSingletonGetter(SettingsBannerBase);
17 SettingsBannerBase.prototype = {
19 * Whether or not the banner has already been dismissed.
21 * This is needed because of the surprising ordering of asynchronous
22 * JS<->native calls when the settings page is opened with specifying a
23 * given sub-page, e.g. chrome://settings/AutomaticSettingsReset.
25 * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which
26 * calls our dismiss() method, would be called before the native Handlers'
27 * InitalizePage() methods have an effect in the JS, which includes calling
28 * our show() method. This would mean that the banner would be first
29 * dismissed, then shown. We want to prevent this.
34 hadBeenDismissed_: false,
37 * Metric name to send when a show event occurs.
42 * Name of the native callback invoked when the banner is dismised.
44 dismissNativeCallbackName_: '',
47 * DOM element whose visibility is set when setVisibility_ is called.
49 setVisibilibyDomElement_: null,
52 * Called by the native code to show the banner if needed.
56 if (!this.hadBeenDismissed_) {
57 chrome.send('metricsHandler:recordAction', [this.showMetricName_]);
58 this.setVisibility_(true);
63 * Called when the banner should be closed as a result of something taking
64 * place on the WebUI page, i.e. when its close button is pressed, or when
65 * the confirmation dialog for the profile settings reset feature is opened.
68 dismiss_: function() {
69 chrome.send(this.dismissNativeCallbackName_);
70 this.hadBeenDismissed_ = true;
71 this.setVisibility_(false);
75 * Sets whether or not the reset profile settings banner shall be visible.
76 * @param {boolean} show Whether or not to show the banner.
79 setVisibility_: function(show) {
80 this.setVisibilibyDomElement_.hidden = !show;
87 SettingsBannerBase: SettingsBannerBase