Bug 603706 - Need a way to track the originating window for all nsIConsoleMessages; r=joe,bzbarsky, a=blocking2.0
authorMihai Sucan <mihai.sucan@gmail.com>
Mon, 20 Dec 2010 12:21:59 -0400
changeset 59516 4e6f930a1363007b847f460ece9ff072d7f76c12
parent 59515 0b88e1ab00c12dc278d460c8d9d81c23397c1d06
child 59517 e59145d3eed65dd7a91d34371b1da8b65242a4b6
child 59520 ea5076f3b4fe2fa4dc9427a0136ed7752db488d6
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjoe, bzbarsky, blocking2
bugs603706
milestone2.0b9pre
Bug 603706 - Need a way to track the originating window for all nsIConsoleMessages; r=joe,bzbarsky, a=blocking2.0
content/html/document/src/nsHTMLDocument.cpp
modules/libpr0n/src/Decoder.cpp
modules/libpr0n/src/Image.cpp
modules/libpr0n/src/Image.h
modules/libpr0n/src/imgLoader.cpp
modules/libpr0n/src/imgRequest.cpp
modules/libpr0n/src/imgRequest.h
toolkit/components/console/hudservice/tests/browser/Makefile.in
toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.html
toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.js
toolkit/components/console/hudservice/tests/browser/test-bug-595934-image.html
toolkit/components/console/hudservice/tests/browser/test-bug-595934-image.jpg
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -2519,21 +2519,20 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLColl
   return NS_OK;
 }
 
 NS_IMETHODIMP
 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());
   nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(window);
   NS_ENSURE_TRUE(pwin, NS_OK);
   NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!");
   NS_ENSURE_TRUE(pwin->GetOuterWindow() &&
                  pwin->GetOuterWindow()->GetCurrentInnerWindow() == pwin,
--- a/modules/libpr0n/src/Decoder.cpp
+++ b/modules/libpr0n/src/Decoder.cpp
@@ -34,16 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Decoder.h"
 #include "nsIServiceManager.h"
 #include "nsIConsoleService.h"
+#include "nsIScriptError.h"
 
 namespace mozilla {
 namespace imagelib {
 
 Decoder::Decoder()
   : mFrameCount(0)
   , mFailCode(NS_OK)
   , mInitialized(false)
@@ -112,21 +113,35 @@ Decoder::Finish()
   if (mInFrame && !HasDecoderError())
     PostFrameStop();
 
   // If PostDecodeDone() has not been called, we need to sent teardown
   // notifications.
   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
     bool salvage = !HasDecoderError() && mImage->GetNumFrames();
 
     // If we're salvaging, say we finished decoding
     if (salvage)
       mImage->DecodingComplete();
--- a/modules/libpr0n/src/Image.cpp
+++ b/modules/libpr0n/src/Image.cpp
@@ -41,17 +41,18 @@ namespace mozilla {
 namespace imagelib {
 
 // Constructor
 Image::Image(imgStatusTracker* aStatusTracker) :
   mAnimationConsumers(0),
   mAnimationMode(kNormalAnimMode),
   mInitialized(PR_FALSE),
   mAnimating(PR_FALSE),
-  mError(PR_FALSE)
+  mError(PR_FALSE),
+  mWindowId(0)
 {
   if (aStatusTracker) {
     mStatusTracker = aStatusTracker;
     mStatusTracker->SetImage(this);
   } else {
     mStatusTracker = new imgStatusTracker(this);
   }
 }
--- a/modules/libpr0n/src/Image.h
+++ b/modules/libpr0n/src/Image.h
@@ -118,28 +118,35 @@ public:
   static eDecoderType GetDecoderType(const char *aMimeType);
 
   void IncrementAnimationConsumers();
   void DecrementAnimationConsumers();
 #ifdef DEBUG
   PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
 #endif
 
+  void SetWindowID(PRUint64 aWindowId) {
+    mWindowId = aWindowId;
+  }
+  PRUint64 WindowID() const { return mWindowId; }
+
 protected:
   Image(imgStatusTracker* aStatusTracker);
 
   /**
    * Decides whether animation should or should not be happening,
    * and makes sure the right thing is being done.
    */
   virtual void EvaluateAnimation();
 
   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;
   PRUint16                    mAnimationMode;   // Enum values in imgIContainer
   PRPackedBool                mInitialized:1;   // Have we been initalized?
   PRPackedBool                mAnimating:1;     // Are we currently animating?
   PRPackedBool                mError:1;         // Error handling
 
--- a/modules/libpr0n/src/imgLoader.cpp
+++ b/modules/libpr0n/src/imgLoader.cpp
@@ -62,16 +62,18 @@
 #include "nsIChannelEventSink.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIProxyObjectManager.h"
 #include "nsIServiceManager.h"
 #include "nsIFileURL.h"
 #include "nsThreadUtils.h"
 #include "nsXPIDLString.h"
 #include "nsCRT.h"
+#include "nsIDocument.h"
+#include "nsPIDOMWindow.h"
 
 #include "netCore.h"
 
 #include "nsURILoader.h"
 #include "ImageLogging.h"
 
 #include "nsIComponentRegistrar.h"
 
@@ -1632,16 +1634,22 @@ NS_IMETHODIMP imgLoader::LoadImage(nsIUR
     // is redirected, we'll have a way to cancel the resulting channel.
     nsCOMPtr<nsILoadGroup> loadGroup =
         do_CreateInstance(NS_LOADGROUP_CONTRACTID);
     newChannel->SetLoadGroup(loadGroup);
 
     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) {
       request->CancelAndAbort(NS_ERROR_OUT_OF_MEMORY);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     NS_ADDREF(pl);
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -184,17 +184,17 @@ NS_IMPL_ISUPPORTS8(imgRequest,
                    nsISupportsWeakReference,
                    nsIChannelEventSink,
                    nsIInterfaceRequestor,
                    nsIAsyncVerifyRedirectCallback)
 
 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()
 {
   if (mKeyURI) {
     nsCAutoString spec;
     mKeyURI->GetSpec(spec);
     LOG_FUNC_WITH_PARAM(gImgLog, "imgRequest::~imgRequest()", "keyuri", spec.get());
@@ -1020,16 +1020,17 @@ NS_IMETHODIMP imgRequest::OnDataAvailabl
     }
 
     /* now we have mimetype, so we can infer the image type that we want */
     if (mContentType.EqualsLiteral(SVG_MIMETYPE)) {
       mImage = new VectorImage(mStatusTracker.forget());
     } else {
       mImage = new RasterImage(mStatusTracker.forget());
     }
+    mImage->SetWindowID(mWindowId);
     imageType = mImage->GetType();
 
     // Notify any imgRequestProxys that are observing us that we have an Image.
     nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mObservers);
     while (iter.HasMore()) {
       iter.GetNext()->SetImage(mImage);
     }
 
--- a/modules/libpr0n/src/imgRequest.h
+++ b/modules/libpr0n/src/imgRequest.h
@@ -115,16 +115,24 @@ public:
   void CancelAndAbort(nsresult aStatus);
 
   // Methods that get forwarded to the Image, or deferred until it's
   // instantiated.
   nsresult LockImage();
   nsresult UnlockImage();
   nsresult RequestDecode();
 
+  inline void SetWindowID(PRUint64 aWindowId) {
+    mWindowId = aWindowId;
+  }
+
+  inline PRUint64 WindowID() const {
+    return mWindowId;
+  }
+
 private:
   friend class imgCacheEntry;
   friend class imgRequestProxy;
   friend class imgLoader;
   friend class imgCacheValidator;
   friend class imgStatusTracker;
   friend class imgCacheExpirationTracker;
   friend class imgRequestNotifyRunnable;
@@ -219,16 +227,20 @@ private:
 
   void *mLoadId;
   PRTime mLoadTime;
 
   imgCacheValidator *mValidator;
   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;
 
   PRPackedBool mIsMultiPartChannel : 1;
   PRPackedBool mGotData : 1;
   PRPackedBool mIsInCache : 1;
 };
--- a/toolkit/components/console/hudservice/tests/browser/Makefile.in
+++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in
@@ -154,16 +154,20 @@ include $(topsrcdir)/config/rules.mk
 	test-bug-595934-css-parser.html \
 	test-bug-595934-css-parser.css \
 	test-bug-595934-canvas-css.html \
 	test-bug-595934-canvas-css.js \
 	test-bug-595934-malformedxml-external.html \
 	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 \
 	test-bug-597756-reopen-closed-tab.html \
 	test-bug-600183-charset.html \
 	test-bug-600183-charset.html^headers^ \
 	test-bug-601177-log-levels.html \
 	test-bug-601177-log-levels.js \
--- a/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
+++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
@@ -89,16 +89,26 @@ const TESTS = [
     category: "DOM",
     matchString: "getElementById",
   },
   { // #15
     file: "test-bug-595934-canvas-css.html",
     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;
 
 let TestObserver = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   observe: function test_observe(aSubject)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.html
@@ -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>
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.js
@@ -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);
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/test-bug-595934-image.html
@@ -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>
+
+
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..947e5f11ba13b7a1728ef64fbdedfa5ee25379cf
GIT binary patch
literal 2532
zc$}S;TU1kL7RS#?P7(+q5IE6<ONar4WU6u#2@nZUE&&Q5h*%420RbUYlskf@4MAv)
zs30ha5CS1wWMPX&!CGrTt|DGQ)B<B8P+~+>1o2Xp30<9;mwA|(-}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