Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6375)

Unified Diff: chrome/browser/resources/net_internals/mobile_main.js

Issue 11635023: First cut at UI for saving net_logs data into a temporary file on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/net_internals/mobile_main.js
===================================================================
--- chrome/browser/resources/net_internals/mobile_main.js (revision 0)
+++ chrome/browser/resources/net_internals/mobile_main.js (revision 0)
@@ -0,0 +1,232 @@
+// 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.
+
+/**
+ * Dictionary of constants (Initialized soon after loading by data from browser,
+ * updated on load log). The *Types dictionaries map strings to numeric IDs,
+ * while the *TypeNames are the other way around.
+ */
+var EventType = null;
+var EventTypeNames = null;
+var EventPhase = null;
+var EventSourceType = null;
+var EventSourceTypeNames = null;
+var LogLevelType = null;
+var ClientInfo = null;
+var NetError = null;
+var LoadFlag = null;
+var LoadState = null;
+var AddressFamily = null;
+
+/**
+ * Dictionary of all constants, used for saving log files.
+ */
+var Constants = null;
+
+/**
+ * Object to communicate between the renderer and the browser.
+ * @type {!BrowserBridge}
+ */
+var g_browser = null;
+
+/**
+ * This class is the root view object of the page. It owns all the other
+ * views, and manages switching between them. It is also responsible for
+ * initializing the views and the BrowserBridge.
+ */
+var MainView = (function() {
+ 'use strict';
+
+ // We inherit from HorizontalSplitView
+ var superClass = HorizontalSplitView;
+
+ /**
+ * Main entry point. Called once the page has loaded.
+ * @constructor
+ */
+ function MainView() {
+ assertFirstConstructorCall(MainView);
+
+ if (hasTouchScreen())
+ document.body.classList.add('touch');
+
+ // This must be initialized before the tabs, so they can register as
+ // observers.
+ g_browser = BrowserBridge.getInstance();
+
+ // This must be the first constants observer, so other constants observers
+ // can safely use the globals, rather than depending on walking through
+ // the constants themselves.
+ g_browser.addConstantsObserver(new ConstantsObserver());
+
+ // This view is a left navigation bar.
+ this.categoryTabSwitcher_ = new TabSwitcherView();
+ var tabs = this.categoryTabSwitcher_;
+
+ // Call superclass's constructor, initializing the view which lets you tab
+ // between the different sub-views.
+ superClass.call(this,
+ new DivView(MainView.CATEGORY_TAB_HANDLES_ID),
+ tabs);
+
+ // Populate the main tabs. Even tabs that don't contain information for the
+ // running OS should be created, so they can load log dumps from other
+ // OSes.
+ tabs.addTab(MobileView.TAB_HANDLE_ID, MobileView.getInstance(),
+ false, true);
mmenke 2013/01/04 16:22:09 You're planning on getting rid of these in a later
+
+ // Build a map from the anchor name of each tab handle to its "tab ID".
+ // We will consider navigations to the #hash as a switch tab request.
+ var anchorMap = {};
+ var tabIds = tabs.getAllTabIds();
+ for (var i = 0; i < tabIds.length; ++i) {
+ var aNode = $(tabIds[i]);
+ anchorMap[aNode.hash] = tabIds[i];
+ }
+ // Default the empty hash to the data tab.
+ anchorMap['#'] = anchorMap[''] = MobileView.TAB_HANDLE_ID;
+
+ window.onhashchange = onUrlHashChange.bind(null, tabs, anchorMap);
+
+ // Cut out a small vertical strip at the top of the window, to display
+ // a high level status (i.e. if we are capturing events, or displaying a
+ // log file). Below it we will position the main tabs and their content
+ // area.
+ this.statusView_ = StatusView.getInstance(this);
+ var verticalSplitView = new VerticalSplitView(this.statusView_, this);
+ this.statusView_.setLayoutParent(verticalSplitView);
+ var windowView = new WindowView(verticalSplitView);
+
+ // Don't cache events from browser in renderer process.
+ var softLimit = 10;
+ var hardLimit = 20;
+ EventsTracker.getInstance().setLimits(softLimit, hardLimit);
+
+ // Trigger initial layout.
+ windowView.resetGeometry();
+
+ // Select the initial view based on the current URL.
+ window.onhashchange();
+
+ // Tell the browser that we are ready to start receiving log events.
+ g_browser.sendReady();
+ }
+
+ // IDs for special HTML elements in index.html
+ MainView.CATEGORY_TAB_HANDLES_ID = 'category-tab-handles';
+
+ cr.addSingletonGetter(MainView);
+
+ // On mobile, disable viewing of a loaded log file.
+ var isViewingLoadedLog = false;
+
+ MainView.isViewingLoadedLog = function() {
+ return isViewingLoadedLog;
+ };
+
+ MainView.prototype = {
+ // Inherit the superclass's methods.
+ __proto__: superClass.prototype,
+
+ // This is exposed so that log_util.js can call it.
+ categoryTabSwitcher: function() {
+ return this.categoryTabSwitcher_;
+ },
+
+ /**
+ * Disabled loading of log files on Mobile.
+ */
+ onLoadLog: function(opt_fileName) {
+ },
+
+ switchToViewOnlyMode: function() {
+ },
+
+ stopCapturing: function() {
+ g_browser.disable();
+ document.styleSheets[0].insertRule(
+ '.hide-when-not-capturing { display: none; }');
+ }
+ };
+
+ /**
+ * Takes the current hash in form of "#tab&param1=value1&param2=value2&...".
+ * Puts the parameters in an object, and passes the resulting object to
+ * |categoryTabSwitcher|. Uses tab and |anchorMap| to find a tab ID,
+ * which it also passes to the tab switcher.
+ *
+ * Parameters and values are decoded with decodeURIComponent().
+ */
+ function onUrlHashChange(categoryTabSwitcher, anchorMap) {
+ var parameters = window.location.hash.split('&');
+
+ var tabId = anchorMap[parameters[0]];
+ if (!tabId)
+ return;
+
+ // Split each string except the first around the '='.
+ var paramDict = null;
+ for (var i = 1; i < parameters.length; i++) {
+ var paramStrings = parameters[i].split('=');
+ if (paramStrings.length != 2)
+ continue;
+ if (paramDict == null)
+ paramDict = {};
+ var key = decodeURIComponent(paramStrings[0]);
+ var value = decodeURIComponent(paramStrings[1]);
+ paramDict[key] = value;
+ }
+
+ categoryTabSwitcher.switchToTab(tabId, paramDict);
+ }
+
+ return MainView;
+})();
+
+function ConstantsObserver() {}
mmenke 2013/01/04 16:22:09 Think it's worth moving the constants stuff to a s
+
+/**
+ * Loads all constants from |constants|. On failure, global dictionaries are
+ * not modifed.
+ * @param {Object} receivedConstants The map of received constants.
+ */
+ConstantsObserver.prototype.onReceivedConstants = function(receivedConstants) {
+ if (!areValidConstants(receivedConstants))
+ return;
+
+ Constants = receivedConstants;
+
+ EventType = Constants.logEventTypes;
+ EventTypeNames = makeInverseMap(EventType);
+ EventPhase = Constants.logEventPhase;
+ EventSourceType = Constants.logSourceType;
+ EventSourceTypeNames = makeInverseMap(EventSourceType);
+ LogLevelType = Constants.logLevelType;
+ ClientInfo = Constants.clientInfo;
+ LoadFlag = Constants.loadFlag;
+ NetError = Constants.netError;
+ AddressFamily = Constants.addressFamily;
+ LoadState = Constants.loadState;
+
+ timeutil.setTimeTickOffset(Constants.timeTickOffset);
+};
+
+/**
+ * Returns true if it's given a valid-looking constants object.
+ * @param {Object} receivedConstants The received map of constants.
+ * @return {boolean} True if the |receivedConstants| object appears valid.
+ */
+function areValidConstants(receivedConstants) {
+ return typeof(receivedConstants) == 'object' &&
+ typeof(receivedConstants.logEventTypes) == 'object' &&
+ typeof(receivedConstants.clientInfo) == 'object' &&
+ typeof(receivedConstants.logEventPhase) == 'object' &&
+ typeof(receivedConstants.logSourceType) == 'object' &&
+ typeof(receivedConstants.logLevelType) == 'object' &&
+ typeof(receivedConstants.loadFlag) == 'object' &&
+ typeof(receivedConstants.netError) == 'object' &&
+ typeof(receivedConstants.addressFamily) == 'object' &&
+ typeof(receivedConstants.timeTickOffset) == 'string' &&
+ typeof(receivedConstants.logFormatVersion) == 'number';
+}

Powered by Google App Engine
This is Rietveld 408576698