summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/reset_page/reset_browser_proxy.js
blob: b9d40047a730adce61bc0a9e2362cf029b774352 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2016 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.

cr.define('settings', function() {
  /** @interface */
  class ResetBrowserProxy {
    /**
     * @param {boolean} sendSettings Whether the user gave consent to upload
     *     broken settings to Google for analysis.
     * @param {string} requestOrigin The origin of the reset request.
     * @return {!Promise} A promise firing once resetting has completed.
     */
    performResetProfileSettings(sendSettings, requestOrigin) {}

    /**
     * A method to be called when the reset profile dialog is hidden.
     */
    onHideResetProfileDialog() {}

    /**
     * A method to be called when the reset profile banner is hidden.
     */
    onHideResetProfileBanner() {}

    /**
     * A method to be called when the reset profile dialog is shown.
     */
    onShowResetProfileDialog() {}

    /**
     * Shows the settings that are about to be reset and which will be reported
     * to Google for analysis, in a new tab.
     */
    showReportedSettings() {}

    /**
     * Retrieves the triggered reset tool name.
     * @return {!Promise<string>} A promise firing with the tool name, once it
     *     has been retrieved.
     */
    getTriggeredResetToolName() {}

    // <if expr="chromeos">
    /**
     * A method to be called when the reset powerwash dialog is shown.
     */
    onPowerwashDialogShow() {}

    /**
     * Initiates a factory reset and restarts ChromeOS.
     */
    requestFactoryResetRestart() {}
    // </if>
  }

  /**
   * @implements {settings.ResetBrowserProxy}
   */
  class ResetBrowserProxyImpl {
    /** @override */
    performResetProfileSettings(sendSettings, requestOrigin) {
      return cr.sendWithPromise(
          'performResetProfileSettings', sendSettings, requestOrigin);
    }

    /** @override */
    onHideResetProfileDialog() {
      chrome.send('onHideResetProfileDialog');
    }

    /** @override */
    onHideResetProfileBanner() {
      chrome.send('onHideResetProfileBanner');
    }

    /** @override */
    onShowResetProfileDialog() {
      chrome.send('onShowResetProfileDialog');
    }

    /** @override */
    showReportedSettings() {
      cr.sendWithPromise('getReportedSettings').then(function(settings) {
        const output = settings.map(function(entry) {
          return entry.key + ': ' + entry.value.replace(/\n/g, ', ');
        });
        const win = window.open('about:blank');
        const div = win.document.createElement('div');
        div.textContent = output.join('\n');
        div.style.whiteSpace = 'pre';
        win.document.body.appendChild(div);
      });
    }

    /** @override */
    getTriggeredResetToolName() {
      return cr.sendWithPromise('getTriggeredResetToolName');
    }

    // <if expr="chromeos">
    /** @override */
    onPowerwashDialogShow() {
      chrome.send('onPowerwashDialogShow');
    }

    /** @override */
    requestFactoryResetRestart() {
      chrome.send('requestFactoryResetRestart');
    }
    // </if>
  }

  cr.addSingletonGetter(ResetBrowserProxyImpl);

  return {
    ResetBrowserProxy: ResetBrowserProxy,
    ResetBrowserProxyImpl: ResetBrowserProxyImpl,
  };
});