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

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

Issue 2547143002: [Presentation API] fire onconnectionavailable and onconnect event asynchronously (Closed)
Patch Set: fire onconnectionavailable event in ::take() instead of PresentationConnectionCallbacks 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
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..d85c78ed3295bd55e32292428f45aaa5aa47ac23 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,9 +192,11 @@ PresentationConnection* PresentationConnection::take(
PresentationConnection* connection = new PresentationConnection(
controller->frame(), client->getId(), client->getUrl());
controller->registerConnection(connection);
- request->dispatchEvent(PresentationConnectionAvailableEvent::create(
- EventTypeNames::connectionavailable, connection));
-
+ request->getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(
+ &PresentationRequest::dispatchConnectionAvailableEvent,
+ wrapPersistent(request), wrapPersistent(connection)));
return connection;
}
@@ -415,10 +418,10 @@ void PresentationConnection::didChangeState(
NOTREACHED();
return;
case WebPresentationConnectionState::Connected:
- dispatchEvent(Event::create(EventTypeNames::connect));
+ dispatchEventAsync(Event::create(EventTypeNames::connect));
return;
case WebPresentationConnectionState::Terminated:
- dispatchEvent(Event::create(EventTypeNames::terminate));
+ dispatchEventAsync(Event::create(EventTypeNames::terminate));
return;
// Closed state is handled in |didClose()|.
case WebPresentationConnectionState::Closed:
@@ -435,7 +438,7 @@ void PresentationConnection::didClose(
return;
m_state = WebPresentationConnectionState::Closed;
- dispatchEvent(PresentationConnectionCloseEvent::create(
+ dispatchEventAsync(PresentationConnectionCloseEvent::create(
EventTypeNames::close, connectionCloseReasonToString(reason), message));
}
@@ -464,6 +467,17 @@ void PresentationConnection::didFailLoadingBlob(
handleMessageQueue();
}
+void PresentationConnection::dispatchEventAsync(Event* event) {
mark a. foltz 2016/12/07 04:23:55 Can this be combined into dispatchStateChangeEvent
zhaobin 2016/12/07 19:30:43 Not sure how to combine them neatly. postTask expe
mark a. foltz 2016/12/07 21:32:44 Ah, got it. Slight preference to call this method
zhaobin 2016/12/08 00:16:46 Done.
+ getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(&PresentationConnection::dispatchStateChangeEvent,
+ wrapPersistent(this), wrapPersistent(event)));
+}
+
+void PresentationConnection::dispatchStateChangeEvent(Event* event) {
+ dispatchEvent(event);
+}
+
void PresentationConnection::tearDown() {
// Cancel current Blob loading if any.
if (m_blobLoader) {

Powered by Google App Engine
This is Rietveld 408576698