Bug 600183 - Web Console: currentContext is always used in network logging code; f=ddahl r=sdwilsh a=blocking2.0

This commit is contained in:
Mihai Sucan 2010-11-20 15:53:14 -04:00
parent 0a52bef6b4
commit 46c665dd8f
5 changed files with 97 additions and 14 deletions

View File

@ -243,7 +243,8 @@ ResponseListener.prototype =
if (HUDService.saveRequestAndResponseBodies &&
this.receivedData.length < RESPONSE_BODY_LIMIT) {
this.receivedData += data;
this.receivedData += NetworkHelper.
convertToUnicode(data, aRequest.contentCharset);
}
binaryOutputStream.writeBytes(data, aCount);
@ -401,10 +402,22 @@ var NetworkHelper =
*/
convertToUnicode: function NH_convertToUnicode(aText, aCharset)
{
if (!aCharset) {
return aText;
}
let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
conv.charset = aCharset || "UTF-8";
return conv.ConvertToUnicode(aText);
conv.charset = aCharset;
try {
return conv.ConvertToUnicode(aText);
}
catch (ex) {
Cu.reportError("NH_convertToUnicode(aText, '" +
aCharset + "') exception: " + ex);
return aText;
}
},
/**
@ -2471,7 +2484,10 @@ HUD_SERVICE.prototype =
return;
}
let msgObject, updatePanel = false;
hudId = httpActivity.hudId;
let msgObject = httpActivity.messageObject;
let updatePanel = false;
let data, textNode;
// Store the time information for this activity subtype.
httpActivity.timing[transCodes[aActivitySubtype]] = aTimestamp;
@ -2483,10 +2499,14 @@ HUD_SERVICE.prototype =
break;
}
let gBrowser = HUDService.currentContext().gBrowser;
let gBrowser = msgObject.messageNode.ownerDocument.
defaultView.gBrowser;
let HUD = HUDService.hudReferences[hudId];
let browser = gBrowser.
getBrowserForDocument(HUD.contentDocument);
let sentBody = NetworkHelper.readPostTextFromRequest(
aChannel, gBrowser);
let sentBody = NetworkHelper.
readPostTextFromRequest(aChannel, browser);
if (!sentBody) {
// If the request URL is the same as the current page url, then
// we can try to get the posted text from the page directly.
@ -2495,8 +2515,8 @@ HUD_SERVICE.prototype =
// function is called for image requests as well but these
// are not web pages and as such don't store the posted text
// in the cache of the webpage.
if (httpActivity.url == gBrowser.contentWindow.location.href) {
sentBody = NetworkHelper.readPostTextFromPage(gBrowser);
if (httpActivity.url == browser.contentWindow.location.href) {
sentBody = NetworkHelper.readPostTextFromPage(browser);
}
if (!sentBody) {
sentBody = "";
@ -2506,8 +2526,6 @@ HUD_SERVICE.prototype =
break;
case activityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER:
msgObject = httpActivity.messageObject;
// aExtraStringData contains the response header. The first line
// contains the response status (e.g. HTTP/1.1 200 OK).
//
@ -2535,9 +2553,6 @@ HUD_SERVICE.prototype =
break;
case activityDistributor.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE:
msgObject = httpActivity.messageObject;
let timing = httpActivity.timing;
let requestDuration =
Math.round((timing.RESPONSE_COMPLETE -

View File

@ -104,6 +104,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_601909_remember_height.js \
browser_webconsole_bug_613013_console_api_iframe.js \
browser_webconsole_bug_597756_reopen_closed_tab.js \
browser_webconsole_bug_600183_charset.js \
head.js \
$(NULL)
@ -138,6 +139,8 @@ _BROWSER_TEST_PAGES = \
test-bug-597136-external-script-errors.js \
test-bug-613013-console-api-iframe.html \
test-bug-597756-reopen-closed-tab.html \
test-bug-600183-charset.html \
test-bug-600183-charset.html^headers^ \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)

View File

@ -0,0 +1,55 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Contributor(s):
* Mihai Șucan <mihai.sucan@gmail.com>
*
* ***** END LICENSE BLOCK ***** */
const TEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-bug-600183-charset.html";
let lastFinishedRequest = null;
function requestDoneCallback(aHttpRequest)
{
lastFinishedRequest = aHttpRequest;
}
function performTest()
{
ok(lastFinishedRequest, "charset test page was loaded and logged");
let body = lastFinishedRequest.response.body;
ok(body, "we have the response body");
let chars = "\u7684\u95ee\u5019!"; // 的问候!
isnot(body.indexOf("<p>" + chars + "</p>"), -1,
"found the chinese simplified string");
lastFinishedRequest = null;
HUDService.saveRequestAndResponseBodies = false;
HUDService.lastFinishedRequestCallback = null;
finishTest();
}
function test()
{
addTab("data:text/html,Web Console - bug 600183 test");
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
waitForFocus(function() {
openConsole();
HUDService.saveRequestAndResponseBodies = true;
HUDService.lastFinishedRequestCallback = requestDoneCallback;
browser.addEventListener("load", performTest, true);
content.location = TEST_URI;
}, content);
}, true);
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE HTML>
<html dir="ltr" xml:lang="en-US" lang="en-US"><head>
<meta charset="gb2312">
<title>Console HTTP test page (chinese)</title>
</head>
<body>
<p>的问候!</p>
</body>
</html>

View File

@ -0,0 +1 @@
Content-Type: text/html; charset=gb2312