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 "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 Loading... | |
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 DCHECK(callback); | |
74 ConnectToPresentationServiceIfNeeded(); | |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
nit: add an empty line, they don't cost anything a
whywhat
2015/02/27 19:15:53
Done.
| |
75 presentation_service_->StartSession( | |
76 presentationUrl.utf8(), | |
77 presentationId.utf8(), | |
78 base::Bind(&PresentationDispatcher::OnSessionCreated, | |
79 base::Unretained(this), | |
80 base::Owned(callback))); | |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
Could you have a comment explaining why using base
whywhat
2015/02/27 19:15:53
Done.
whywhat
2015/02/27 19:15:53
Done.
| |
81 } | |
82 | |
83 void PresentationDispatcher::joinSession( | |
84 const blink::WebString& presentationUrl, | |
85 const blink::WebString& presentationId, | |
86 blink::WebPresentationSessionClientCallbacks* callback) { | |
87 DCHECK(callback); | |
88 ConnectToPresentationServiceIfNeeded(); | |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
ditto
whywhat
2015/02/27 19:15:53
Done.
| |
89 presentation_service_->JoinSession( | |
90 presentationUrl.utf8(), | |
91 presentationId.utf8(), | |
92 base::Bind(&PresentationDispatcher::OnSessionCreated, | |
93 base::Unretained(this), | |
94 base::Owned(callback))); | |
mlamouri (slow - plz ping)
2015/02/27 18:41:51
ditto
whywhat
2015/02/27 19:15:53
Done.
| |
95 } | |
96 | |
47 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | 97 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { |
48 if (!controller_) | 98 if (!controller_) |
49 return; | 99 return; |
50 | 100 |
51 // Reset the callback to get the next event. | 101 // Reset the callback to get the next event. |
52 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | 102 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); |
53 | 103 |
54 controller_->didChangeAvailability(available); | 104 controller_->didChangeAvailability(available); |
55 } | 105 } |
56 | 106 |
107 void PresentationDispatcher::OnSessionCreated( | |
108 blink::WebPresentationSessionClientCallbacks* callback, | |
109 presentation::PresentationSessionInfoPtr session_info, | |
110 presentation::PresentationErrorPtr error) { | |
111 DCHECK(callback); | |
112 if (!error.is_null()) { | |
113 DCHECK(session_info.is_null()); | |
114 callback->onError(new blink::WebPresentationError( | |
115 GetWebPresentationErrorTypeFromMojo(error->errorType), | |
116 blink::WebString::fromUTF8(error->message))); | |
117 return; | |
118 } | |
119 | |
120 DCHECK(!session_info.is_null()); | |
121 PresentationSessionDispatcher* session_dispatcher = | |
122 new PresentationSessionDispatcher(session_info.Pass()); | |
123 presentation_session_dispatchers_.push_back(session_dispatcher); | |
124 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); | |
125 } | |
126 | |
57 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 127 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
58 if (presentation_service_.get()) | 128 if (presentation_service_.get()) |
59 return; | 129 return; |
60 | 130 |
61 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 131 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
62 &presentation_service_); | 132 &presentation_service_); |
63 } | 133 } |
64 | 134 |
65 } // namespace content | 135 } // namespace content |
OLD | NEW |