tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 0495b5abd302e2b7583d43e877c45707b9599441
parent 82874a096b1c7e7123087c6b7b3d8b21b47503a8
Author: Tom Schuster <tschuster@mozilla.com>
Date:   Tue, 16 Dec 2025 15:37:07 +0000

Bug 2003180 - Remove custom Sanitizer logging code. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D276641

Diffstat:
Mdom/locales/en-US/chrome/security/security.properties | 4++--
Mdom/security/sanitizer/Sanitizer.cpp | 50++++++--------------------------------------------
Mdom/security/sanitizer/Sanitizer.h | 19-------------------
3 files changed, 8 insertions(+), 65 deletions(-)

diff --git a/dom/locales/en-US/chrome/security/security.properties b/dom/locales/en-US/chrome/security/security.properties @@ -165,8 +165,8 @@ IframeSandboxBlockedDownload = Download of “%S” was blocked because the trig SandboxBlockedCustomProtocols = Blocked navigation to custom protocol “%S” from a sandboxed context. # Sanitizer API -# LOCALIZATION NOTE: %S is the URL of the blocked request; -SanitizerAllowElementIgnored = Calling allowElement() with “attributes” or non-empty “removeAttributes” was ignored because of the global “removeElements” list. +# LOCALIZATION NOTE: Do not translate Sanitizer, allowElement, attributes, removeAttributes or removeElements. +SanitizerAllowElementIgnored2 = Sanitizer: Calling allowElement() with “attributes” or non-empty “removeAttributes” was ignored because of the global “removeElements” list. # LOCALIZATION NOTE: %S is the URI of the blocked script. IntegrityPolicyEnforceBlockedScript = The page’s settings blocked a script at %S from being loaded because it is missing integrity metadata. diff --git a/dom/security/sanitizer/Sanitizer.cpp b/dom/security/sanitizer/Sanitizer.cpp @@ -1073,8 +1073,12 @@ bool Sanitizer::AllowElement( !elementAttributes.mRemoveAttributes->IsEmpty())) { // Step 3.1.1. The user agent may report a warning to the console that this // operation is not supported. - LogLocalizedString("SanitizerAllowElementIgnored", {}, - nsIScriptError::warningFlag); + if (auto* win = mGlobal->GetAsInnerWindow()) { + nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, + "Sanitizer"_ns, win->GetDoc(), + nsContentUtils::eSECURITY_PROPERTIES, + "SanitizerAllowElementIgnored2"); + } // Step 3.1.2. Return false. return false; @@ -1973,46 +1977,4 @@ void Sanitizer::SanitizeDefaultConfigAttributes( } } -/* ------ Logging ------ */ - -void Sanitizer::LogLocalizedString(const char* aName, - const nsTArray<nsString>& aParams, - uint32_t aFlags) { - uint64_t innerWindowID = 0; - bool isPrivateBrowsing = true; - nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal); - if (window && window->GetDoc()) { - auto* doc = window->GetDoc(); - innerWindowID = doc->InnerWindowID(); - isPrivateBrowsing = doc->IsInPrivateBrowsing(); - } - nsAutoString logMsg; - nsContentUtils::FormatLocalizedString(nsContentUtils::eSECURITY_PROPERTIES, - aName, aParams, logMsg); - LogMessage(logMsg, aFlags, innerWindowID, isPrivateBrowsing); -} - -/* static */ -void Sanitizer::LogMessage(const nsAString& aMessage, uint32_t aFlags, - uint64_t aInnerWindowID, bool aFromPrivateWindow) { - // Prepending 'Sanitizer' to the outgoing console message - nsString message; - message.AppendLiteral(u"Sanitizer: "); - message.Append(aMessage); - - // Allow for easy distinction in devtools code. - constexpr auto category = "Sanitizer"_ns; - - if (aInnerWindowID > 0) { - // Send to content console - nsContentUtils::ReportToConsoleByWindowID(message, aFlags, category, - aInnerWindowID); - } else { - // Send to browser console - nsContentUtils::LogSimpleConsoleError(message, category, aFromPrivateWindow, - true /* from chrome context */, - aFlags); - } -} - } // namespace mozilla::dom diff --git a/dom/security/sanitizer/Sanitizer.h b/dom/security/sanitizer/Sanitizer.h @@ -99,25 +99,6 @@ class Sanitizer final : public nsISupports, public nsWrapperCache { StaticAtomSet* aElementAttributes, bool aSafe); - /** - * Logs localized message to either content console or browser console - * @param aName Localization key - * @param aParams Localization parameters - * @param aFlags Logging Flag (see nsIScriptError) - */ - void LogLocalizedString(const char* aName, const nsTArray<nsString>& aParams, - uint32_t aFlags); - - /** - * Logs localized message to either content console or browser console - * @param aMessage Message to log - * @param aFlags Logging Flag (see nsIScriptError) - * @param aInnerWindowID Inner Window ID (Logged on browser console if 0) - * @param aFromPrivateWindow If from private window - */ - static void LogMessage(const nsAString& aMessage, uint32_t aFlags, - uint64_t aInnerWindowID, bool aFromPrivateWindow); - void AssertIsValid(); void AssertNoLists() {