[Clipboard API] Remove user gesture requirement for read/writeText.

Adding user gesture requirement for readText and writeText APIs
breaks NTP doodle sharing. We are relaxing this check for now, but
we should fix this for sites to not rely on these APIs to be called
without a user gesture.
See NewTabPageDoodleShareDialogFocusTest.All test for more details.

Bug: 106449, 1334203

Change-Id: I42ace345ab7f3a227f8214d582916a963d753f4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3688846
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Anupam Snigdha <snianu@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1011495}
diff --git a/third_party/blink/renderer/modules/clipboard/clipboard_promise.cc b/third_party/blink/renderer/modules/clipboard/clipboard_promise.cc
index d398e4b..ac3150f 100644
--- a/third_party/blink/renderer/modules/clipboard/clipboard_promise.cc
+++ b/third_party/blink/renderer/modules/clipboard/clipboard_promise.cc
@@ -537,7 +537,13 @@
       LocalFrame::HasTransientUserActivation(GetLocalFrame());
   base::UmaHistogramBoolean("Blink.Clipboard.HasTransientUserActivation",
                             has_transient_user_activation);
-  if (RuntimeEnabledFeatures::ClipboardCustomFormatsEnabled() &&
+  // `allow_without_sanitization` is true only when we are trying to read/write
+  // web custom formats.
+  // TODO(crbug.com/1334203): Remove the `allow_without_sanitization` check.
+  // Currently NTP relies on readText & writeText to be called without any user
+  // gesture.
+  if (allow_without_sanitization &&
+      RuntimeEnabledFeatures::ClipboardCustomFormatsEnabled() &&
       !has_transient_user_activation) {
     script_promise_resolver_->Reject(MakeGarbageCollected<DOMException>(
         DOMExceptionCode::kSecurityError,