Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / settings_banner.js
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 // TODO(engedy): AutomaticSettingsResetBanner is the sole class to derive from
6 // SettingsBannerBase. Refactor this into automatic_settings_reset_banner.js.
7
8 cr.define('options', function() {
9
10   /**
11    * Base class for banners that appear at the top of the settings page.
12    */
13   function SettingsBannerBase() {}
14
15   cr.addSingletonGetter(SettingsBannerBase);
16
17   SettingsBannerBase.prototype = {
18     /**
19      * Whether or not the banner has already been dismissed.
20      *
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.
24      *
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.
30      *
31      * @type {boolean}
32      * @private
33      */
34     hadBeenDismissed_: false,
35
36     /**
37      * Metric name to send when a show event occurs.
38      */
39     showMetricName_: '',
40
41     /**
42      * Name of the native callback invoked when the banner is dismised.
43      */
44     dismissNativeCallbackName_: '',
45
46     /**
47      * DOM element whose visibility is set when setVisibility_ is called.
48      */
49     setVisibilibyDomElement_: null,
50
51     /**
52      * Called by the native code to show the banner if needed.
53      * @private
54      */
55     show_: function() {
56       if (!this.hadBeenDismissed_) {
57         chrome.send('metricsHandler:recordAction', [this.showMetricName_]);
58         this.setVisibility_(true);
59       }
60     },
61
62     /**
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.
66      * @private
67      */
68     dismiss_: function() {
69       chrome.send(this.dismissNativeCallbackName_);
70       this.hadBeenDismissed_ = true;
71       this.setVisibility_(false);
72     },
73
74     /**
75      * Sets whether or not the reset profile settings banner shall be visible.
76      * @param {boolean} show Whether or not to show the banner.
77      * @private
78      */
79     setVisibility_: function(show) {
80       this.setVisibilibyDomElement_.hidden = !show;
81     },
82
83   };
84
85   // Export
86   return {
87     SettingsBannerBase: SettingsBannerBase
88   };
89 });