Bug 769298 - Avoid logging script errors coming from private windows in the global error console
☠☠ backed out by d439018c0523 ☠ ☠
authorAndres Hernandez <andres@appcoast.com>
Thu, 18 Oct 2012 00:24:56 -0600
changeset 110702 12002e126b397695d7d4c840958d52849f904429
parent 110701 49138b4f5fc92cbc103efe706e9fd913a8386d1b
child 110703 53a930cc32b53c35a7ce67ecc5b8769cb9558273
push id16693
push userjosh@joshmatthews.net
push dateThu, 18 Oct 2012 20:58:11 +0000
treeherdermozilla-inbound@12002e126b39 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs769298
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 769298 - Avoid logging script errors coming from private windows in the global error console
js/xpconnect/idl/nsIScriptError.idl
js/xpconnect/src/nsScriptError.cpp
js/xpconnect/src/xpcprivate.h
toolkit/components/console/content/consoleBindings.xml
toolkit/components/console/jar.mn
--- a/js/xpconnect/idl/nsIScriptError.idl
+++ b/js/xpconnect/idl/nsIScriptError.idl
@@ -6,17 +6,17 @@
 /*
  * nsIConsoleMessage subclass for representing JavaScript errors and warnings.
  */
 
 
 #include "nsISupports.idl"
 #include "nsIConsoleMessage.idl"
 
-[scriptable, uuid(ddc19b34-e22e-46d5-9f7f-c7768a7dc50a)]
+[scriptable, uuid(ec640482-be5f-49a0-a9cb-c87eacce9291)]
 interface nsIScriptError : nsIConsoleMessage
 {
     /** pseudo-flag for default case */
     const unsigned long errorFlag = 0x0;
 
     /** message is warning */
     const unsigned long warningFlag = 0x1;
 
@@ -61,16 +61,18 @@ interface nsIScriptError : nsIConsoleMes
     /* Get the window id this was initialized with.  Zero will be
        returned if init() was used instead of initWithWindowID(). */
     readonly attribute unsigned long long outerWindowID;
 
     /* Get the inner window id this was initialized with.  Zero will be
        returned if init() was used instead of initWithWindowID(). */
     readonly attribute unsigned long long innerWindowID;
 
+    readonly attribute boolean isFromPrivateWindow;
+
     void init(in AString message,
               in AString sourceName,
               in AString sourceLine,
               in uint32_t lineNumber,
               in uint32_t columnNumber,
               in uint32_t flags,
               in string category);
 
--- a/js/xpconnect/src/nsScriptError.cpp
+++ b/js/xpconnect/src/nsScriptError.cpp
@@ -6,30 +6,33 @@
 /*
  * nsIScriptError implementation.  Defined here, lacking a JS-specific
  * place to put XPCOM things.
  */
 
 #include "xpcprivate.h"
 #include "nsGlobalWindow.h"
 #include "nsPIDOMWindow.h"
+#include "nsILoadContext.h"
+#include "nsIDocShell.h"
 
 NS_IMPL_THREADSAFE_ISUPPORTS2(nsScriptError, nsIConsoleMessage, nsIScriptError)
 
 nsScriptError::nsScriptError()
     :  mMessage(),
        mSourceName(),
        mLineNumber(0),
        mSourceLine(),
        mColumnNumber(0),
        mFlags(0),
        mCategory(),
        mOuterWindowID(0),
        mInnerWindowID(0),
-       mTimeStamp(0)
+       mTimeStamp(0),
+       mIsFromPrivateWindow(false)
 {
 }
 
 nsScriptError::~nsScriptError() {}
 
 // nsIConsoleMessage methods
 NS_IMETHODIMP
 nsScriptError::GetMessageMoz(PRUnichar **result) {
@@ -125,16 +128,20 @@ nsScriptError::InitWithWindowID(const ns
 
     if (aInnerWindowID) {
         nsGlobalWindow* window =
           nsGlobalWindow::GetInnerWindowWithId(aInnerWindowID);
         if (window) {
             nsPIDOMWindow* outer = window->GetOuterWindow();
             if (outer)
                 mOuterWindowID = outer->WindowID();
+
+            nsIDocShell* docShell = window->GetDocShell();
+            nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
+            mIsFromPrivateWindow = loadContext->UsePrivateBrowsing();
         }
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScriptError::ToString(nsACString& /*UTF8*/ aResult)
@@ -212,8 +219,15 @@ nsScriptError::GetInnerWindowID(uint64_t
 }
 
 NS_IMETHODIMP
 nsScriptError::GetTimeStamp(int64_t *aTimeStamp)
 {
     *aTimeStamp = mTimeStamp;
     return NS_OK;
 }
+
+NS_IMETHODIMP
+nsScriptError::GetIsFromPrivateWindow(bool *aIsFromPrivateWindow)
+{
+    *aIsFromPrivateWindow = mIsFromPrivateWindow;
+    return NS_OK;
+}
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3865,16 +3865,17 @@ private:
     uint32_t mLineNumber;
     nsString mSourceLine;
     uint32_t mColumnNumber;
     uint32_t mFlags;
     nsCString mCategory;
     uint64_t mOuterWindowID;
     uint64_t mInnerWindowID;
     int64_t mTimeStamp;
+    bool mIsFromPrivateWindow;
 };
 
 /******************************************************************************
  * Handles pre/post script processing and the setting/resetting the error
  * reporter
  */
 class NS_STACK_CLASS AutoScriptEvaluate
 {
--- a/toolkit/components/console/content/consoleBindings.xml
+++ b/toolkit/components/console/content/consoleBindings.xml
@@ -157,17 +157,23 @@
         <body><![CDATA[
           try {
             // Try to QI it to a script error to get more info
             var scriptError = aObject.QueryInterface(Components.interfaces.nsIScriptError);
             
             // filter chrome urls
             if (!this.showChromeErrors && scriptError.sourceName.substr(0, 9) == "chrome://")
               return;
- 
+
+#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
+            // filter private windows
+            if (scriptError.isFromPrivateWindow)
+              return;
+#endif
+
             this.appendError(scriptError);
           } catch (ex) {
             try {
               // Try to QI it to a console message
               var msg = aObject.QueryInterface(Components.interfaces.nsIConsoleMessage);
               if (msg.message)
                 this.appendMessage(msg.message);
               else // observed a null/"clear" message
@@ -506,9 +512,8 @@
           var line = getAttribute("line");
           gViewSourceUtils.viewSource(url, null, null, line);
         ]]>
       </handler>
     </handlers>
   </binding>
 
 </bindings>
-
--- a/toolkit/components/console/jar.mn
+++ b/toolkit/components/console/jar.mn
@@ -1,9 +1,9 @@
 # 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/.
 
 toolkit.jar:
    content/global/console.js                            (content/console.js)
    content/global/console.xul                           (content/console.xul)
    content/global/console.css                           (content/console.css)
-   content/global/consoleBindings.xml                   (content/consoleBindings.xml)
+*  content/global/consoleBindings.xml                   (content/consoleBindings.xml)