Commit 24ac5100 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

screen orientation: Use ScriptPromise::RejectWithDOMException().

No functional changes; simplify the code by using the function above rather
than manually creating a ScriptPromiseResolver, a ScriptPromise and then
passing a DOMException to the ScriptPromise.

Change-Id: I65a266dfd95f7d03b5b06cd6ca4fdd85aff67df3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1878069
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710033}
parent 53f852a7
......@@ -149,28 +149,25 @@ void ScreenOrientation::SetAngle(uint16_t angle) {
ScriptPromise ScreenOrientation::lock(ScriptState* state,
const AtomicString& lock_string) {
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(state);
ScriptPromise promise = resolver->Promise();
Document* document = GetFrame() ? GetFrame()->GetDocument() : nullptr;
if (!document || !Controller()) {
auto* exception = MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError,
"The object is no longer associated to a document.");
resolver->Reject(exception);
return promise;
return ScriptPromise::RejectWithDOMException(
state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError,
"The object is no longer associated to a document."));
}
if (document->IsSandboxed(WebSandboxFlags::kOrientationLock)) {
auto* exception = MakeGarbageCollected<DOMException>(
DOMExceptionCode::kSecurityError,
"The document is sandboxed and lacks the "
"'allow-orientation-lock' flag.");
resolver->Reject(exception);
return promise;
return ScriptPromise::RejectWithDOMException(
state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kSecurityError,
"The document is sandboxed and lacks the "
"'allow-orientation-lock' flag."));
}
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(state);
ScriptPromise promise = resolver->Promise();
Controller()->lock(StringToOrientationLock(lock_string),
std::make_unique<LockOrientationCallback>(resolver));
return promise;
......
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