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 cr.define('options', function() {
8 * Base class for banners that appear at the top of the settings page.
11 function SettingsBannerBase() {}
13 cr.addSingletonGetter(SettingsBannerBase);
15 SettingsBannerBase.prototype = {
17 * Whether or not the banner has already been dismissed.
19 * This is needed because of the surprising ordering of asynchronous
20 * JS<->native calls when the settings page is opened with specifying a
21 * given sub-page, e.g. chrome://settings/AutomaticSettingsReset.
23 * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which
24 * calls our dismiss() method, would be called before the native Handlers'
25 * InitalizePage() methods have an effect in the JS, which includes calling
26 * our show() method. This would mean that the banner would be first
27 * dismissed, then shown. We want to prevent this.
32 hadBeenDismissed_: false,
35 * Metric name to send when a show event occurs.
41 * Name of the native callback invoked when the banner is dismised.
44 dismissNativeCallbackName: '',
47 * DOM element whose visibility is set when setVisibility_ is called.
50 visibilityDomElement: null,
53 * Called by the native code to show the banner if needed.
57 if (!this.hadBeenDismissed_) {
58 chrome.send('metricsHandler:recordAction', [this.showMetricName]);
59 this.setVisibility_(true);
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.
70 chrome.send(this.dismissNativeCallbackName);
71 this.hadBeenDismissed_ = true;
72 this.setVisibility_(false);
76 * Sets whether or not the reset profile settings banner shall be visible.
77 * @param {boolean} show Whether or not to show the banner.
80 setVisibility_: function(show) {
81 this.visibilityDomElement.hidden = !show;
87 SettingsBannerBase: SettingsBannerBase