Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement canvas blocking v2 #5541

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3,9 +3,18 @@
* 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 "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"

#define BRAVE_IS_POINT_IN_PATH \
LocalDOMWindow* window = LocalDOMWindow::From(script_state); \
if (window && !AllowFingerprinting(window->GetFrame())) { \
return false; \
}

#define BRAVE_IS_POINT_IN_STROKE BRAVE_IS_POINT_IN_PATH

#define BRAVE_GET_IMAGE_DATA \
LocalDOMWindow* window = LocalDOMWindow::From(script_state); \
if (window) { \
@@ -1,16 +1,60 @@
diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc b/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
index 9ce2506096723d04b7aab6267d5c452cfe0424e8..87fafafc4cdad52cfe5cc9f62e78950358778cf2 100644
index 9ce2506096723d04b7aab6267d5c452cfe0424e8..ccd60f85467462435e1d04e43041a89940fcd360 100644
--- a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
+++ b/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
@@ -1545,6 +1545,7 @@ ImageData* BaseRenderingContext2D::createImageData(
@@ -779,16 +779,20 @@ void BaseRenderingContext2D::clip(Path2D* dom_path,
ClipInternal(dom_path->GetPath(), winding_rule_string);
}

-bool BaseRenderingContext2D::isPointInPath(const double x,
+bool BaseRenderingContext2D::isPointInPath(ScriptState* script_state,
+ const double x,
const double y,
const String& winding_rule_string) {
+ BRAVE_IS_POINT_IN_PATH
return IsPointInPathInternal(path_, x, y, winding_rule_string);
}

-bool BaseRenderingContext2D::isPointInPath(Path2D* dom_path,
+bool BaseRenderingContext2D::isPointInPath(ScriptState* script_state,
+ Path2D* dom_path,
const double x,
const double y,
const String& winding_rule_string) {
+ BRAVE_IS_POINT_IN_PATH
return IsPointInPathInternal(dom_path->GetPath(), x, y, winding_rule_string);
}

@@ -813,13 +817,18 @@ bool BaseRenderingContext2D::IsPointInPathInternal(
SkFillTypeToWindRule(ParseWinding(winding_rule_string)));
}

-bool BaseRenderingContext2D::isPointInStroke(const double x, const double y) {
+bool BaseRenderingContext2D::isPointInStroke(ScriptState* script_state,
+ const double x,
+ const double y) {
+ BRAVE_IS_POINT_IN_STROKE
return IsPointInStrokeInternal(path_, x, y);
}

-bool BaseRenderingContext2D::isPointInStroke(Path2D* dom_path,
+bool BaseRenderingContext2D::isPointInStroke(ScriptState* script_state,
+ Path2D* dom_path,
const double x,
const double y) {
+ BRAVE_IS_POINT_IN_STROKE
return IsPointInStrokeInternal(dom_path->GetPath(), x, y);
}

@@ -1545,6 +1554,7 @@ ImageData* BaseRenderingContext2D::createImageData(
}

ImageData* BaseRenderingContext2D::getImageData(
+ ScriptState* script_state,
int sx,
int sy,
int sw,
@@ -1624,6 +1625,7 @@ ImageData* BaseRenderingContext2D::getImageData(
@@ -1624,6 +1634,7 @@ ImageData* BaseRenderingContext2D::getImageData(
return nullptr;
}

@@ -1,8 +1,30 @@
diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h b/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h
index a823b929d4c0f492eaca09bd07beccd9bbb60f7c..8f4fc6ec9bedebf278a3d29cb18d6ce54f842bc3 100644
index a823b929d4c0f492eaca09bd07beccd9bbb60f7c..0e80f7777ac506eb0cd044268d556f2e9ec34b6b 100644
--- a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h
+++ b/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h
@@ -195,7 +195,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
@@ -108,15 +108,17 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
void clip(const String& winding = "nonzero");
void clip(Path2D*, const String& winding = "nonzero");

- bool isPointInPath(const double x,
+ bool isPointInPath(ScriptState*,
+ const double x,
const double y,
const String& winding = "nonzero");
- bool isPointInPath(Path2D*,
+ bool isPointInPath(ScriptState*,
+ Path2D*,
const double x,
const double y,
const String& winding = "nonzero");
- bool isPointInStroke(const double x, const double y);
- bool isPointInStroke(Path2D*, const double x, const double y);
+ bool isPointInStroke(ScriptState*, const double x, const double y);
+ bool isPointInStroke(ScriptState*, Path2D*, const double x, const double y);

void clearRect(double x, double y, double width, double height);
void fillRect(double x, double y, double width, double height);
@@ -195,7 +197,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,

// For deferred canvases this will have the side effect of drawing recorded
// commands in order to finalize the frame
@@ -1,7 +1,22 @@
diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.idl b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.idl
index b4b6ae1e108614dfb2e20eb51922cd98efdd6ae5..321bdc99bf9eb74e9fdc64634ff17f5e9d0ea459 100644
index b4b6ae1e108614dfb2e20eb51922cd98efdd6ae5..b9b3600b901a6373e0895ccb8519b58982766623 100644
--- a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.idl
+++ b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.idl
@@ -103,10 +103,10 @@ interface CanvasRenderingContext2D {
[RuntimeEnabled=Canvas2dScrollPathIntoView] void scrollPathIntoView(optional Path2D path);
void clip(optional CanvasFillRule winding);
void clip(Path2D path, optional CanvasFillRule winding);
- boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInStroke(unrestricted double x, unrestricted double y);
- boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// text (see also the CanvasDrawingStyles interface)
void fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
@@ -126,7 +126,7 @@ interface CanvasRenderingContext2D {
// pixel manipulation
[RaisesException] ImageData createImageData(ImageData imagedata);
@@ -1,7 +1,22 @@
diff --git a/third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.idl b/third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.idl
index 4371777bcd68c6e334d12a0ba5fd38874cdbdd49..657e9eee13c50f92b11cf5c77aee825c3a561bac 100644
index 4371777bcd68c6e334d12a0ba5fd38874cdbdd49..c6cb08969bd211ef1eed06f1fc9d5d74a210f1a4 100644
--- a/third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.idl
+++ b/third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.idl
@@ -62,10 +62,10 @@
void stroke(Path2D path);
void clip(optional CanvasFillRule winding);
void clip(Path2D path, optional CanvasFillRule winding);
- [HighEntropy, MeasureAs=OffscreenCanvasIsPointInPath] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- [HighEntropy, MeasureAs=OffscreenCanvasIsPointInPath] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- [HighEntropy, MeasureAs=OffscreenCanvasIsPointInStroke] boolean isPointInStroke(unrestricted double x, unrestricted double y);
- [HighEntropy, MeasureAs=OffscreenCanvasIsPointInStroke] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasIsPointInPath] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasIsPointInPath] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasIsPointInStroke] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasIsPointInStroke] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// text (see also the CanvasDrawingStyles interface)
void fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
@@ -80,7 +80,7 @@
// pixel manipulation
[RaisesException] ImageData createImageData(ImageData imagedata);
@@ -0,0 +1,19 @@
diff --git a/third_party/blink/renderer/modules/csspaint/paint_rendering_context_2d.idl b/third_party/blink/renderer/modules/csspaint/paint_rendering_context_2d.idl
index 94d6d46580570a81e0baf12dc042262ccc84899a..b23ce72df411e63a17a2d2508a735ec127a4bd04 100644
--- a/third_party/blink/renderer/modules/csspaint/paint_rendering_context_2d.idl
+++ b/third_party/blink/renderer/modules/csspaint/paint_rendering_context_2d.idl
@@ -58,10 +58,10 @@

void clip(optional CanvasFillRule winding);
void clip(Path2D path, optional CanvasFillRule winding);
- [HighEntropy, Measure] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- [HighEntropy, Measure] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- [HighEntropy, Measure] boolean isPointInStroke(unrestricted double x, unrestricted double y);
- [HighEntropy, Measure] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState, HighEntropy, Measure] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState, HighEntropy, Measure] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState, HighEntropy, Measure] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState, HighEntropy, Measure] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// drawing images
[CallWith=ScriptState, RaisesException] void drawImage(CanvasImageSource image, unrestricted double x, unrestricted double y);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.