Home | History | Annotate | Download | only in net_export
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 /**
      6  * Main entry point called once the page has loaded.
      7  */
      8 function onLoad() {
      9   NetExportView.getInstance();
     10 }
     11 
     12 document.addEventListener('DOMContentLoaded', onLoad);
     13 
     14 /**
     15  * This class handles the presentation of our profiler view. Used as a
     16  * singleton.
     17  */
     18 var NetExportView = (function() {
     19   'use strict';
     20 
     21   /**
     22    * Delay in milliseconds between updates of certain browser information.
     23    */
     24   /** @const */ var POLL_INTERVAL_MS = 5000;
     25 
     26   // --------------------------------------------------------------------------
     27 
     28   /**
     29    * @constructor
     30    */
     31   function NetExportView() {
     32     $('export-view-start-data').onclick = this.onStartData_.bind(this);
     33     $('export-view-stop-data').onclick = this.onStopData_.bind(this);
     34     $('export-view-send-data').onclick = this.onSendData_.bind(this);
     35 
     36     window.setInterval(function() { chrome.send('getExportNetLogInfo'); },
     37                        POLL_INTERVAL_MS);
     38 
     39     chrome.send('getExportNetLogInfo');
     40   }
     41 
     42   cr.addSingletonGetter(NetExportView);
     43 
     44   NetExportView.prototype = {
     45     /**
     46      * Starts saving NetLog data to a file.
     47      */
     48     onStartData_: function() {
     49       var stripPrivateData = $('export-view-private-data-toggle').checked;
     50       chrome.send('startNetLog', [stripPrivateData]);
     51     },
     52 
     53     /**
     54      * Stops saving NetLog data to a file.
     55      */
     56     onStopData_: function() {
     57       chrome.send('stopNetLog');
     58     },
     59 
     60     /**
     61      * Sends NetLog data via email from browser.
     62      */
     63     onSendData_: function() {
     64       chrome.send('sendNetLog');
     65     },
     66 
     67     /**
     68      * Updates the UI to reflect the current state. Displays the path name of
     69      * the file where NetLog data is collected.
     70      */
     71     onExportNetLogInfoChanged: function(exportNetLogInfo) {
     72       if (exportNetLogInfo.file) {
     73         var message = '';
     74         if (exportNetLogInfo.state == 'LOGGING')
     75           message = 'NetLog data is collected in: ';
     76         else if (exportNetLogInfo.logType != 'NONE')
     77           message = 'NetLog data to send is in: ';
     78         $('export-view-file-path-text').textContent =
     79             message + exportNetLogInfo.file;
     80       } else {
     81         $('export-view-file-path-text').textContent = '';
     82       }
     83 
     84       $('export-view-private-data-toggle').disabled = true;
     85       $('export-view-start-data').disabled = true;
     86       $('export-view-deletes-log-text').hidden = true;
     87       $('export-view-stop-data').disabled = true;
     88       $('export-view-send-data').disabled = true;
     89       $('export-view-private-data-text').hidden = true;
     90       $('export-view-send-old-log-text').hidden = true;
     91       if (exportNetLogInfo.state == 'NOT_LOGGING') {
     92         // Allow making a new log.
     93         $('export-view-private-data-toggle').disabled = false;
     94         $('export-view-start-data').disabled = false;
     95 
     96         // If there's an existing log, allow sending it.
     97         if (exportNetLogInfo.logType != 'NONE') {
     98           $('export-view-deletes-log-text').hidden = false;
     99           $('export-view-send-data').disabled = false;
    100           if (exportNetLogInfo.logType == 'UNKNOWN') {
    101             $('export-view-send-old-log-text').hidden = false;
    102           } else if (exportNetLogInfo.logType == 'NORMAL') {
    103             $('export-view-private-data-text').hidden = false;
    104           }
    105         }
    106       } else if (exportNetLogInfo.state == 'LOGGING') {
    107         // Only possible to stop logging. Checkbox reflects current state.
    108         $('export-view-private-data-toggle').checked =
    109             (exportNetLogInfo.logType == 'STRIP_PRIVATE_DATA');
    110         $('export-view-stop-data').disabled = false;
    111       } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
    112         $('export-view-file-path-text').textContent =
    113             'Unable to initialize NetLog data file.';
    114       }
    115     }
    116   };
    117 
    118   return NetExportView;
    119 })();
    120