Bug 597502 - Web Console network inspector saves all network requests, causing Firefox to become unusably slow, r=sdwilsh, a=blocking2.0

This commit is contained in:
Patrick Walton 2010-09-21 21:00:15 -03:00
Родитель 766f0777aa
Коммит db787104aa
5 изменённых файлов: 62 добавлений и 10 удалений

Просмотреть файл

@ -254,8 +254,8 @@ ResponseListener.prototype =
*
* If aRequest is an nsIHttpChannel then the response header is stored on the
* httpActivity object. Also, the response body is set on the httpActivity
* object and the HUDService.lastFinishedRequestCallback is called if there
* is one.
* object (if the user has turned on response content logging) and the
* HUDService.lastFinishedRequestCallback is called if there is one.
*
* @param nsIRequest aRequest
* @param nsISupports aContext
@ -269,7 +269,13 @@ ResponseListener.prototype =
catch (ex) { }
this.setResponseHeader(aRequest);
this.httpActivity.response.body = this.receivedData;
if (HUDService.saveRequestAndResponseBodies) {
this.httpActivity.response.body = this.receivedData;
}
else {
this.httpActivity.response.bodyDiscarded = true;
}
if (HUDService.lastFinishedRequestCallback) {
HUDService.lastFinishedRequestCallback(this.httpActivity);
@ -1036,7 +1042,7 @@ NetworkPanel.prototype =
case this._DISPLAYED_REQUEST_HEADER:
// Process the request body if there is one.
if (request.body) {
if (!request.bodyDiscarded && request.body) {
// Check if we send some form data. If so, display the form data special.
if (this._isRequestBodyFormData) {
this._displayRequestForm();
@ -1062,7 +1068,10 @@ NetworkPanel.prototype =
case this._DISPLAYED_RESPONSE_HEADER:
// Check if the transition is done.
if (timing.TRANSACTION_CLOSE && response.isDone) {
if (this._responseIsImage) {
if (response.bodyDiscarded) {
this._callIsDone();
}
else if (this._responseIsImage) {
this._displayResponseImage();
this._callIsDone();
}
@ -1239,6 +1248,12 @@ HUD_SERVICE.prototype =
*/
filterPrefs: {},
/**
* Whether to save the bodies of network requests and responses. Disabled by
* default to save memory.
*/
saveRequestAndResponseBodies: false,
/**
* Event handler to get window errors
* TODO: a bit of a hack but is able to associate
@ -2251,6 +2266,11 @@ HUD_SERVICE.prototype =
switch (aActivitySubtype) {
case activityDistributor.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT:
if (!self.saveRequestAndResponseBodies) {
httpActivity.request.bodyDiscarded = true;
break;
}
let gBrowser = HUDService.currentContext().gBrowser;
let sentBody = NetworkHelper.readPostTextFromRequest(
@ -3204,6 +3224,17 @@ HeadsUpDisplay.prototype = {
let id = this.hudId + "-output-contextmenu";
menuPopup.setAttribute("id", id);
let saveBodiesItem = this.makeXULNode("menuitem");
saveBodiesItem.setAttribute("label", this.getStr("saveBodies.label"));
saveBodiesItem.setAttribute("accesskey",
this.getStr("saveBodies.accesskey"));
saveBodiesItem.setAttribute("type", "checkbox");
saveBodiesItem.setAttribute("buttonType", "saveBodies");
saveBodiesItem.setAttribute("oncommand", "HUDConsoleUI.command(this);");
menuPopup.appendChild(saveBodiesItem);
menuPopup.appendChild(this.makeXULNode("menuseparator"));
let copyItem = this.makeXULNode("menuitem");
copyItem.setAttribute("label", this.getStr("copyCmd.label"));
copyItem.setAttribute("accesskey", this.getStr("copyCmd.accesskey"));
@ -4791,6 +4822,11 @@ HeadsUpDisplayUICommands = {
let commandController = chromeWindow.commandController;
commandController.selectAll(outputNode);
break;
case "saveBodies": {
let checked = aButton.getAttribute("checked") === "true";
HUDService.saveRequestAndResponseBodies = checked;
break;
}
}
},

Просмотреть файл

@ -634,6 +634,7 @@ function testNetworkPanel()
var httpActivity = {
url: "http://www.testpage.com",
method: "GET",
body: null,
panels: [],
request: {

Просмотреть файл

@ -71,7 +71,7 @@ function testSelectionWhenMovingBetweenBoxes() {
let contextMenu = document.getElementById(contextMenuId);
ok(contextMenu != null, "the output node has a context menu");
let selectAllItem = contextMenu.childNodes[1];
let selectAllItem = contextMenu.querySelector("*[buttonType=\"selectAll\"]");
ok(selectAllItem != null,
"the context menu on the output node has a \"Select All\" item");

Просмотреть файл

@ -74,9 +74,22 @@ function testNetworkLogging()
is(httpActivity.url, TEST_NETWORK_REQUEST_URI,
"Logged network entry is page load");
is(httpActivity.method, "GET", "Method is correct");
is(httpActivity.request.body, undefined, "No request body sent");
ok(httpActivity.response.body.indexOf("<!DOCTYPE HTML>") == 0,
"Response body's beginning is okay");
ok(!("body" in httpActivity.request), "No request body was stored");
ok(!("body" in httpActivity.response), "No response body was stored");
// Turn on logging of request bodies and check again.
HUDService.saveRequestAndResponseBodies = true;
browser.addEventListener("load", function onLoad () {
browser.removeEventListener("load", onLoad, true);
loggingGen.next();
}, true);
content.location.reload();
yield;
let httpActivity = lastFinishedRequest;
ok(httpActivity, "Page load was logged again");
ok(httpActivity.response.body.indexOf("<!DOCTYPE HTML>") == 0,
"Response body's beginning is okay");
// Start xhr-get test.
browser.contentWindow.wrappedJSObject.testXhrGet(loggingGen);
@ -90,7 +103,7 @@ function testNetworkLogging()
httpActivity = lastFinishedRequest;
isnot(httpActivity, null, "testXhrGet() was logged");
is(httpActivity.method, "GET", "Method is correct");
is(httpActivity.request.body, undefined, "No request body was sent");
is(httpActivity.request.body, null, "No request body was sent");
is(httpActivity.response.body, TEST_DATA_JSON_CONTENT,
"Response is correct");
lastFinishedRequest = null;

Просмотреть файл

@ -61,6 +61,8 @@ jsPropertyTitle=Object Inspector
# is set to `Inspect: window.document` because the clicked `document` object was
# evaluated based on the `window.document` string.
jsPropertyInspectTitle=Inspect: %S
saveBodies.label=Log Request and Response Bodies
saveBodies.accesskey=L
copyCmd.label=Copy
copyCmd.accesskey=C
selectAllCmd.label=Select All