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

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: Fixed the last round of comments 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 "base/logging.h"
7 #include "content/common/presentation/presentation_service.mojom.h" 8 #include "content/common/presentation/presentation_service.mojom.h"
8 #include "content/public/common/service_registry.h" 9 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
11 #include "content/renderer/presentation/presentation_session_client.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
15
16 namespace {
17
18 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
19 presentation::PresentationErrorType mojoErrorType) {
20 switch (mojoErrorType) {
21 case presentation::PRESENTATION_ERROR_TYPE_NO_AVAILABLE_SCREENS:
22 return blink::WebPresentationError::ErrorTypeNoAvailableScreens;
23 case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED:
24 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled;
25 case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND:
26 return blink::WebPresentationError::ErrorTypeNoPresentationFound;
27 case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN:
28 default:
29 return blink::WebPresentationError::ErrorTypeUnknown;
30 }
31 }
32
33 } // namespace
11 34
12 namespace content { 35 namespace content {
13 36
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) 37 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
15 : RenderFrameObserver(render_frame), 38 : RenderFrameObserver(render_frame),
16 controller_(nullptr) { 39 controller_(nullptr) {
17 } 40 }
18 41
19 PresentationDispatcher::~PresentationDispatcher() { 42 PresentationDispatcher::~PresentationDispatcher() {
20 // Controller should be destroyed before the dispatcher when frame is 43 // Controller should be destroyed before the dispatcher when frame is
(...skipping 16 matching lines...) Expand all
37 if (watched) { 60 if (watched) {
38 presentation_service_->GetScreenAvailability( 61 presentation_service_->GetScreenAvailability(
39 mojo::String(), 62 mojo::String(),
40 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, 63 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged,
41 base::Unretained(this))); 64 base::Unretained(this)));
42 } else { 65 } else {
43 presentation_service_->OnScreenAvailabilityListenerRemoved(); 66 presentation_service_->OnScreenAvailabilityListenerRemoved();
44 } 67 }
45 } 68 }
46 69
70 void PresentationDispatcher::startSession(
71 const blink::WebString& presentationUrl,
72 const blink::WebString& presentationId,
73 blink::WebPresentationSessionClientCallbacks* callback) {
74 DCHECK(callback);
75 ConnectToPresentationServiceIfNeeded();
76
77 // The dispatcher owns the service so |this| will be valid when
78 // OnSessionCreated() is called. |callback| needs to be alive and also needs
79 // to be destroyed so we transfer its ownership to the mojo callback.
80 presentation_service_->StartSession(
81 presentationUrl.utf8(),
82 presentationId.utf8(),
83 base::Bind(&PresentationDispatcher::OnSessionCreated,
84 base::Unretained(this),
85 base::Owned(callback)));
86 }
87
88 void PresentationDispatcher::joinSession(
89 const blink::WebString& presentationUrl,
90 const blink::WebString& presentationId,
91 blink::WebPresentationSessionClientCallbacks* callback) {
92 DCHECK(callback);
93 ConnectToPresentationServiceIfNeeded();
94
95 // The dispatcher owns the service so |this| will be valid when
96 // OnSessionCreated() is called. |callback| needs to be alive and also needs
97 // to be destroyed so we transfer its ownership to the mojo callback.
98 presentation_service_->JoinSession(
99 presentationUrl.utf8(),
100 presentationId.utf8(),
101 base::Bind(&PresentationDispatcher::OnSessionCreated,
102 base::Unretained(this),
103 base::Owned(callback)));
104 }
105
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { 106 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) {
48 if (!controller_) 107 if (!controller_)
49 return; 108 return;
50 109
51 // Reset the callback to get the next event. 110 // Reset the callback to get the next event.
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); 111 updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
53 112
54 controller_->didChangeAvailability(available); 113 controller_->didChangeAvailability(available);
55 } 114 }
56 115
116 void PresentationDispatcher::OnSessionCreated(
117 blink::WebPresentationSessionClientCallbacks* callback,
118 presentation::PresentationSessionInfoPtr session_info,
119 presentation::PresentationErrorPtr error) {
120 DCHECK(callback);
121 if (!error.is_null()) {
122 DCHECK(session_info.is_null());
123 callback->onError(new blink::WebPresentationError(
124 GetWebPresentationErrorTypeFromMojo(error->errorType),
125 blink::WebString::fromUTF8(error->message)));
126 return;
127 }
128
129 DCHECK(!session_info.is_null());
130 PresentationSessionDispatcher* session_dispatcher =
131 new PresentationSessionDispatcher(session_info.Pass());
132 presentation_session_dispatchers_.push_back(session_dispatcher);
133 callback->onSuccess(new PresentationSessionClient(session_dispatcher));
134 }
135
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { 136 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
58 if (presentation_service_.get()) 137 if (presentation_service_.get())
59 return; 138 return;
60 139
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 140 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
62 &presentation_service_); 141 &presentation_service_);
63 } 142 }
64 143
65 } // namespace content 144 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | content/renderer/presentation/presentation_session_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698