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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 935083002: [PresentationAPI] Implementing start/joinSession from WebPresentationClient to PresentationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full change Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/presentation/presentation_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include "content/common/presentation/presentation_service.mojom.h" 7 #include "content/common/presentation/presentation_service.mojom.h"
8 #include "content/public/common/service_registry.h" 8 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h" 9 #include "content/public/renderer/render_frame.h"
10 #include "content/renderer/presentation/presentation_session_client.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
14
15 namespace {
16
17 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
18 presentation::PresentationErrorType mojoErrorType) {
19 switch (mojoErrorType) {
20 case presentation::PRESENTATION_ERROR_TYPE_NO_AVAILABLE_SCREENS:
21 return blink::WebPresentationError::ErrorTypeNoAvailableScreens;
22 case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED:
23 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled;
24 case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND:
25 return blink::WebPresentationError::ErrorTypeNoPresentationFound;
26 case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN:
27 default:
28 return blink::WebPresentationError::ErrorTypeUnknown;
29 }
30 }
31
32 } // namespace
11 33
12 namespace content { 34 namespace content {
13 35
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) 36 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
15 : RenderFrameObserver(render_frame), 37 : RenderFrameObserver(render_frame),
16 controller_(nullptr) { 38 controller_(nullptr) {
17 } 39 }
18 40
19 PresentationDispatcher::~PresentationDispatcher() { 41 PresentationDispatcher::~PresentationDispatcher() {
20 // Controller should be destroyed before the dispatcher when frame is 42 // Controller should be destroyed before the dispatcher when frame is
(...skipping 16 matching lines...) Expand all
37 if (watched) { 59 if (watched) {
38 presentation_service_->GetScreenAvailability( 60 presentation_service_->GetScreenAvailability(
39 mojo::String(), 61 mojo::String(),
40 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, 62 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged,
41 base::Unretained(this))); 63 base::Unretained(this)));
42 } else { 64 } else {
43 presentation_service_->OnScreenAvailabilityListenerRemoved(); 65 presentation_service_->OnScreenAvailabilityListenerRemoved();
44 } 66 }
45 } 67 }
46 68
69 void PresentationDispatcher::startSession(
70 const blink::WebString& presentationUrl,
71 const blink::WebString& presentationId,
72 blink::WebPresentationSessionClientCallbacks* callback) {
73 ConnectToPresentationServiceIfNeeded();
74 presentation_service_->StartSession(
75 presentationUrl.utf8(),
76 presentationId.utf8(),
77 base::Bind(&PresentationDispatcher::OnSessionCreated,
78 base::Unretained(this),
79 base::Owned(callback)));
80 }
81
82 void PresentationDispatcher::joinSession(
83 const blink::WebString& presentationUrl,
84 const blink::WebString& presentationId,
85 blink::WebPresentationSessionClientCallbacks* callback) {
86 ConnectToPresentationServiceIfNeeded();
87 presentation_service_->JoinSession(
mlamouri (slow - plz ping) 2015/02/26 22:24:26 You don't have to apply that change but I wonder i
whywhat 2015/02/27 14:44:45 Would look a little better but then you can't real
88 presentationUrl.utf8(),
89 presentationId.utf8(),
90 base::Bind(&PresentationDispatcher::OnSessionCreated,
91 base::Unretained(this),
92 base::Owned(callback)));
93 }
94
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { 95 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
48 if (!controller_) 96 if (!controller_)
49 return; 97 return;
50 98
51 // Reset the callback to get the next event. 99 // Reset the callback to get the next event.
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); 100 updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
53 101
54 controller_->didChangeAvailability(available); 102 controller_->didChangeAvailability(available);
55 } 103 }
56 104
105 void PresentationDispatcher::OnSessionCreated(
106 blink::WebPresentationSessionClientCallbacks* callback,
107 presentation::PresentationSessionInfoPtr session_info,
108 presentation::PresentationErrorPtr error) {
109 if (!callback)
110 return;
mlamouri (slow - plz ping) 2015/02/26 22:24:26 How could that happen? If it's not expected, pleas
whywhat 2015/02/27 14:44:45 Done.
111 if (!error.is_null()) {
112 DCHECK(session_info.is_null());
113 callback->onError(new blink::WebPresentationError(
114 GetWebPresentationErrorTypeFromMojo(error->errorType),
115 blink::WebString::fromUTF8(error->message)));
116 return;
117 }
118
119 DCHECK(!session_info.is_null());
120 PresentationSessionDispatcher* session_dispatcher =
121 new PresentationSessionDispatcher(session_info.Pass());
122 presentation_sessions_.push_back(session_dispatcher);
123 callback->onSuccess(new PresentationSessionClient(session_dispatcher));
124 }
125
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { 126 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
58 if (presentation_service_.get()) 127 if (presentation_service_.get())
59 return; 128 return;
60 129
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 130 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
62 &presentation_service_); 131 &presentation_service_);
63 } 132 }
64 133
65 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698