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. 4 5 cr.define('options', function() { 6 7 /** 8 * Base class for banners that appear at the top of the settings page. 9 * @constructor 10 */ 11 function SettingsBannerBase() {} 12 13 cr.addSingletonGetter(SettingsBannerBase); 14 15 SettingsBannerBase.prototype = { 16 /** 17 * Whether or not the banner has already been dismissed. 18 * 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. 22 * 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. 28 * 29 * @type {boolean} 30 * @private 31 */ 32 hadBeenDismissed_: false, 33 34 /** 35 * Metric name to send when a show event occurs. 36 * @protected 37 */ 38 showMetricName: '', 39 40 /** 41 * Name of the native callback invoked when the banner is dismised. 42 * @protected 43 */ 44 dismissNativeCallbackName: '', 45 46 /** 47 * DOM element whose visibility is set when setVisibility_ is called. 48 * @protected 49 */ 50 visibilityDomElement: null, 51 52 /** 53 * Called by the native code to show the banner if needed. 54 * @protected 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 * @protected 68 */ 69 dismiss: function() { 70 chrome.send(this.dismissNativeCallbackName); 71 this.hadBeenDismissed_ = true; 72 this.setVisibility_(false); 73 }, 74 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 79 */ 80 setVisibility_: function(show) { 81 this.visibilityDomElement.hidden = !show; 82 }, 83 }; 84 85 // Export 86 return { 87 SettingsBannerBase: SettingsBannerBase 88 }; 89 }); 90