2013-03-11 23:50:42 -07:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
|
2013-05-10 02:01:05 -07:00
|
|
|
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
2013-03-11 23:50:42 -07:00
|
|
|
const EPSILON = 0.001;
|
2013-05-24 11:36:52 -07:00
|
|
|
const SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE = 102400; // 100 KB in bytes
|
2013-05-10 02:01:05 -07:00
|
|
|
const RESIZE_REFRESH_RATE = 50; // ms
|
2013-03-11 23:50:42 -07:00
|
|
|
const REQUESTS_REFRESH_RATE = 50; // ms
|
2013-04-22 11:12:17 -07:00
|
|
|
const REQUESTS_HEADERS_SAFE_BOUNDS = 30; // px
|
2014-02-14 11:22:06 -08:00
|
|
|
const REQUESTS_TOOLTIP_POSITION = "topcenter bottomleft";
|
|
|
|
const REQUESTS_TOOLTIP_IMAGE_MAX_DIM = 400; // px
|
2013-05-10 02:01:05 -07:00
|
|
|
const REQUESTS_WATERFALL_SAFE_BOUNDS = 90; // px
|
|
|
|
const REQUESTS_WATERFALL_HEADER_TICKS_MULTIPLE = 5; // ms
|
|
|
|
const REQUESTS_WATERFALL_HEADER_TICKS_SPACING_MIN = 60; // px
|
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_MULTIPLE = 5; // ms
|
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_SCALES = 3;
|
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_SPACING_MIN = 10; // px
|
2013-05-15 13:33:10 -07:00
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_COLOR_RGB = [128, 136, 144];
|
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_OPACITY_MIN = 32; // byte
|
|
|
|
const REQUESTS_WATERFALL_BACKGROUND_TICKS_OPACITY_ADD = 32; // byte
|
2013-03-11 23:50:42 -07:00
|
|
|
const DEFAULT_HTTP_VERSION = "HTTP/1.1";
|
2014-01-31 22:37:53 -08:00
|
|
|
const REQUEST_TIME_DECIMALS = 2;
|
2013-03-11 23:50:42 -07:00
|
|
|
const HEADERS_SIZE_DECIMALS = 3;
|
|
|
|
const CONTENT_SIZE_DECIMALS = 2;
|
|
|
|
const CONTENT_MIME_TYPE_ABBREVIATIONS = {
|
|
|
|
"ecmascript": "js",
|
|
|
|
"javascript": "js",
|
|
|
|
"x-javascript": "js"
|
|
|
|
};
|
|
|
|
const CONTENT_MIME_TYPE_MAPPINGS = {
|
2013-10-24 10:08:17 -07:00
|
|
|
"/ecmascript": Editor.modes.js,
|
|
|
|
"/javascript": Editor.modes.js,
|
|
|
|
"/x-javascript": Editor.modes.js,
|
|
|
|
"/html": Editor.modes.html,
|
|
|
|
"/xhtml": Editor.modes.html,
|
|
|
|
"/xml": Editor.modes.html,
|
|
|
|
"/atom": Editor.modes.html,
|
|
|
|
"/soap": Editor.modes.html,
|
|
|
|
"/rdf": Editor.modes.css,
|
|
|
|
"/rss": Editor.modes.css,
|
|
|
|
"/css": Editor.modes.css
|
2013-03-11 23:50:42 -07:00
|
|
|
};
|
|
|
|
const DEFAULT_EDITOR_CONFIG = {
|
2013-10-24 10:08:17 -07:00
|
|
|
mode: Editor.modes.text,
|
2013-03-11 23:50:42 -07:00
|
|
|
readOnly: true,
|
2013-10-24 10:08:17 -07:00
|
|
|
lineNumbers: true
|
2013-03-11 23:50:42 -07:00
|
|
|
};
|
|
|
|
const GENERIC_VARIABLES_VIEW_SETTINGS = {
|
2013-06-21 07:33:56 -07:00
|
|
|
lazyEmpty: true,
|
2013-03-11 23:50:42 -07:00
|
|
|
lazyEmptyDelay: 10, // ms
|
|
|
|
searchEnabled: true,
|
|
|
|
editableValueTooltip: "",
|
|
|
|
editableNameTooltip: "",
|
2013-12-02 20:07:13 -08:00
|
|
|
preventDisableOnChange: true,
|
2013-06-21 07:33:56 -07:00
|
|
|
preventDescriptorModifiers: true,
|
2014-02-13 12:15:42 -08:00
|
|
|
eval: () => {}
|
2013-03-11 23:50:42 -07:00
|
|
|
};
|
2014-01-31 22:37:53 -08:00
|
|
|
const NETWORK_ANALYSIS_PIE_CHART_DIAMETER = 200; // px
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Object defining the network monitor view components.
|
|
|
|
*/
|
|
|
|
let NetMonitorView = {
|
|
|
|
/**
|
|
|
|
* Initializes the network monitor view.
|
|
|
|
*/
|
2013-07-10 01:40:51 -07:00
|
|
|
initialize: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
this._initializePanes();
|
|
|
|
|
|
|
|
this.Toolbar.initialize();
|
|
|
|
this.RequestsMenu.initialize();
|
|
|
|
this.NetworkDetails.initialize();
|
2014-01-28 05:50:34 -08:00
|
|
|
this.CustomRequest.initialize();
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the network monitor view.
|
|
|
|
*/
|
2013-07-10 01:40:51 -07:00
|
|
|
destroy: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
this.Toolbar.destroy();
|
|
|
|
this.RequestsMenu.destroy();
|
|
|
|
this.NetworkDetails.destroy();
|
2014-01-28 05:50:34 -08:00
|
|
|
this.CustomRequest.destroy();
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
this._destroyPanes();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the UI for all the displayed panes.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_initializePanes: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Initializing the NetMonitorView panes");
|
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
this._body = $("#body");
|
2013-03-11 23:50:42 -07:00
|
|
|
this._detailsPane = $("#details-pane");
|
|
|
|
this._detailsPaneToggleButton = $("#details-pane-toggle");
|
|
|
|
|
|
|
|
this._collapsePaneString = L10N.getStr("collapseDetailsPane");
|
|
|
|
this._expandPaneString = L10N.getStr("expandDetailsPane");
|
|
|
|
|
|
|
|
this._detailsPane.setAttribute("width", Prefs.networkDetailsWidth);
|
2013-04-22 11:12:17 -07:00
|
|
|
this._detailsPane.setAttribute("height", Prefs.networkDetailsHeight);
|
2013-03-11 23:50:42 -07:00
|
|
|
this.toggleDetailsPane({ visible: false });
|
2014-01-31 22:37:53 -08:00
|
|
|
|
|
|
|
// Disable the performance statistics mode.
|
|
|
|
if (!Prefs.statistics) {
|
|
|
|
$("#request-menu-context-perf").hidden = true;
|
|
|
|
$("#notice-perf-message").hidden = true;
|
|
|
|
$("#requests-menu-network-summary-button").hidden = true;
|
|
|
|
$("#requests-menu-network-summary-label").hidden = true;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the UI for all the displayed panes.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_destroyPanes: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Destroying the NetMonitorView panes");
|
|
|
|
|
|
|
|
Prefs.networkDetailsWidth = this._detailsPane.getAttribute("width");
|
2013-04-22 11:12:17 -07:00
|
|
|
Prefs.networkDetailsHeight = this._detailsPane.getAttribute("height");
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
this._detailsPane = null;
|
|
|
|
this._detailsPaneToggleButton = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the visibility state of the network details pane.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-01-31 22:37:53 -08:00
|
|
|
get detailsPaneHidden() {
|
|
|
|
return this._detailsPane.hasAttribute("pane-collapsed");
|
|
|
|
},
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network details pane hidden or visible.
|
|
|
|
*
|
|
|
|
* @param object aFlags
|
|
|
|
* An object containing some of the following properties:
|
|
|
|
* - visible: true if the pane should be shown, false to hide
|
|
|
|
* - animated: true to display an animation on toggle
|
|
|
|
* - delayed: true to wait a few cycles before toggle
|
|
|
|
* - callback: a function to invoke when the toggle finishes
|
|
|
|
* @param number aTabIndex [optional]
|
|
|
|
* The index of the intended selected tab in the details pane.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
toggleDetailsPane: function(aFlags, aTabIndex) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let pane = this._detailsPane;
|
|
|
|
let button = this._detailsPaneToggleButton;
|
|
|
|
|
|
|
|
ViewHelpers.togglePane(aFlags, pane);
|
|
|
|
|
|
|
|
if (aFlags.visible) {
|
2013-05-24 10:53:10 -07:00
|
|
|
this._body.removeAttribute("pane-collapsed");
|
2013-03-11 23:50:42 -07:00
|
|
|
button.removeAttribute("pane-collapsed");
|
|
|
|
button.setAttribute("tooltiptext", this._collapsePaneString);
|
|
|
|
} else {
|
2013-05-24 10:53:10 -07:00
|
|
|
this._body.setAttribute("pane-collapsed", "");
|
2013-03-11 23:50:42 -07:00
|
|
|
button.setAttribute("pane-collapsed", "");
|
|
|
|
button.setAttribute("tooltiptext", this._expandPaneString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex !== undefined) {
|
2013-06-26 02:09:59 -07:00
|
|
|
$("#event-details-pane").selectedIndex = aTabIndex;
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
},
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
/**
|
|
|
|
* Gets the current mode for this tool.
|
|
|
|
* @return string (e.g, "network-inspector-view" or "network-statistics-view")
|
|
|
|
*/
|
|
|
|
get currentFrontendMode() {
|
|
|
|
return this._body.selectedPanel.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles between the frontend view modes ("Inspector" vs. "Statistics").
|
|
|
|
*/
|
|
|
|
toggleFrontendMode: function() {
|
|
|
|
if (this.currentFrontendMode != "network-inspector-view") {
|
|
|
|
this.showNetworkInspectorView();
|
|
|
|
} else {
|
|
|
|
this.showNetworkStatisticsView();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches to the "Inspector" frontend view mode.
|
|
|
|
*/
|
|
|
|
showNetworkInspectorView: function() {
|
|
|
|
this._body.selectedPanel = $("#network-inspector-view");
|
|
|
|
this.RequestsMenu._flushWaterfallViews(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches to the "Statistics" frontend view mode.
|
|
|
|
*/
|
|
|
|
showNetworkStatisticsView: function() {
|
|
|
|
this._body.selectedPanel = $("#network-statistics-view");
|
|
|
|
|
|
|
|
let controller = NetMonitorController;
|
|
|
|
let requestsView = this.RequestsMenu;
|
|
|
|
let statisticsView = this.PerformanceStatistics;
|
|
|
|
|
2014-03-03 07:59:49 -08:00
|
|
|
Task.spawn(function*() {
|
2014-01-31 22:37:53 -08:00
|
|
|
statisticsView.displayPlaceholderCharts();
|
|
|
|
yield controller.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// • The response headers and status code are required for determining
|
|
|
|
// whether a response is "fresh" (cacheable).
|
|
|
|
// • The response content size and request total time are necessary for
|
|
|
|
// populating the statistics view.
|
|
|
|
// • The response mime type is used for categorization.
|
|
|
|
yield whenDataAvailable(requestsView.attachments, [
|
|
|
|
"responseHeaders", "status", "contentSize", "mimeType", "totalTime"
|
|
|
|
]);
|
|
|
|
} catch (ex) {
|
|
|
|
// Timed out while waiting for data. Continue with what we have.
|
|
|
|
DevToolsUtils.reportException("showNetworkStatisticsView", ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
statisticsView.createPrimedCacheChart(requestsView.items);
|
|
|
|
statisticsView.createEmptyCacheChart(requestsView.items);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
2013-10-24 10:08:17 -07:00
|
|
|
* Lazily initializes and returns a promise for a Editor instance.
|
2013-03-11 23:50:42 -07:00
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* The id of the editor placeholder node.
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
* A promise that is resolved when the editor is available.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
editor: function(aId) {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Getting a NetMonitorView editor: " + aId);
|
|
|
|
|
|
|
|
if (this._editorPromises.has(aId)) {
|
|
|
|
return this._editorPromises.get(aId);
|
|
|
|
}
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
let deferred = promise.defer();
|
2013-03-11 23:50:42 -07:00
|
|
|
this._editorPromises.set(aId, deferred.promise);
|
|
|
|
|
|
|
|
// Initialize the source editor and store the newly created instance
|
|
|
|
// in the ether of a resolved promise's value.
|
2013-10-24 10:08:17 -07:00
|
|
|
let editor = new Editor(DEFAULT_EDITOR_CONFIG);
|
|
|
|
editor.appendTo($(aId)).then(() => deferred.resolve(editor));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
_body: null,
|
|
|
|
_detailsPane: null,
|
|
|
|
_detailsPaneToggleButton: null,
|
2013-03-11 23:50:42 -07:00
|
|
|
_collapsePaneString: "",
|
|
|
|
_expandPaneString: "",
|
2013-07-10 01:40:51 -07:00
|
|
|
_editorPromises: new Map()
|
2013-03-11 23:50:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions handling the toolbar view: expand/collapse button etc.
|
|
|
|
*/
|
|
|
|
function ToolbarView() {
|
|
|
|
dumpn("ToolbarView was instantiated");
|
|
|
|
|
|
|
|
this._onTogglePanesPressed = this._onTogglePanesPressed.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarView.prototype = {
|
|
|
|
/**
|
|
|
|
* Initialization function, called when the debugger is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Initializing the ToolbarView");
|
|
|
|
|
|
|
|
this._detailsPaneToggleButton = $("#details-pane-toggle");
|
|
|
|
this._detailsPaneToggleButton.addEventListener("mousedown", this._onTogglePanesPressed, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the debugger is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Destroying the ToolbarView");
|
|
|
|
|
|
|
|
this._detailsPaneToggleButton.removeEventListener("mousedown", this._onTogglePanesPressed, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listener handling the toggle button click event.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onTogglePanesPressed: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
let requestsMenu = NetMonitorView.RequestsMenu;
|
2013-05-24 10:10:07 -07:00
|
|
|
let selectedIndex = requestsMenu.selectedIndex;
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
// Make sure there's a selection if the button is pressed, to avoid
|
|
|
|
// showing an empty network details pane.
|
2013-05-24 10:10:07 -07:00
|
|
|
if (selectedIndex == -1 && requestsMenu.itemCount) {
|
2013-03-11 23:50:42 -07:00
|
|
|
requestsMenu.selectedIndex = 0;
|
2013-05-24 10:10:07 -07:00
|
|
|
} else {
|
|
|
|
requestsMenu.selectedIndex = -1;
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_detailsPaneToggleButton: null
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions handling the requests menu (containing details about each request,
|
|
|
|
* like status, method, file, domain, as well as a waterfall representing
|
|
|
|
* timing imformation).
|
|
|
|
*/
|
|
|
|
function RequestsMenuView() {
|
|
|
|
dumpn("RequestsMenuView was instantiated");
|
|
|
|
|
|
|
|
this._flushRequests = this._flushRequests.bind(this);
|
2014-02-14 11:22:06 -08:00
|
|
|
this._onHover = this._onHover.bind(this);
|
2013-03-11 23:50:42 -07:00
|
|
|
this._onSelect = this._onSelect.bind(this);
|
2014-02-14 11:22:06 -08:00
|
|
|
this._onSwap = this._onSwap.bind(this);
|
2013-03-11 23:50:42 -07:00
|
|
|
this._onResize = this._onResize.bind(this);
|
2013-05-24 10:53:10 -07:00
|
|
|
this._byFile = this._byFile.bind(this);
|
|
|
|
this._byDomain = this._byDomain.bind(this);
|
|
|
|
this._byType = this._byType.bind(this);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the network monitor is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Initializing the RequestsMenuView");
|
|
|
|
|
2014-01-07 01:58:07 -08:00
|
|
|
this.widget = new SideMenuWidget($("#requests-menu-contents"));
|
2014-01-31 22:37:53 -08:00
|
|
|
this._splitter = $("#network-inspector-view-splitter");
|
|
|
|
this._summary = $("#requests-menu-network-summary-label");
|
|
|
|
this._summary.setAttribute("value", L10N.getStr("networkMenu.empty"));
|
2013-05-30 11:46:36 -07:00
|
|
|
|
2014-02-11 06:25:21 -08:00
|
|
|
Prefs.filters.forEach(type => this.filterOn(type));
|
2014-02-04 05:51:41 -08:00
|
|
|
this.sortContents(this._byTiming);
|
2014-02-11 06:25:21 -08:00
|
|
|
|
2013-06-26 13:35:38 -07:00
|
|
|
this.allowFocusOnRightClick = true;
|
2014-02-04 05:51:41 -08:00
|
|
|
this.maintainSelectionVisible = true;
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.autoscrollWithAppendedItems = true;
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.addEventListener("select", this._onSelect, false);
|
2014-02-14 11:22:06 -08:00
|
|
|
this.widget.addEventListener("swap", this._onSwap, false);
|
2013-08-27 20:55:48 -07:00
|
|
|
this._splitter.addEventListener("mousemove", this._onResize, false);
|
2013-03-11 23:50:42 -07:00
|
|
|
window.addEventListener("resize", this._onResize, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
|
|
|
|
this.requestsMenuSortEvent = getKeyWithEvent(this.sortBy.bind(this));
|
|
|
|
this.requestsMenuFilterEvent = getKeyWithEvent(this.filterOn.bind(this));
|
2014-01-31 22:37:53 -08:00
|
|
|
this.reqeustsMenuClearEvent = this.clear.bind(this);
|
2014-01-28 05:50:34 -08:00
|
|
|
this._onContextShowing = this._onContextShowing.bind(this);
|
|
|
|
this._onContextNewTabCommand = this.openRequestInTab.bind(this);
|
|
|
|
this._onContextCopyUrlCommand = this.copyUrl.bind(this);
|
2014-02-02 00:39:53 -08:00
|
|
|
this._onContextCopyImageAsDataUriCommand = this.copyImageAsDataUri.bind(this);
|
2014-01-28 05:50:34 -08:00
|
|
|
this._onContextResendCommand = this.cloneSelectedRequest.bind(this);
|
2014-01-31 22:37:53 -08:00
|
|
|
this._onContextPerfCommand = () => NetMonitorView.toggleFrontendMode();
|
2014-01-28 05:50:34 -08:00
|
|
|
|
|
|
|
this.sendCustomRequestEvent = this.sendCustomRequest.bind(this);
|
|
|
|
this.closeCustomRequestEvent = this.closeCustomRequest.bind(this);
|
|
|
|
this.cloneSelectedRequestEvent = this.cloneSelectedRequest.bind(this);
|
|
|
|
|
|
|
|
$("#toolbar-labels").addEventListener("click", this.requestsMenuSortEvent, false);
|
|
|
|
$("#requests-menu-footer").addEventListener("click", this.requestsMenuFilterEvent, false);
|
2014-01-31 22:37:53 -08:00
|
|
|
$("#requests-menu-clear-button").addEventListener("click", this.reqeustsMenuClearEvent, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
$("#network-request-popup").addEventListener("popupshowing", this._onContextShowing, false);
|
|
|
|
$("#request-menu-context-newtab").addEventListener("command", this._onContextNewTabCommand, false);
|
|
|
|
$("#request-menu-context-copy-url").addEventListener("command", this._onContextCopyUrlCommand, false);
|
2014-02-02 00:39:53 -08:00
|
|
|
$("#request-menu-context-copy-image-as-data-uri").addEventListener("command", this._onContextCopyImageAsDataUriCommand, false);
|
2014-01-31 22:37:53 -08:00
|
|
|
|
2014-03-07 04:14:53 -08:00
|
|
|
window.once("connected", this._onConnect.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onConnect: function() {
|
|
|
|
if (NetMonitorController.supportsCustomRequest) {
|
|
|
|
$("#request-menu-context-resend").addEventListener("command", this._onContextResendCommand, false);
|
|
|
|
$("#custom-request-send-button").addEventListener("click", this.sendCustomRequestEvent, false);
|
|
|
|
$("#custom-request-close-button").addEventListener("click", this.closeCustomRequestEvent, false);
|
|
|
|
$("#headers-summary-resend").addEventListener("click", this.cloneSelectedRequestEvent, false);
|
|
|
|
} else {
|
|
|
|
$("#request-menu-context-resend").hidden = true;
|
|
|
|
$("#headers-summary-resend").hidden = true;
|
|
|
|
}
|
2014-01-28 05:50:34 -08:00
|
|
|
|
2014-03-07 04:14:53 -08:00
|
|
|
if (NetMonitorController.supportsPerfStats) {
|
|
|
|
$("#request-menu-context-perf").addEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
$("#requests-menu-perf-notice-button").addEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
$("#requests-menu-network-summary-button").addEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
$("#requests-menu-network-summary-label").addEventListener("click", this._onContextPerfCommand, false);
|
|
|
|
} else {
|
|
|
|
$("#notice-perf-message").hidden = true;
|
|
|
|
$("#request-menu-context-perf").hidden = true;
|
|
|
|
$("#requests-menu-network-summary-button").hidden = true;
|
|
|
|
$("#requests-menu-network-summary-label").hidden = true;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the network monitor is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
dumpn("Destroying the SourcesView");
|
|
|
|
|
2014-02-11 06:25:21 -08:00
|
|
|
Prefs.filters = this._activeFilters;
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.removeEventListener("select", this._onSelect, false);
|
2014-02-14 11:22:06 -08:00
|
|
|
this.widget.removeEventListener("swap", this._onSwap, false);
|
2013-08-27 20:55:48 -07:00
|
|
|
this._splitter.removeEventListener("mousemove", this._onResize, false);
|
2013-03-11 23:50:42 -07:00
|
|
|
window.removeEventListener("resize", this._onResize, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
|
|
|
|
$("#toolbar-labels").removeEventListener("click", this.requestsMenuSortEvent, false);
|
|
|
|
$("#requests-menu-footer").removeEventListener("click", this.requestsMenuFilterEvent, false);
|
2014-01-31 22:37:53 -08:00
|
|
|
$("#requests-menu-clear-button").removeEventListener("click", this.reqeustsMenuClearEvent, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
$("#network-request-popup").removeEventListener("popupshowing", this._onContextShowing, false);
|
|
|
|
$("#request-menu-context-newtab").removeEventListener("command", this._onContextNewTabCommand, false);
|
|
|
|
$("#request-menu-context-copy-url").removeEventListener("command", this._onContextCopyUrlCommand, false);
|
2014-02-02 00:39:53 -08:00
|
|
|
$("#request-menu-context-copy-image-as-data-uri").removeEventListener("command", this._onContextCopyImageAsDataUriCommand, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
$("#request-menu-context-resend").removeEventListener("command", this._onContextResendCommand, false);
|
2014-01-31 22:37:53 -08:00
|
|
|
$("#request-menu-context-perf").removeEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
|
|
|
|
$("#requests-menu-perf-notice-button").removeEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
$("#requests-menu-network-summary-button").removeEventListener("command", this._onContextPerfCommand, false);
|
|
|
|
$("#requests-menu-network-summary-label").removeEventListener("click", this._onContextPerfCommand, false);
|
2014-01-28 05:50:34 -08:00
|
|
|
|
|
|
|
$("#custom-request-send-button").removeEventListener("click", this.sendCustomRequestEvent, false);
|
|
|
|
$("#custom-request-close-button").removeEventListener("click", this.closeCustomRequestEvent, false);
|
|
|
|
$("#headers-summary-resend").removeEventListener("click", this.cloneSelectedRequestEvent, false);
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets this container (removes all the networking information).
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
reset: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
this.empty();
|
|
|
|
this._firstRequestStartedMillis = -1;
|
|
|
|
this._lastRequestEndedMillis = -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies if this view may be updated lazily.
|
|
|
|
*/
|
|
|
|
lazyUpdate: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a network request to this container.
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* An identifier coming from the network monitor controller.
|
|
|
|
* @param string aStartedDateTime
|
|
|
|
* A string representation of when the request was started, which
|
|
|
|
* can be parsed by Date (for example "2012-09-17T19:50:03.699Z").
|
|
|
|
* @param string aMethod
|
|
|
|
* Specifies the request method (e.g. "GET", "POST", etc.)
|
|
|
|
* @param string aUrl
|
|
|
|
* Specifies the request's url.
|
2013-05-24 10:53:10 -07:00
|
|
|
* @param boolean aIsXHR
|
|
|
|
* True if this request was initiated via XHR.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2013-05-24 10:53:10 -07:00
|
|
|
addRequest: function(aId, aStartedDateTime, aMethod, aUrl, aIsXHR) {
|
2013-03-11 23:50:42 -07:00
|
|
|
// Convert the received date/time string to a unix timestamp.
|
|
|
|
let unixTime = Date.parse(aStartedDateTime);
|
|
|
|
|
|
|
|
// Create the element node for the network request item.
|
|
|
|
let menuView = this._createMenuView(aMethod, aUrl);
|
|
|
|
|
|
|
|
// Remember the first and last event boundaries.
|
|
|
|
this._registerFirstRequestStart(unixTime);
|
|
|
|
this._registerLastRequestEnd(unixTime);
|
|
|
|
|
|
|
|
// Append a network request item to this container.
|
2014-01-03 13:42:16 -08:00
|
|
|
let requestItem = this.push([menuView, aId], {
|
2013-03-11 23:50:42 -07:00
|
|
|
attachment: {
|
|
|
|
startedDeltaMillis: unixTime - this._firstRequestStartedMillis,
|
|
|
|
startedMillis: unixTime,
|
|
|
|
method: aMethod,
|
2013-05-24 10:53:10 -07:00
|
|
|
url: aUrl,
|
|
|
|
isXHR: aIsXHR
|
2013-06-21 07:33:57 -07:00
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
});
|
|
|
|
|
2014-02-14 11:22:06 -08:00
|
|
|
// Create a tooltip for the newly appended network request item.
|
|
|
|
let requestTooltip = requestItem.attachment.tooltip = new Tooltip(document, {
|
|
|
|
closeOnEvents: [{
|
|
|
|
emitter: $("#requests-menu-contents"),
|
|
|
|
event: "scroll",
|
|
|
|
useCapture: true
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
2013-05-10 02:01:08 -07:00
|
|
|
$("#details-pane-toggle").disabled = false;
|
2013-05-24 10:53:10 -07:00
|
|
|
$("#requests-menu-empty-notice").hidden = true;
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-30 11:46:36 -07:00
|
|
|
this.refreshSummary();
|
2013-06-21 07:33:58 -07:00
|
|
|
this.refreshZebra();
|
2014-02-14 11:22:06 -08:00
|
|
|
this.refreshTooltip(requestItem);
|
2013-06-26 02:09:59 -07:00
|
|
|
|
|
|
|
if (aId == this._preferredItemId) {
|
|
|
|
this.selectedItem = requestItem;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-27 04:39:44 -07:00
|
|
|
/**
|
|
|
|
* Opens selected item in a new tab.
|
|
|
|
*/
|
|
|
|
openRequestInTab: function() {
|
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
let selected = this.selectedItem.attachment;
|
|
|
|
win.openUILinkIn(selected.url, "tab", { relatedToCurrent: true });
|
|
|
|
},
|
|
|
|
|
2013-07-10 18:50:16 -07:00
|
|
|
/**
|
|
|
|
* Copy the request url from the currently selected item.
|
|
|
|
*/
|
|
|
|
copyUrl: function() {
|
|
|
|
let selected = this.selectedItem.attachment;
|
2013-07-11 03:00:34 -07:00
|
|
|
clipboardHelper.copyString(selected.url, document);
|
2013-07-10 18:50:16 -07:00
|
|
|
},
|
|
|
|
|
2014-03-19 18:02:08 -07:00
|
|
|
/**
|
|
|
|
* Copy a cURL command from the currently selected item.
|
|
|
|
*/
|
|
|
|
copyAsCurl: function() {
|
|
|
|
let selected = this.selectedItem.attachment;
|
2014-03-31 08:14:47 -07:00
|
|
|
|
2014-03-19 18:02:08 -07:00
|
|
|
Task.spawn(function*() {
|
|
|
|
// Create a sanitized object for the Curl command generator.
|
|
|
|
let data = {
|
|
|
|
url: selected.url,
|
|
|
|
method: selected.method,
|
|
|
|
headers: [],
|
|
|
|
httpVersion: selected.httpVersion,
|
|
|
|
postDataText: null
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fetch header values.
|
|
|
|
for (let { name, value } of selected.requestHeaders.headers) {
|
|
|
|
let text = yield gNetwork.getString(value);
|
|
|
|
data.headers.push({ name: name, value: text });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the request payload.
|
|
|
|
if (selected.requestPostData) {
|
|
|
|
let postData = selected.requestPostData.postData.text;
|
|
|
|
data.postDataText = yield gNetwork.getString(postData);
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboardHelper.copyString(Curl.generateCommand(data), document);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-02-02 00:39:53 -08:00
|
|
|
/**
|
|
|
|
* Copy image as data uri.
|
|
|
|
*/
|
|
|
|
copyImageAsDataUri: function() {
|
|
|
|
let selected = this.selectedItem.attachment;
|
|
|
|
let { mimeType, text, encoding } = selected.responseContent.content;
|
2014-02-14 11:22:06 -08:00
|
|
|
|
2014-02-02 00:39:53 -08:00
|
|
|
gNetwork.getString(text).then(aString => {
|
|
|
|
let data = "data:" + mimeType + ";" + encoding + "," + aString;
|
|
|
|
clipboardHelper.copyString(data, document);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
2014-02-04 05:51:41 -08:00
|
|
|
* Create a new custom request form populated with the data from
|
|
|
|
* the currently selected request.
|
2013-06-26 02:09:59 -07:00
|
|
|
*/
|
2014-02-04 05:51:41 -08:00
|
|
|
cloneSelectedRequest: function() {
|
2013-06-26 02:09:59 -07:00
|
|
|
let selected = this.selectedItem.attachment;
|
|
|
|
|
2014-02-04 05:51:41 -08:00
|
|
|
// Create the element node for the network request item.
|
|
|
|
let menuView = this._createMenuView(selected.method, selected.url);
|
|
|
|
|
|
|
|
// Append a network request item to this container.
|
|
|
|
let newItem = this.push([menuView], {
|
|
|
|
attachment: Object.create(selected, {
|
|
|
|
isCustom: { value: true }
|
|
|
|
})
|
2013-06-26 02:09:59 -07:00
|
|
|
});
|
|
|
|
|
2014-02-04 05:51:41 -08:00
|
|
|
// Immediately switch to new request pane.
|
|
|
|
this.selectedItem = newItem;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a new HTTP request using the data in the custom request form.
|
|
|
|
*/
|
|
|
|
sendCustomRequest: function() {
|
|
|
|
let selected = this.selectedItem.attachment;
|
|
|
|
|
2014-03-07 04:14:53 -08:00
|
|
|
let data = {
|
|
|
|
url: selected.url,
|
2014-03-31 08:14:47 -07:00
|
|
|
method: selected.method,
|
2014-03-07 04:14:53 -08:00
|
|
|
httpVersion: selected.httpVersion,
|
|
|
|
};
|
2014-02-04 05:51:41 -08:00
|
|
|
if (selected.requestHeaders) {
|
|
|
|
data.headers = selected.requestHeaders.headers;
|
|
|
|
}
|
2013-06-26 02:09:59 -07:00
|
|
|
if (selected.requestPostData) {
|
|
|
|
data.body = selected.requestPostData.postData.text;
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:40:51 -07:00
|
|
|
NetMonitorController.webConsoleClient.sendHTTPRequest(data, aResponse => {
|
|
|
|
let id = aResponse.eventActor.actor;
|
2013-06-26 02:09:59 -07:00
|
|
|
this._preferredItemId = id;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.closeCustomRequest();
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
|
|
|
* Remove the currently selected custom request.
|
|
|
|
*/
|
|
|
|
closeCustomRequest: function() {
|
|
|
|
this.remove(this.selectedItem);
|
|
|
|
NetMonitorView.Sidebar.toggle(false);
|
2014-02-04 05:51:41 -08:00
|
|
|
},
|
2013-06-26 02:09:59 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
/**
|
|
|
|
* Filters all network requests in this container by a specified type.
|
|
|
|
*
|
|
|
|
* @param string aType
|
2013-06-21 07:33:57 -07:00
|
|
|
* Either "all", "html", "css", "js", "xhr", "fonts", "images", "media"
|
2014-01-31 22:37:53 -08:00
|
|
|
* "flash" or "other".
|
2013-05-24 10:53:10 -07:00
|
|
|
*/
|
2013-06-21 07:33:57 -07:00
|
|
|
filterOn: function(aType = "all") {
|
2014-02-10 10:18:45 -08:00
|
|
|
if (aType === "all") {
|
|
|
|
// The filter "all" is special as it doesn't toggle.
|
|
|
|
// - If some filters are selected and 'all' is clicked, the previously
|
|
|
|
// selected filters will be disabled and 'all' is the only active one.
|
|
|
|
// - If 'all' is already selected, do nothing.
|
|
|
|
if (this._activeFilters.indexOf("all") !== -1) {
|
|
|
|
return;
|
2013-05-24 10:53:10 -07:00
|
|
|
}
|
|
|
|
|
2014-02-10 10:18:45 -08:00
|
|
|
// Uncheck all other filters and select 'all'. Must create a copy as
|
|
|
|
// _disableFilter removes the filters from the list while it's being
|
|
|
|
// iterated. 'all' will be enabled automatically by _disableFilter once
|
|
|
|
// the last filter is disabled.
|
|
|
|
this._activeFilters.slice().forEach(this._disableFilter, this);
|
|
|
|
}
|
|
|
|
else if (this._activeFilters.indexOf(aType) === -1) {
|
|
|
|
this._enableFilter(aType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._disableFilter(aType);
|
2013-05-24 10:53:10 -07:00
|
|
|
}
|
2013-05-30 11:46:36 -07:00
|
|
|
|
2014-02-10 10:18:45 -08:00
|
|
|
this.filterContents(this._filterPredicate);
|
2013-05-30 11:46:36 -07:00
|
|
|
this.refreshSummary();
|
2013-06-21 07:33:58 -07:00
|
|
|
this.refreshZebra();
|
2013-05-24 10:53:10 -07:00
|
|
|
},
|
|
|
|
|
2014-02-11 08:55:07 -08:00
|
|
|
/**
|
|
|
|
* Same as `filterOn`, except that it only allows a single type exclusively.
|
|
|
|
*
|
|
|
|
* @param string aType
|
|
|
|
* @see RequestsMenuView.prototype.fitlerOn
|
|
|
|
*/
|
|
|
|
filterOnlyOn: function(aType = "all") {
|
|
|
|
this._activeFilters.slice().forEach(this._disableFilter, this);
|
|
|
|
this.filterOn(aType);
|
|
|
|
},
|
|
|
|
|
2014-02-10 10:18:45 -08:00
|
|
|
/**
|
|
|
|
* Disables the given filter, its button and toggles 'all' on if the filter to
|
|
|
|
* be disabled is the last one active.
|
|
|
|
*
|
|
|
|
* @param string aType
|
|
|
|
* Either "all", "html", "css", "js", "xhr", "fonts", "images", "media"
|
|
|
|
* "flash" or "other".
|
|
|
|
*/
|
|
|
|
_disableFilter: function (aType) {
|
|
|
|
// Remove the filter from list of active filters.
|
|
|
|
this._activeFilters.splice(this._activeFilters.indexOf(aType), 1);
|
|
|
|
|
|
|
|
// Remove the checked status from the filter.
|
|
|
|
let target = $("#requests-menu-filter-" + aType + "-button");
|
|
|
|
target.removeAttribute("checked");
|
|
|
|
|
|
|
|
// Check if the filter disabled was the last one. If so, toggle all on.
|
2014-02-11 06:25:21 -08:00
|
|
|
if (this._activeFilters.length === 0) {
|
2014-02-10 10:18:45 -08:00
|
|
|
this._enableFilter("all");
|
2014-02-11 06:25:21 -08:00
|
|
|
}
|
2014-02-10 10:18:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables the given filter, its button and toggles 'all' off if the filter to
|
|
|
|
* be enabled is the first one active.
|
|
|
|
*
|
|
|
|
* @param string aType
|
|
|
|
* Either "all", "html", "css", "js", "xhr", "fonts", "images", "media"
|
|
|
|
* "flash" or "other".
|
|
|
|
*/
|
|
|
|
_enableFilter: function (aType) {
|
2014-03-26 13:08:02 -07:00
|
|
|
// Make sure this is a valid filter type.
|
|
|
|
if (Object.keys(this._allFilterPredicates).indexOf(aType) == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 10:18:45 -08:00
|
|
|
// Add the filter to the list of active filters.
|
|
|
|
this._activeFilters.push(aType);
|
|
|
|
|
|
|
|
// Add the checked status to the filter button.
|
|
|
|
let target = $("#requests-menu-filter-" + aType + "-button");
|
|
|
|
target.setAttribute("checked", true);
|
|
|
|
|
|
|
|
// Check if 'all' was selected before. If so, disable it.
|
|
|
|
if (aType !== "all" && this._activeFilters.indexOf("all") !== -1) {
|
|
|
|
this._disableFilter("all");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a predicate that can be used to test if a request matches any of
|
|
|
|
* the active filters.
|
|
|
|
*/
|
|
|
|
get _filterPredicate() {
|
2014-03-26 13:08:02 -07:00
|
|
|
let filterPredicates = this._allFilterPredicates;
|
2014-02-10 10:18:45 -08:00
|
|
|
|
|
|
|
if (this._activeFilters.length === 1) {
|
|
|
|
// The simplest case: only one filter active.
|
|
|
|
return filterPredicates[this._activeFilters[0]].bind(this);
|
|
|
|
} else {
|
|
|
|
// Multiple filters active.
|
|
|
|
return requestItem => {
|
|
|
|
return this._activeFilters.some(filterName => {
|
|
|
|
return filterPredicates[filterName].call(this, requestItem);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-26 13:08:02 -07:00
|
|
|
/**
|
|
|
|
* Returns an object with all the filter predicates as [key: function] pairs.
|
|
|
|
*/
|
|
|
|
get _allFilterPredicates() ({
|
|
|
|
all: () => true,
|
|
|
|
html: this.isHtml,
|
|
|
|
css: this.isCss,
|
|
|
|
js: this.isJs,
|
|
|
|
xhr: this.isXHR,
|
|
|
|
fonts: this.isFont,
|
|
|
|
images: this.isImage,
|
|
|
|
media: this.isMedia,
|
|
|
|
flash: this.isFlash,
|
|
|
|
other: this.isOther
|
|
|
|
}),
|
|
|
|
|
2013-05-10 02:01:08 -07:00
|
|
|
/**
|
|
|
|
* Sorts all network requests in this container by a specified detail.
|
|
|
|
*
|
|
|
|
* @param string aType
|
2013-06-21 07:33:57 -07:00
|
|
|
* Either "status", "method", "file", "domain", "type", "size" or
|
|
|
|
* "waterfall".
|
2013-05-10 02:01:08 -07:00
|
|
|
*/
|
2013-06-04 00:55:48 -07:00
|
|
|
sortBy: function(aType = "waterfall") {
|
2013-05-10 02:01:08 -07:00
|
|
|
let target = $("#requests-menu-" + aType + "-button");
|
|
|
|
let headers = document.querySelectorAll(".requests-menu-header-button");
|
|
|
|
|
|
|
|
for (let header of headers) {
|
|
|
|
if (header != target) {
|
|
|
|
header.removeAttribute("sorted");
|
|
|
|
header.removeAttribute("tooltiptext");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let direction = "";
|
|
|
|
if (target) {
|
2013-06-04 00:55:48 -07:00
|
|
|
if (target.getAttribute("sorted") == "ascending") {
|
2013-05-10 02:01:08 -07:00
|
|
|
target.setAttribute("sorted", direction = "descending");
|
|
|
|
target.setAttribute("tooltiptext", L10N.getStr("networkMenu.sortedDesc"));
|
|
|
|
} else {
|
2013-06-04 00:55:48 -07:00
|
|
|
target.setAttribute("sorted", direction = "ascending");
|
|
|
|
target.setAttribute("tooltiptext", L10N.getStr("networkMenu.sortedAsc"));
|
2013-05-10 02:01:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by whatever was requested.
|
2013-06-04 00:55:48 -07:00
|
|
|
switch (aType) {
|
2013-05-10 02:01:08 -07:00
|
|
|
case "status":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byStatus);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byStatus(a, b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "method":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byMethod);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byMethod(a, b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "file":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byFile);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byFile(a, b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "domain":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byDomain);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byDomain(a, b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "type":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byType);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byType(a, b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "size":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._bySize);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._bySize(a, b));
|
|
|
|
}
|
|
|
|
break;
|
2013-06-04 00:55:48 -07:00
|
|
|
case "waterfall":
|
|
|
|
if (direction == "ascending") {
|
|
|
|
this.sortContents(this._byTiming);
|
|
|
|
} else {
|
|
|
|
this.sortContents((a, b) => !this._byTiming(a, b));
|
|
|
|
}
|
|
|
|
break;
|
2013-05-10 02:01:08 -07:00
|
|
|
}
|
2013-06-21 07:33:58 -07:00
|
|
|
|
|
|
|
this.refreshSummary();
|
|
|
|
this.refreshZebra();
|
2013-05-10 02:01:08 -07:00
|
|
|
},
|
|
|
|
|
2013-11-26 11:21:23 -08:00
|
|
|
/**
|
|
|
|
* Removes all network requests and closes the sidebar if open.
|
|
|
|
*/
|
|
|
|
clear: function() {
|
|
|
|
NetMonitorView.Sidebar.toggle(false);
|
|
|
|
$("#details-pane-toggle").disabled = true;
|
|
|
|
|
|
|
|
this.empty();
|
|
|
|
this.refreshSummary();
|
|
|
|
},
|
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
/**
|
|
|
|
* Predicates used when filtering items.
|
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aItem
|
|
|
|
* The filtered item.
|
2013-05-24 10:53:10 -07:00
|
|
|
* @return boolean
|
2013-06-21 07:33:56 -07:00
|
|
|
* True if the item should be visible, false otherwise.
|
2013-05-24 10:53:10 -07:00
|
|
|
*/
|
2014-01-31 22:37:53 -08:00
|
|
|
isHtml: function({ attachment: { mimeType } })
|
2013-05-24 10:53:10 -07:00
|
|
|
mimeType && mimeType.contains("/html"),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isCss: function({ attachment: { mimeType } })
|
2013-05-24 10:53:10 -07:00
|
|
|
mimeType && mimeType.contains("/css"),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isJs: function({ attachment: { mimeType } })
|
2013-05-24 10:53:10 -07:00
|
|
|
mimeType && (
|
|
|
|
mimeType.contains("/ecmascript") ||
|
|
|
|
mimeType.contains("/javascript") ||
|
|
|
|
mimeType.contains("/x-javascript")),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isXHR: function({ attachment: { isXHR } })
|
2013-05-24 10:53:10 -07:00
|
|
|
isXHR,
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isFont: function({ attachment: { url, mimeType } }) // Fonts are a mess.
|
2013-05-24 10:53:10 -07:00
|
|
|
(mimeType && (
|
|
|
|
mimeType.contains("font/") ||
|
|
|
|
mimeType.contains("/font"))) ||
|
|
|
|
url.contains(".eot") ||
|
|
|
|
url.contains(".ttf") ||
|
|
|
|
url.contains(".otf") ||
|
|
|
|
url.contains(".woff"),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isImage: function({ attachment: { mimeType } })
|
2013-05-24 10:53:10 -07:00
|
|
|
mimeType && mimeType.contains("image/"),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isMedia: function({ attachment: { mimeType } }) // Not including images.
|
2013-05-24 10:53:10 -07:00
|
|
|
mimeType && (
|
|
|
|
mimeType.contains("audio/") ||
|
|
|
|
mimeType.contains("video/") ||
|
|
|
|
mimeType.contains("model/")),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isFlash: function({ attachment: { url, mimeType } }) // Flash is a mess.
|
2013-05-24 10:53:10 -07:00
|
|
|
(mimeType && (
|
|
|
|
mimeType.contains("/x-flv") ||
|
|
|
|
mimeType.contains("/x-shockwave-flash"))) ||
|
|
|
|
url.contains(".swf") ||
|
|
|
|
url.contains(".flv"),
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
isOther: function(e)
|
|
|
|
!this.isHtml(e) && !this.isCss(e) && !this.isJs(e) && !this.isXHR(e) &&
|
|
|
|
!this.isFont(e) && !this.isImage(e) && !this.isMedia(e) && !this.isFlash(e),
|
|
|
|
|
2013-05-10 02:01:08 -07:00
|
|
|
/**
|
|
|
|
* Predicates used when sorting items.
|
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aFirst
|
|
|
|
* The first item used in the comparison.
|
|
|
|
* @param object aSecond
|
|
|
|
* The second item used in the comparison.
|
2013-05-10 02:01:08 -07:00
|
|
|
* @return number
|
|
|
|
* -1 to sort aFirst to a lower index than aSecond
|
|
|
|
* 0 to leave aFirst and aSecond unchanged with respect to each other
|
|
|
|
* 1 to sort aSecond to a lower index than aFirst
|
|
|
|
*/
|
2013-05-24 10:53:10 -07:00
|
|
|
_byTiming: function({ attachment: first }, { attachment: second })
|
|
|
|
first.startedMillis > second.startedMillis,
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
_byStatus: function({ attachment: first }, { attachment: second })
|
2013-09-12 23:58:43 -07:00
|
|
|
first.status == second.status
|
|
|
|
? first.startedMillis > second.startedMillis
|
|
|
|
: first.status > second.status,
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
_byMethod: function({ attachment: first }, { attachment: second })
|
2013-09-12 23:58:43 -07:00
|
|
|
first.method == second.method
|
|
|
|
? first.startedMillis > second.startedMillis
|
|
|
|
: first.method > second.method,
|
|
|
|
|
|
|
|
_byFile: function({ attachment: first }, { attachment: second }) {
|
|
|
|
let firstUrl = this._getUriNameWithQuery(first.url).toLowerCase();
|
|
|
|
let secondUrl = this._getUriNameWithQuery(second.url).toLowerCase();
|
|
|
|
return firstUrl == secondUrl
|
|
|
|
? first.startedMillis > second.startedMillis
|
|
|
|
: firstUrl > secondUrl;
|
|
|
|
},
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-09-12 23:58:43 -07:00
|
|
|
_byDomain: function({ attachment: first }, { attachment: second }) {
|
|
|
|
let firstDomain = this._getUriHostPort(first.url).toLowerCase();
|
|
|
|
let secondDomain = this._getUriHostPort(second.url).toLowerCase();
|
|
|
|
return firstDomain == secondDomain
|
|
|
|
? first.startedMillis > second.startedMillis
|
|
|
|
: firstDomain > secondDomain;
|
|
|
|
},
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-09-12 23:58:43 -07:00
|
|
|
_byType: function({ attachment: first }, { attachment: second }) {
|
|
|
|
let firstType = this._getAbbreviatedMimeType(first.mimeType).toLowerCase();
|
|
|
|
let secondType = this._getAbbreviatedMimeType(second.mimeType).toLowerCase();
|
|
|
|
return firstType == secondType
|
|
|
|
? first.startedMillis > second.startedMillis
|
|
|
|
: firstType > secondType;
|
|
|
|
},
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
_bySize: function({ attachment: first }, { attachment: second })
|
|
|
|
first.contentSize > second.contentSize,
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-30 11:46:36 -07:00
|
|
|
/**
|
|
|
|
* Refreshes the status displayed in this container's footer, providing
|
|
|
|
* concise information about all requests.
|
|
|
|
*/
|
|
|
|
refreshSummary: function() {
|
|
|
|
let visibleItems = this.visibleItems;
|
|
|
|
let visibleRequestsCount = visibleItems.length;
|
|
|
|
if (!visibleRequestsCount) {
|
|
|
|
this._summary.setAttribute("value", L10N.getStr("networkMenu.empty"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let totalBytes = this._getTotalBytesOfRequests(visibleItems);
|
|
|
|
let totalMillis =
|
|
|
|
this._getNewestRequest(visibleItems).attachment.endedMillis -
|
|
|
|
this._getOldestRequest(visibleItems).attachment.startedMillis;
|
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Localization_and_Plurals
|
|
|
|
let str = PluralForm.get(visibleRequestsCount, L10N.getStr("networkMenu.summary"));
|
|
|
|
this._summary.setAttribute("value", str
|
|
|
|
.replace("#1", visibleRequestsCount)
|
2014-01-31 22:37:53 -08:00
|
|
|
.replace("#2", L10N.numberWithDecimals((totalBytes || 0) / 1024, CONTENT_SIZE_DECIMALS))
|
|
|
|
.replace("#3", L10N.numberWithDecimals((totalMillis || 0) / 1000, REQUEST_TIME_DECIMALS))
|
2013-05-30 11:46:36 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2013-06-21 07:33:58 -07:00
|
|
|
/**
|
|
|
|
* Adds odd/even attributes to all the visible items in this container.
|
|
|
|
*/
|
|
|
|
refreshZebra: function() {
|
2013-09-13 06:23:14 -07:00
|
|
|
let visibleItems = this.visibleItems;
|
2013-06-21 07:33:58 -07:00
|
|
|
|
|
|
|
for (let i = 0, len = visibleItems.length; i < len; i++) {
|
|
|
|
let requestItem = visibleItems[i];
|
|
|
|
let requestTarget = requestItem.target;
|
|
|
|
|
|
|
|
if (i % 2 == 0) {
|
|
|
|
requestTarget.setAttribute("even", "");
|
|
|
|
requestTarget.removeAttribute("odd");
|
|
|
|
} else {
|
|
|
|
requestTarget.setAttribute("odd", "");
|
|
|
|
requestTarget.removeAttribute("even");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-14 11:22:06 -08:00
|
|
|
/**
|
|
|
|
* Refreshes the toggling anchor for the specified item's tooltip.
|
|
|
|
*
|
|
|
|
* @param object aItem
|
|
|
|
* The network request item in this container.
|
|
|
|
*/
|
|
|
|
refreshTooltip: function(aItem) {
|
|
|
|
let tooltip = aItem.attachment.tooltip;
|
|
|
|
tooltip.hide();
|
|
|
|
tooltip.startTogglingOnHover(aItem.target, this._onHover);
|
|
|
|
tooltip.defaultPosition = REQUESTS_TOOLTIP_POSITION;
|
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Schedules adding additional information to a network request.
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* An identifier coming from the network monitor controller.
|
|
|
|
* @param object aData
|
|
|
|
* An object containing several { key: value } tuples of network info.
|
|
|
|
* Supported keys are "httpVersion", "status", "statusText" etc.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
updateRequest: function(aId, aData) {
|
2013-03-11 23:50:42 -07:00
|
|
|
// Prevent interference from zombie updates received after target closed.
|
|
|
|
if (NetMonitorView._isDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._updateQueue.push([aId, aData]);
|
|
|
|
|
|
|
|
// Lazy updating is disabled in some tests.
|
|
|
|
if (!this.lazyUpdate) {
|
|
|
|
return void this._flushRequests();
|
|
|
|
}
|
2013-05-10 02:01:05 -07:00
|
|
|
// Allow requests to settle down first.
|
2013-09-13 06:23:13 -07:00
|
|
|
setNamedTimeout(
|
|
|
|
"update-requests", REQUESTS_REFRESH_RATE, () => this._flushRequests());
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts adding all queued additional information about network requests.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_flushRequests: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
// For each queued additional information packet, get the corresponding
|
|
|
|
// request item in the view and update it based on the specified data.
|
|
|
|
for (let [id, data] of this._updateQueue) {
|
2013-06-21 07:33:57 -07:00
|
|
|
let requestItem = this.getItemByValue(id);
|
2013-03-11 23:50:42 -07:00
|
|
|
if (!requestItem) {
|
|
|
|
// Packet corresponds to a dead request item, target navigated.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each information packet may contain several { key: value } tuples of
|
|
|
|
// network info, so update the view based on each one.
|
|
|
|
for (let key in data) {
|
|
|
|
let value = data[key];
|
|
|
|
if (value === undefined) {
|
|
|
|
// The information in the packet is empty, it can be safely ignored.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case "requestHeaders":
|
|
|
|
requestItem.attachment.requestHeaders = value;
|
|
|
|
break;
|
|
|
|
case "requestCookies":
|
|
|
|
requestItem.attachment.requestCookies = value;
|
|
|
|
break;
|
|
|
|
case "requestPostData":
|
2014-03-03 07:59:49 -08:00
|
|
|
// Search the POST data upload stream for request headers and add
|
|
|
|
// them to a separate store, different from the classic headers.
|
|
|
|
// XXX: Be really careful here! We're creating a function inside
|
|
|
|
// a loop, so remember the actual request item we want to modify.
|
|
|
|
let currentItem = requestItem;
|
|
|
|
let currentStore = { headers: [], headersSize: 0 };
|
2014-03-31 08:14:46 -07:00
|
|
|
|
|
|
|
Task.spawn(function*() {
|
|
|
|
let postData = yield gNetwork.getString(value.postData.text);
|
|
|
|
let payloadHeaders = CurlUtils.getHeadersFromMultipartText(postData);
|
|
|
|
|
|
|
|
currentStore.headers = payloadHeaders;
|
|
|
|
currentStore.headersSize = payloadHeaders.reduce(
|
|
|
|
(acc, { name, value }) => acc + name.length + value.length + 2, 0);
|
|
|
|
|
2014-03-03 07:59:49 -08:00
|
|
|
// The `getString` promise is async, so we need to refresh the
|
|
|
|
// information displayed in the network details pane again here.
|
|
|
|
refreshNetworkDetailsPaneIfNecessary(currentItem);
|
|
|
|
});
|
2014-03-31 08:14:46 -07:00
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
requestItem.attachment.requestPostData = value;
|
2014-03-03 07:59:49 -08:00
|
|
|
requestItem.attachment.requestHeadersFromUploadStream = currentStore;
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "responseHeaders":
|
|
|
|
requestItem.attachment.responseHeaders = value;
|
|
|
|
break;
|
|
|
|
case "responseCookies":
|
|
|
|
requestItem.attachment.responseCookies = value;
|
|
|
|
break;
|
|
|
|
case "httpVersion":
|
|
|
|
requestItem.attachment.httpVersion = value;
|
|
|
|
break;
|
|
|
|
case "status":
|
|
|
|
requestItem.attachment.status = value;
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(requestItem, key, value);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "statusText":
|
|
|
|
requestItem.attachment.statusText = value;
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(requestItem, key,
|
2013-04-09 16:05:09 -07:00
|
|
|
requestItem.attachment.status + " " +
|
|
|
|
requestItem.attachment.statusText);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "headersSize":
|
|
|
|
requestItem.attachment.headersSize = value;
|
|
|
|
break;
|
|
|
|
case "contentSize":
|
|
|
|
requestItem.attachment.contentSize = value;
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(requestItem, key, value);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "mimeType":
|
|
|
|
requestItem.attachment.mimeType = value;
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(requestItem, key, value);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "responseContent":
|
2014-01-31 22:37:53 -08:00
|
|
|
// If there's no mime type available when the response content
|
|
|
|
// is received, assume text/plain as a fallback.
|
|
|
|
if (!requestItem.attachment.mimeType) {
|
|
|
|
requestItem.attachment.mimeType = "text/plain";
|
|
|
|
this.updateMenuView(requestItem, "mimeType", "text/plain");
|
|
|
|
}
|
2014-02-14 11:22:06 -08:00
|
|
|
requestItem.attachment.responseContent = value;
|
|
|
|
this.updateMenuView(requestItem, key, value);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
case "totalTime":
|
|
|
|
requestItem.attachment.totalTime = value;
|
|
|
|
requestItem.attachment.endedMillis = requestItem.attachment.startedMillis + value;
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(requestItem, key, value);
|
2013-03-11 23:50:42 -07:00
|
|
|
this._registerLastRequestEnd(requestItem.attachment.endedMillis);
|
|
|
|
break;
|
|
|
|
case "eventTimings":
|
|
|
|
requestItem.attachment.eventTimings = value;
|
|
|
|
this._createWaterfallView(requestItem, value.timings);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 07:59:49 -08:00
|
|
|
refreshNetworkDetailsPaneIfNecessary(requestItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refreshes the information displayed in the sidebar, in case this update
|
|
|
|
* may have additional information about a request which isn't shown yet
|
|
|
|
* in the network details pane.
|
|
|
|
*
|
|
|
|
* @param object aRequestItem
|
|
|
|
* The item to repopulate the sidebar with in case it's selected in
|
|
|
|
* this requests menu.
|
|
|
|
*/
|
|
|
|
function refreshNetworkDetailsPaneIfNecessary(aRequestItem) {
|
|
|
|
let selectedItem = NetMonitorView.RequestsMenu.selectedItem;
|
|
|
|
if (selectedItem == aRequestItem) {
|
2013-03-11 23:50:42 -07:00
|
|
|
NetMonitorView.NetworkDetails.populate(selectedItem.attachment);
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
// We're done flushing all the requests, clear the update queue.
|
|
|
|
this._updateQueue = [];
|
2013-05-10 02:01:08 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
// Make sure all the requests are sorted and filtered.
|
|
|
|
// Freshly added requests may not yet contain all the information required
|
|
|
|
// for sorting and filtering predicates, so this is done each time the
|
|
|
|
// network requests table is flushed (don't worry, events are drained first
|
|
|
|
// so this doesn't happen once per network event update).
|
2013-05-10 02:01:08 -07:00
|
|
|
this.sortContents();
|
2013-05-24 10:53:10 -07:00
|
|
|
this.filterContents();
|
2013-05-30 11:46:36 -07:00
|
|
|
this.refreshSummary();
|
2013-06-21 07:33:58 -07:00
|
|
|
this.refreshZebra();
|
2014-02-13 07:26:09 -08:00
|
|
|
|
|
|
|
// Rescale all the waterfalls so that everything is visible at once.
|
|
|
|
this._flushWaterfallViews();
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI.
|
|
|
|
*
|
|
|
|
* @param string aMethod
|
|
|
|
* Specifies the request method (e.g. "GET", "POST", etc.)
|
|
|
|
* @param string aUrl
|
|
|
|
* Specifies the request's url.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
* The network request view.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createMenuView: function(aMethod, aUrl) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let template = $("#requests-menu-item-template");
|
2013-04-09 16:05:09 -07:00
|
|
|
let fragment = document.createDocumentFragment();
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
this.updateMenuView(template, 'method', aMethod);
|
|
|
|
this.updateMenuView(template, 'url', aUrl);
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2013-05-24 10:10:07 -07:00
|
|
|
let waterfall = $(".requests-menu-waterfall", template);
|
|
|
|
waterfall.style.backgroundImage = this._cachedWaterfallBackground;
|
|
|
|
|
2013-04-09 16:05:09 -07:00
|
|
|
// Flatten the DOM by removing one redundant box (the template container).
|
|
|
|
for (let node of template.childNodes) {
|
|
|
|
fragment.appendChild(node.cloneNode(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
return fragment;
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the information displayed in a network request item view.
|
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aItem
|
2013-03-11 23:50:42 -07:00
|
|
|
* The network request item in this container.
|
|
|
|
* @param string aKey
|
|
|
|
* The type of information that is to be updated.
|
|
|
|
* @param any aValue
|
|
|
|
* The new value to be shown.
|
2014-03-31 08:14:47 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved once the information is displayed.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
updateMenuView: Task.async(function*(aItem, aKey, aValue) {
|
2013-06-26 02:09:59 -07:00
|
|
|
let target = aItem.target || aItem;
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
switch (aKey) {
|
2013-06-26 02:09:59 -07:00
|
|
|
case "method": {
|
|
|
|
let node = $(".requests-menu-method", target);
|
|
|
|
node.setAttribute("value", aValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "url": {
|
|
|
|
let uri;
|
|
|
|
try {
|
|
|
|
uri = nsIURL(aValue);
|
|
|
|
} catch(e) {
|
|
|
|
break; // User input may not make a well-formed url yet.
|
|
|
|
}
|
|
|
|
let nameWithQuery = this._getUriNameWithQuery(uri);
|
|
|
|
let hostPort = this._getUriHostPort(uri);
|
|
|
|
|
2014-02-14 11:22:06 -08:00
|
|
|
let file = $(".requests-menu-file", target);
|
|
|
|
file.setAttribute("value", nameWithQuery);
|
|
|
|
file.setAttribute("tooltiptext", nameWithQuery);
|
2013-06-26 02:09:59 -07:00
|
|
|
|
|
|
|
let domain = $(".requests-menu-domain", target);
|
|
|
|
domain.setAttribute("value", hostPort);
|
|
|
|
domain.setAttribute("tooltiptext", hostPort);
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
case "status": {
|
2013-06-26 02:09:59 -07:00
|
|
|
let node = $(".requests-menu-status", target);
|
2014-03-03 08:13:00 -08:00
|
|
|
let codeNode = $(".requests-menu-status-code", target);
|
|
|
|
codeNode.setAttribute("value", aValue);
|
2013-03-11 23:50:42 -07:00
|
|
|
node.setAttribute("code", aValue);
|
|
|
|
break;
|
|
|
|
}
|
2013-04-09 16:05:09 -07:00
|
|
|
case "statusText": {
|
2013-06-26 02:09:59 -07:00
|
|
|
let node = $(".requests-menu-status-and-method", target);
|
2013-04-09 16:05:09 -07:00
|
|
|
node.setAttribute("tooltiptext", aValue);
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
case "contentSize": {
|
2013-04-17 23:35:27 -07:00
|
|
|
let kb = aValue / 1024;
|
|
|
|
let size = L10N.numberWithDecimals(kb, CONTENT_SIZE_DECIMALS);
|
2013-06-26 02:09:59 -07:00
|
|
|
let node = $(".requests-menu-size", target);
|
2013-04-09 16:05:09 -07:00
|
|
|
let text = L10N.getFormatStr("networkMenu.sizeKB", size);
|
|
|
|
node.setAttribute("value", text);
|
|
|
|
node.setAttribute("tooltiptext", text);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "mimeType": {
|
2013-05-24 10:53:10 -07:00
|
|
|
let type = this._getAbbreviatedMimeType(aValue);
|
2013-06-26 02:09:59 -07:00
|
|
|
let node = $(".requests-menu-type", target);
|
2013-04-09 16:05:09 -07:00
|
|
|
let text = CONTENT_MIME_TYPE_ABBREVIATIONS[type] || type;
|
|
|
|
node.setAttribute("value", text);
|
|
|
|
node.setAttribute("tooltiptext", aValue);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-02-14 11:22:06 -08:00
|
|
|
case "responseContent": {
|
|
|
|
let { mimeType } = aItem.attachment;
|
|
|
|
let { text, encoding } = aValue.content;
|
|
|
|
|
|
|
|
if (mimeType.contains("image/")) {
|
2014-03-31 08:14:47 -07:00
|
|
|
let responseBody = yield gNetwork.getString(text);
|
|
|
|
let node = $(".requests-menu-icon", aItem.target);
|
|
|
|
node.src = "data:" + mimeType + ";" + encoding + "," + responseBody;
|
|
|
|
node.setAttribute("type", "thumbnail");
|
|
|
|
node.removeAttribute("hidden");
|
|
|
|
|
|
|
|
window.emit(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
|
2014-02-14 11:22:06 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
case "totalTime": {
|
2013-06-26 02:09:59 -07:00
|
|
|
let node = $(".requests-menu-timings-total", target);
|
2013-04-17 23:35:27 -07:00
|
|
|
let text = L10N.getFormatStr("networkMenu.totalMS", aValue); // integer
|
2013-04-09 16:05:09 -07:00
|
|
|
node.setAttribute("value", text);
|
|
|
|
node.setAttribute("tooltiptext", text);
|
2013-03-11 23:50:42 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a waterfall representing timing information in a network request item view.
|
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aItem
|
2013-03-11 23:50:42 -07:00
|
|
|
* The network request item in this container.
|
|
|
|
* @param object aTimings
|
|
|
|
* An object containing timing information.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createWaterfallView: function(aItem, aTimings) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let { target, attachment } = aItem;
|
2013-04-17 23:35:27 -07:00
|
|
|
let sections = ["dns", "connect", "send", "wait", "receive"];
|
|
|
|
// Skipping "blocked" because it doesn't work yet.
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
let timingsNode = $(".requests-menu-timings", target);
|
2014-02-03 10:10:00 -08:00
|
|
|
let timingsTotal = $(".requests-menu-timings-total", timingsNode);
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
// Add a set of boxes representing timing information.
|
|
|
|
for (let key of sections) {
|
|
|
|
let width = aTimings[key];
|
|
|
|
|
|
|
|
// Don't render anything if it surely won't be visible.
|
|
|
|
// One millisecond == one unscaled pixel.
|
|
|
|
if (width > 0) {
|
|
|
|
let timingBox = document.createElement("hbox");
|
|
|
|
timingBox.className = "requests-menu-timings-box " + key;
|
|
|
|
timingBox.setAttribute("width", width);
|
2014-02-03 10:10:00 -08:00
|
|
|
timingsNode.insertBefore(timingBox, timingsTotal);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-05-10 02:01:05 -07:00
|
|
|
* Rescales and redraws all the waterfall views in this container.
|
2013-03-11 23:50:42 -07:00
|
|
|
*
|
|
|
|
* @param boolean aReset
|
|
|
|
* True if this container's width was changed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_flushWaterfallViews: function(aReset) {
|
2014-02-13 07:26:09 -08:00
|
|
|
// Don't paint things while the waterfall view isn't even visible,
|
|
|
|
// or there are no items added to this container.
|
|
|
|
if (NetMonitorView.currentFrontendMode != "network-inspector-view" || !this.itemCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:01:05 -07:00
|
|
|
// To avoid expensive operations like getBoundingClientRect() and
|
|
|
|
// rebuilding the waterfall background each time a new request comes in,
|
|
|
|
// stuff is cached. However, in certain scenarios like when the window
|
|
|
|
// is resized, this needs to be invalidated.
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aReset) {
|
|
|
|
this._cachedWaterfallWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the scaling to be applied to all the waterfalls so that
|
|
|
|
// everything is visible at once. One millisecond == one unscaled pixel.
|
|
|
|
let availableWidth = this._waterfallWidth - REQUESTS_WATERFALL_SAFE_BOUNDS;
|
|
|
|
let longestWidth = this._lastRequestEndedMillis - this._firstRequestStartedMillis;
|
|
|
|
let scale = Math.min(Math.max(availableWidth / longestWidth, EPSILON), 1);
|
|
|
|
|
2013-05-10 02:01:05 -07:00
|
|
|
// Redraw and set the canvas background for each waterfall view.
|
|
|
|
this._showWaterfallDivisionLabels(scale);
|
|
|
|
this._drawWaterfallBackground(scale);
|
|
|
|
this._flushWaterfallBackgrounds();
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
// Apply CSS transforms to each waterfall in this container totalTime
|
|
|
|
// accurately translate and resize as needed.
|
2013-11-07 13:23:55 -08:00
|
|
|
for (let { target, attachment } of this) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let timingsNode = $(".requests-menu-timings", target);
|
|
|
|
let totalNode = $(".requests-menu-timings-total", target);
|
2013-06-05 23:53:09 -07:00
|
|
|
let direction = window.isRTL ? -1 : 1;
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
// Render the timing information at a specific horizontal translation
|
|
|
|
// based on the delta to the first monitored event network.
|
2013-06-05 23:53:09 -07:00
|
|
|
let translateX = "translateX(" + (direction * attachment.startedDeltaMillis) + "px)";
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
// Based on the total time passed until the last request, rescale
|
|
|
|
// all the waterfalls to a reasonable size.
|
|
|
|
let scaleX = "scaleX(" + scale + ")";
|
|
|
|
|
|
|
|
// Certain nodes should not be scaled, even if they're children of
|
|
|
|
// another scaled node. In this case, apply a reversed transformation.
|
|
|
|
let revScaleX = "scaleX(" + (1 / scale) + ")";
|
|
|
|
|
|
|
|
timingsNode.style.transform = scaleX + " " + translateX;
|
|
|
|
totalNode.style.transform = revScaleX;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-10 02:01:05 -07:00
|
|
|
/**
|
|
|
|
* Creates the labels displayed on the waterfall header in this container.
|
|
|
|
*
|
|
|
|
* @param number aScale
|
|
|
|
* The current waterfall scale.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_showWaterfallDivisionLabels: function(aScale) {
|
2013-06-04 00:55:48 -07:00
|
|
|
let container = $("#requests-menu-waterfall-button");
|
2013-05-10 02:01:05 -07:00
|
|
|
let availableWidth = this._waterfallWidth - REQUESTS_WATERFALL_SAFE_BOUNDS;
|
|
|
|
|
|
|
|
// Nuke all existing labels.
|
|
|
|
while (container.hasChildNodes()) {
|
|
|
|
container.firstChild.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build new millisecond tick labels...
|
|
|
|
let timingStep = REQUESTS_WATERFALL_HEADER_TICKS_MULTIPLE;
|
|
|
|
let optimalTickIntervalFound = false;
|
|
|
|
|
|
|
|
while (!optimalTickIntervalFound) {
|
|
|
|
// Ignore any divisions that would end up being too close to each other.
|
|
|
|
let scaledStep = aScale * timingStep;
|
|
|
|
if (scaledStep < REQUESTS_WATERFALL_HEADER_TICKS_SPACING_MIN) {
|
|
|
|
timingStep <<= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
optimalTickIntervalFound = true;
|
|
|
|
|
|
|
|
// Insert one label for each division on the current scale.
|
|
|
|
let fragment = document.createDocumentFragment();
|
2013-06-05 23:53:09 -07:00
|
|
|
let direction = window.isRTL ? -1 : 1;
|
2013-05-10 02:01:05 -07:00
|
|
|
|
|
|
|
for (let x = 0; x < availableWidth; x += scaledStep) {
|
2013-06-05 23:53:09 -07:00
|
|
|
let translateX = "translateX(" + ((direction * x) | 0) + "px)";
|
2014-01-08 06:47:59 -08:00
|
|
|
let millisecondTime = x / aScale;
|
|
|
|
|
|
|
|
let normalizedTime = millisecondTime;
|
|
|
|
let divisionScale = "millisecond";
|
|
|
|
|
|
|
|
// If the division is greater than 1 minute.
|
|
|
|
if (normalizedTime > 60000) {
|
|
|
|
normalizedTime /= 60000;
|
|
|
|
divisionScale = "minute";
|
|
|
|
}
|
|
|
|
// If the division is greater than 1 second.
|
|
|
|
else if (normalizedTime > 1000) {
|
|
|
|
normalizedTime /= 1000;
|
|
|
|
divisionScale = "second";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Showing too many decimals is bad UX.
|
|
|
|
if (divisionScale == "millisecond") {
|
|
|
|
normalizedTime |= 0;
|
|
|
|
} else {
|
2014-01-31 22:37:53 -08:00
|
|
|
normalizedTime = L10N.numberWithDecimals(normalizedTime, REQUEST_TIME_DECIMALS);
|
2014-01-08 06:47:59 -08:00
|
|
|
}
|
2013-05-10 02:01:05 -07:00
|
|
|
|
|
|
|
let node = document.createElement("label");
|
2014-01-08 06:47:59 -08:00
|
|
|
let text = L10N.getFormatStr("networkMenu." + divisionScale, normalizedTime);
|
2013-05-10 02:01:05 -07:00
|
|
|
node.className = "plain requests-menu-timings-division";
|
2014-01-08 06:47:59 -08:00
|
|
|
node.setAttribute("division-scale", divisionScale);
|
2013-05-10 02:01:05 -07:00
|
|
|
node.style.transform = translateX;
|
|
|
|
|
|
|
|
node.setAttribute("value", text);
|
|
|
|
fragment.appendChild(node);
|
|
|
|
}
|
|
|
|
container.appendChild(fragment);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the background displayed on each waterfall view in this container.
|
|
|
|
*
|
|
|
|
* @param number aScale
|
|
|
|
* The current waterfall scale.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_drawWaterfallBackground: function(aScale) {
|
2013-05-10 02:01:05 -07:00
|
|
|
if (!this._canvas || !this._ctx) {
|
|
|
|
this._canvas = document.createElementNS(HTML_NS, "canvas");
|
|
|
|
this._ctx = this._canvas.getContext("2d");
|
|
|
|
}
|
|
|
|
let canvas = this._canvas;
|
|
|
|
let ctx = this._ctx;
|
|
|
|
|
|
|
|
// Nuke the context.
|
|
|
|
let canvasWidth = canvas.width = this._waterfallWidth;
|
|
|
|
let canvasHeight = canvas.height = 1; // Awww yeah, 1px, repeats on Y axis.
|
|
|
|
|
|
|
|
// Start over.
|
|
|
|
let imageData = ctx.createImageData(canvasWidth, canvasHeight);
|
|
|
|
let pixelArray = imageData.data;
|
|
|
|
|
|
|
|
let buf = new ArrayBuffer(pixelArray.length);
|
|
|
|
let buf8 = new Uint8ClampedArray(buf);
|
|
|
|
let data32 = new Uint32Array(buf);
|
|
|
|
|
|
|
|
// Build new millisecond tick lines...
|
|
|
|
let timingStep = REQUESTS_WATERFALL_BACKGROUND_TICKS_MULTIPLE;
|
2013-05-15 13:33:10 -07:00
|
|
|
let [r, g, b] = REQUESTS_WATERFALL_BACKGROUND_TICKS_COLOR_RGB;
|
2013-05-10 02:01:05 -07:00
|
|
|
let alphaComponent = REQUESTS_WATERFALL_BACKGROUND_TICKS_OPACITY_MIN;
|
|
|
|
let optimalTickIntervalFound = false;
|
|
|
|
|
|
|
|
while (!optimalTickIntervalFound) {
|
|
|
|
// Ignore any divisions that would end up being too close to each other.
|
|
|
|
let scaledStep = aScale * timingStep;
|
|
|
|
if (scaledStep < REQUESTS_WATERFALL_BACKGROUND_TICKS_SPACING_MIN) {
|
|
|
|
timingStep <<= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
optimalTickIntervalFound = true;
|
|
|
|
|
|
|
|
// Insert one pixel for each division on each scale.
|
|
|
|
for (let i = 1; i <= REQUESTS_WATERFALL_BACKGROUND_TICKS_SCALES; i++) {
|
|
|
|
let increment = scaledStep * Math.pow(2, i);
|
|
|
|
for (let x = 0; x < canvasWidth; x += increment) {
|
2013-06-05 23:53:09 -07:00
|
|
|
let position = (window.isRTL ? canvasWidth - x : x) | 0;
|
|
|
|
data32[position] = (alphaComponent << 24) | (b << 16) | (g << 8) | r;
|
2013-05-10 02:01:05 -07:00
|
|
|
}
|
|
|
|
alphaComponent += REQUESTS_WATERFALL_BACKGROUND_TICKS_OPACITY_ADD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush the image data and cache the waterfall background.
|
|
|
|
pixelArray.set(buf8);
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
|
|
this._cachedWaterfallBackground = "url(" + canvas.toDataURL() + ")";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reapplies the current waterfall background on all request items.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_flushWaterfallBackgrounds: function() {
|
2013-11-07 13:23:55 -08:00
|
|
|
for (let { target } of this) {
|
2013-05-10 02:01:05 -07:00
|
|
|
let waterfallNode = $(".requests-menu-waterfall", target);
|
|
|
|
waterfallNode.style.backgroundImage = this._cachedWaterfallBackground;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* The selection listener for this container.
|
|
|
|
*/
|
2013-05-24 10:10:07 -07:00
|
|
|
_onSelect: function({ detail: item }) {
|
|
|
|
if (item) {
|
2013-06-26 02:09:59 -07:00
|
|
|
NetMonitorView.Sidebar.populate(item.attachment);
|
|
|
|
NetMonitorView.Sidebar.toggle(true);
|
2013-05-24 10:10:07 -07:00
|
|
|
} else {
|
2013-06-26 02:09:59 -07:00
|
|
|
NetMonitorView.Sidebar.toggle(false);
|
2013-05-24 10:10:07 -07:00
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
2014-02-14 11:22:06 -08:00
|
|
|
/**
|
|
|
|
* The swap listener for this container.
|
|
|
|
* Called when two items switch places, when the contents are sorted.
|
|
|
|
*/
|
|
|
|
_onSwap: function({ detail: [firstItem, secondItem] }) {
|
|
|
|
// Sorting will create new anchor nodes for all the swapped request items
|
|
|
|
// in this container, so it's necessary to refresh the Tooltip instances.
|
|
|
|
this.refreshTooltip(firstItem);
|
|
|
|
this.refreshTooltip(secondItem);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The predicate used when deciding whether a popup should be shown
|
|
|
|
* over a request item or not.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aTarget
|
|
|
|
* The element node currently being hovered.
|
|
|
|
* @param object aTooltip
|
|
|
|
* The current tooltip instance.
|
|
|
|
*/
|
|
|
|
_onHover: function(aTarget, aTooltip) {
|
|
|
|
let requestItem = this.getItemForElement(aTarget);
|
|
|
|
if (!requestItem || !requestItem.attachment.responseContent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let hovered = requestItem.attachment;
|
|
|
|
let { url } = hovered;
|
|
|
|
let { mimeType, text, encoding } = hovered.responseContent.content;
|
|
|
|
|
|
|
|
if (mimeType && mimeType.contains("image/") && (
|
|
|
|
aTarget.classList.contains("requests-menu-icon") ||
|
|
|
|
aTarget.classList.contains("requests-menu-file")))
|
|
|
|
{
|
|
|
|
return gNetwork.getString(text).then(aString => {
|
|
|
|
let anchor = $(".requests-menu-icon", requestItem.target);
|
|
|
|
let src = "data:" + mimeType + ";" + encoding + "," + aString;
|
|
|
|
aTooltip.setImageContent(src, { maxDim: REQUESTS_TOOLTIP_IMAGE_MAX_DIM });
|
|
|
|
return anchor;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* The resize listener for this container's window.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onResize: function(e) {
|
2013-05-10 02:01:05 -07:00
|
|
|
// Allow requests to settle down first.
|
2013-09-13 06:23:13 -07:00
|
|
|
setNamedTimeout(
|
|
|
|
"resize-events", RESIZE_REFRESH_RATE, () => this._flushWaterfallViews(true));
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
|
|
|
* Handle the context menu opening. Hide items if no request is selected.
|
|
|
|
*/
|
|
|
|
_onContextShowing: function() {
|
2014-02-02 00:39:53 -08:00
|
|
|
let selectedItem = this.selectedItem;
|
|
|
|
|
2013-07-10 18:50:16 -07:00
|
|
|
let resendElement = $("#request-menu-context-resend");
|
2014-03-07 04:14:53 -08:00
|
|
|
resendElement.hidden = !NetMonitorController.supportsCustomRequest ||
|
2014-03-31 08:14:47 -07:00
|
|
|
!selectedItem || selectedItem.attachment.isCustom;
|
2013-07-10 18:50:16 -07:00
|
|
|
|
|
|
|
let copyUrlElement = $("#request-menu-context-copy-url");
|
2014-02-02 00:39:53 -08:00
|
|
|
copyUrlElement.hidden = !selectedItem;
|
|
|
|
|
2014-03-19 18:02:08 -07:00
|
|
|
let copyAsCurlElement = $("#request-menu-context-copy-as-curl");
|
|
|
|
copyAsCurlElement.hidden = !selectedItem || !selectedItem.attachment.responseContent;
|
|
|
|
|
2014-02-02 00:39:53 -08:00
|
|
|
let copyImageAsDataUriElement = $("#request-menu-context-copy-image-as-data-uri");
|
|
|
|
copyImageAsDataUriElement.hidden = !selectedItem ||
|
|
|
|
!selectedItem.attachment.responseContent ||
|
|
|
|
!selectedItem.attachment.responseContent.content.mimeType.contains("image/");
|
2014-01-13 09:32:00 -08:00
|
|
|
|
|
|
|
let newTabElement = $("#request-menu-context-newtab");
|
2014-02-02 00:39:53 -08:00
|
|
|
newTabElement.hidden = !selectedItem;
|
2013-06-26 02:09:59 -07:00
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Checks if the specified unix time is the first one to be known of,
|
|
|
|
* and saves it if so.
|
|
|
|
*
|
|
|
|
* @param number aUnixTime
|
|
|
|
* The milliseconds to check and save.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_registerFirstRequestStart: function(aUnixTime) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (this._firstRequestStartedMillis == -1) {
|
|
|
|
this._firstRequestStartedMillis = aUnixTime;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the specified unix time is the last one to be known of,
|
|
|
|
* and saves it if so.
|
|
|
|
*
|
|
|
|
* @param number aUnixTime
|
|
|
|
* The milliseconds to check and save.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_registerLastRequestEnd: function(aUnixTime) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (this._lastRequestEndedMillis < aUnixTime) {
|
|
|
|
this._lastRequestEndedMillis = aUnixTime;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
/**
|
|
|
|
* Helpers for getting details about an nsIURL.
|
|
|
|
*
|
|
|
|
* @param nsIURL | string aUrl
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
_getUriNameWithQuery: function(aUrl) {
|
|
|
|
if (!(aUrl instanceof Ci.nsIURL)) {
|
|
|
|
aUrl = nsIURL(aUrl);
|
|
|
|
}
|
|
|
|
let name = NetworkHelper.convertToUnicode(unescape(aUrl.fileName)) || "/";
|
|
|
|
let query = NetworkHelper.convertToUnicode(unescape(aUrl.query));
|
|
|
|
return name + (query ? "?" + query : "");
|
|
|
|
},
|
|
|
|
_getUriHostPort: function(aUrl) {
|
|
|
|
if (!(aUrl instanceof Ci.nsIURL)) {
|
|
|
|
aUrl = nsIURL(aUrl);
|
|
|
|
}
|
|
|
|
return NetworkHelper.convertToUnicode(unescape(aUrl.hostPort));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for getting an abbreviated string for a mime type.
|
|
|
|
*
|
|
|
|
* @param string aMimeType
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
_getAbbreviatedMimeType: function(aMimeType) {
|
|
|
|
if (!aMimeType) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return (aMimeType.split(";")[0].split("/")[1] || "").split("+")[0];
|
|
|
|
},
|
|
|
|
|
2013-05-30 11:46:36 -07:00
|
|
|
/**
|
|
|
|
* Gets the total number of bytes representing the cumulated content size of
|
|
|
|
* a set of requests. Returns 0 for an empty set.
|
|
|
|
*
|
|
|
|
* @param array aItemsArray
|
|
|
|
* @return number
|
|
|
|
*/
|
|
|
|
_getTotalBytesOfRequests: function(aItemsArray) {
|
|
|
|
if (!aItemsArray.length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return aItemsArray.reduce((prev, curr) => prev + curr.attachment.contentSize || 0, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the oldest (first performed) request in a set. Returns null for an
|
|
|
|
* empty set.
|
|
|
|
*
|
|
|
|
* @param array aItemsArray
|
2013-06-21 07:33:56 -07:00
|
|
|
* @return object
|
2013-05-30 11:46:36 -07:00
|
|
|
*/
|
|
|
|
_getOldestRequest: function(aItemsArray) {
|
|
|
|
if (!aItemsArray.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return aItemsArray.reduce((prev, curr) =>
|
|
|
|
prev.attachment.startedMillis < curr.attachment.startedMillis ? prev : curr);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the newest (latest performed) request in a set. Returns null for an
|
|
|
|
* empty set.
|
|
|
|
*
|
|
|
|
* @param array aItemsArray
|
2013-06-21 07:33:56 -07:00
|
|
|
* @return object
|
2013-05-30 11:46:36 -07:00
|
|
|
*/
|
|
|
|
_getNewestRequest: function(aItemsArray) {
|
|
|
|
if (!aItemsArray.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return aItemsArray.reduce((prev, curr) =>
|
|
|
|
prev.attachment.startedMillis > curr.attachment.startedMillis ? prev : curr);
|
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Gets the available waterfall width in this container.
|
|
|
|
* @return number
|
|
|
|
*/
|
|
|
|
get _waterfallWidth() {
|
|
|
|
if (this._cachedWaterfallWidth == 0) {
|
|
|
|
let container = $("#requests-menu-toolbar");
|
2013-05-10 02:01:05 -07:00
|
|
|
let waterfall = $("#requests-menu-waterfall-header-box");
|
2013-03-11 23:50:42 -07:00
|
|
|
let containerBounds = container.getBoundingClientRect();
|
|
|
|
let waterfallBounds = waterfall.getBoundingClientRect();
|
2013-06-05 23:53:09 -07:00
|
|
|
if (!window.isRTL) {
|
|
|
|
this._cachedWaterfallWidth = containerBounds.width - waterfallBounds.left;
|
|
|
|
} else {
|
|
|
|
this._cachedWaterfallWidth = waterfallBounds.right;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
return this._cachedWaterfallWidth;
|
|
|
|
},
|
|
|
|
|
2013-08-27 20:55:48 -07:00
|
|
|
_splitter: null,
|
2013-05-30 11:46:36 -07:00
|
|
|
_summary: null,
|
2013-05-10 02:01:05 -07:00
|
|
|
_canvas: null,
|
|
|
|
_ctx: null,
|
2013-03-11 23:50:42 -07:00
|
|
|
_cachedWaterfallWidth: 0,
|
2013-05-24 10:10:07 -07:00
|
|
|
_cachedWaterfallBackground: "",
|
2013-03-11 23:50:42 -07:00
|
|
|
_firstRequestStartedMillis: -1,
|
|
|
|
_lastRequestEndedMillis: -1,
|
|
|
|
_updateQueue: [],
|
2013-05-10 02:01:05 -07:00
|
|
|
_updateTimeout: null,
|
2014-02-10 10:18:45 -08:00
|
|
|
_resizeTimeout: null,
|
|
|
|
_activeFilters: ["all"]
|
2013-03-11 23:50:42 -07:00
|
|
|
});
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
|
|
|
* Functions handling the sidebar details view.
|
|
|
|
*/
|
|
|
|
function SidebarView() {
|
|
|
|
dumpn("SidebarView was instantiated");
|
|
|
|
}
|
|
|
|
|
|
|
|
SidebarView.prototype = {
|
|
|
|
/**
|
|
|
|
* Sets this view hidden or visible. It's visible by default.
|
|
|
|
*
|
|
|
|
* @param boolean aVisibleFlag
|
|
|
|
* Specifies the intended visibility.
|
|
|
|
*/
|
|
|
|
toggle: function(aVisibleFlag) {
|
|
|
|
NetMonitorView.toggleDetailsPane({ visible: aVisibleFlag });
|
|
|
|
NetMonitorView.RequestsMenu._flushWaterfallViews(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param object aData
|
|
|
|
* The data source (this should be the attachment of a request item).
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* Returns a promise that resolves upon population of the subview.
|
2013-06-26 02:09:59 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
populate: Task.async(function*(aData) {
|
2013-12-02 08:34:47 -08:00
|
|
|
let isCustom = aData.isCustom;
|
|
|
|
let view = isCustom ?
|
|
|
|
NetMonitorView.CustomRequest :
|
|
|
|
NetMonitorView.NetworkDetails;
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
yield view.populate(aData);
|
|
|
|
$("#details-pane").selectedIndex = isCustom ? 0 : 1;
|
|
|
|
|
|
|
|
window.emit(EVENTS.SIDEBAR_POPULATED);
|
|
|
|
})
|
2013-06-26 02:09:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions handling the custom request view.
|
|
|
|
*/
|
|
|
|
function CustomRequestView() {
|
|
|
|
dumpn("CustomRequestView was instantiated");
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomRequestView.prototype = {
|
2014-01-28 05:50:34 -08:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the network monitor is started.
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
|
|
|
dumpn("Initializing the CustomRequestView");
|
|
|
|
|
|
|
|
this.updateCustomRequestEvent = getKeyWithEvent(this.onUpdate.bind(this));
|
|
|
|
$("#custom-pane").addEventListener("input", this.updateCustomRequestEvent, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the network monitor is closed.
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
|
|
|
dumpn("Destroying the CustomRequestView");
|
|
|
|
|
|
|
|
$("#custom-pane").removeEventListener("input", this.updateCustomRequestEvent, false);
|
|
|
|
},
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
|
|
|
* Populates this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param object aData
|
|
|
|
* The data source (this should be the attachment of a request item).
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* Returns a promise that resolves upon population the view.
|
2013-06-26 02:09:59 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
populate: Task.async(function*(aData) {
|
2013-06-26 02:09:59 -07:00
|
|
|
$("#custom-url-value").value = aData.url;
|
|
|
|
$("#custom-method-value").value = aData.method;
|
2014-03-31 08:14:47 -07:00
|
|
|
this.updateCustomQuery(aData.url);
|
2013-12-02 08:34:47 -08:00
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
if (aData.requestHeaders) {
|
|
|
|
let headers = aData.requestHeaders.headers;
|
|
|
|
$("#custom-headers-value").value = writeHeaderText(headers);
|
|
|
|
}
|
2013-06-26 02:09:59 -07:00
|
|
|
if (aData.requestPostData) {
|
2014-03-31 08:14:47 -07:00
|
|
|
let postData = aData.requestPostData.postData.text;
|
|
|
|
$("#custom-postdata-value").value = yield gNetwork.getString(postData);
|
2013-06-26 02:09:59 -07:00
|
|
|
}
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
window.emit(EVENTS.CUSTOMREQUESTVIEW_POPULATED);
|
|
|
|
}),
|
2013-06-26 02:09:59 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle user input in the custom request form.
|
|
|
|
*
|
|
|
|
* @param object aField
|
|
|
|
* the field that the user updated.
|
|
|
|
*/
|
|
|
|
onUpdate: function(aField) {
|
|
|
|
let selectedItem = NetMonitorView.RequestsMenu.selectedItem;
|
|
|
|
let field = aField;
|
|
|
|
let value;
|
|
|
|
|
|
|
|
switch(aField) {
|
|
|
|
case 'method':
|
|
|
|
value = $("#custom-method-value").value.trim();
|
|
|
|
selectedItem.attachment.method = value;
|
|
|
|
break;
|
|
|
|
case 'url':
|
|
|
|
value = $("#custom-url-value").value;
|
|
|
|
this.updateCustomQuery(value);
|
|
|
|
selectedItem.attachment.url = value;
|
|
|
|
break;
|
|
|
|
case 'query':
|
|
|
|
let query = $("#custom-query-value").value;
|
|
|
|
this.updateCustomUrl(query);
|
|
|
|
field = 'url';
|
|
|
|
value = $("#custom-url-value").value
|
|
|
|
selectedItem.attachment.url = value;
|
|
|
|
break;
|
|
|
|
case 'body':
|
|
|
|
value = $("#custom-postdata-value").value;
|
2014-01-31 22:37:53 -08:00
|
|
|
selectedItem.attachment.requestPostData = { postData: { text: value } };
|
2013-06-26 02:09:59 -07:00
|
|
|
break;
|
|
|
|
case 'headers':
|
|
|
|
let headersText = $("#custom-headers-value").value;
|
2014-03-03 07:59:49 -08:00
|
|
|
value = parseHeadersText(headersText);
|
2014-01-31 22:37:53 -08:00
|
|
|
selectedItem.attachment.requestHeaders = { headers: value };
|
2013-06-26 02:09:59 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NetMonitorView.RequestsMenu.updateMenuView(selectedItem, field, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the query string field based on the url.
|
|
|
|
*
|
|
|
|
* @param object aUrl
|
2014-03-31 08:14:47 -07:00
|
|
|
* The URL to extract query string from.
|
2013-06-26 02:09:59 -07:00
|
|
|
*/
|
|
|
|
updateCustomQuery: function(aUrl) {
|
|
|
|
let paramsArray = parseQueryString(nsIURL(aUrl).query);
|
|
|
|
if (!paramsArray) {
|
|
|
|
$("#custom-query").hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$("#custom-query").hidden = false;
|
|
|
|
$("#custom-query-value").value = writeQueryText(paramsArray);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the url based on the query string field.
|
|
|
|
*
|
|
|
|
* @param object aQueryText
|
2014-03-31 08:14:47 -07:00
|
|
|
* The contents of the query string field.
|
2013-06-26 02:09:59 -07:00
|
|
|
*/
|
|
|
|
updateCustomUrl: function(aQueryText) {
|
|
|
|
let params = parseQueryText(aQueryText);
|
|
|
|
let queryString = writeQueryString(params);
|
|
|
|
|
|
|
|
let url = $("#custom-url-value").value;
|
|
|
|
let oldQuery = nsIURL(url).query;
|
|
|
|
let path = url.replace(oldQuery, queryString);
|
|
|
|
|
|
|
|
$("#custom-url-value").value = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Functions handling the requests details view.
|
|
|
|
*/
|
|
|
|
function NetworkDetailsView() {
|
|
|
|
dumpn("NetworkDetailsView was instantiated");
|
2013-05-14 10:03:24 -07:00
|
|
|
|
|
|
|
this._onTabSelect = this._onTabSelect.bind(this);
|
2013-03-11 23:50:42 -07:00
|
|
|
};
|
|
|
|
|
2013-05-24 11:36:51 -07:00
|
|
|
NetworkDetailsView.prototype = {
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the network monitor is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2013-06-26 02:09:59 -07:00
|
|
|
dumpn("Initializing the NetworkDetailsView");
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
this.widget = $("#event-details-pane");
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
this._headers = new VariablesView($("#all-headers"),
|
2013-06-21 07:33:56 -07:00
|
|
|
Heritage.extend(GENERIC_VARIABLES_VIEW_SETTINGS, {
|
|
|
|
emptyText: L10N.getStr("headersEmptyText"),
|
|
|
|
searchPlaceholder: L10N.getStr("headersFilterText")
|
2013-03-11 23:50:42 -07:00
|
|
|
}));
|
|
|
|
this._cookies = new VariablesView($("#all-cookies"),
|
2013-06-21 07:33:56 -07:00
|
|
|
Heritage.extend(GENERIC_VARIABLES_VIEW_SETTINGS, {
|
|
|
|
emptyText: L10N.getStr("cookiesEmptyText"),
|
|
|
|
searchPlaceholder: L10N.getStr("cookiesFilterText")
|
2013-03-11 23:50:42 -07:00
|
|
|
}));
|
|
|
|
this._params = new VariablesView($("#request-params"),
|
2013-06-21 07:33:56 -07:00
|
|
|
Heritage.extend(GENERIC_VARIABLES_VIEW_SETTINGS, {
|
|
|
|
emptyText: L10N.getStr("paramsEmptyText"),
|
|
|
|
searchPlaceholder: L10N.getStr("paramsFilterText")
|
2013-03-11 23:50:42 -07:00
|
|
|
}));
|
|
|
|
this._json = new VariablesView($("#response-content-json"),
|
2013-06-21 07:33:56 -07:00
|
|
|
Heritage.extend(GENERIC_VARIABLES_VIEW_SETTINGS, {
|
2013-10-17 01:21:08 -07:00
|
|
|
onlyEnumVisible: true,
|
2013-06-21 07:33:56 -07:00
|
|
|
searchPlaceholder: L10N.getStr("jsonFilterText")
|
2013-03-11 23:50:42 -07:00
|
|
|
}));
|
2013-10-01 13:17:20 -07:00
|
|
|
VariablesViewController.attach(this._json);
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
this._paramsQueryString = L10N.getStr("paramsQueryString");
|
|
|
|
this._paramsFormData = L10N.getStr("paramsFormData");
|
|
|
|
this._paramsPostPayload = L10N.getStr("paramsPostPayload");
|
|
|
|
this._requestHeaders = L10N.getStr("requestHeaders");
|
2014-03-03 07:59:49 -08:00
|
|
|
this._requestHeadersFromUpload = L10N.getStr("requestHeadersFromUpload");
|
2013-03-11 23:50:42 -07:00
|
|
|
this._responseHeaders = L10N.getStr("responseHeaders");
|
|
|
|
this._requestCookies = L10N.getStr("requestCookies");
|
|
|
|
this._responseCookies = L10N.getStr("responseCookies");
|
2013-05-14 10:03:24 -07:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
$("tabpanels", this.widget).addEventListener("select", this._onTabSelect);
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the network monitor is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2013-06-26 02:09:59 -07:00
|
|
|
dumpn("Destroying the NetworkDetailsView");
|
2013-06-26 02:06:07 -07:00
|
|
|
},
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Populates this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param object aData
|
|
|
|
* The data source (this should be the attachment of a request item).
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* Returns a promise that resolves upon population the view.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
populate: function(aData) {
|
2013-03-11 23:50:42 -07:00
|
|
|
$("#request-params-box").setAttribute("flex", "1");
|
|
|
|
$("#request-params-box").hidden = false;
|
|
|
|
$("#request-post-data-textarea-box").hidden = true;
|
2013-06-12 00:37:46 -07:00
|
|
|
$("#response-content-info-header").hidden = true;
|
2013-03-11 23:50:42 -07:00
|
|
|
$("#response-content-json-box").hidden = true;
|
|
|
|
$("#response-content-textarea-box").hidden = true;
|
|
|
|
$("#response-content-image-box").hidden = true;
|
|
|
|
|
2014-02-13 07:26:09 -08:00
|
|
|
let isHtml = RequestsMenuView.prototype.isHtml({ attachment: aData });
|
|
|
|
|
|
|
|
// Show the "Preview" tabpanel only for plain HTML responses.
|
|
|
|
$("#preview-tab").hidden = !isHtml;
|
|
|
|
$("#preview-tabpanel").hidden = !isHtml;
|
|
|
|
|
|
|
|
// Switch to the "Headers" tabpanel if the "Preview" previously selected
|
|
|
|
// and this is not an HTML response.
|
|
|
|
if (!isHtml && this.widget.selectedIndex == 5) {
|
|
|
|
this.widget.selectedIndex = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
this._headers.empty();
|
|
|
|
this._cookies.empty();
|
|
|
|
this._params.empty();
|
|
|
|
this._json.empty();
|
|
|
|
|
2013-05-14 10:03:24 -07:00
|
|
|
this._dataSrc = { src: aData, populated: [] };
|
|
|
|
this._onTabSelect();
|
2013-12-02 08:34:47 -08:00
|
|
|
window.emit(EVENTS.NETWORKDETAILSVIEW_POPULATED);
|
|
|
|
|
|
|
|
return promise.resolve();
|
2013-05-14 10:03:24 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listener handling the tab selection event.
|
|
|
|
*/
|
|
|
|
_onTabSelect: function() {
|
|
|
|
let { src, populated } = this._dataSrc || {};
|
2013-06-21 07:33:56 -07:00
|
|
|
let tab = this.widget.selectedIndex;
|
2013-12-02 08:34:47 -08:00
|
|
|
let view = this;
|
2013-05-14 10:03:24 -07:00
|
|
|
|
|
|
|
// Make sure the data source is valid and don't populate the same tab twice.
|
|
|
|
if (!src || populated[tab]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-02 08:34:47 -08:00
|
|
|
Task.spawn(function*() {
|
|
|
|
switch (tab) {
|
|
|
|
case 0: // "Headers"
|
|
|
|
yield view._setSummary(src);
|
|
|
|
yield view._setResponseHeaders(src.responseHeaders);
|
2014-03-03 07:59:49 -08:00
|
|
|
yield view._setRequestHeaders(
|
|
|
|
src.requestHeaders,
|
|
|
|
src.requestHeadersFromUploadStream);
|
2013-12-02 08:34:47 -08:00
|
|
|
break;
|
|
|
|
case 1: // "Cookies"
|
|
|
|
yield view._setResponseCookies(src.responseCookies);
|
|
|
|
yield view._setRequestCookies(src.requestCookies);
|
|
|
|
break;
|
|
|
|
case 2: // "Params"
|
|
|
|
yield view._setRequestGetParams(src.url);
|
2014-03-03 07:59:49 -08:00
|
|
|
yield view._setRequestPostParams(
|
|
|
|
src.requestHeaders,
|
|
|
|
src.requestHeadersFromUploadStream,
|
|
|
|
src.requestPostData);
|
2013-12-02 08:34:47 -08:00
|
|
|
break;
|
|
|
|
case 3: // "Response"
|
|
|
|
yield view._setResponseBody(src.url, src.responseContent);
|
|
|
|
break;
|
|
|
|
case 4: // "Timings"
|
|
|
|
yield view._setTimingsInformation(src.eventTimings);
|
|
|
|
break;
|
2014-02-13 07:26:09 -08:00
|
|
|
case 5: // "Preview"
|
|
|
|
yield view._setHtmlPreview(src.responseContent);
|
|
|
|
break;
|
2013-12-02 08:34:47 -08:00
|
|
|
}
|
|
|
|
populated[tab] = true;
|
|
|
|
window.emit(EVENTS.TAB_UPDATED);
|
2014-02-14 11:22:06 -08:00
|
|
|
NetMonitorView.RequestsMenu.ensureSelectedItemIsVisible();
|
2013-12-02 08:34:47 -08:00
|
|
|
});
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network request summary shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aData
|
|
|
|
* The data source (this should be the attachment of a request item).
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_setSummary: function(aData) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aData.url) {
|
|
|
|
let unicodeUrl = NetworkHelper.convertToUnicode(unescape(aData.url));
|
|
|
|
$("#headers-summary-url-value").setAttribute("value", unicodeUrl);
|
2013-04-09 16:05:09 -07:00
|
|
|
$("#headers-summary-url-value").setAttribute("tooltiptext", unicodeUrl);
|
2013-03-11 23:50:42 -07:00
|
|
|
$("#headers-summary-url").removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
$("#headers-summary-url").setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.method) {
|
|
|
|
$("#headers-summary-method-value").setAttribute("value", aData.method);
|
|
|
|
$("#headers-summary-method").removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
$("#headers-summary-method").setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.status) {
|
|
|
|
$("#headers-summary-status-circle").setAttribute("code", aData.status);
|
|
|
|
$("#headers-summary-status-value").setAttribute("value", aData.status + " " + aData.statusText);
|
|
|
|
$("#headers-summary-status").removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
$("#headers-summary-status").setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.httpVersion && aData.httpVersion != DEFAULT_HTTP_VERSION) {
|
|
|
|
$("#headers-summary-version-value").setAttribute("value", aData.httpVersion);
|
|
|
|
$("#headers-summary-version").removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
$("#headers-summary-version").setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network request headers shown in this view.
|
|
|
|
*
|
2014-03-03 07:59:49 -08:00
|
|
|
* @param object aHeadersResponse
|
|
|
|
* The "requestHeaders" message received from the server.
|
|
|
|
* @param object aHeadersFromUploadStream
|
|
|
|
* The "requestHeadersFromUploadStream" inferred from the POST payload.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that resolves when request headers are set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setRequestHeaders: Task.async(function*(aHeadersResponse, aHeadersFromUploadStream) {
|
2014-03-03 07:59:49 -08:00
|
|
|
if (aHeadersResponse && aHeadersResponse.headers.length) {
|
2014-03-31 08:14:47 -07:00
|
|
|
yield this._addHeaders(this._requestHeaders, aHeadersResponse);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2014-03-03 07:59:49 -08:00
|
|
|
if (aHeadersFromUploadStream && aHeadersFromUploadStream.headers.length) {
|
2014-03-31 08:14:47 -07:00
|
|
|
yield this._addHeaders(this._requestHeadersFromUpload, aHeadersFromUploadStream);
|
2014-03-03 07:59:49 -08:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network response headers shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that resolves when response headers are set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setResponseHeaders: Task.async(function*(aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aResponse && aResponse.headers.length) {
|
|
|
|
aResponse.headers.sort((a, b) => a.name > b.name);
|
2014-03-31 08:14:47 -07:00
|
|
|
yield this._addHeaders(this._responseHeaders, aResponse);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the headers container in this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The type of headers to populate (request or response).
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that resolves when headers are added.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_addHeaders: Task.async(function*(aName, aResponse) {
|
2013-04-17 23:35:27 -07:00
|
|
|
let kb = aResponse.headersSize / 1024;
|
|
|
|
let size = L10N.numberWithDecimals(kb, HEADERS_SIZE_DECIMALS);
|
|
|
|
let text = L10N.getFormatStr("networkMenu.sizeKB", size);
|
2014-03-31 08:14:47 -07:00
|
|
|
|
2013-04-17 23:35:27 -07:00
|
|
|
let headersScope = this._headers.addScope(aName + " (" + text + ")");
|
2013-03-11 23:50:42 -07:00
|
|
|
headersScope.expanded = true;
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
for (let header of aResponse.headers) {
|
2013-06-21 07:33:56 -07:00
|
|
|
let headerVar = headersScope.addItem(header.name, {}, true);
|
2014-03-31 08:14:47 -07:00
|
|
|
let headerValue = yield gNetwork.getString(header.value);
|
|
|
|
headerVar.setGrip(headerValue);
|
|
|
|
}
|
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network request cookies shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved when the request cookies are set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setRequestCookies: Task.async(function*(aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aResponse && aResponse.cookies.length) {
|
|
|
|
aResponse.cookies.sort((a, b) => a.name > b.name);
|
2014-03-31 08:14:47 -07:00
|
|
|
yield this._addCookies(this._requestCookies, aResponse);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network response cookies shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved when the response cookies are set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setResponseCookies: Task.async(function*(aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aResponse && aResponse.cookies.length) {
|
2014-03-31 08:14:47 -07:00
|
|
|
yield this._addCookies(this._responseCookies, aResponse);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the cookies container in this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The type of cookies to populate (request or response).
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* Returns a promise that resolves upon the adding of cookies.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_addCookies: Task.async(function*(aName, aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let cookiesScope = this._cookies.addScope(aName);
|
|
|
|
cookiesScope.expanded = true;
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
for (let cookie of aResponse.cookies) {
|
2013-06-21 07:33:56 -07:00
|
|
|
let cookieVar = cookiesScope.addItem(cookie.name, {}, true);
|
2014-03-31 08:14:47 -07:00
|
|
|
let cookieValue = yield gNetwork.getString(cookie.value);
|
|
|
|
cookieVar.setGrip(cookieValue);
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
// By default the cookie name and value are shown. If this is the only
|
|
|
|
// information available, then nothing else is to be displayed.
|
|
|
|
let cookieProps = Object.keys(cookie);
|
|
|
|
if (cookieProps.length == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display any other information other than the cookie name and value
|
|
|
|
// which may be available.
|
|
|
|
let rawObject = Object.create(null);
|
|
|
|
let otherProps = cookieProps.filter(e => e != "name" && e != "value");
|
|
|
|
for (let prop of otherProps) {
|
|
|
|
rawObject[prop] = cookie[prop];
|
|
|
|
}
|
|
|
|
cookieVar.populate(rawObject);
|
|
|
|
cookieVar.twisty = true;
|
|
|
|
cookieVar.expanded = true;
|
|
|
|
}
|
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network request get params shown in this view.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The request's url.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_setRequestGetParams: function(aUrl) {
|
2013-05-24 10:53:10 -07:00
|
|
|
let query = nsIURL(aUrl).query;
|
2013-03-11 23:50:42 -07:00
|
|
|
if (query) {
|
2013-04-11 11:11:46 -07:00
|
|
|
this._addParams(this._paramsQueryString, query);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network request post params shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aHeadersResponse
|
|
|
|
* The "requestHeaders" message received from the server.
|
2014-03-03 07:59:49 -08:00
|
|
|
* @param object aHeadersFromUploadStream
|
|
|
|
* The "requestHeadersFromUploadStream" inferred from the POST payload.
|
2013-06-12 00:37:46 -07:00
|
|
|
* @param object aPostDataResponse
|
2013-03-11 23:50:42 -07:00
|
|
|
* The "requestPostData" message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved when the request post params are set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setRequestPostParams: Task.async(function*(aHeadersResponse, aHeadersFromUploadStream, aPostDataResponse) {
|
2014-03-03 07:59:49 -08:00
|
|
|
if (!aHeadersResponse || !aHeadersFromUploadStream || !aPostDataResponse) {
|
2014-03-31 08:14:47 -07:00
|
|
|
return;
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
|
2014-03-03 07:59:49 -08:00
|
|
|
let { headers: requestHeaders } = aHeadersResponse;
|
|
|
|
let { headers: payloadHeaders } = aHeadersFromUploadStream;
|
|
|
|
let allHeaders = [...payloadHeaders, ...requestHeaders];
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
let contentTypeHeader = allHeaders.find(e => e.name.toLowerCase() == "content-type");
|
2014-03-03 07:59:49 -08:00
|
|
|
let contentTypeLongString = contentTypeHeader ? contentTypeHeader.value : "";
|
|
|
|
let postDataLongString = aPostDataResponse.postData.text;
|
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
let postData = yield gNetwork.getString(postDataLongString);
|
|
|
|
let contentType = yield gNetwork.getString(contentTypeLongString);
|
|
|
|
|
|
|
|
// Handle query strings (e.g. "?foo=bar&baz=42").
|
|
|
|
if (contentType.contains("x-www-form-urlencoded")) {
|
|
|
|
for (let section of postData.split(/\r\n|\r|\n/)) {
|
|
|
|
// Before displaying it, make sure this section of the POST data
|
|
|
|
// isn't a line containing upload stream headers.
|
|
|
|
if (payloadHeaders.every(header => !section.startsWith(header.name))) {
|
|
|
|
this._addParams(this._paramsFormData, section);
|
2013-06-12 00:37:46 -07:00
|
|
|
}
|
2014-03-03 07:59:49 -08:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}
|
|
|
|
// Handle actual forms ("multipart/form-data" content type).
|
|
|
|
else {
|
|
|
|
// This is really awkward, but hey, it works. Let's show an empty
|
|
|
|
// scope in the params view and place the source editor containing
|
|
|
|
// the raw post data directly underneath.
|
|
|
|
$("#request-params-box").removeAttribute("flex");
|
|
|
|
let paramsScope = this._params.addScope(this._paramsPostPayload);
|
|
|
|
paramsScope.expanded = true;
|
|
|
|
paramsScope.locked = true;
|
|
|
|
|
|
|
|
$("#request-post-data-textarea-box").hidden = false;
|
|
|
|
let editor = yield NetMonitorView.editor("#request-post-data-textarea");
|
|
|
|
// Most POST bodies are usually JSON, so they can be neatly
|
|
|
|
// syntax highlighted as JS. Otheriwse, fall back to plain text.
|
|
|
|
try {
|
|
|
|
JSON.parse(postData);
|
|
|
|
editor.setMode(Editor.modes.js);
|
|
|
|
} catch (e) {
|
|
|
|
editor.setMode(Editor.modes.text);
|
|
|
|
} finally {
|
|
|
|
editor.setText(postData);
|
2014-03-03 07:59:49 -08:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
window.emit(EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
|
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the params container in this view with the specified data.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The type of params to populate (get or post).
|
2013-06-26 02:09:59 -07:00
|
|
|
* @param string aQueryString
|
2013-04-11 11:11:46 -07:00
|
|
|
* A query string of params (e.g. "?foo=bar&baz=42").
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2013-06-26 02:09:59 -07:00
|
|
|
_addParams: function(aName, aQueryString) {
|
|
|
|
let paramsArray = parseQueryString(aQueryString);
|
|
|
|
if (!paramsArray) {
|
2013-06-12 00:37:46 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-03-11 23:50:42 -07:00
|
|
|
let paramsScope = this._params.addScope(aName);
|
|
|
|
paramsScope.expanded = true;
|
|
|
|
|
2013-04-11 11:11:46 -07:00
|
|
|
for (let param of paramsArray) {
|
2014-02-13 12:15:42 -08:00
|
|
|
let paramVar = paramsScope.addItem(param.name, {}, true);
|
|
|
|
paramVar.setGrip(param.value);
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the network response body shown in this view.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The request's url.
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
2013-12-02 08:34:47 -08:00
|
|
|
* @return object
|
2014-03-31 08:14:47 -07:00
|
|
|
* A promise that is resolved when the response body is set.
|
2013-03-11 23:50:42 -07:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setResponseBody: Task.async(function*(aUrl, aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (!aResponse) {
|
2014-03-31 08:14:47 -07:00
|
|
|
return;
|
2013-03-11 23:50:42 -07:00
|
|
|
}
|
2013-04-11 11:11:46 -07:00
|
|
|
let { mimeType, text, encoding } = aResponse.content;
|
2014-03-31 08:14:47 -07:00
|
|
|
let responseBody = yield gNetwork.getString(text);
|
|
|
|
|
|
|
|
// Handle json, which we tentatively identify by checking the MIME type
|
|
|
|
// for "json" after any word boundary. This works for the standard
|
|
|
|
// "application/json", and also for custom types like "x-bigcorp-json".
|
|
|
|
// Additionally, we also directly parse the response text content to
|
|
|
|
// verify whether it's json or not, to handle responses incorrectly
|
|
|
|
// labeled as text/plain instead.
|
|
|
|
let jsonMimeType, jsonObject, jsonObjectParseError;
|
|
|
|
try {
|
|
|
|
jsonMimeType = /\bjson/.test(mimeType);
|
|
|
|
jsonObject = JSON.parse(responseBody);
|
|
|
|
} catch (e) {
|
|
|
|
jsonObjectParseError = e;
|
|
|
|
}
|
|
|
|
if (jsonMimeType || jsonObject) {
|
|
|
|
// Extract the actual json substring in case this might be a "JSONP".
|
|
|
|
// This regex basically parses a function call and captures the
|
|
|
|
// function name and arguments in two separate groups.
|
|
|
|
let jsonpRegex = /^\s*([\w$]+)\s*\(\s*([^]*)\s*\)\s*;?\s*$/;
|
|
|
|
let [_, callbackPadding, jsonpString] = responseBody.match(jsonpRegex) || [];
|
|
|
|
|
|
|
|
// Make sure this is a valid JSON object first. If so, nicely display
|
|
|
|
// the parsing results in a variables view. Otherwise, simply show
|
|
|
|
// the contents as plain text.
|
|
|
|
if (callbackPadding && jsonpString) {
|
|
|
|
try {
|
|
|
|
jsonObject = JSON.parse(jsonpString);
|
|
|
|
} catch (e) {
|
|
|
|
jsonObjectParseError = e;
|
2013-06-12 00:37:46 -07:00
|
|
|
}
|
2013-04-11 11:11:46 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
|
|
|
|
// Valid JSON or JSONP.
|
|
|
|
if (jsonObject) {
|
|
|
|
$("#response-content-json-box").hidden = false;
|
|
|
|
let jsonScopeName = callbackPadding
|
|
|
|
? L10N.getFormatStr("jsonpScopeName", callbackPadding)
|
|
|
|
: L10N.getStr("jsonScopeName");
|
|
|
|
|
|
|
|
let jsonVar = { label: jsonScopeName, rawObject: jsonObject };
|
|
|
|
yield this._json.controller.setSingleVariable(jsonVar).expanded;
|
2013-04-11 11:11:46 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
// Malformed JSON.
|
2013-04-11 11:11:46 -07:00
|
|
|
else {
|
|
|
|
$("#response-content-textarea-box").hidden = false;
|
2014-03-31 08:14:47 -07:00
|
|
|
let infoHeader = $("#response-content-info-header");
|
|
|
|
infoHeader.setAttribute("value", jsonObjectParseError);
|
|
|
|
infoHeader.setAttribute("tooltiptext", jsonObjectParseError);
|
|
|
|
infoHeader.hidden = false;
|
|
|
|
|
|
|
|
let editor = yield NetMonitorView.editor("#response-content-textarea");
|
|
|
|
editor.setMode(Editor.modes.js);
|
|
|
|
editor.setText(responseBody);
|
2013-04-11 11:11:46 -07:00
|
|
|
}
|
2014-03-31 08:14:47 -07:00
|
|
|
}
|
|
|
|
// Handle images.
|
|
|
|
else if (mimeType.contains("image/")) {
|
|
|
|
$("#response-content-image-box").setAttribute("align", "center");
|
|
|
|
$("#response-content-image-box").setAttribute("pack", "center");
|
|
|
|
$("#response-content-image-box").hidden = false;
|
|
|
|
$("#response-content-image").src =
|
|
|
|
"data:" + mimeType + ";" + encoding + "," + responseBody;
|
|
|
|
|
|
|
|
// Immediately display additional information about the image:
|
|
|
|
// file name, mime type and encoding.
|
|
|
|
$("#response-content-image-name-value").setAttribute("value", nsIURL(aUrl).fileName);
|
|
|
|
$("#response-content-image-mime-value").setAttribute("value", mimeType);
|
|
|
|
$("#response-content-image-encoding-value").setAttribute("value", encoding);
|
|
|
|
|
|
|
|
// Wait for the image to load in order to display the width and height.
|
|
|
|
$("#response-content-image").onload = e => {
|
|
|
|
// XUL images are majestic so they don't bother storing their dimensions
|
|
|
|
// in width and height attributes like the rest of the folk. Hack around
|
|
|
|
// this by getting the bounding client rect and subtracting the margins.
|
|
|
|
let { width, height } = e.target.getBoundingClientRect();
|
|
|
|
let dimensions = (width - 2) + " x " + (height - 2);
|
|
|
|
$("#response-content-image-dimensions-value").setAttribute("value", dimensions);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Handle anything else.
|
|
|
|
else {
|
|
|
|
$("#response-content-textarea-box").hidden = false;
|
|
|
|
let editor = yield NetMonitorView.editor("#response-content-textarea");
|
|
|
|
editor.setMode(Editor.modes.text);
|
|
|
|
editor.setText(responseBody);
|
|
|
|
|
|
|
|
// Maybe set a more appropriate mode in the Source Editor if possible,
|
|
|
|
// but avoid doing this for very large files.
|
|
|
|
if (responseBody.length < SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE) {
|
|
|
|
let mapping = Object.keys(CONTENT_MIME_TYPE_MAPPINGS).find(key => mimeType.contains(key));
|
|
|
|
if (mapping) {
|
|
|
|
editor.setMode(CONTENT_MIME_TYPE_MAPPINGS[mapping]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.emit(EVENTS.RESPONSE_BODY_DISPLAYED);
|
|
|
|
}),
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the timings information shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_setTimingsInformation: function(aResponse) {
|
2013-03-11 23:50:42 -07:00
|
|
|
if (!aResponse) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let { blocked, dns, connect, send, wait, receive } = aResponse.timings;
|
|
|
|
|
|
|
|
let tabboxWidth = $("#details-pane").getAttribute("width");
|
|
|
|
let availableWidth = tabboxWidth / 2; // Other nodes also take some space.
|
|
|
|
let scale = Math.max(availableWidth / aResponse.totalTime, 0);
|
|
|
|
|
|
|
|
$("#timings-summary-blocked .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", blocked * scale);
|
|
|
|
$("#timings-summary-blocked .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", blocked));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-dns .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", dns * scale);
|
|
|
|
$("#timings-summary-dns .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", dns));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-connect .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", connect * scale);
|
|
|
|
$("#timings-summary-connect .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", connect));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-send .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", send * scale);
|
|
|
|
$("#timings-summary-send .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", send));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-wait .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", wait * scale);
|
|
|
|
$("#timings-summary-wait .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", wait));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-receive .requests-menu-timings-box")
|
|
|
|
.setAttribute("width", receive * scale);
|
|
|
|
$("#timings-summary-receive .requests-menu-timings-total")
|
2013-04-08 11:34:45 -07:00
|
|
|
.setAttribute("value", L10N.getFormatStr("networkMenu.totalMS", receive));
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
$("#timings-summary-dns .requests-menu-timings-box")
|
|
|
|
.style.transform = "translateX(" + (scale * blocked) + "px)";
|
|
|
|
$("#timings-summary-connect .requests-menu-timings-box")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns)) + "px)";
|
|
|
|
$("#timings-summary-send .requests-menu-timings-box")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect)) + "px)";
|
|
|
|
$("#timings-summary-wait .requests-menu-timings-box")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect + send)) + "px)";
|
|
|
|
$("#timings-summary-receive .requests-menu-timings-box")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect + send + wait)) + "px)";
|
|
|
|
|
|
|
|
$("#timings-summary-dns .requests-menu-timings-total")
|
|
|
|
.style.transform = "translateX(" + (scale * blocked) + "px)";
|
|
|
|
$("#timings-summary-connect .requests-menu-timings-total")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns)) + "px)";
|
|
|
|
$("#timings-summary-send .requests-menu-timings-total")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect)) + "px)";
|
|
|
|
$("#timings-summary-wait .requests-menu-timings-total")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect + send)) + "px)";
|
|
|
|
$("#timings-summary-receive .requests-menu-timings-total")
|
|
|
|
.style.transform = "translateX(" + (scale * (blocked + dns + connect + send + wait)) + "px)";
|
|
|
|
},
|
|
|
|
|
2014-02-13 07:26:09 -08:00
|
|
|
/**
|
|
|
|
* Sets the preview for HTML responses shown in this view.
|
|
|
|
*
|
|
|
|
* @param object aResponse
|
|
|
|
* The message received from the server.
|
|
|
|
* @return object
|
2014-03-31 08:14:47 -07:00
|
|
|
* A promise that is resolved when the html preview is rendered.
|
2014-02-13 07:26:09 -08:00
|
|
|
*/
|
2014-03-31 08:14:47 -07:00
|
|
|
_setHtmlPreview: Task.async(function*(aResponse) {
|
2014-02-13 07:26:09 -08:00
|
|
|
if (!aResponse) {
|
|
|
|
return promise.resolve();
|
|
|
|
}
|
|
|
|
let { text } = aResponse.content;
|
2014-03-31 08:14:47 -07:00
|
|
|
let responseBody = yield gNetwork.getString(text);
|
2014-02-13 07:26:09 -08:00
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
// Always disable JS when previewing HTML responses.
|
|
|
|
let iframe = $("#response-preview");
|
|
|
|
iframe.contentDocument.docShell.allowJavascript = false;
|
|
|
|
iframe.contentDocument.documentElement.innerHTML = responseBody;
|
2014-02-13 07:26:09 -08:00
|
|
|
|
2014-03-31 08:14:47 -07:00
|
|
|
window.emit(EVENTS.RESPONSE_HTML_PREVIEW_DISPLAYED);
|
|
|
|
}),
|
2014-02-13 07:26:09 -08:00
|
|
|
|
2013-05-14 10:03:24 -07:00
|
|
|
_dataSrc: null,
|
2013-03-11 23:50:42 -07:00
|
|
|
_headers: null,
|
|
|
|
_cookies: null,
|
|
|
|
_params: null,
|
|
|
|
_json: null,
|
|
|
|
_paramsQueryString: "",
|
|
|
|
_paramsFormData: "",
|
|
|
|
_paramsPostPayload: "",
|
|
|
|
_requestHeaders: "",
|
|
|
|
_responseHeaders: "",
|
|
|
|
_requestCookies: "",
|
|
|
|
_responseCookies: ""
|
2013-05-24 11:36:51 -07:00
|
|
|
};
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
/**
|
|
|
|
* Functions handling the performance statistics view.
|
|
|
|
*/
|
|
|
|
function PerformanceStatisticsView() {
|
|
|
|
}
|
|
|
|
|
|
|
|
PerformanceStatisticsView.prototype = {
|
|
|
|
/**
|
|
|
|
* Initializes and displays empty charts in this container.
|
|
|
|
*/
|
|
|
|
displayPlaceholderCharts: function() {
|
|
|
|
this._createChart({
|
|
|
|
id: "#primed-cache-chart",
|
|
|
|
title: "charts.cacheEnabled"
|
|
|
|
});
|
|
|
|
this._createChart({
|
|
|
|
id: "#empty-cache-chart",
|
|
|
|
title: "charts.cacheDisabled"
|
|
|
|
});
|
|
|
|
window.emit(EVENTS.PLACEHOLDER_CHARTS_DISPLAYED);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates and displays the primed cache chart in this container.
|
|
|
|
*
|
|
|
|
* @param array aItems
|
|
|
|
* @see this._sanitizeChartDataSource
|
|
|
|
*/
|
|
|
|
createPrimedCacheChart: function(aItems) {
|
|
|
|
this._createChart({
|
|
|
|
id: "#primed-cache-chart",
|
|
|
|
title: "charts.cacheEnabled",
|
|
|
|
data: this._sanitizeChartDataSource(aItems),
|
2014-02-04 06:57:08 -08:00
|
|
|
strings: this._commonChartStrings,
|
|
|
|
totals: this._commonChartTotals,
|
|
|
|
sorted: true
|
2014-01-31 22:37:53 -08:00
|
|
|
});
|
|
|
|
window.emit(EVENTS.PRIMED_CACHE_CHART_DISPLAYED);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates and displays the empty cache chart in this container.
|
|
|
|
*
|
|
|
|
* @param array aItems
|
|
|
|
* @see this._sanitizeChartDataSource
|
|
|
|
*/
|
|
|
|
createEmptyCacheChart: function(aItems) {
|
|
|
|
this._createChart({
|
|
|
|
id: "#empty-cache-chart",
|
|
|
|
title: "charts.cacheDisabled",
|
|
|
|
data: this._sanitizeChartDataSource(aItems, true),
|
2014-02-04 06:57:08 -08:00
|
|
|
strings: this._commonChartStrings,
|
|
|
|
totals: this._commonChartTotals,
|
|
|
|
sorted: true
|
2014-01-31 22:37:53 -08:00
|
|
|
});
|
|
|
|
window.emit(EVENTS.EMPTY_CACHE_CHART_DISPLAYED);
|
|
|
|
},
|
|
|
|
|
2014-02-04 06:57:08 -08:00
|
|
|
/**
|
|
|
|
* Common stringifier predicates used for items and totals in both the
|
|
|
|
* "primed" and "empty" cache charts.
|
|
|
|
*/
|
|
|
|
_commonChartStrings: {
|
|
|
|
size: value => {
|
|
|
|
let string = L10N.numberWithDecimals(value / 1024, CONTENT_SIZE_DECIMALS);
|
|
|
|
return L10N.getFormatStr("charts.sizeKB", string);
|
|
|
|
},
|
|
|
|
time: value => {
|
|
|
|
let string = L10N.numberWithDecimals(value / 1000, REQUEST_TIME_DECIMALS);
|
|
|
|
return L10N.getFormatStr("charts.totalS", string);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_commonChartTotals: {
|
|
|
|
size: total => {
|
|
|
|
let string = L10N.numberWithDecimals(total / 1024, CONTENT_SIZE_DECIMALS);
|
|
|
|
return L10N.getFormatStr("charts.totalSize", string);
|
|
|
|
},
|
|
|
|
time: total => {
|
2014-02-04 06:57:09 -08:00
|
|
|
let seconds = total / 1000;
|
|
|
|
let string = L10N.numberWithDecimals(seconds, REQUEST_TIME_DECIMALS);
|
|
|
|
return PluralForm.get(seconds, L10N.getStr("charts.totalSeconds")).replace("#1", string);
|
2014-02-04 06:57:08 -08:00
|
|
|
},
|
|
|
|
cached: total => {
|
|
|
|
return L10N.getFormatStr("charts.totalCached", total);
|
|
|
|
},
|
|
|
|
count: total => {
|
|
|
|
return L10N.getFormatStr("charts.totalCount", total);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
/**
|
|
|
|
* Adds a specific chart to this container.
|
|
|
|
*
|
|
|
|
* @param object
|
|
|
|
* An object containing all or some the following properties:
|
|
|
|
* - id: either "#primed-cache-chart" or "#empty-cache-chart"
|
2014-02-04 06:57:08 -08:00
|
|
|
* - title/data/strings/totals/sorted: @see Chart.jsm for details
|
2014-01-31 22:37:53 -08:00
|
|
|
*/
|
2014-02-04 06:57:08 -08:00
|
|
|
_createChart: function({ id, title, data, strings, totals, sorted }) {
|
2014-01-31 22:37:53 -08:00
|
|
|
let container = $(id);
|
|
|
|
|
|
|
|
// Nuke all existing charts of the specified type.
|
|
|
|
while (container.hasChildNodes()) {
|
|
|
|
container.firstChild.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new chart.
|
|
|
|
let chart = Chart.PieTable(document, {
|
|
|
|
diameter: NETWORK_ANALYSIS_PIE_CHART_DIAMETER,
|
|
|
|
title: L10N.getStr(title),
|
|
|
|
data: data,
|
2014-02-04 06:57:08 -08:00
|
|
|
strings: strings,
|
|
|
|
totals: totals,
|
|
|
|
sorted: sorted
|
2014-01-31 22:37:53 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
chart.on("click", (_, item) => {
|
2014-02-11 08:55:07 -08:00
|
|
|
NetMonitorView.RequestsMenu.filterOnlyOn(item.label);
|
2014-01-31 22:37:53 -08:00
|
|
|
NetMonitorView.showNetworkInspectorView();
|
|
|
|
});
|
|
|
|
|
|
|
|
container.appendChild(chart.node);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sanitizes the data source used for creating charts, to follow the
|
|
|
|
* data format spec defined in Chart.jsm.
|
|
|
|
*
|
|
|
|
* @param array aItems
|
|
|
|
* A collection of request items used as the data source for the chart.
|
|
|
|
* @param boolean aEmptyCache
|
|
|
|
* True if the cache is considered enabled, false for disabled.
|
|
|
|
*/
|
|
|
|
_sanitizeChartDataSource: function(aItems, aEmptyCache) {
|
|
|
|
let data = [
|
|
|
|
"html", "css", "js", "xhr", "fonts", "images", "media", "flash", "other"
|
|
|
|
].map(e => ({
|
|
|
|
cached: 0,
|
|
|
|
count: 0,
|
|
|
|
label: e,
|
|
|
|
size: 0,
|
|
|
|
time: 0
|
|
|
|
}));
|
|
|
|
|
|
|
|
for (let requestItem of aItems) {
|
|
|
|
let details = requestItem.attachment;
|
|
|
|
let type;
|
|
|
|
|
|
|
|
if (RequestsMenuView.prototype.isHtml(requestItem)) {
|
|
|
|
type = 0; // "html"
|
|
|
|
} else if (RequestsMenuView.prototype.isCss(requestItem)) {
|
|
|
|
type = 1; // "css"
|
|
|
|
} else if (RequestsMenuView.prototype.isJs(requestItem)) {
|
|
|
|
type = 2; // "js"
|
|
|
|
} else if (RequestsMenuView.prototype.isFont(requestItem)) {
|
|
|
|
type = 4; // "fonts"
|
|
|
|
} else if (RequestsMenuView.prototype.isImage(requestItem)) {
|
|
|
|
type = 5; // "images"
|
|
|
|
} else if (RequestsMenuView.prototype.isMedia(requestItem)) {
|
|
|
|
type = 6; // "media"
|
|
|
|
} else if (RequestsMenuView.prototype.isFlash(requestItem)) {
|
|
|
|
type = 7; // "flash"
|
|
|
|
} else if (RequestsMenuView.prototype.isXHR(requestItem)) {
|
|
|
|
// Verify XHR last, to categorize other mime types in their own blobs.
|
|
|
|
type = 3; // "xhr"
|
|
|
|
} else {
|
|
|
|
type = 8; // "other"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEmptyCache || !responseIsFresh(details)) {
|
|
|
|
data[type].time += details.totalTime || 0;
|
|
|
|
data[type].size += details.contentSize || 0;
|
|
|
|
} else {
|
|
|
|
data[type].cached++;
|
|
|
|
}
|
|
|
|
data[type].count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.filter(e => e.count > 0);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-05-10 02:01:05 -07:00
|
|
|
/**
|
|
|
|
* DOM query helper.
|
|
|
|
*/
|
|
|
|
function $(aSelector, aTarget = document) aTarget.querySelector(aSelector);
|
2013-10-25 00:15:53 -07:00
|
|
|
function $all(aSelector, aTarget = document) aTarget.querySelectorAll(aSelector);
|
2013-05-10 02:01:05 -07:00
|
|
|
|
2013-05-24 10:53:10 -07:00
|
|
|
/**
|
|
|
|
* Helper for getting an nsIURL instance out of a string.
|
|
|
|
*/
|
|
|
|
function nsIURL(aUrl, aStore = nsIURL.store) {
|
|
|
|
if (aStore.has(aUrl)) {
|
|
|
|
return aStore.get(aUrl);
|
|
|
|
}
|
|
|
|
let uri = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
|
|
|
|
aStore.set(aUrl, uri);
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
nsIURL.store = new Map();
|
|
|
|
|
2013-06-26 02:09:59 -07:00
|
|
|
/**
|
|
|
|
* Parse a url's query string into its components
|
|
|
|
*
|
2014-01-31 22:37:53 -08:00
|
|
|
* @param string aQueryString
|
|
|
|
* The query part of a url
|
2013-06-26 02:09:59 -07:00
|
|
|
* @return array
|
|
|
|
* Array of query params {name, value}
|
|
|
|
*/
|
|
|
|
function parseQueryString(aQueryString) {
|
|
|
|
// Make sure there's at least one param available.
|
2014-02-13 12:15:42 -08:00
|
|
|
// Be careful here, params don't necessarily need to have values, so
|
|
|
|
// no need to verify the existence of a "=".
|
|
|
|
if (!aQueryString) {
|
2013-06-26 02:09:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Turn the params string into an array containing { name: value } tuples.
|
2013-07-10 01:40:51 -07:00
|
|
|
let paramsArray = aQueryString.replace(/^[?&]/, "").split("&").map(e =>
|
2013-06-26 02:09:59 -07:00
|
|
|
let (param = e.split("=")) {
|
2014-02-13 12:15:42 -08:00
|
|
|
name: param[0] ? NetworkHelper.convertToUnicode(unescape(param[0])) : "",
|
|
|
|
value: param[1] ? NetworkHelper.convertToUnicode(unescape(param[1])) : ""
|
2013-06-26 02:09:59 -07:00
|
|
|
});
|
|
|
|
return paramsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-03 07:59:49 -08:00
|
|
|
* Parse text representation of multiple HTTP headers.
|
2013-06-26 02:09:59 -07:00
|
|
|
*
|
2014-01-31 22:37:53 -08:00
|
|
|
* @param string aText
|
|
|
|
* Text of headers
|
2013-06-26 02:09:59 -07:00
|
|
|
* @return array
|
|
|
|
* Array of headers info {name, value}
|
|
|
|
*/
|
2014-03-03 07:59:49 -08:00
|
|
|
function parseHeadersText(aText) {
|
|
|
|
return parseRequestText(aText, "\\S+?", ":");
|
2013-06-26 02:09:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse readable text list of a query string.
|
|
|
|
*
|
2014-01-31 22:37:53 -08:00
|
|
|
* @param string aText
|
|
|
|
* Text of query string represetation
|
2013-06-26 02:09:59 -07:00
|
|
|
* @return array
|
|
|
|
* Array of query params {name, value}
|
|
|
|
*/
|
|
|
|
function parseQueryText(aText) {
|
2014-03-03 07:59:49 -08:00
|
|
|
return parseRequestText(aText, ".+?", "=");
|
2013-06-26 02:09:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-03 07:59:49 -08:00
|
|
|
* Parse a text representation of a name[divider]value list with
|
|
|
|
* the given name regex and divider character.
|
2013-06-26 02:09:59 -07:00
|
|
|
*
|
2014-01-31 22:37:53 -08:00
|
|
|
* @param string aText
|
|
|
|
* Text of list
|
2013-06-26 02:09:59 -07:00
|
|
|
* @return array
|
|
|
|
* Array of headers info {name, value}
|
|
|
|
*/
|
2014-03-03 07:59:49 -08:00
|
|
|
function parseRequestText(aText, aName, aDivider) {
|
|
|
|
let regex = new RegExp("(" + aName + ")\\" + aDivider + "\\s*(.+)");
|
2013-06-26 02:09:59 -07:00
|
|
|
let pairs = [];
|
|
|
|
for (let line of aText.split("\n")) {
|
|
|
|
let matches;
|
|
|
|
if (matches = regex.exec(line)) {
|
|
|
|
let [, name, value] = matches;
|
|
|
|
pairs.push({name: name, value: value});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pairs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write out a list of headers into a chunk of text
|
|
|
|
*
|
|
|
|
* @param array aHeaders
|
|
|
|
* Array of headers info {name, value}
|
|
|
|
* @return string aText
|
|
|
|
* List of headers in text format
|
|
|
|
*/
|
|
|
|
function writeHeaderText(aHeaders) {
|
|
|
|
return [(name + ": " + value) for ({name, value} of aHeaders)].join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write out a list of query params into a chunk of text
|
|
|
|
*
|
|
|
|
* @param array aParams
|
|
|
|
* Array of query params {name, value}
|
|
|
|
* @return string
|
|
|
|
* List of query params in text format
|
|
|
|
*/
|
|
|
|
function writeQueryText(aParams) {
|
|
|
|
return [(name + "=" + value) for ({name, value} of aParams)].join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write out a list of query params into a query string
|
|
|
|
*
|
|
|
|
* @param array aParams
|
|
|
|
* Array of query params {name, value}
|
|
|
|
* @return string
|
|
|
|
* Query string that can be appended to a url.
|
|
|
|
*/
|
|
|
|
function writeQueryString(aParams) {
|
|
|
|
return [(name + "=" + value) for ({name, value} of aParams)].join("&");
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:37:53 -08:00
|
|
|
/**
|
|
|
|
* Checks if the "Expiration Calculations" defined in section 13.2.4 of the
|
|
|
|
* "HTTP/1.1: Caching in HTTP" spec holds true for a collection of headers.
|
|
|
|
*
|
|
|
|
* @param object
|
|
|
|
* An object containing the { responseHeaders, status } properties.
|
|
|
|
* @return boolean
|
|
|
|
* True if the response is fresh and loaded from cache.
|
|
|
|
*/
|
|
|
|
function responseIsFresh({ responseHeaders, status }) {
|
|
|
|
// Check for a "304 Not Modified" status and response headers availability.
|
|
|
|
if (status != 304 || !responseHeaders) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let list = responseHeaders.headers;
|
|
|
|
let cacheControl = list.filter(e => e.name.toLowerCase() == "cache-control")[0];
|
|
|
|
let expires = list.filter(e => e.name.toLowerCase() == "expires")[0];
|
|
|
|
|
|
|
|
// Check the "Cache-Control" header for a maximum age value.
|
|
|
|
if (cacheControl) {
|
|
|
|
let maxAgeMatch =
|
|
|
|
cacheControl.value.match(/s-maxage\s*=\s*(\d+)/) ||
|
|
|
|
cacheControl.value.match(/max-age\s*=\s*(\d+)/);
|
|
|
|
|
|
|
|
if (maxAgeMatch && maxAgeMatch.pop() > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the "Expires" header for a valid date.
|
|
|
|
if (expires && Date.parse(expires.value)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-28 05:50:34 -08:00
|
|
|
/**
|
|
|
|
* Helper method to get a wrapped function which can be bound to as an event listener directly and is executed only when data-key is present in event.target.
|
|
|
|
*
|
|
|
|
* @param function callback
|
|
|
|
* Function to execute execute when data-key is present in event.target.
|
|
|
|
* @return function
|
|
|
|
* Wrapped function with the target data-key as the first argument.
|
|
|
|
*/
|
|
|
|
function getKeyWithEvent(callback) {
|
|
|
|
return function(event) {
|
|
|
|
var key = event.target.getAttribute("data-key");
|
|
|
|
if (key) {
|
|
|
|
callback.call(null, key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
/**
|
|
|
|
* Preliminary setup for the NetMonitorView object.
|
|
|
|
*/
|
|
|
|
NetMonitorView.Toolbar = new ToolbarView();
|
|
|
|
NetMonitorView.RequestsMenu = new RequestsMenuView();
|
2013-06-26 02:09:59 -07:00
|
|
|
NetMonitorView.Sidebar = new SidebarView();
|
|
|
|
NetMonitorView.CustomRequest = new CustomRequestView();
|
2013-03-11 23:50:42 -07:00
|
|
|
NetMonitorView.NetworkDetails = new NetworkDetailsView();
|
2014-01-31 22:37:53 -08:00
|
|
|
NetMonitorView.PerformanceStatistics = new PerformanceStatisticsView();
|