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 nError.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::WebPresentationSessionClientCallbacks* 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))); | |
mlamouri (slow - plz ping)
2015/02/23 14:07:39
base::Owned(callback)
whywhat
2015/02/25 14:12:41
Done. Actually atm the callback owns/deletes itsel
| |
59 } | |
60 | |
61 void PresentationDispatcher::joinSession( | |
62 const blink::WebString& presentationUrl, | |
63 const blink::WebString& presentationId, | |
64 blink::WebPresentationSessionClientCallbacks* 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))); | |
mlamouri (slow - plz ping)
2015/02/23 14:07:39
ditto
whywhat
2015/02/25 14:12:41
Done.
| |
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::WebPresentationSessionClientCallbacks* callback, | |
86 presentation::PresentationSessionInfoPtr session_info, | |
87 presentation::PresentationErrorPtr error) { | |
88 if (!callback) | |
89 return; | |
90 if (!error.is_null()) { | |
91 DCHECK(session_info.is_null()); | |
92 callback->onError(new blink::WebPresentationError( | |
93 error->errorCode, | |
mlamouri (slow - plz ping)
2015/02/23 14:07:39
You will need a switch to go from PresentationServ
whywhat
2015/02/25 14:12:41
Done.
| |
94 blink::WebString::fromUTF8(error->message))); | |
95 return; | |
96 } | |
97 | |
98 DCHECK(!session_info.is_null()); | |
99 PresentationSessionDispatcher* session_dispatcher = | |
100 new PresentationSessionDispatcher(session_info.Pass()); | |
101 presentation_sessions_.push_back(session_dispatcher); | |
102 callback->onSuccess(session_dispatcher); | |
mlamouri (slow - plz ping)
2015/02/23 14:07:39
PresentationDispatcher owns the callback. Please d
whywhat
2015/02/25 14:12:41
As I understand, it will be deleted automatically
| |
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 |