Commit 3b38e72c authored by cfredric's avatar cfredric Committed by Commit Bot

Add UKM collection for HTMLCanvas readbacks and RenderingContext creations.

Bug: 973801
Change-Id: Ifa3c3e2a26187b0b813a5984e7ad75b97f9ba53c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2173394
Commit-Queue: Chris Fredrickson <cfredric@google.com>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766557}
parent 53bf4dfb
......@@ -42,6 +42,10 @@ class IdentifiableSurface {
// Input is a mojom::WebFeature
kWebFeature = 1,
// Represents a readback of a canvas. Input is the
// CanvasRenderingContextType.
kCanvasReadback = 2,
// We can use values up to and including |kMax|.
kMax = 0xff
};
......
......@@ -2618,6 +2618,7 @@ enum WebFeature {
kV8HTMLVideoElement_CancelVideoFrameCallback_Method = 3281,
kRubyElementWithDisplayBlock = 3282,
kLocationFragmentDirectiveAccessed = 3283,
kCanvasRenderingContext = 3284,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -79,6 +79,12 @@ class CORE_EXPORT CanvasRenderingContextHost : public CanvasResourceHost,
virtual void Commit(scoped_refptr<CanvasResource> canvas_resource,
const SkIRect& damage_rect);
// For deferred canvases this will have the side effect of drawing recorded
// commands in order to finalize the frame.
virtual ScriptPromise convertToBlob(ScriptState*,
const ImageEncodeOptions*,
ExceptionState&);
bool IsPaintable() const;
// Required by template functions in WebGLRenderingContextBase
......@@ -96,12 +102,6 @@ class CORE_EXPORT CanvasRenderingContextHost : public CanvasResourceHost,
bool Is2d() const;
CanvasColorParams ColorParams() const;
// For deferred canvases this will have the side effect of drawing recorded
// commands in order to finalize the frame.
ScriptPromise convertToBlob(ScriptState*,
const ImageEncodeOptions*,
ExceptionState&);
// blink::CanvasImageSource
bool IsOffscreenCanvas() const override;
......
......@@ -38,7 +38,10 @@
#include "base/metrics/histogram_macros.h"
#include "base/numerics/checked_math.h"
#include "build/build_config.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_metrics.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/resources/grit/blink_image_resources.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
......@@ -55,6 +58,7 @@
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_async_blob_creator.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_draw_listener.h"
......@@ -249,6 +253,15 @@ void HTMLCanvasElement::RegisterRenderingContextFactory(
RenderingContextFactories()[type] = std::move(rendering_context_factory);
}
void HTMLCanvasElement::RecordIdentifiabilityMetric(
const blink::IdentifiableSurface& surface,
int64_t value) const {
blink::IdentifiabilityMetricBuilder(
base::UkmSourceId::FromInt64(GetDocument().UkmSourceID()))
.Set(surface, value)
.Record(GetDocument().UkmRecorder());
}
CanvasRenderingContext* HTMLCanvasElement::GetCanvasRenderingContext(
const String& type,
const CanvasContextCreationAttributesCore& attributes) {
......@@ -271,8 +284,14 @@ CanvasRenderingContext* HTMLCanvasElement::GetCanvasRenderingContextInternal(
}
// Log the aliased context type used.
if (!context_)
if (!context_) {
RecordIdentifiabilityMetric(
blink::IdentifiableSurface::FromTypeAndInput(
blink::IdentifiableSurface::Type::kWebFeature,
static_cast<uint64_t>(blink::WebFeature::kCanvasRenderingContext)),
blink::IdentifiabilityDigestHelper(context_type));
UMA_HISTOGRAM_ENUMERATION("Blink.Canvas.ContextType", context_type);
}
context_type =
CanvasRenderingContext::ResolveContextTypeAliases(context_type);
......@@ -354,6 +373,20 @@ CanvasRenderingContext* HTMLCanvasElement::GetCanvasRenderingContextInternal(
return context_.Get();
}
ScriptPromise HTMLCanvasElement::convertToBlob(
ScriptState* script_state,
const ImageEncodeOptions* options,
ExceptionState& exception_state) {
RecordIdentifiabilityMetric(
blink::IdentifiableSurface::FromTypeAndInput(
blink::IdentifiableSurface::Type::kCanvasReadback,
context_ ? context_->GetContextType()
: CanvasRenderingContext::kContextTypeUnknown),
0);
return CanvasRenderingContextHost::convertToBlob(script_state, options,
exception_state);
}
bool HTMLCanvasElement::ShouldBeDirectComposited() const {
return (context_ && context_->IsComposited()) || (!!surface_layer_bridge_);
}
......@@ -925,6 +958,12 @@ String HTMLCanvasElement::ToDataURLInternal(
// Currently we only support three encoding types.
NOTREACHED();
}
RecordIdentifiabilityMetric(
blink::IdentifiableSurface::FromTypeAndInput(
blink::IdentifiableSurface::Type::kCanvasReadback,
context_ ? context_->GetContextType()
: CanvasRenderingContext::kContextTypeUnknown),
0);
return data_url;
}
......@@ -991,6 +1030,13 @@ void HTMLCanvasElement::toBlob(V8BlobCallback* callback,
GetExecutionContext());
}
RecordIdentifiabilityMetric(
blink::IdentifiableSurface::FromTypeAndInput(
blink::IdentifiableSurface::Type::kCanvasReadback,
context_ ? context_->GetContextType()
: CanvasRenderingContext::kContextTypeUnknown),
0);
if (async_creator) {
async_creator->ScheduleAsyncBlobCreation(quality);
} else {
......
......@@ -32,6 +32,7 @@
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_blob_callback.h"
#include "third_party/blink/renderer/core/core_export.h"
......@@ -289,6 +290,10 @@ class CORE_EXPORT HTMLCanvasElement final
context_creation_was_blocked_ = true;
}
ScriptPromise convertToBlob(ScriptState*,
const ImageEncodeOptions*,
ExceptionState&) override;
bool NeedsUnbufferedInputEvents() const { return needs_unbuffered_input_; }
void SetNeedsUnbufferedInputEvents(bool value) {
......@@ -314,6 +319,9 @@ class CORE_EXPORT HTMLCanvasElement final
private:
void Dispose();
void RecordIdentifiabilityMetric(const blink::IdentifiableSurface& surface,
int64_t value) const;
void PaintInternal(GraphicsContext&, const PhysicalRect&);
using ContextFactoryVector =
......
......@@ -27198,6 +27198,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3281" label="V8HTMLVideoElement_CancelVideoFrameCallback_Method"/>
<int value="3282" label="RubyElementWithDisplayBlock"/>
<int value="3283" label="LocationFragmentDirectiveAccessed"/>
<int value="3284" label="CanvasRenderingContext"/>
</enum>
<enum name="FeaturePolicyAllowlistType">
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