summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/bluetooth_internals/debug_log_page.js
blob: 5c13a39a26ebf0bd29fd6816a059c67dbefd45fb (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
// Copyright 2019 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.

/**
 * Javascript for DebugLogPage, served from chrome://bluetooth-internals/.
 */
cr.define('debug_log_page', function() {
  /** @const {string} */
  const LOGS_NOT_SUPPORTED_STRING = 'Debug logs not supported';

  /**
   * Page that allows user to enable/disable debug logs.
   */
  class DebugLogPage extends cr.ui.pageManager.Page {
    /**
     * @param {!mojom.BluetoothInternalsHandlerRemote} bluetoothInternalsHandler
     */
    constructor(bluetoothInternalsHandler) {
      super('debug', 'Debug Logs', 'debug');

      /**
       * @private {?mojom.DebugLogsChangeHandlerRemote}
       */
      this.debugLogsChangeHandler_ = null;

      /** @private {?HTMLInputElement} */
      this.inputElement_ = null;

      /** @private {!HTMLDivElement} */
      this.debugContainer_ =
          /** @type {!HTMLDivElement} */ ($('debug-container'));

      bluetoothInternalsHandler.getDebugLogsChangeHandler().then((params) => {
        if (params.handler) {
          this.setUpInput(params.handler, params.initialToggleValue);
        } else {
          this.debugContainer_.textContent = LOGS_NOT_SUPPORTED_STRING;
        }
      });
    }

    /**
     * @param {!mojom.DebugLogsChangeHandlerRemote} handler
     * @param {boolean} initialInputValue
     */
    setUpInput(handler, initialInputValue) {
      this.debugLogsChangeHandler_ = handler;

      this.inputElement_ =
          /** @type {!HTMLInputElement} */ (document.createElement('input'));
      this.inputElement_.setAttribute('type', 'checkbox');
      this.inputElement_.checked = initialInputValue;
      this.inputElement_.addEventListener(
          'change', this.onToggleChange.bind(this));
      this.debugContainer_.appendChild(this.inputElement_);
    }

    onToggleChange() {
      this.debugLogsChangeHandler_.changeDebugLogsState(
          this.inputElement_.checked);
    }
  }

  return {
    DebugLogPage: DebugLogPage,
  };
});