summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/languages_page/languages_browser_proxy.js
blob: e23dd2500694c3a6f8d73ddefe2892c17652f2ab (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
// Copyright 2017 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.

/**
 * @fileoverview A helper object used from the languages section
 * to interact with the browser.
 */

cr.define('settings', function() {
  /** @interface */
  class LanguagesBrowserProxy {
    // <if expr="chromeos or is_win">
    /**
     * Sets the prospective UI language to the chosen language. This won't
     * affect the actual UI language until a restart.
     * @param {string} languageCode
     */
    setProspectiveUILanguage(languageCode) {}

    /** @return {!Promise<string>} */
    getProspectiveUILanguage() {}

    // </if>

    /** @return {!LanguageSettingsPrivate} */
    getLanguageSettingsPrivate() {}

    // <if expr="chromeos">
    /** @return {!InputMethodPrivate} */
    getInputMethodPrivate() {}
    // </if>
  }

  /**
   * @implements {settings.LanguagesBrowserProxy}
   */
  class LanguagesBrowserProxyImpl {
    // <if expr="chromeos or is_win">
    /** @override */
    setProspectiveUILanguage(languageCode) {
      chrome.send('setProspectiveUILanguage', [languageCode]);
    }

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

    // </if>

    /** @override */
    getLanguageSettingsPrivate() {
      return /** @type {!LanguageSettingsPrivate} */ (
          chrome.languageSettingsPrivate);
    }

    // <if expr="chromeos">
    /** @override */
    getInputMethodPrivate() {
      return /** @type {!InputMethodPrivate} */ (chrome.inputMethodPrivate);
    }
    // </if>
  }

  // The singleton instance_ is replaced with a test version of this wrapper
  // during testing.
  cr.addSingletonGetter(LanguagesBrowserProxyImpl);

  return {
    LanguagesBrowserProxy: LanguagesBrowserProxy,
    LanguagesBrowserProxyImpl: LanguagesBrowserProxyImpl,
  };
});