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 "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 "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
| 11 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionCreateCallback.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 15 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
15 : RenderFrameObserver(render_frame), | 16 : RenderFrameObserver(render_frame), |
16 controller_(nullptr) { | 17 controller_(nullptr) { |
17 } | 18 } |
18 | 19 |
19 PresentationDispatcher::~PresentationDispatcher() { | 20 PresentationDispatcher::~PresentationDispatcher() { |
20 // Controller should be destroyed before the dispatcher when frame is | 21 // Controller should be destroyed before the dispatcher when frame is |
(...skipping 16 matching lines...) Expand all Loading... |
37 if (watched) { | 38 if (watched) { |
38 presentation_service_->GetScreenAvailability( | 39 presentation_service_->GetScreenAvailability( |
39 mojo::String(), | 40 mojo::String(), |
40 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | 41 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, |
41 base::Unretained(this))); | 42 base::Unretained(this))); |
42 } else { | 43 } else { |
43 presentation_service_->OnScreenAvailabilityListenerRemoved(); | 44 presentation_service_->OnScreenAvailabilityListenerRemoved(); |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
| 48 void PresentationDispatcher::startSession( |
| 49 const blink::WebString& presentationUrl, |
| 50 const blink::WebString& presentationId, |
| 51 blink::WebPresentationSessionCreateCallback* callback) { |
| 52 ConnectToPresentationServiceIfNeeded(); |
| 53 presentation_service_->StartSession( |
| 54 presentationUrl.utf8(), |
| 55 presentationId.utf8(), |
| 56 base::Bind(&PresentationDispatcher::OnSessionCreated, |
| 57 base::Unretained(this), |
| 58 base::Unretained(callback))); |
| 59 } |
| 60 |
| 61 void PresentationDispatcher::joinSession( |
| 62 const blink::WebString& presentationUrl, |
| 63 const blink::WebString& presentationId, |
| 64 blink::WebPresentationSessionCreateCallback* callback) { |
| 65 ConnectToPresentationServiceIfNeeded(); |
| 66 presentation_service_->JoinSession( |
| 67 presentationUrl.utf8(), |
| 68 presentationId.utf8(), |
| 69 base::Bind(&PresentationDispatcher::OnSessionCreated, |
| 70 base::Unretained(this), |
| 71 base::Unretained(callback))); |
| 72 } |
| 73 |
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | 74 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
48 if (!controller_) | 75 if (!controller_) |
49 return; | 76 return; |
50 | 77 |
51 // Reset the callback to get the next event. | 78 // Reset the callback to get the next event. |
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | 79 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); |
53 | 80 |
54 controller_->didChangeAvailability(available); | 81 controller_->didChangeAvailability(available); |
55 } | 82 } |
56 | 83 |
| 84 void PresentationDispatcher::OnSessionCreated( |
| 85 blink::WebPresentationSessionCreateCallback* callback, |
| 86 bool success, |
| 87 mojo::InterfaceRequest<presentation::PresentationSession> session_request, |
| 88 const mojo::String& url, |
| 89 const mojo::String& id, |
| 90 const mojo::String& error) { |
| 91 if (!callback) |
| 92 return; |
| 93 if (!success) { |
| 94 callback->onError(blink::WebString::fromUTF8(error)); |
| 95 return; |
| 96 } |
| 97 |
| 98 linked_ptr<PresentationSessionDispatcher> session_dispatcher; |
| 99 session_dispatcher.reset( |
| 100 new PresentationSessionDispatcher(session_request.Pass(), url, id)); |
| 101 presentation_sessions_.push_back(session_dispatcher); |
| 102 callback->onSuccess(session_dispatcher.get()); |
| 103 } |
| 104 |
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 105 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
58 if (presentation_service_.get()) | 106 if (presentation_service_.get()) |
59 return; | 107 return; |
60 | 108 |
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 109 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
62 &presentation_service_); | 110 &presentation_service_); |
63 } | 111 } |
64 | 112 |
65 } // namespace content | 113 } // namespace content |
OLD | NEW |