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

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

Issue 2547143002: [Presentation API] fire onconnectionavailable and onconnect event asynchronously (Closed)
Patch Set: resolve code review comments from Mark Created 4 years 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 | « third_party/WebKit/Source/modules/presentation/PresentationConnection.h ('k') | 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/PresentationConnection.cpp
diff --git a/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp b/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
index e7d005333b686f332fb64a173e789ece4d5ca05e..1d26327369b935b219d1d516bde12cae552b33ac 100644
--- a/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
+++ b/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
@@ -9,6 +9,7 @@
#include "core/dom/DOMArrayBufferView.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/ExecutionContextTask.h"
#include "core/events/Event.h"
#include "core/events/MessageEvent.h"
#include "core/fileapi/FileReaderLoader.h"
@@ -191,8 +192,14 @@ PresentationConnection* PresentationConnection::take(
PresentationConnection* connection = new PresentationConnection(
controller->frame(), client->getId(), client->getUrl());
controller->registerConnection(connection);
- request->dispatchEvent(PresentationConnectionAvailableEvent::create(
- EventTypeNames::connectionavailable, connection));
+
+ // Fire onconnectionavailable event asynchronously.
+ auto* event = PresentationConnectionAvailableEvent::create(
+ EventTypeNames::connectionavailable, connection);
+ request->getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(&PresentationConnection::dispatchEventAsync,
+ wrapPersistent(request), wrapPersistent(event)));
return connection;
}
@@ -415,10 +422,10 @@ void PresentationConnection::didChangeState(
NOTREACHED();
return;
case WebPresentationConnectionState::Connected:
- dispatchEvent(Event::create(EventTypeNames::connect));
+ dispatchStateChangeEvent(Event::create(EventTypeNames::connect));
return;
case WebPresentationConnectionState::Terminated:
- dispatchEvent(Event::create(EventTypeNames::terminate));
+ dispatchStateChangeEvent(Event::create(EventTypeNames::terminate));
return;
// Closed state is handled in |didClose()|.
case WebPresentationConnectionState::Closed:
@@ -435,7 +442,7 @@ void PresentationConnection::didClose(
return;
m_state = WebPresentationConnectionState::Closed;
- dispatchEvent(PresentationConnectionCloseEvent::create(
+ dispatchStateChangeEvent(PresentationConnectionCloseEvent::create(
EventTypeNames::close, connectionCloseReasonToString(reason), message));
}
@@ -464,6 +471,21 @@ void PresentationConnection::didFailLoadingBlob(
handleMessageQueue();
}
+void PresentationConnection::dispatchStateChangeEvent(Event* event) {
+ getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(&PresentationConnection::dispatchEventAsync,
+ wrapPersistent(this), wrapPersistent(event)));
+}
+
+// static
+void PresentationConnection::dispatchEventAsync(EventTarget* target,
+ Event* event) {
+ DCHECK(target);
+ DCHECK(event);
+ target->dispatchEvent(event);
+}
+
void PresentationConnection::tearDown() {
// Cancel current Blob loading if any.
if (m_blobLoader) {
« no previous file with comments | « third_party/WebKit/Source/modules/presentation/PresentationConnection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698