Commit 75a3c8f0 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

Instrument media query evaluation for identifiability study.

We would like to see how much entropy is leaked via it.
The approach taken here is to instrument at CSS layer, which means
things that would be defined in CSS and checked via getComputedStyle or
the like get caught, and not just things explicitly Window.matchMedia;
but has the downside of counting purely declarative use that's not
actually actively observed by the page.

Bug: 973801
Change-Id: If762d74c1b6b17ca96533b9040cd31e44fdb06cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2449913
Commit-Queue: Maksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818666}
parent 90f042bd
......@@ -221,6 +221,10 @@ class IdentifiableSurface {
// constraints.
kNavigator_GetUserMedia = 27,
// Represents a media query being tested. Input is combination of property
// name and the target value. Output is the result --- true or false.
kMediaQuery = 28,
// Represents loading a font locally. Input is the PostScript name.
kLocalFontLoadPostScriptName = 29,
......
......@@ -32,6 +32,11 @@
#include "third_party/blink/public/common/css/forced_colors.h"
#include "third_party/blink/public/common/css/navigation_controls.h"
#include "third_party/blink/public/common/css/screen_spanning.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/public/common/privacy_budget/identifiable_surface.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/css_resolution_units.h"
......@@ -53,11 +58,31 @@
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/graphics/color_space_gamut.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/privacy_budget/identifiability_digest_helpers.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "ui/base/pointer/pointer_device.h"
namespace blink {
namespace {
void RecordMediaQueryResult(Document* doc,
const MediaQueryExp& expr,
bool result) {
IdentifiableTokenBuilder input_builder;
input_builder.AddToken(IdentifiabilityBenignStringToken(expr.MediaFeature()));
input_builder.AddToken(
IdentifiabilityBenignStringToken(expr.ExpValue().CssText()));
IdentifiableSurface surface = IdentifiableSurface::FromTypeAndToken(
IdentifiableSurface::Type::kMediaQuery, input_builder.GetToken());
IdentifiabilityMetricBuilder(doc->UkmSourceID())
.Set(surface, result)
.Record(doc->UkmRecorder());
}
} // namespace
enum MediaFeaturePrefix { kMinPrefix, kMaxPrefix, kNoPrefix };
using EvalFunc = bool (*)(const MediaQueryExpValue&,
......@@ -976,8 +1001,17 @@ bool MediaQueryEvaluator::Eval(const MediaQueryExp& expr) const {
// Call the media feature evaluation function. Assume no prefix and let
// trampoline functions override the prefix if prefix is used.
EvalFunc func = g_function_map->at(expr.MediaFeature().Impl());
if (func)
return func(expr.ExpValue(), kNoPrefix, *media_values_);
if (func) {
bool result = func(expr.ExpValue(), kNoPrefix, *media_values_);
Document* doc = nullptr;
if (!skip_ukm_reporting_ && (doc = media_values_->GetDocument()) &&
(IdentifiabilityStudySettings::Get()->IsTypeAllowed(
IdentifiableSurface::Type::kMediaQuery))) {
RecordMediaQueryResult(doc, expr, result);
}
return result;
}
return false;
}
......
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