Bug 603706 - Need a way to track the originating window for all nsIConsoleMessages; r=joe,bzbarsky, a=blocking2.0

This commit is contained in:
Mihai Sucan 2010-12-20 12:21:59 -04:00
Родитель 990dc3c926
Коммит 4117a8aa02
13 изменённых файлов: 106 добавлений и 10 удалений

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

@ -2524,11 +2524,10 @@ nsHTMLDocument::GetSelection(nsAString& aReturn)
{
aReturn.Truncate();
nsCOMPtr<nsIConsoleService> consoleService
(do_GetService("@mozilla.org/consoleservice;1"));
if (consoleService) {
consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get());
nsCOMPtr<nsIJSContextStack> stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
JSContext* ccx = nsnull;
if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) {
JS_ReportWarning(ccx, "Deprecated method document.getSelection() called. Please use window.getSelection() instead.");
}
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetScopeObject());

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

@ -39,6 +39,7 @@
#include "Decoder.h"
#include "nsIServiceManager.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
namespace mozilla {
namespace imagelib {
@ -117,11 +118,25 @@ Decoder::Finish()
if (!IsSizeDecode() && !mDecodeDone) {
// Log data errors to the error console
nsCOMPtr<nsIConsoleService> aConsoleService = do_GetService("@mozilla.org/consoleservice;1");
if (aConsoleService && !HasDecoderError()) {
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
nsCOMPtr<nsIScriptError2> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
if (consoleService && errorObject && !HasDecoderError()) {
nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated: ") +
NS_ConvertASCIItoUTF16(mImage->GetURIString()));
aConsoleService->LogStringMessage(msg.get());
errorObject->InitWithWindowID
(msg.get(),
NS_ConvertUTF8toUTF16(mImage->GetURIString()).get(),
nsnull,
0, 0, nsIScriptError::errorFlag,
"Image", mImage->WindowID()
);
nsCOMPtr<nsIScriptError> error = do_QueryInterface(errorObject);
consoleService->LogMessage(error);
}
// If we only have a data error, see if things are worth salvaging

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

@ -46,7 +46,8 @@ Image::Image(imgStatusTracker* aStatusTracker) :
mAnimationMode(kNormalAnimMode),
mInitialized(PR_FALSE),
mAnimating(PR_FALSE),
mError(PR_FALSE)
mError(PR_FALSE),
mWindowId(0)
{
if (aStatusTracker) {
mStatusTracker = aStatusTracker;

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

@ -123,6 +123,11 @@ public:
PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
#endif
void SetWindowID(PRUint64 aWindowId) {
mWindowId = aWindowId;
}
PRUint64 WindowID() const { return mWindowId; }
protected:
Image(imgStatusTracker* aStatusTracker);
@ -135,6 +140,8 @@ protected:
virtual nsresult StartAnimation() = 0;
virtual nsresult StopAnimation() = 0;
PRUint64 mWindowId;
// Member data shared by all implementations of this abstract class
nsAutoPtr<imgStatusTracker> mStatusTracker;
PRUint32 mAnimationConsumers;

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

@ -67,6 +67,8 @@
#include "nsThreadUtils.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "nsIDocument.h"
#include "nsPIDOMWindow.h"
#include "netCore.h"
@ -1637,6 +1639,12 @@ NS_IMETHODIMP imgLoader::LoadImage(nsIURI *aURI,
void *cacheId = NS_GetCurrentThread();
request->Init(aURI, aURI, loadGroup, newChannel, entry, cacheId, aCX);
// Pass the windowID of the loading document, if possible.
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
if (doc) {
request->SetWindowID(doc->OuterWindowID());
}
// create the proxy listener
ProxyListener *pl = new ProxyListener(static_cast<nsIStreamListener *>(request.get()));
if (!pl) {

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

@ -189,7 +189,7 @@ NS_IMPL_ISUPPORTS8(imgRequest,
imgRequest::imgRequest() :
mCacheId(0), mValidator(nsnull), mImageSniffers("image-sniffing-services"),
mDecodeRequested(PR_FALSE), mIsMultiPartChannel(PR_FALSE),
mGotData(PR_FALSE), mIsInCache(PR_FALSE)
mGotData(PR_FALSE), mIsInCache(PR_FALSE), mWindowId(0)
{}
imgRequest::~imgRequest()
@ -1025,6 +1025,7 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
} else {
mImage = new RasterImage(mStatusTracker.forget());
}
mImage->SetWindowID(mWindowId);
imageType = mImage->GetType();
// Notify any imgRequestProxys that are observing us that we have an Image.

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

@ -120,6 +120,14 @@ public:
nsresult UnlockImage();
nsresult RequestDecode();
inline void SetWindowID(PRUint64 aWindowId) {
mWindowId = aWindowId;
}
inline PRUint64 WindowID() const {
return mWindowId;
}
private:
friend class imgCacheEntry;
friend class imgRequestProxy;
@ -224,6 +232,10 @@ private:
nsCategoryCache<nsIContentSniffer> mImageSniffers;
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
nsCOMPtr<nsIChannel> mNewRedirectChannel;
// Originating outer window ID. Used for error reporting.
PRUint64 mWindowId;
// Sometimes consumers want to do things before the image is ready. Let them,
// and apply the action when the image becomes available.
PRPackedBool mDecodeRequested : 1;

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

@ -159,6 +159,10 @@ _BROWSER_TEST_PAGES = \
test-bug-595934-malformedxml-external.xml \
test-bug-595934-empty-getelementbyid.html \
test-bug-595934-empty-getelementbyid.js \
test-bug-595934-getselection.html \
test-bug-595934-getselection.js \
test-bug-595934-image.html \
test-bug-595934-image.jpg \
test-bug-597136-external-script-errors.html \
test-bug-597136-external-script-errors.js \
test-bug-613013-console-api-iframe.html \

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

@ -94,6 +94,16 @@ const TESTS = [
category: "CSS Parser",
matchString: "foobarCanvasCssParser",
},
{ // #17
file: "test-bug-595934-getselection.html",
category: "content javascript",
matchString: "getSelection",
},
{ // #18
file: "test-bug-595934-image.html",
category: "Image",
matchString: "corrupt",
},
];
let pos = -1;

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

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Console test for bug 595934 - category: content javascript.
(getSelection())</title>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<script type="text/javascript"
src="test-bug-595934-getselection.js"></script>
</head>
<body>
<p>Web Console test for bug 595934 - category "content javascript"
(getSelection()).</p>
</body>
</html>

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

@ -0,0 +1,9 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
window.addEventListener("load", function() {
document.getSelection();
}, false);

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

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Console test for bug 595934 - category: Image</title>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Web Console test for bug 595934 - category Image.</p>
<p><img src="test-bug-595934-image.jpg" alt="corrupted image"></p>
</body>
</html>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB