summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/options/reset_profile_settings_banner.js
blob: 4785113d17f67c3242809dc50d2b6c1df815812d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Note: the native-side handler for this is ResetProfileSettingsHandler.

cr.define('options', function() {
  /** @const */ var PageManager = cr.ui.pageManager.PageManager;
  /** @const */ var SettingsBannerBase = options.SettingsBannerBase;

  /**
   * ResetProfileSettingsBanner class
   * Provides encapsulated handling of the Reset Profile Settings banner.
   * @constructor
   * @extends {options.SettingsBannerBase}
   */
  function ResetProfileSettingsBanner() {}

  cr.addSingletonGetter(ResetProfileSettingsBanner);

  ResetProfileSettingsBanner.prototype = {
    __proto__: SettingsBannerBase.prototype,

    /**
     * Initializes the banner's event handlers.
     * @suppress {checkTypes}
     * TODO(vitalyp): remove the suppression. See the explanation in
     * chrome/browser/resources/options/automatic_settings_reset_banner.js.
     */
    initialize: function() {
      this.showMetricName = 'AutomaticReset_WebUIBanner_BannerShown';

      this.dismissNativeCallbackName =
          'onDismissedResetProfileSettingsBanner';

      this.visibilityDomElement = $('reset-profile-settings-banner');

      $('reset-profile-settings-banner-close').onclick = function(event) {
        chrome.send('metricsHandler:recordAction',
            ['AutomaticReset_WebUIBanner_ManuallyClosed']);
        ResetProfileSettingsBanner.dismiss();
      };
      $('reset-profile-settings-banner-activate').onclick = function(event) {
        chrome.send('metricsHandler:recordAction',
            ['AutomaticReset_WebUIBanner_ResetClicked']);
        PageManager.showPageByName('resetProfileSettings');
      };
    },
  };

  // Forward public APIs to protected implementations.
  [
    'show',
    'dismiss',
  ].forEach(function(name) {
    ResetProfileSettingsBanner[name] = function() {
      var instance = ResetProfileSettingsBanner.getInstance();
      return instance[name].apply(instance, arguments);
    };
  });

  // Export
  return {
    ResetProfileSettingsBanner: ResetProfileSettingsBanner
  };
});