Index: content/renderer/presentation/presentation_dispatcher.cc |
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc |
index 04b44eca6fe231e3e98c363f1f4b64339ad4ec8f..88236345a26ab374f4a9fdc7ca6ee917ba8fb7b5 100644 |
--- a/content/renderer/presentation/presentation_dispatcher.cc |
+++ b/content/renderer/presentation/presentation_dispatcher.cc |
@@ -4,10 +4,33 @@ |
#include "content/renderer/presentation/presentation_dispatcher.h" |
+#include "base/logging.h" |
#include "content/common/presentation/presentation_service.mojom.h" |
#include "content/public/common/service_registry.h" |
#include "content/public/renderer/render_frame.h" |
+#include "content/renderer/presentation/presentation_session_client.h" |
+#include "third_party/WebKit/public/platform/WebString.h" |
#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h" |
+#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationError.h" |
+ |
+namespace { |
+ |
+blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( |
+ presentation::PresentationErrorType mojoErrorType) { |
+ switch (mojoErrorType) { |
+ case presentation::PRESENTATION_ERROR_TYPE_NO_AVAILABLE_SCREENS: |
+ return blink::WebPresentationError::ErrorTypeNoAvailableScreens; |
+ case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED: |
+ return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; |
+ case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND: |
+ return blink::WebPresentationError::ErrorTypeNoPresentationFound; |
+ case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN: |
+ default: |
+ return blink::WebPresentationError::ErrorTypeUnknown; |
+ } |
+} |
+ |
+} // namespace |
namespace content { |
@@ -44,6 +67,42 @@ void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
} |
} |
+void PresentationDispatcher::startSession( |
+ const blink::WebString& presentationUrl, |
+ const blink::WebString& presentationId, |
+ blink::WebPresentationSessionClientCallbacks* callback) { |
+ DCHECK(callback); |
+ ConnectToPresentationServiceIfNeeded(); |
+ |
+ // The dispatcher owns the service so |this| will be valid when |
+ // OnSessionCreated() is called. |callback| needs to be alive and also needs |
+ // to be destroyed so we transfer its ownership to the mojo callback. |
+ presentation_service_->StartSession( |
+ presentationUrl.utf8(), |
+ presentationId.utf8(), |
+ base::Bind(&PresentationDispatcher::OnSessionCreated, |
+ base::Unretained(this), |
+ base::Owned(callback))); |
+} |
+ |
+void PresentationDispatcher::joinSession( |
+ const blink::WebString& presentationUrl, |
+ const blink::WebString& presentationId, |
+ blink::WebPresentationSessionClientCallbacks* callback) { |
+ DCHECK(callback); |
+ ConnectToPresentationServiceIfNeeded(); |
+ |
+ // The dispatcher owns the service so |this| will be valid when |
+ // OnSessionCreated() is called. |callback| needs to be alive and also needs |
+ // to be destroyed so we transfer its ownership to the mojo callback. |
+ presentation_service_->JoinSession( |
+ presentationUrl.utf8(), |
+ presentationId.utf8(), |
+ base::Bind(&PresentationDispatcher::OnSessionCreated, |
+ base::Unretained(this), |
+ base::Owned(callback))); |
+} |
+ |
void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
if (!controller_) |
return; |
@@ -54,6 +113,26 @@ void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
controller_->didChangeAvailability(available); |
} |
+void PresentationDispatcher::OnSessionCreated( |
+ blink::WebPresentationSessionClientCallbacks* callback, |
+ presentation::PresentationSessionInfoPtr session_info, |
+ presentation::PresentationErrorPtr error) { |
+ DCHECK(callback); |
+ if (!error.is_null()) { |
+ DCHECK(session_info.is_null()); |
+ callback->onError(new blink::WebPresentationError( |
+ GetWebPresentationErrorTypeFromMojo(error->errorType), |
+ blink::WebString::fromUTF8(error->message))); |
+ return; |
+ } |
+ |
+ DCHECK(!session_info.is_null()); |
+ PresentationSessionDispatcher* session_dispatcher = |
+ new PresentationSessionDispatcher(session_info.Pass()); |
+ presentation_session_dispatchers_.push_back(session_dispatcher); |
+ callback->onSuccess(new PresentationSessionClient(session_dispatcher)); |
+} |
+ |
void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
if (presentation_service_.get()) |
return; |