| Index: chrome/browser/resources/net_export/net_export.js
|
| ===================================================================
|
| --- chrome/browser/resources/net_export/net_export.js (revision 0)
|
| +++ chrome/browser/resources/net_export/net_export.js (revision 0)
|
| @@ -0,0 +1,162 @@
|
| +// 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.
|
| +
|
| +/**
|
| + * Object to communicate between the renderer and the browser.
|
| + * @type {!BrowserBridge}
|
| + */
|
| +var g_exportBrowserBridge = null;
|
| +
|
| +/**
|
| + * Main entry point called once the page has loaded.
|
| + */
|
| +function onLoad() {
|
| + g_exportBrowserBridge = new BrowserBridge();
|
| + MainView.getInstance();
|
| +}
|
| +
|
| +document.addEventListener('DOMContentLoaded', onLoad);
|
| +
|
| +
|
| +/**
|
| + * This class provides a "bridge" for communicating between the javascript and
|
| + * the browser.
|
| + */
|
| +var BrowserBridge = (function() {
|
| + 'use strict';
|
| +
|
| + /**
|
| + * Delay in milliseconds between updates of certain browser information.
|
| + */
|
| + var POLL_INTERVAL_MS = 5000;
|
| +
|
| + /**
|
| + * @constructor
|
| + */
|
| + function BrowserBridge() {
|
| + }
|
| +
|
| + BrowserBridge.prototype = {
|
| +
|
| + //--------------------------------------------------------------------------
|
| + // Messages sent to the browser
|
| + //--------------------------------------------------------------------------
|
| +
|
| + setPollInterval: function() {
|
| + window.setInterval(this.sendGetExportNetLogInfo.bind(this),
|
| + POLL_INTERVAL_MS);
|
| + },
|
| +
|
| + sendGetExportNetLogInfo: function() {
|
| + chrome.send('getExportNetLogInfo');
|
| + },
|
| +
|
| + sendStartNetLog: function() {
|
| + chrome.send('startNetLog');
|
| + },
|
| +
|
| + sendStopNetLog: function() {
|
| + chrome.send('stopNetLog');
|
| + },
|
| +
|
| + sendSendNetLog: function() {
|
| + chrome.send('sendNetLog');
|
| + },
|
| +
|
| + //--------------------------------------------------------------------------
|
| + // Messages received from the browser.
|
| + //--------------------------------------------------------------------------
|
| +
|
| + receivedData: function(data) {
|
| + MainView.getInstance().onExportNetLogInfoChanged(data);
|
| + }
|
| + };
|
| +
|
| + return BrowserBridge;
|
| +})();
|
| +
|
| +/**
|
| + * This class handles the presentation of our profiler view. Used as a
|
| + * singleton.
|
| + */
|
| +var MainView = (function() {
|
| + 'use strict';
|
| +
|
| + // --------------------------------------------------------------------------
|
| + // Important IDs in the HTML document
|
| + // --------------------------------------------------------------------------
|
| +
|
| + var START_DATA_BUTTON_ID = 'export-view-start-data';
|
| + var STOP_DATA_BUTTON_ID = 'export-view-stop-data';
|
| + var SEND_DATA_BUTTON_ID = 'export-view-send-data';
|
| + var FILE_PATH_TEXT_ID = 'export-view-file-path-text';
|
| +
|
| + // --------------------------------------------------------------------------
|
| +
|
| + /**
|
| + * @constructor
|
| + */
|
| + function MainView() {
|
| + $(START_DATA_BUTTON_ID).onclick = this.onStartData_.bind(this);
|
| + $(STOP_DATA_BUTTON_ID).onclick = this.onStopData_.bind(this);
|
| + $(SEND_DATA_BUTTON_ID).onclick = this.onSendData_.bind(this);
|
| +
|
| + g_exportBrowserBridge.setPollInterval();
|
| +
|
| + g_exportBrowserBridge.sendGetExportNetLogInfo();
|
| + }
|
| +
|
| + cr.addSingletonGetter(MainView);
|
| +
|
| + MainView.prototype = {
|
| + /**
|
| + * Starts saving NetLog data to a file.
|
| + */
|
| + onStartData_: function() {
|
| + g_exportBrowserBridge.sendStartNetLog();
|
| + },
|
| +
|
| + /**
|
| + * Stops saving NetLog data to a file.
|
| + */
|
| + onStopData_: function() {
|
| + g_exportBrowserBridge.sendStopNetLog();
|
| + },
|
| +
|
| + /**
|
| + * Sends NetLog data via email from browser.
|
| + */
|
| + onSendData_: function() {
|
| + g_exportBrowserBridge.sendSendNetLog();
|
| + },
|
| +
|
| + onExportNetLogInfoChanged: function(exportNetLogInfo) {
|
| + if (exportNetLogInfo.file) {
|
| + var message = '';
|
| + if (exportNetLogInfo.state == 'ALLOW_STOP') {
|
| + message = 'NetLog data is collected in: ';
|
| + } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') {
|
| + message = 'NetLog data to send is in: ';
|
| + }
|
| + $(FILE_PATH_TEXT_ID).textContent = message + exportNetLogInfo.file;
|
| + } else {
|
| + $(FILE_PATH_TEXT_ID).textContent = '';
|
| + }
|
| +
|
| + $(START_DATA_BUTTON_ID).disabled = true;
|
| + $(STOP_DATA_BUTTON_ID).disabled = true;
|
| + $(SEND_DATA_BUTTON_ID).disabled = true;
|
| + if (exportNetLogInfo.state == 'ALLOW_START') {
|
| + $(START_DATA_BUTTON_ID).disabled = false;
|
| + } else if (exportNetLogInfo.state == 'ALLOW_STOP') {
|
| + $(STOP_DATA_BUTTON_ID).disabled = false;
|
| + } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') {
|
| + $(START_DATA_BUTTON_ID).disabled = false;
|
| + $(SEND_DATA_BUTTON_ID).disabled = false;
|
| + }
|
| + }
|
| + };
|
| +
|
| + return MainView;
|
| +})();
|
|
|