Skip to content

Commit

Permalink
Add histogram for user activation in async clipboard API.
Browse files Browse the repository at this point in the history
In this change, we are adding a histogram to see if sites are calling
async clipboard APIs without transient user activation. This will
help us determine whether we can make transient user activation a
strict requirement for async APIs regardless of what formats are
being read/written.
This will also help address the below github issue:
w3c/clipboard-apis#75 (comment)

Bug: 106449

Change-Id: I269eb69695a5d41b02db29732bab7144ffcfa8d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650789
Reviewed-by: Austin Sullivan <[email protected]>
Reviewed-by: Stephen Chenney <[email protected]>
Commit-Queue: Anupam Snigdha <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1005514}
NOKEYCHECK=True
GitOrigin-RevId: 88afaabd3ee6e7413e379870c9cd7dba77e3353d
  • Loading branch information
snianu authored and copybara-github committed May 20, 2022
1 parent fc046c5 commit 38fc9c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions blink/renderer/modules/clipboard/clipboard_promise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <utility>

#include "base/metrics/histogram_functions.h"
#include "base/task/single_thread_task_runner.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "third_party/blink/public/common/features.h"
Expand Down Expand Up @@ -554,8 +555,11 @@ void ClipboardPromise::RequestPermission(
return;
}

if (!custom_format_items_.IsEmpty() &&
!LocalFrame::HasTransientUserActivation(GetLocalFrame())) {
bool has_transient_user_activation =
LocalFrame::HasTransientUserActivation(GetLocalFrame());
base::UmaHistogramBoolean("Blink.Clipboard.HasTransientUserActivation",
has_transient_user_activation);
if (!custom_format_items_.IsEmpty() && !has_transient_user_activation) {
script_promise_resolver_->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kSecurityError,
"Must be handling a user gesture to use custom clipboard"));
Expand Down

0 comments on commit 38fc9c6

Please sign in to comment.