Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / resources / options / settings_banner.js
blob666aaf2aa500c29ce3b68ee685923fc23bf104ea
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() {
7 /**
8 * Base class for banners that appear at the top of the settings page.
9 * @constructor
11 function SettingsBannerBase() {}
13 cr.addSingletonGetter(SettingsBannerBase);
15 SettingsBannerBase.prototype = {
16 /**
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.
29 * @type {boolean}
30 * @private
32 hadBeenDismissed_: false,
34 /**
35 * Metric name to send when a show event occurs.
36 * @protected
38 showMetricName: '',
40 /**
41 * Name of the native callback invoked when the banner is dismised.
42 * @protected
44 dismissNativeCallbackName: '',
46 /**
47 * DOM element whose visibility is set when setVisibility_ is called.
48 * @protected
50 visibilityDomElement: null,
52 /**
53 * Called by the native code to show the banner if needed.
54 * @protected
56 show: function() {
57 if (!this.hadBeenDismissed_) {
58 chrome.send('metricsHandler:recordAction', [this.showMetricName]);
59 this.setVisibility_(true);
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 * @protected
69 dismiss: function() {
70 chrome.send(this.dismissNativeCallbackName);
71 this.hadBeenDismissed_ = true;
72 this.setVisibility_(false);
75 /**
76 * Sets whether or not the reset profile settings banner shall be visible.
77 * @param {boolean} show Whether or not to show the banner.
78 * @private
80 setVisibility_: function(show) {
81 this.visibilityDomElement.hidden = !show;
85 // Export
86 return {
87 SettingsBannerBase: SettingsBannerBase
89 });