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..869d607afb6717f4442888b72525ed5c89cb51a5 100644 |
--- a/content/renderer/presentation/presentation_dispatcher.cc |
+++ b/content/renderer/presentation/presentation_dispatcher.cc |
@@ -7,7 +7,29 @@ |
#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 +66,34 @@ void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
} |
} |
+void PresentationDispatcher::startSession( |
+ const blink::WebString& presentationUrl, |
+ const blink::WebString& presentationId, |
+ blink::WebPresentationSessionClientCallbacks* callback) { |
+ DCHECK(callback); |
+ ConnectToPresentationServiceIfNeeded(); |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
nit: add an empty line, they don't cost anything a
whywhat
2015/02/27 19:15:53
Done.
|
+ presentation_service_->StartSession( |
+ presentationUrl.utf8(), |
+ presentationId.utf8(), |
+ base::Bind(&PresentationDispatcher::OnSessionCreated, |
+ base::Unretained(this), |
+ base::Owned(callback))); |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
Could you have a comment explaining why using base
whywhat
2015/02/27 19:15:53
Done.
whywhat
2015/02/27 19:15:53
Done.
|
+} |
+ |
+void PresentationDispatcher::joinSession( |
+ const blink::WebString& presentationUrl, |
+ const blink::WebString& presentationId, |
+ blink::WebPresentationSessionClientCallbacks* callback) { |
+ DCHECK(callback); |
+ ConnectToPresentationServiceIfNeeded(); |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
ditto
whywhat
2015/02/27 19:15:53
Done.
|
+ presentation_service_->JoinSession( |
+ presentationUrl.utf8(), |
+ presentationId.utf8(), |
+ base::Bind(&PresentationDispatcher::OnSessionCreated, |
+ base::Unretained(this), |
+ base::Owned(callback))); |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
ditto
whywhat
2015/02/27 19:15:53
Done.
|
+} |
+ |
void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
if (!controller_) |
return; |
@@ -54,6 +104,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; |