Commit 922b91cd authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Async Clipboard: Move repeated check into a function

- no logic changes, just cleaning up code

Change-Id: I3bb1943d3160a3e2007c86b9c6d0b1b5b05fc586
Reviewed-on: https://chromium-review.googlesource.com/c/1474290
Auto-Submit: Darwin Huang <huangdarwin@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632421}
parent d7b31658
...@@ -110,6 +110,7 @@ PermissionService* ClipboardPromise::GetPermissionService() { ...@@ -110,6 +110,7 @@ PermissionService* ClipboardPromise::GetPermissionService() {
bool ClipboardPromise::IsFocusedDocument(ExecutionContext* context) { bool ClipboardPromise::IsFocusedDocument(ExecutionContext* context) {
DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker);
DCHECK(context->IsSecureContext()); // [SecureContext] in IDL
Document* doc = To<Document>(context); Document* doc = To<Document>(context);
return doc && doc->hasFocus(); return doc && doc->hasFocus();
} }
...@@ -119,10 +120,7 @@ void ClipboardPromise::RequestReadPermission( ...@@ -119,10 +120,7 @@ void ClipboardPromise::RequestReadPermission(
DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker);
DCHECK(script_promise_resolver_); DCHECK(script_promise_resolver_);
ExecutionContext* context = ExecutionContext::From(script_state_); if (!IsFocusedDocument(ExecutionContext::From(script_state_))) {
DCHECK(context->IsSecureContext()); // [SecureContext] in IDL
if (!IsFocusedDocument(context)) {
script_promise_resolver_->Reject(DOMException::Create( script_promise_resolver_->Reject(DOMException::Create(
DOMExceptionCode::kNotAllowedError, "Document is not focused.")); DOMExceptionCode::kNotAllowedError, "Document is not focused."));
return; return;
...@@ -147,10 +145,7 @@ void ClipboardPromise::CheckWritePermission( ...@@ -147,10 +145,7 @@ void ClipboardPromise::CheckWritePermission(
DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(async_clipboard_sequence_checker);
DCHECK(script_promise_resolver_); DCHECK(script_promise_resolver_);
ExecutionContext* context = ExecutionContext::From(script_state_); if (!IsFocusedDocument(ExecutionContext::From(script_state_))) {
DCHECK(context->IsSecureContext()); // [SecureContext] in IDL
if (!IsFocusedDocument(context)) {
script_promise_resolver_->Reject(DOMException::Create( script_promise_resolver_->Reject(DOMException::Create(
DOMExceptionCode::kNotAllowedError, "Document is not focused.")); DOMExceptionCode::kNotAllowedError, "Document is not focused."));
return; return;
......
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