Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Unified Diff: third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp

Issue 2178463002: Presentation API: clean up around usage of promises. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp
diff --git a/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp b/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp
index 9daf2ae742fe7167e7482fe20232817438dd31b5..0d4e18917acdd6e123c8b3ffe71292316811d0d5 100644
--- a/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp
+++ b/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp
@@ -91,67 +91,50 @@ bool PresentationRequest::hasPendingActivity() const
ScriptPromise PresentationRequest::start(ScriptState* scriptState)
{
- ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
- ScriptPromise promise = resolver->promise();
-
Settings* contextSettings = settings(getExecutionContext());
bool isUserGestureRequired = !contextSettings || contextSettings->presentationRequiresUserGesture();
- if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) {
- resolver->reject(DOMException::create(InvalidAccessError, "PresentationRequest::start() requires user gesture."));
- return promise;
- }
+ if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture())
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidAccessError, "PresentationRequest::start() requires user gesture."));
- if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
- resolver->reject(DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
- return promise;
- }
+ if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation))
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
WebPresentationClient* client = presentationClient(getExecutionContext());
- if (!client) {
- resolver->reject(DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame."));
- return promise;
- }
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame."));
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
client->startSession(m_url.getString(), new PresentationConnectionCallbacks(resolver, this));
- return promise;
+ return resolver->promise();
}
ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const String& id)
{
- ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
- ScriptPromise promise = resolver->promise();
-
- if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
- resolver->reject(DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
- return promise;
- }
+ if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation))
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
WebPresentationClient* client = presentationClient(getExecutionContext());
- if (!client) {
- resolver->reject(DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame."));
- return promise;
- }
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame."));
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
client->joinSession(m_url.getString(), id, new PresentationConnectionCallbacks(resolver, this));
- return promise;
+ return resolver->promise();
}
ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState)
{
- ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
- ScriptPromise promise = resolver->promise();
-
- if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) {
- resolver->reject(DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
- return promise;
- }
+ if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation))
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-presentation' flag."));
WebPresentationClient* client = presentationClient(getExecutionContext());
- if (!client) {
- resolver->reject(DOMException::create(InvalidStateError, "The object is no longer associated to a frame."));
- return promise;
- }
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame."));
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
client->getAvailability(m_url.getString(), new PresentationAvailabilityCallbacks(resolver, m_url));
- return promise;
+ return resolver->promise();
}
const KURL& PresentationRequest::url() const
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698