Skip to content

Commit

Permalink
Implement canvas blocking v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgrim-brave committed May 13, 2020
1 parent 2058be0 commit 80e54a8
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 80e54a8

Please sign in to comment.