Commit 00f30f55 authored by Dylan Cutler's avatar Dylan Cutler Committed by Commit Bot

Instrument scrollbar width computation for identifiability study

Bug: 973801
Change-Id: Ied5726f9add1ed7dbd84dbebf5953cf82e7a5ee4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436650
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815949}
parent 1b4bf96b
...@@ -184,6 +184,11 @@ class IdentifiableSurface { ...@@ -184,6 +184,11 @@ class IdentifiableSurface {
// will key this type on a digest of both the enums' values. // will key this type on a digest of both the enums' values.
kWebGLShaderPrecisionFormat = 16, kWebGLShaderPrecisionFormat = 16,
// A type for recording reads of the offsetWidth and offsetHeight properties
// when we believe it may be trying to detect the size of the scrollbar.
// The input for this surface should be a member of ScrollbarSurfaces.
kScrollbarSize = 17,
// WebGL2RenderingContext.getInternal // WebGL2RenderingContext.getInternal
kWebGLInternalFormatParameter = 18, kWebGLInternalFormatParameter = 18,
...@@ -208,6 +213,13 @@ class IdentifiableSurface { ...@@ -208,6 +213,13 @@ class IdentifiableSurface {
kMax = (1 << kTypeBits) - 1 kMax = (1 << kTypeBits) - 1
}; };
enum class ScrollbarSurface : uint64_t {
kBodyOffsetWidth = 0,
kBodyOffsetHeight = 1,
kElemScrollbarWidth = 2,
kElemScrollbarHeight = 3,
};
// Default constructor is invalid. // Default constructor is invalid.
IdentifiableSurface() : IdentifiableSurface(kInvalidHash) {} IdentifiableSurface() : IdentifiableSurface(kInvalidHash) {}
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "third_party/blink/renderer/core/html/html_element.h" #include "third_party/blink/renderer/core/html/html_element.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/renderer/bindings/core/v8/js_event_handler_for_content_attribute.h" #include "third_party/blink/renderer/bindings/core/v8/js_event_handler_for_content_attribute.h"
#include "third_party/blink/renderer/bindings/core/v8/string_or_trusted_script.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_trusted_script.h"
#include "third_party/blink/renderer/bindings/core/v8/string_treat_null_as_empty_string_or_trusted_script.h" #include "third_party/blink/renderer/bindings/core/v8/string_treat_null_as_empty_string_or_trusted_script.h"
...@@ -51,6 +53,7 @@ ...@@ -51,6 +53,7 @@
#include "third_party/blink/renderer/core/events/keyboard_event.h" #include "third_party/blink/renderer/core/events/keyboard_event.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/deprecation.h" #include "third_party/blink/renderer/core/frame/deprecation.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/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/custom/custom_element.h" #include "third_party/blink/renderer/core/html/custom/custom_element.h"
...@@ -69,10 +72,12 @@ ...@@ -69,10 +72,12 @@
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input_type_names.h" #include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h" #include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h" #include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/mathml_names.h" #include "third_party/blink/renderer/core/mathml_names.h"
#include "third_party/blink/renderer/core/page/spatial_navigation.h" #include "third_party/blink/renderer/core/page/spatial_navigation.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_script.h" #include "third_party/blink/renderer/core/trustedtypes/trusted_script.h"
#include "third_party/blink/renderer/core/xml_names.h" #include "third_party/blink/renderer/core/xml_names.h"
...@@ -1492,17 +1497,81 @@ int HTMLElement::offsetTopForBinding() { ...@@ -1492,17 +1497,81 @@ int HTMLElement::offsetTopForBinding() {
return 0; return 0;
} }
void HTMLElement::RecordScrollbarSizeForStudy(int offset_measurement,
bool is_width) {
if (!IdentifiabilityStudySettings::Get()->IsTypeAllowed(
IdentifiableSurface::Type::kScrollbarSize))
return;
// Check for presence of a scrollbar.
PaintLayerScrollableArea* area;
if (this == GetDocument().ScrollingElementNoLayout()) {
auto* view = GetDocument().View();
if (!view)
return;
area = view->LayoutViewport();
} else {
auto* layout = GetLayoutBox();
if (!layout)
return;
area = layout->GetScrollableArea();
}
if (!area || area->HasOverlayOverflowControls())
return;
Scrollbar* scrollbar =
is_width ? area->VerticalScrollbar() : area->HorizontalScrollbar();
// We intentionally exclude platform overlay scrollbars since their size
// cannot be detected in JavaScript using the methods below.
if (!scrollbar)
return;
IdentifiableSurface::ScrollbarSurface surface;
int scrollbar_size;
// There are two common ways to detect the size of a scrollbar in a DOM
// window. They are:
// 1. Compute the difference of the window.inner[Width|Height] and the
// corresponding document.scrollingElement.offset[Width|Height].
// 2. Any HTML element that insets the layout to fit a scrollbar, so it is
// measurable by a JavaScript program on a site.
if (this == GetDocument().scrollingElement()) {
LocalDOMWindow* dom_window = GetDocument().domWindow();
scrollbar_size =
(is_width ? dom_window->innerWidth() : dom_window->innerHeight()) -
offset_measurement;
surface = is_width
? IdentifiableSurface::ScrollbarSurface::kBodyOffsetWidth
: IdentifiableSurface::ScrollbarSurface::kBodyOffsetHeight;
} else {
scrollbar_size =
offset_measurement - (is_width ? clientWidth() : clientHeight());
surface = is_width
? IdentifiableSurface::ScrollbarSurface::kElemScrollbarWidth
: IdentifiableSurface::ScrollbarSurface::kElemScrollbarHeight;
}
blink::IdentifiabilityMetricBuilder(GetDocument().UkmSourceID())
.Set(blink::IdentifiableSurface::FromTypeAndToken(
blink::IdentifiableSurface::Type::kScrollbarSize, surface),
scrollbar_size)
.Record(GetDocument().UkmRecorder());
}
int HTMLElement::offsetWidthForBinding() { int HTMLElement::offsetWidthForBinding() {
GetDocument().EnsurePaintLocationDataValidForNode( GetDocument().EnsurePaintLocationDataValidForNode(
this, DocumentUpdateReason::kJavaScript); this, DocumentUpdateReason::kJavaScript);
Element* offset_parent = unclosedOffsetParent(); Element* offset_parent = unclosedOffsetParent();
if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) int result = 0;
return AdjustForAbsoluteZoom::AdjustLayoutUnit( if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) {
LayoutUnit( result =
layout_object->PixelSnappedOffsetWidth(offset_parent)), AdjustForAbsoluteZoom::AdjustLayoutUnit(
layout_object->StyleRef()) LayoutUnit(layout_object->PixelSnappedOffsetWidth(offset_parent)),
.Round(); layout_object->StyleRef())
return 0; .Round();
RecordScrollbarSizeForStudy(result, /* isWidth= */ true);
}
return result;
} }
DISABLE_CFI_PERF DISABLE_CFI_PERF
...@@ -1510,13 +1579,16 @@ int HTMLElement::offsetHeightForBinding() { ...@@ -1510,13 +1579,16 @@ int HTMLElement::offsetHeightForBinding() {
GetDocument().EnsurePaintLocationDataValidForNode( GetDocument().EnsurePaintLocationDataValidForNode(
this, DocumentUpdateReason::kJavaScript); this, DocumentUpdateReason::kJavaScript);
Element* offset_parent = unclosedOffsetParent(); Element* offset_parent = unclosedOffsetParent();
if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) int result = 0;
return AdjustForAbsoluteZoom::AdjustLayoutUnit( if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) {
LayoutUnit( result =
layout_object->PixelSnappedOffsetHeight(offset_parent)), AdjustForAbsoluteZoom::AdjustLayoutUnit(
layout_object->StyleRef()) LayoutUnit(layout_object->PixelSnappedOffsetHeight(offset_parent)),
.Round(); layout_object->StyleRef())
return 0; .Round();
RecordScrollbarSizeForStudy(result, /* isWidth= */ false);
}
return result;
} }
Element* HTMLElement::unclosedOffsetParent() { Element* HTMLElement::unclosedOffsetParent() {
......
...@@ -212,6 +212,8 @@ class CORE_EXPORT HTMLElement : public Element { ...@@ -212,6 +212,8 @@ class CORE_EXPORT HTMLElement : public Element {
void HandleKeypressEvent(KeyboardEvent&); void HandleKeypressEvent(KeyboardEvent&);
void RecordScrollbarSizeForStudy(int, bool);
static AttributeTriggers* TriggersForAttributeName( static AttributeTriggers* TriggersForAttributeName(
const QualifiedName& attr_name); const QualifiedName& attr_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment