OLD | NEW |
---|---|
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 "base/logging.h" |
8 #include "content/common/presentation/presentation_service.mojom.h" | 8 #include "content/common/presentation/presentation_service.mojom.h" |
9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); | 52 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); |
53 return url.is_valid() ? url : GURL(); | 53 return url.is_valid() ? url : GURL(); |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 namespace content { | 58 namespace content { |
59 | 59 |
60 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 60 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
61 : RenderFrameObserver(render_frame), | 61 : RenderFrameObserver(render_frame), |
62 controller_(nullptr) { | 62 controller_(nullptr), |
63 binding_(this) { | |
63 } | 64 } |
64 | 65 |
65 PresentationDispatcher::~PresentationDispatcher() { | 66 PresentationDispatcher::~PresentationDispatcher() { |
66 // Controller should be destroyed before the dispatcher when frame is | 67 // Controller should be destroyed before the dispatcher when frame is |
67 // destroyed. | 68 // destroyed. |
68 DCHECK(!controller_); | 69 DCHECK(!controller_); |
69 } | 70 } |
70 | 71 |
71 void PresentationDispatcher::setController( | 72 void PresentationDispatcher::setController( |
72 blink::WebPresentationController* controller) { | 73 blink::WebPresentationController* controller) { |
73 // There shouldn't be any swapping from one non-null controller to another. | 74 // There shouldn't be any swapping from one non-null controller to another. |
74 DCHECK(controller != controller_ && (!controller || !controller_)); | 75 DCHECK(controller != controller_ && (!controller || !controller_)); |
75 controller_ = controller; | 76 controller_ = controller; |
76 // The controller is set to null when the frame is about to be detached. | 77 // The controller is set to null when the frame is about to be detached. |
77 // Nothing is listening for screen availability anymore but the Mojo service | 78 // Nothing is listening for screen availability anymore but the Mojo service |
78 // will know about the frame being detached anyway. | 79 // will know about the frame being detached anyway. |
79 } | 80 } |
80 | 81 |
81 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | 82 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
82 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | |
83 DoUpdateAvailableChangeWatched(presentation_url.spec(), watched); | |
84 } | |
85 | |
86 void PresentationDispatcher::DoUpdateAvailableChangeWatched( | |
87 const std::string& presentation_url, bool watched) { | |
88 ConnectToPresentationServiceIfNeeded(); | 83 ConnectToPresentationServiceIfNeeded(); |
89 if (watched) { | 84 if (watched) { |
90 presentation_service_->ListenForScreenAvailability( | 85 presentation_service_->ListenForScreenAvailability(); |
91 presentation_url, | |
92 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | |
93 base::Unretained(this))); | |
94 } else { | 86 } else { |
whywhat
2015/05/11 17:58:19
nit: don't need the {}
imcheng (use chromium acct)
2015/05/11 22:04:12
Done.
| |
95 presentation_service_->RemoveScreenAvailabilityListener(presentation_url); | 87 presentation_service_->StopListeningForScreenAvailability(); |
96 } | 88 } |
97 } | 89 } |
98 | 90 |
99 void PresentationDispatcher::startSession( | 91 void PresentationDispatcher::startSession( |
100 const blink::WebString& presentationUrl, | 92 const blink::WebString& presentationUrl, |
101 const blink::WebString& presentationId, | 93 const blink::WebString& presentationId, |
102 blink::WebPresentationSessionClientCallbacks* callback) { | 94 blink::WebPresentationSessionClientCallbacks* callback) { |
103 DCHECK(callback); | 95 DCHECK(callback); |
104 ConnectToPresentationServiceIfNeeded(); | 96 ConnectToPresentationServiceIfNeeded(); |
105 | 97 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 135 } |
144 | 136 |
145 void PresentationDispatcher::DidChangeDefaultPresentation() { | 137 void PresentationDispatcher::DidChangeDefaultPresentation() { |
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 138 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
147 | 139 |
148 ConnectToPresentationServiceIfNeeded(); | 140 ConnectToPresentationServiceIfNeeded(); |
149 presentation_service_->SetDefaultPresentationURL( | 141 presentation_service_->SetDefaultPresentationURL( |
150 presentation_url.spec(), mojo::String()); | 142 presentation_url.spec(), mojo::String()); |
151 } | 143 } |
152 | 144 |
153 void PresentationDispatcher::OnScreenAvailabilityChanged( | 145 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
154 const std::string& presentation_url, bool available) { | 146 if (controller_) |
155 if (!controller_) | 147 controller_->didChangeAvailability(available); |
156 return; | |
157 | |
158 // Reset the callback to get the next event. | |
159 DoUpdateAvailableChangeWatched(presentation_url, | |
160 controller_->isAvailableChangeWatched()); | |
161 | |
162 controller_->didChangeAvailability(available); | |
163 } | 148 } |
164 | 149 |
165 void PresentationDispatcher::OnDefaultSessionStarted( | 150 void PresentationDispatcher::OnDefaultSessionStarted( |
166 presentation::PresentationSessionInfoPtr session_info) { | 151 presentation::PresentationSessionInfoPtr session_info) { |
167 if (!controller_) | 152 if (!controller_) |
168 return; | 153 return; |
169 | 154 |
170 // Reset the callback to get the next event. | 155 // Reset the callback to get the next event. |
171 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 156 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
172 &PresentationDispatcher::OnDefaultSessionStarted, | 157 &PresentationDispatcher::OnDefaultSessionStarted, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 218 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
234 base::Unretained(this))); | 219 base::Unretained(this))); |
235 } | 220 } |
236 | 221 |
237 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 222 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
238 if (presentation_service_.get()) | 223 if (presentation_service_.get()) |
239 return; | 224 return; |
240 | 225 |
241 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 226 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
242 &presentation_service_); | 227 &presentation_service_); |
228 presentation::PresentationServiceClientPtr client_ptr; | |
229 binding_.Bind(GetProxy(&client_ptr)); | |
230 presentation_service_->SetClient(client_ptr.Pass()); | |
231 | |
243 // TODO(imcheng): Uncomment these once they are implemented on the browser | 232 // TODO(imcheng): Uncomment these once they are implemented on the browser |
244 // side. (crbug.com/459006) | 233 // side. (crbug.com/459006) |
245 /* | 234 /* |
246 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 235 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
247 &PresentationDispatcher::OnDefaultSessionStarted, | 236 &PresentationDispatcher::OnDefaultSessionStarted, |
248 base::Unretained(this))); | 237 base::Unretained(this))); |
249 presentation_service_->ListenForSessionStateChange(base::Bind( | 238 presentation_service_->ListenForSessionStateChange(base::Bind( |
250 &PresentationDispatcher::OnSessionStateChange, | 239 &PresentationDispatcher::OnSessionStateChange, |
251 base::Unretained(this))); | 240 base::Unretained(this))); |
252 presentation_service_->ListenForSessionMessages( | 241 presentation_service_->ListenForSessionMessages( |
253 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 242 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
254 base::Unretained(this))); | 243 base::Unretained(this))); |
255 */ | 244 */ |
256 } | 245 } |
257 | 246 |
258 } // namespace content | 247 } // namespace content |
OLD | NEW |