Bug 1548375 - Send canvas fingerprinting logs to page console. r=baku
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 01 May 2019 21:51:41 +0000
changeset 472245 1376a67f22b4d4d28c712bd74217644fbd5fb040
parent 472244 cee3233dc4f3741e294c2b3026391e0561eb3aa8
child 472246 69fb960771d254fde9b7567fd3f527a205a60555
push id112987
push usercbrindusan@mozilla.com
push dateThu, 02 May 2019 15:35:11 +0000
treeherdermozilla-inbound@56a1e86bccf1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1548375
milestone68.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 1548375 - Send canvas fingerprinting logs to page console. r=baku By directing fingerprinting logs to the page console (instead of the browser console), web developers are much more likely to see them and understand what's wrong. Differential Revision: https://phabricator.services.mozilla.com/D29572
dom/canvas/CanvasUtils.cpp
--- a/dom/canvas/CanvasUtils.cpp
+++ b/dom/canvas/CanvasUtils.cpp
@@ -20,16 +20,17 @@
 #include "nsGfxCIID.h"
 
 #include "nsTArray.h"
 
 #include "CanvasUtils.h"
 #include "mozilla/gfx/Matrix.h"
 #include "WebGL2Context.h"
 
+#include "nsIScriptError.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIPermissionManager.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozIThirdPartyUtil.h"
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsPrintfCString.h"
@@ -107,24 +108,26 @@ bool IsImageExtractionAllowed(Document* 
       do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, false);
 
   // Block all third-party attempts to extract canvas.
   bool isThirdParty = true;
   rv = thirdPartyUtil->IsThirdPartyURI(topLevelDocURI, docURI, &isThirdParty);
   NS_ENSURE_SUCCESS(rv, false);
   if (isThirdParty) {
-    nsAutoCString message;
+    nsAutoString message;
     message.AppendPrintf(
         "Blocked third party %s in page %s from extracting canvas data.",
         docURISpec.get(), topLevelDocURISpec.get());
     if (isScriptKnown) {
       message.AppendPrintf(" %s:%u.", scriptFile.get(), scriptLine);
     }
-    nsContentUtils::LogMessageToConsole(message.get());
+    nsContentUtils::ReportToConsoleNonLocalized(
+        message, nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Security"),
+        aDocument);
     return false;
   }
 
   // Load Permission Manager service.
   nsCOMPtr<nsIPermissionManager> permissionManager =
       do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, false);
 
@@ -148,36 +151,40 @@ bool IsImageExtractionAllowed(Document* 
 
   // Check if the request is in response to user input
   bool isAutoBlockCanvas =
       StaticPrefs::
           privacy_resistFingerprinting_autoDeclineNoUserInputCanvasPrompts() &&
       !EventStateManager::IsHandlingUserInput();
 
   if (isAutoBlockCanvas) {
-    nsAutoCString message;
+    nsAutoString message;
     message.AppendPrintf(
         "Blocked %s in page %s from extracting canvas data because no user "
         "input was detected.",
         docURISpec.get(), topLevelDocURISpec.get());
     if (isScriptKnown) {
       message.AppendPrintf(" %s:%u.", scriptFile.get(), scriptLine);
     }
-    nsContentUtils::LogMessageToConsole(message.get());
+    nsContentUtils::ReportToConsoleNonLocalized(
+        message, nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Security"),
+        aDocument);
   } else {
     // It was in response to user input, so log and display the prompt.
-    nsAutoCString message;
+    nsAutoString message;
     message.AppendPrintf(
         "Blocked %s in page %s from extracting canvas data, but prompting the "
         "user.",
         docURISpec.get(), topLevelDocURISpec.get());
     if (isScriptKnown) {
       message.AppendPrintf(" %s:%u.", scriptFile.get(), scriptLine);
     }
-    nsContentUtils::LogMessageToConsole(message.get());
+    nsContentUtils::ReportToConsoleNonLocalized(
+        message, nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Security"),
+        aDocument);
   }
 
   // Prompt the user (asynchronous).
   nsPIDOMWindowOuter* win = aDocument->GetWindow();
   if (XRE_IsContentProcess()) {
     BrowserChild* browserChild = BrowserChild::GetFrom(win);
     if (browserChild) {
       browserChild->SendShowCanvasPermissionPrompt(topLevelDocURISpec,