ContentSettingsAgentImpl moved to //components.

Chromium change:

https://chromium.googlesource.com/chromium/src/+/af3597cb7e26db8909a4883bd528efb84c6d7ce2

commit af3597cb7e26db8909a4883bd528efb84c6d7ce2
Author: Clark DuVall <cduvall@chromium.org>
Date:   Wed Apr 15 19:20:24 2020 +0000

    Move ContentSettingsAgentImpl to //components/content_settings

    This splits chrome-specific logic into
    ChromeContentSettingsAgentDelegate, and moves common logic into
    //components/content_settings. This will allow sharing the content
    settings agent with WebLayer.

    The unit test for WhitelistedSchemes was moved into the browser tests,
    which means we no longer need a static version of
    IsWhitelistedForContentSettings() just for testing.

    Bug: 1065537
This commit is contained in:
mkarolin
2020-07-01 18:11:38 -04:00
parent 19fc99741e
commit d80b85d303
27 changed files with 277 additions and 212 deletions
@@ -0,0 +1,8 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
* 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 "brave/components/content_settings/renderer/brave_content_settings_agent_impl.h"
#include "../../../../chrome/renderer/chrome_content_renderer_client.cc"
@@ -1,14 +0,0 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
* 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/. */
#ifndef BRAVE_CHROMIUM_SRC_CHROME_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
#define BRAVE_CHROMIUM_SRC_CHROME_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
#define BRAVE_CONTENT_SETTINGS_AGENT_IMPL_H_ \
friend class BraveContentSettingsAgentImpl;
#include "../../../../chrome/renderer/content_settings_agent_impl.h"
#endif // BRAVE_CHROMIUM_SRC_CHROME_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
@@ -0,0 +1,16 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
* 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 "components/content_settings/renderer/content_settings_agent_impl.h"
#define BRAVE_CONTENT_SETTINGS_AGENT_IMPL_IS_WHITELISTED_FOR_CONTENT_SETTINGS \
return IsWhitelistedForContentSettings(origin, document_url); \
} \
\
bool ContentSettingsAgentImpl::IsWhitelistedForContentSettings( \
const WebSecurityOrigin& origin, const WebURL& document_url) const {
#include "../../../../../components/content_settings/renderer/content_settings_agent_impl.cc"
#undef IsWhitelistedForContentSettings
@@ -0,0 +1,20 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
* 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/. */
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
#define BRAVE_CONTENT_SETTINGS_AGENT_IMPL_H_ \
friend class BraveContentSettingsAgentImpl;
#define IsWhitelistedForContentSettings \
IsWhitelistedForContentSettings(const blink::WebSecurityOrigin& origin, \
const blink::WebURL& document_url) const; \
bool IsWhitelistedForContentSettings
#include "../../../../../components/content_settings/renderer/content_settings_agent_impl.h"
#undef IsWhitelistedForContentSettings
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_RENDERER_CONTENT_SETTINGS_AGENT_IMPL_H_
@@ -3,7 +3,7 @@
* 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 "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
@@ -0,0 +1,13 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* 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 "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#define BRAVE_CANVAS_RENDERING_CONTEXT_2D_MEASURE_TEXT \
if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return MakeGarbageCollected<TextMetrics>();
#include "../../../../../../../third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc"
#undef BRAVE_CANVAS_RENDERING_CONTEXT_2D_MEASURE_TEXT
@@ -0,0 +1,14 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* 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 "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#define BRAVE_MEDIA_DEVICES_ENUMERATE_DEVICES \
if (!AllowFingerprinting(frame)) { \
return ScriptPromise::CastUndefined(script_state); \
}
#include "../../../../../../third_party/blink/renderer/modules/mediastream/media_devices.cc"
#undef BRAVE_MEDIA_DEVICES_ENUMERATE_DEVICES
@@ -3,7 +3,7 @@
* 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 "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#define BRAVE_RTC_PEER_CONNECTION \
if (!AllowFingerprinting(Document::From(GetExecutionContext())->GetFrame())) \
@@ -0,0 +1,13 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* 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 "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#define BRAVE_WEBGL2_RENDERING_CONTEXT_BASE \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return ScriptValue::CreateNull(script_state->GetIsolate());
#include "../../../../../../third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc"
#undef BRAVE_WEBGL2_RENDERING_CONTEXT_BASE
@@ -3,9 +3,37 @@
* 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 "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "brave/components/content_settings/renderer/brave_content_settings_agent_impl_helper.h"
#include "third_party/blink/renderer/core/dom/document.h"
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_RETURN \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return;
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return nullptr;
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLOPT \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return base::nullopt;
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_ZERO \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return 0;
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_MINUS_ONE \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return -1;
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return ScriptValue::CreateNull(script_state->GetIsolate());
#define BRAVE_WEBGL_RENDERING_CONTEXT_BASE_STRING \
if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
return String();
#define BRAVE_WEBGL_GET_PARAMETER_UNMASKED_RENDERER \
if (ExtensionEnabled(kWebGLDebugRendererInfoName) && canvas() && \
!AllowFingerprinting(canvas()->GetDocument().GetFrame())) \
@@ -22,7 +50,13 @@
String(brave::BraveSessionCache::From(canvas()->GetDocument()) \
.GenerateRandomString("UNMASKED_VENDOR_WEBGL", 8)));
#include "../../../../../../third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc" // NOLINT
#include "../../../../../../third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc"
#undef BRAVE_WEBGL_GET_PARAMETER_UNMASKED_RENDERER
#undef BRAVE_WEBGL_GET_PARAMETER_UNMASKED_VENDOR
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_STRING
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_MINUS_ONE
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_ZERO
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLOPT
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
#undef BRAVE_WEBGL_RENDERING_CONTEXT_BASE_RETURN
@@ -14,6 +14,7 @@ source_set("browser") {
"//brave/common:network_constants",
"//brave/common:pref_names",
"//brave/common:shield_exceptions",
"//brave/components/brave_shields/common",
"//brave/components/content_settings/core/common",
"//components/content_settings/core/common",
"//components/prefs",
@@ -0,0 +1,31 @@
import("//build/config/features.gni")
source_set("renderer") {
visibility = [
"//chrome/renderer/*",
"//components/content_settings/renderer/*",
"//brave/renderer/*",
"//brave:child_dependencies",
"//brave/test:*"
]
sources = [
"brave_content_settings_agent_impl.cc",
"brave_content_settings_agent_impl.h",
]
deps = [
"//base",
"//brave/common",
"//brave/components/brave_shields/common",
"//chrome/common",
"//components/content_settings/core/common",
"//components/content_settings/renderer",
"//content/public/renderer",
"//mojo/public/cpp/bindings",
"//services/service_manager/public/cpp",
"//third_party/blink/public:blink",
"//brave/content:common",
"//url",
]
}
@@ -3,7 +3,7 @@
* 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 "brave/renderer/brave_content_settings_agent_impl.h"
#include "brave/components/content_settings/renderer/brave_content_settings_agent_impl.h"
#include <string>
#include <utility>
@@ -33,6 +33,7 @@
#include "third_party/blink/public/web/web_local_frame.h"
#include "url/url_constants.h"
namespace content_settings {
namespace {
GURL GetOriginOrURL(
@@ -70,9 +71,10 @@ bool IsBraveShieldsDown(const blink::WebFrame* frame,
BraveContentSettingsAgentImpl::BraveContentSettingsAgentImpl(
content::RenderFrame* render_frame,
bool should_whitelist,
service_manager::BinderRegistry* registry)
: ContentSettingsAgentImpl(render_frame, should_whitelist, registry) {
}
std::unique_ptr<Delegate> delegate)
: ContentSettingsAgentImpl(render_frame,
should_whitelist,
std::move(delegate)) {}
BraveContentSettingsAgentImpl::~BraveContentSettingsAgentImpl() {
}
@@ -182,8 +184,8 @@ bool BraveContentSettingsAgentImpl::IsBraveShieldsDown(
const blink::WebFrame* frame,
const GURL& secondary_url) {
return !content_setting_rules_ ||
::IsBraveShieldsDown(frame, secondary_url,
content_setting_rules_->brave_shields_rules);
::content_settings::IsBraveShieldsDown(
frame, secondary_url, content_setting_rules_->brave_shields_rules);
}
bool BraveContentSettingsAgentImpl::AllowFingerprinting(
@@ -295,3 +297,5 @@ bool BraveContentSettingsAgentImpl::AllowAutoplay(bool default_value) {
"ContentSettingsAgentImpl::AllowAutoplay says so";
return allow;
}
} // namespace content_settings
@@ -11,40 +11,38 @@
#include "base/strings/string16.h"
#include "brave/third_party/blink/renderer/brave_farbling_constants.h"
#include "chrome/renderer/content_settings_agent_impl.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/renderer/content_settings_agent_impl.h"
namespace blink {
class WebLocalFrame;
}
namespace content_settings {
// Handles blocking content per content settings for each RenderFrame.
class BraveContentSettingsAgentImpl
: public ContentSettingsAgentImpl {
class BraveContentSettingsAgentImpl : public ContentSettingsAgentImpl {
public:
BraveContentSettingsAgentImpl(content::RenderFrame* render_frame,
bool should_whitelist,
service_manager::BinderRegistry* registry);
bool should_whitelist,
std::unique_ptr<Delegate> delegate);
~BraveContentSettingsAgentImpl() override;
protected:
bool AllowScript(bool enabled_per_settings) override;
void DidNotAllowScript() override;
bool AllowScriptFromSource(bool enabled_per_settings,
const blink::WebURL& script_url) override;
const blink::WebURL& script_url) override;
void DidNotAllowScript() override;
bool AllowFingerprinting(bool enabled_per_settings) override;
BraveFarblingLevel GetBraveFarblingLevel() override;
void BraveSpecificDidBlockJavaScript(const base::string16& details);
bool AllowAutoplay(bool default_value) override;
void BraveSpecificDidBlockJavaScript(
const base::string16& details);
bool AllowFingerprinting(bool enabled_per_settings) override;
void DidBlockFingerprinting(const base::string16& details);
void DidBlockFingerprinting(
const base::string16& details);
BraveFarblingLevel GetBraveFarblingLevel() override;
private:
bool IsBraveShieldsDown(
@@ -72,4 +70,6 @@ class BraveContentSettingsAgentImpl
DISALLOW_COPY_AND_ASSIGN(BraveContentSettingsAgentImpl);
};
} // namespace content_settings
#endif // BRAVE_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_H_
@@ -3,14 +3,11 @@
* 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/. */
#ifndef BRAVE_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
#define BRAVE_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
static bool AllowFingerprinting(blink::LocalFrame* frame) {
if (!frame || !frame->GetContentSettingsClient()) {
@@ -19,4 +16,4 @@ static bool AllowFingerprinting(blink::LocalFrame* frame) {
return frame->GetContentSettingsClient()->AllowFingerprinting(true);
}
#endif // BRAVE_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_RENDERER_BRAVE_CONTENT_SETTINGS_AGENT_IMPL_HELPER_H_
@@ -1,21 +1,13 @@
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index b96048aec4f7d58438a5b08d688756d8c639a6fc..2a69290a211d6d951975705122e539619c16f2ba 100644
index c1d92ae00fe58a7f0d80914830d9607246231d33..9a175b5e2d0889f53ad17a6124d3a02d00bddd29 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -23,6 +23,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
+#include "brave/renderer/brave_content_settings_agent_impl.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_content_client.h"
@@ -471,7 +472,7 @@ void ChromeContentRendererClient::RenderFrameCreated(
bool should_whitelist_for_content_settings =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kInstantProcess);
- ContentSettingsAgentImpl* content_settings = new ContentSettingsAgentImpl(
+ ContentSettingsAgentImpl* content_settings = new BraveContentSettingsAgentImpl(
render_frame, should_whitelist_for_content_settings, registry);
#if BUILDFLAG(ENABLE_EXTENSIONS)
content_settings->SetExtensionDispatcher(
@@ -483,7 +483,7 @@ void ChromeContentRendererClient::RenderFrameCreated(
ChromeExtensionsRendererClient::GetInstance()->extension_dispatcher());
#endif
content_settings::ContentSettingsAgentImpl* content_settings =
- new content_settings::ContentSettingsAgentImpl(
+ new content_settings::BraveContentSettingsAgentImpl(
render_frame, should_whitelist_for_content_settings,
std::move(content_settings_delegate));
if (chrome_observer_.get()) {
@@ -1,12 +0,0 @@
diff --git a/chrome/renderer/content_settings_agent_impl.h b/chrome/renderer/content_settings_agent_impl.h
index cb9d73fded66930c19e1e0a3e881436da6c0e39b..ef48eda514c41f55ff8cd1eadf562339050ac53b 100644
--- a/chrome/renderer/content_settings_agent_impl.h
+++ b/chrome/renderer/content_settings_agent_impl.h
@@ -111,6 +111,7 @@ class ContentSettingsAgentImpl
return allow_running_insecure_content_;
}
+BRAVE_CONTENT_SETTINGS_AGENT_IMPL_H_
protected:
// Allow this to be overridden by tests.
virtual void BindContentSettingsManager(
@@ -0,0 +1,12 @@
diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc
index 3338944900578f91d9e3afbfe73caee303dde2a1..e5c78f0947acbc679cc76bafa3240fd67420fe17 100644
--- a/components/content_settings/renderer/content_settings_agent_impl.cc
+++ b/components/content_settings/renderer/content_settings_agent_impl.cc
@@ -533,6 +533,7 @@ bool ContentSettingsAgentImpl::IsWhitelistedForContentSettings() const {
const WebDocument& document = render_frame()->GetWebFrame()->GetDocument();
WebSecurityOrigin origin = document.GetSecurityOrigin();
WebURL document_url = document.Url();
+ BRAVE_CONTENT_SETTINGS_AGENT_IMPL_IS_WHITELISTED_FOR_CONTENT_SETTINGS
if (document_url.GetString() == content::kUnreachableWebDataURL)
return true;
@@ -0,0 +1,12 @@
diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h
index 2522fdb1971a70c7685de606aa490deacc8bab72..b75659e76c0f76bc61412a2fb0ce80acd7674c8f 100644
--- a/components/content_settings/renderer/content_settings_agent_impl.h
+++ b/components/content_settings/renderer/content_settings_agent_impl.h
@@ -125,6 +125,7 @@ class ContentSettingsAgentImpl
const blink::WebFrame* frame,
const blink::WebURL& secondary_url);
+ BRAVE_CONTENT_SETTINGS_AGENT_IMPL_H_
protected:
// Allow this to be overridden by tests.
virtual void BindContentSettingsManager(
@@ -1,22 +1,12 @@
diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc
index f59471191285f83f66037d546b32816528c2dcb1..0c66e6e1fae805c247a7de7c915bd16e0b96fc9e 100644
index e916fc83dabca0a6006383ddb9c596a5109bec74..6cc85d42abfb0341504e4dd68136b0b6ac694c4f 100644
--- a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc
+++ b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc
@@ -35,6 +35,7 @@
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
+#include "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
@@ -804,6 +805,9 @@ TextMetrics* CanvasRenderingContext2D::measureText(const String& text) {
@@ -804,6 +804,7 @@ TextMetrics* CanvasRenderingContext2D::measureText(const String& text) {
if (!canvas()->GetDocument().GetFrame())
return MakeGarbageCollected<TextMetrics>();
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return MakeGarbageCollected<TextMetrics>();
+
+ BRAVE_CANVAS_RENDERING_CONTEXT_2D_MEASURE_TEXT
canvas()->GetDocument().UpdateStyleAndLayoutTreeForNode(canvas());
const Font& font = AccessFont();
@@ -1,22 +1,12 @@
diff --git a/third_party/blink/renderer/modules/mediastream/media_devices.cc b/third_party/blink/renderer/modules/mediastream/media_devices.cc
index 1fc3e9ae1c57f287fb7badb80b915ba8703c6da4..d8ea07ec461d4ec20d1b5a4650789f141527f577 100644
index 323c7e42421a80803dd9579066e5616ca8ccbe3d..3603281c6ac71aff4dcea032978cfb6e17d3f45a 100644
--- a/third_party/blink/renderer/modules/mediastream/media_devices.cc
+++ b/third_party/blink/renderer/modules/mediastream/media_devices.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/task_type.h"
@@ -76,6 +77,9 @@ ScriptPromise MediaDevices::enumerateDevices(ScriptState* script_state,
@@ -74,6 +74,7 @@ ScriptPromise MediaDevices::enumerateDevices(ScriptState* script_state,
"Current frame is detached.");
return ScriptPromise();
}
+ if (!AllowFingerprinting(frame)) {
+ return ScriptPromise::CastUndefined(script_state);
+ }
+ BRAVE_MEDIA_DEVICES_ENUMERATE_DEVICES
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
@@ -1,39 +1,28 @@
diff --git a/third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc b/third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc
index a8cae56cbe4d78551d394cdea94b73bb1a26f09e..34ff0d6341a79e3617c06d24a7296807c2a0a5be 100644
index a8cae56cbe4d78551d394cdea94b73bb1a26f09e..92b513b1ce9a2f83a2fd3ce8ee6bc3e89bd1088b 100644
--- a/third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc
+++ b/third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc
@@ -9,6 +9,7 @@
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
+#include "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/bindings/modules/v8/webgl_any.h"
@@ -5040,6 +5041,8 @@ ScriptValue WebGL2RenderingContextBase::getParameter(ScriptState* script_state,
@@ -5040,6 +5040,7 @@ ScriptValue WebGL2RenderingContextBase::getParameter(ScriptState* script_state,
GLenum pname) {
if (isContextLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL2_RENDERING_CONTEXT_BASE
switch (pname) {
case GL_SHADING_LANGUAGE_VERSION: {
return WebGLAny(
@@ -5581,6 +5584,8 @@ ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(
@@ -5581,6 +5582,7 @@ ScriptValue WebGL2RenderingContextBase::getFramebufferAttachmentParameter(
if (isContextLost() || !ValidateGetFramebufferAttachmentParameterFunc(
kFunctionName, target, attachment))
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL2_RENDERING_CONTEXT_BASE
WebGLFramebuffer* framebuffer_binding = GetFramebufferBinding(target);
DCHECK(!framebuffer_binding || framebuffer_binding->Object());
@@ -5793,6 +5798,8 @@ ScriptValue WebGL2RenderingContextBase::getTexParameter(
@@ -5793,6 +5795,7 @@ ScriptValue WebGL2RenderingContextBase::getTexParameter(
GLenum pname) {
if (isContextLost() || !ValidateTextureBinding("getTexParameter", target))
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL2_RENDERING_CONTEXT_BASE
switch (pname) {
case GL_TEXTURE_WRAP_R:
@@ -1,80 +1,64 @@
diff --git a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
index 39d00937e8a17183c22dcfc99692aed9a8638ac6..0978c4d44be945e4d600a3844939e50247489796 100644
index 39d00937e8a17183c22dcfc99692aed9a8638ac6..9c595b493d3be1970e79a3fc0af4c55f5581b2dd 100644
--- a/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
+++ b/third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.cc
@@ -31,6 +31,7 @@
#include "base/feature_list.h"
#include "base/numerics/checked_math.h"
#include "base/stl_util.h"
+#include "brave/renderer/brave_content_settings_agent_impl_helper.h"
#include "build/build_config.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gles2_interface.h"
@@ -2836,6 +2837,8 @@ WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(
@@ -2836,6 +2836,7 @@ WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(
GLuint index) {
if (!ValidateWebGLProgramOrShader("getActiveAttrib", program))
return nullptr;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return nullptr;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
GLuint program_id = ObjectNonZero(program);
GLint max_name_length = -1;
ContextGL()->GetProgramiv(program_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH,
@@ -2867,6 +2870,8 @@ WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(
@@ -2867,6 +2868,7 @@ WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(
GLuint index) {
if (!ValidateWebGLProgramOrShader("getActiveUniform", program))
return nullptr;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return nullptr;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
GLuint program_id = ObjectNonZero(program);
GLint max_name_length = -1;
ContextGL()->GetProgramiv(program_id, GL_ACTIVE_UNIFORM_MAX_LENGTH,
@@ -2897,6 +2902,8 @@ base::Optional<HeapVector<Member<WebGLShader>>>
@@ -2897,6 +2899,7 @@ base::Optional<HeapVector<Member<WebGLShader>>>
WebGLRenderingContextBase::getAttachedShaders(WebGLProgram* program) {
if (!ValidateWebGLProgramOrShader("getAttachedShaders", program))
return base::nullopt;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return base::nullopt;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLOPT
HeapVector<Member<WebGLShader>> shader_objects;
const GLenum kShaderType[] = {GL_VERTEX_SHADER, GL_FRAGMENT_SHADER,
@@ -2913,6 +2920,8 @@ GLint WebGLRenderingContextBase::getAttribLocation(WebGLProgram* program,
@@ -2913,6 +2916,7 @@ GLint WebGLRenderingContextBase::getAttribLocation(WebGLProgram* program,
const String& name) {
if (!ValidateWebGLProgramOrShader("getAttribLocation", program))
return -1;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return -1;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_MINUS_ONE
if (!ValidateLocationLength("getAttribLocation", name))
return -1;
if (!ValidateString("getAttribLocation", name))
@@ -2946,6 +2955,8 @@ ScriptValue WebGLRenderingContextBase::getBufferParameter(
@@ -2946,6 +2950,7 @@ ScriptValue WebGLRenderingContextBase::getBufferParameter(
GLenum pname) {
if (isContextLost() || !ValidateBufferTarget("getBufferParameter", target))
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
switch (pname) {
case GL_BUFFER_USAGE: {
@@ -2971,6 +2982,8 @@ WebGLContextAttributes* WebGLRenderingContextBase::getContextAttributes()
@@ -2971,6 +2976,7 @@ WebGLContextAttributes* WebGLRenderingContextBase::getContextAttributes()
const {
if (isContextLost())
return nullptr;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return nullptr;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
WebGLContextAttributes* result =
ToWebGLContextAttributes(CreationAttributes());
@@ -3081,6 +3094,9 @@ ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(
@@ -3081,6 +3087,7 @@ ScriptValue WebGLRenderingContextBase::getFramebufferAttachmentParameter(
target, attachment))
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (!framebuffer_binding_ || !framebuffer_binding_->Object()) {
SynthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParameter",
"no framebuffer bound");
@@ -3373,6 +3389,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* script_state,
@@ -3373,6 +3380,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* script_state,
"invalid parameter name, OES_standard_derivatives not enabled");
return ScriptValue::CreateNull(script_state->GetIsolate());
case WebGLDebugRendererInfo::kUnmaskedRendererWebgl:
@@ -82,7 +66,7 @@ index 39d00937e8a17183c22dcfc99692aed9a8638ac6..0978c4d44be945e4d600a3844939e502
if (ExtensionEnabled(kWebGLDebugRendererInfoName))
return WebGLAny(script_state,
String(ContextGL()->GetString(GL_RENDERER)));
@@ -3381,6 +3398,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* script_state,
@@ -3381,6 +3389,7 @@ ScriptValue WebGLRenderingContextBase::getParameter(ScriptState* script_state,
"invalid parameter name, WEBGL_debug_renderer_info not enabled");
return ScriptValue::CreateNull(script_state->GetIsolate());
case WebGLDebugRendererInfo::kUnmaskedVendorWebgl:
@@ -90,133 +74,115 @@ index 39d00937e8a17183c22dcfc99692aed9a8638ac6..0978c4d44be945e4d600a3844939e502
if (ExtensionEnabled(kWebGLDebugRendererInfoName))
return WebGLAny(script_state,
String(ContextGL()->GetString(GL_VENDOR)));
@@ -3462,10 +3480,11 @@ ScriptValue WebGLRenderingContextBase::getProgramParameter(
@@ -3462,6 +3471,7 @@ ScriptValue WebGLRenderingContextBase::getProgramParameter(
ScriptState* script_state,
WebGLProgram* program,
GLenum pname) {
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (!ValidateWebGLProgramOrShader("getProgramParamter", program)) {
return ScriptValue::CreateNull(script_state->GetIsolate());
}
-
GLint value = 0;
switch (pname) {
case GL_DELETE_STATUS:
@@ -3523,6 +3542,8 @@ ScriptValue WebGLRenderingContextBase::getProgramParameter(
@@ -3523,6 +3533,7 @@ ScriptValue WebGLRenderingContextBase::getProgramParameter(
String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program) {
if (!ValidateWebGLProgramOrShader("getProgramInfoLog", program))
return String();
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return String();
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_STRING
GLStringQuery query(ContextGL());
return query.Run<GLStringQuery::ProgramInfoLog>(ObjectNonZero(program));
}
@@ -3533,6 +3554,8 @@ ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(
@@ -3533,6 +3544,7 @@ ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(
GLenum pname) {
if (isContextLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (target != GL_RENDERBUFFER) {
SynthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter",
"invalid target");
@@ -3578,6 +3601,8 @@ ScriptValue WebGLRenderingContextBase::getShaderParameter(
@@ -3578,6 +3590,7 @@ ScriptValue WebGLRenderingContextBase::getShaderParameter(
ScriptState* script_state,
WebGLShader* shader,
GLenum pname) {
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (!ValidateWebGLProgramOrShader("getShaderParameter", shader)) {
return ScriptValue::CreateNull(script_state->GetIsolate());
}
@@ -3609,6 +3634,8 @@ ScriptValue WebGLRenderingContextBase::getShaderParameter(
@@ -3609,6 +3622,7 @@ ScriptValue WebGLRenderingContextBase::getShaderParameter(
String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader) {
if (!ValidateWebGLProgramOrShader("getShaderInfoLog", shader))
return String();
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return String();
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_STRING
GLStringQuery query(ContextGL());
return query.Run<GLStringQuery::ShaderInfoLog>(ObjectNonZero(shader));
}
@@ -3621,6 +3648,8 @@ WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
@@ -3621,6 +3635,7 @@ WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
if (!ValidateShaderType("getShaderPrecisionFormat", shader_type)) {
return nullptr;
}
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return nullptr;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
switch (precision_type) {
case GL_LOW_FLOAT:
case GL_MEDIUM_FLOAT:
@@ -3646,6 +3675,8 @@ WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
@@ -3646,6 +3661,7 @@ WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
String WebGLRenderingContextBase::getShaderSource(WebGLShader* shader) {
if (!ValidateWebGLProgramOrShader("getShaderSource", shader))
return String();
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return String();
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_STRING
return EnsureNotNull(shader->Source());
}
@@ -3653,6 +3684,8 @@ base::Optional<Vector<String>>
@@ -3653,6 +3669,7 @@ base::Optional<Vector<String>>
WebGLRenderingContextBase::getSupportedExtensions() {
if (isContextLost())
return base::nullopt;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return base::nullopt;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLOPT
Vector<String> result;
@@ -3675,6 +3708,8 @@ ScriptValue WebGLRenderingContextBase::getTexParameter(
@@ -3675,6 +3692,7 @@ ScriptValue WebGLRenderingContextBase::getTexParameter(
GLenum pname) {
if (isContextLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (!ValidateTextureBinding("getTexParameter", target))
return ScriptValue::CreateNull(script_state->GetIsolate());
switch (pname) {
@@ -3709,6 +3744,8 @@ ScriptValue WebGLRenderingContextBase::getUniform(
@@ -3709,6 +3727,7 @@ ScriptValue WebGLRenderingContextBase::getUniform(
const WebGLUniformLocation* uniform_location) {
if (!ValidateWebGLProgramOrShader("getUniform", program))
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
DCHECK(uniform_location);
if (uniform_location->Program() != program) {
SynthesizeGLError(GL_INVALID_OPERATION, "getUniform",
@@ -3989,6 +4026,8 @@ WebGLUniformLocation* WebGLRenderingContextBase::getUniformLocation(
@@ -3989,6 +4008,7 @@ WebGLUniformLocation* WebGLRenderingContextBase::getUniformLocation(
const String& name) {
if (!ValidateWebGLProgramOrShader("getUniformLocation", program))
return nullptr;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return nullptr;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_NULLPTR
if (!ValidateLocationLength("getUniformLocation", name))
return nullptr;
if (!ValidateString("getUniformLocation", name))
@@ -4013,6 +4052,8 @@ ScriptValue WebGLRenderingContextBase::getVertexAttrib(
@@ -4013,6 +4033,7 @@ ScriptValue WebGLRenderingContextBase::getVertexAttrib(
GLenum pname) {
if (isContextLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return ScriptValue::CreateNull(script_state->GetIsolate());
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_SCRIPT_VALUE
if (index >= max_vertex_attribs_) {
SynthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib",
"index out of range");
@@ -4090,6 +4131,8 @@ int64_t WebGLRenderingContextBase::getVertexAttribOffset(GLuint index,
@@ -4090,6 +4111,7 @@ int64_t WebGLRenderingContextBase::getVertexAttribOffset(GLuint index,
GLenum pname) {
if (isContextLost())
return 0;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return 0;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_ZERO
GLvoid* result = nullptr;
// NOTE: If pname is ever a value that returns more than 1 element
// this will corrupt memory.
@@ -4437,6 +4480,8 @@ void WebGLRenderingContextBase::ReadPixelsHelper(GLint x,
@@ -4437,6 +4459,7 @@ void WebGLRenderingContextBase::ReadPixelsHelper(GLint x,
int64_t offset) {
if (isContextLost())
return;
+ if (canvas() && !AllowFingerprinting(canvas()->GetDocument().GetFrame()))
+ return;
+ BRAVE_WEBGL_RENDERING_CONTEXT_BASE_RETURN
// Due to WebGL's same-origin restrictions, it is not possible to
// taint the origin using the WebGL API.
DCHECK(Host()->OriginClean());
+1 -12
View File
@@ -11,21 +11,10 @@ source_set("renderer") {
sources = [
"brave_content_renderer_client.cc",
"brave_content_renderer_client.h",
"brave_content_settings_agent_impl.cc",
"brave_content_settings_agent_impl.h",
]
deps = [
"//base",
"//brave/common",
"//brave/components/brave_shields/common",
"//chrome/common",
"//components/content_settings/core/common",
"//content/public/renderer",
"//mojo/public/cpp/bindings",
"//services/service_manager/public/cpp",
"//brave/components/content_settings/renderer",
"//third_party/blink/public:blink",
"//brave/content:common",
"//url",
]
}
+2 -2
View File
@@ -551,10 +551,10 @@ test("brave_browser_tests") {
"//brave/components/brave_shields/browser/https_everywhere_service_browsertest.cc",
"//brave/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc",
"//brave/components/brave_shields/browser/tracking_protection_service_browsertest.cc",
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_browsertest.cc",
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_flash_browsertest.cc",
"//brave/components/l10n/browser/locale_helper_mock.cc",
"//brave/components/l10n/browser/locale_helper_mock.h",
"//brave/renderer/brave_content_settings_agent_impl_browsertest.cc",
"//brave/renderer/brave_content_settings_agent_impl_flash_browsertest.cc",
"//brave/third_party/blink/renderer/modules/brave/navigator_browsertest.cc",
"//chrome/browser/extensions/browsertest_util.cc",
"//chrome/browser/extensions/browsertest_util.h",