summaryrefslogtreecommitdiff
path: root/chromium/components/net_log/resources/net_export.js
blob: b13b90d4859f0155cf417c4b04abb4c940a2525d (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
121
122
123
124
125
126
127
128
// Copyright (c) 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.

/**
 * Main entry point called once the page has loaded.
 */
function onLoad() {
  NetExportView.getInstance();
}

document.addEventListener('DOMContentLoaded', onLoad);

/**
 * This class handles the presentation of our profiler view. Used as a
 * singleton.
 */
var NetExportView = (function() {
  'use strict';

  // --------------------------------------------------------------------------

  /**
   * @constructor
   */
  function NetExportView() {
    $('export-view-start-data').onclick = this.onStartData_.bind(this);
    $('export-view-stop-data').onclick = this.onStopData_.bind(this);
    $('export-view-send-data').onclick = this.onSendData_.bind(this);

    // Tell NetExportMessageHandler to notify the UI of future state changes
    // from this point on (through onExportNetLogInfoChanged()).
    chrome.send('enableNotifyUIWithState');
  }

  cr.addSingletonGetter(NetExportView);

  NetExportView.prototype = {
    /**
     * Starts saving NetLog data to a file.
     */
    onStartData_: function() {
      var logMode =
          document.querySelector('input[name="log-mode"]:checked').value;
      chrome.send('startNetLog', [logMode]);
    },

    /**
     * Stops saving NetLog data to a file.
     */
    onStopData_: function() {
      chrome.send('stopNetLog');
    },

    /**
     * Sends NetLog data via email from browser.
     */
    onSendData_: function() {
      chrome.send('sendNetLog');
    },

    /**
     * Updates the UI to reflect the current state. Displays the path name of
     * the file where NetLog data is collected.
     */
    onExportNetLogInfoChanged: function(exportNetLogInfo) {
      if (!exportNetLogInfo.useMobileUI) {
        document.getElementById('export-view-send-data').style.display =
          "none";
        document.getElementById('export-view-deletes-log-text').style.display =
          "none";
      }

      if (exportNetLogInfo.file) {
        var message = '';
        if (exportNetLogInfo.state == 'LOGGING')
          message = 'NetLog data is collected in: ';
        else if (exportNetLogInfo.logType != 'NONE')
          message = 'NetLog data to send is in: ';
        $('export-view-file-path-text').textContent =
            message + exportNetLogInfo.file;
      } else {
        $('export-view-file-path-text').textContent = '';
      }

      // Disable all controls.  Useable controls are enabled below.
      var controls = document.querySelectorAll('button, input');
      for (var i = 0; i < controls.length; ++i) {
        controls[i].disabled = true;
      }

      $('export-view-deletes-log-text').hidden = true;
      $('export-view-private-data-text').hidden = true;
      $('export-view-send-old-log-text').hidden = true;
      if (exportNetLogInfo.state == 'NOT_LOGGING') {
        // Allow making a new log.
        $('export-view-strip-private-data-button').disabled = false;
        $('export-view-include-private-data-button').disabled = false;
        $('export-view-log-bytes-button').disabled = false;
        $('export-view-start-data').disabled = false;

        // If there's an existing log, allow sending it.
        if (!!exportNetLogInfo.logExists) {
          $('export-view-deletes-log-text').hidden = false;
          $('export-view-send-data').disabled = false;
          if (!exportNetLogInfo.logCaptureModeKnown) {
            $('export-view-send-old-log-text').hidden = false;
          } else if (exportNetLogInfo.captureMode != 'STRIP_PRIVATE_DATA') {
            $('export-view-private-data-text').hidden = false;
          }
        }
      } else if (exportNetLogInfo.state == 'LOGGING') {
        // Only possible to stop logging. Radio buttons reflects current state.
        document
            .querySelector(
                'input[name="log-mode"][value="' +
                exportNetLogInfo.captureMode + '"]')
            .checked = true;
        $('export-view-stop-data').disabled = false;
      } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
        $('export-view-file-path-text').textContent =
            'Unable to initialize NetLog data file.';
      }
    }
  };

  return NetExportView;
})();