Bug 1079338 - Log resources blocked by tracking protection. r=mcmanus,mmc,dcamp
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 10 Oct 2014 12:19:14 -0700
changeset 233013 92a33c4dbe459f887fd548874f0ba03ae33e86a7
parent 233012 e5d3834c61a4662564609466dcde4e315c24dc60
child 233014 15e3bf0b1847032b930b1f3e0f7131abf329b7e9
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersmcmanus, mmc, dcamp
bugs1079338
milestone35.0a1
Bug 1079338 - Log resources blocked by tracking protection. r=mcmanus,mmc,dcamp * * * Bug 1079338 - Put tracking protection logging in the Security tab
browser/devtools/webconsole/webconsole.js
content/base/public/nsContentUtils.h
content/base/src/nsContentUtils.cpp
netwerk/base/src/nsChannelClassifier.cpp
netwerk/locales/en-US/necko.properties
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -4674,16 +4674,17 @@ var Utils = {
       case "Mixed Content Message":
       case "CSP":
       case "Invalid HSTS Headers":
       case "Invalid HPKP Headers":
       case "Insecure Password Field":
       case "SSL":
       case "CORS":
       case "Iframe Sandbox":
+      case "Tracking Protection":
         return CATEGORY_SECURITY;
 
       default:
         return CATEGORY_JS;
     }
   },
 
   /**
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -784,16 +784,17 @@ public:
     ePRINTING_PROPERTIES,
     eDOM_PROPERTIES,
     eHTMLPARSER_PROPERTIES,
     eSVG_PROPERTIES,
     eBRAND_PROPERTIES,
     eCOMMON_DIALOG_PROPERTIES,
     eMATHML_PROPERTIES,
     eSECURITY_PROPERTIES,
+    eNECKO_PROPERTIES,
     PropertiesFile_COUNT
   };
   static nsresult ReportToConsole(uint32_t aErrorFlags,
                                   const nsACString& aCategory,
                                   nsIDocument* aDocument,
                                   PropertiesFile aFile,
                                   const char *aMessageName,
                                   const char16_t **aParams = nullptr,
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3233,17 +3233,18 @@ static const char gPropertiesFiles[nsCon
   "chrome://global/locale/layout/HtmlForm.properties",
   "chrome://global/locale/printing.properties",
   "chrome://global/locale/dom/dom.properties",
   "chrome://global/locale/layout/htmlparser.properties",
   "chrome://global/locale/svg/svg.properties",
   "chrome://branding/locale/brand.properties",
   "chrome://global/locale/commonDialogs.properties",
   "chrome://global/locale/mathml/mathml.properties",
-  "chrome://global/locale/security/security.properties"
+  "chrome://global/locale/security/security.properties",
+  "chrome://necko/locale/necko.properties"
 };
 
 /* static */ nsresult
 nsContentUtils::EnsureStringBundle(PropertiesFile aFile)
 {
   if (!sStringBundles[aFile]) {
     if (!sStringBundleService) {
       nsresult rv =
--- a/netwerk/base/src/nsChannelClassifier.cpp
+++ b/netwerk/base/src/nsChannelClassifier.cpp
@@ -1,36 +1,39 @@
 /* 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/. */
 
 #include "nsChannelClassifier.h"
 
 #include "mozIThirdPartyUtil.h"
+#include "nsContentUtils.h"
 #include "nsNetUtil.h"
 #include "nsICacheEntry.h"
 #include "nsICachingChannel.h"
 #include "nsIChannel.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMWindow.h"
 #include "nsIIOService.h"
 #include "nsIPermissionManager.h"
 #include "nsIProtocolHandler.h"
+#include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISecureBrowserUI.h"
 #include "nsISecurityEventSink.h"
 #include "nsIWebProgressListener.h"
 #include "nsPIDOMWindow.h"
 
 #include "mozilla/Preferences.h"
 
 #include "prlog.h"
 
+using mozilla::ArrayLength;
 using mozilla::Preferences;
 
 #if defined(PR_LOGGING)
 //
 // NSPR_LOG_MODULES=nsChannelClassifier:5
 //
 static PRLogModuleInfo *gChannelClassifierLog;
 #endif
@@ -354,16 +357,30 @@ nsChannelClassifier::SetBlockedTrackingC
   if (!securityUI) {
     return NS_OK;
   }
   doc->SetHasTrackingContentBlocked(true);
   securityUI->GetState(&state);
   state |= nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT;
   eventSink->OnSecurityChange(nullptr, state);
 
+  // Log a warning to the web console.
+  nsCOMPtr<nsIURI> uri;
+  channel->GetURI(getter_AddRefs(uri));
+  nsCString utf8spec;
+  uri->GetSpec(utf8spec);
+  NS_ConvertUTF8toUTF16 spec(utf8spec);
+  const char16_t* params[] = { spec.get() };
+  nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+                                  NS_LITERAL_CSTRING("Tracking Protection"),
+                                  doc,
+                                  nsContentUtils::eNECKO_PROPERTIES,
+                                  "TrackingUriBlocked",
+                                  params, ArrayLength(params));
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsChannelClassifier::OnClassifyComplete(nsresult aErrorCode)
 {
     if (mSuspendedChannel) {
         MarkEntryClassified(aErrorCode);
--- a/netwerk/locales/en-US/necko.properties
+++ b/netwerk/locales/en-US/necko.properties
@@ -32,8 +32,10 @@ DirColName=Name
 DirColSize=Size
 DirColMTime=Last Modified
 DirFileLabel=File: 
 
 PhishingAuth=You are about to visit "%1$S". This site may be attempting to trick you into thinking you are visiting a different site. Use extreme caution.
 PhishingAuthAccept=I understand and will be very careful
 SuperfluousAuth=You are about to log in to the site "%1$S" with the username "%2$S", but the website does not require authentication. This may be an attempt to trick you.\n\nIs "%1$S" the site you want to visit?
 AutomaticAuth=You are about to log in to the site "%1$S" with the username "%2$S".
+
+TrackingUriBlocked=The resource at "%1$S" was blocked because tracking protection is enabled.