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 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
28 #include "content/public/common/frame_navigate_params.h" | 28 #include "content/public/common/frame_navigate_params.h" |
29 #include "mojo/public/cpp/bindings/binding.h" | 29 #include "mojo/public/cpp/bindings/binding.h" |
30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 | 34 |
35 struct FrameNavigateParams; | 35 struct FrameNavigateParams; |
36 struct LoadCommittedDetails; | 36 struct LoadCommittedDetails; |
37 struct PresentationSessionMessage; | 37 struct PresentationConnectionMessage; |
38 class RenderFrameHost; | 38 class RenderFrameHost; |
39 | 39 |
40 // Implementation of Mojo PresentationService. | 40 // Implementation of Mojo PresentationService. |
41 // It handles Presentation API requests coming from Blink / renderer process | 41 // It handles Presentation API requests coming from Blink / renderer process |
42 // and delegates the requests to the embedder's media router via | 42 // and delegates the requests to the embedder's media router via |
43 // PresentationServiceDelegate. | 43 // PresentationServiceDelegate. |
44 // An instance of this class tied to a RenderFrameHost and listens to events | 44 // An instance of this class tied to a RenderFrameHost and listens to events |
45 // related to the RFH via implementing WebContentsObserver. | 45 // related to the RFH via implementing WebContentsObserver. |
46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService | 46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService |
47 // from the renderer when the first presentation API request is handled. | 47 // from the renderer when the first presentation API request is handled. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 SetSameDefaultPresentationUrls); | 79 SetSameDefaultPresentationUrls); |
80 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 80 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
81 ClearDefaultPresentationUrls); | 81 ClearDefaultPresentationUrls); |
82 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 82 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
83 ListenForDefaultSessionStart); | 83 ListenForDefaultSessionStart); |
84 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 84 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
85 ListenForDefaultSessionStartAfterSet); | 85 ListenForDefaultSessionStartAfterSet); |
86 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 86 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
87 DefaultSessionStartReset); | 87 DefaultSessionStartReset); |
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
89 ReceiveSessionMessagesAfterReset); | 89 ReceiveConnectionMessagesAfterReset); |
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
91 MaxPendingStartSessionRequests); | 91 MaxPendingStartSessionRequests); |
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
93 MaxPendingJoinSessionRequests); | 93 MaxPendingJoinSessionRequests); |
94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
95 ListenForConnectionStateChangeAndChangeState); | 95 ListenForConnectionStateChangeAndChangeState); |
96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
97 ListenForConnectionClose); | 97 ListenForConnectionClose); |
98 | 98 |
99 // Maximum number of pending JoinSession requests at any given time. | 99 // Maximum number of pending JoinSession requests at any given time. |
100 static const int kMaxNumQueuedSessionRequests = 10; | 100 static const int kMaxNumQueuedSessionRequests = 10; |
101 | 101 |
102 using SessionMessagesCallback = | 102 using ConnectionMessagesCallback = |
103 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; | 103 base::Callback<void(mojo::Array<blink::mojom::ConnectionMessagePtr>)>; |
104 using SendSessionMessageCallback = base::Callback<void(bool)>; | 104 using SendConnectionMessageCallback = base::Callback<void(bool)>; |
105 | 105 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 106 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 107 // this is created when PresentationRequest.getAvailability() is resolved. |
108 // The instance receives screen availability results from the embedder and | 108 // The instance receives screen availability results from the embedder and |
109 // propagates results back to PresentationServiceImpl. | 109 // propagates results back to PresentationServiceImpl. |
110 class CONTENT_EXPORT ScreenAvailabilityListenerImpl | 110 class CONTENT_EXPORT ScreenAvailabilityListenerImpl |
111 : public PresentationScreenAvailabilityListener { | 111 : public PresentationScreenAvailabilityListener { |
112 public: | 112 public: |
113 ScreenAvailabilityListenerImpl(const GURL& availability_url, | 113 ScreenAvailabilityListenerImpl(const GURL& availability_url, |
114 PresentationServiceImpl* service); | 114 PresentationServiceImpl* service); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void SetDefaultPresentationUrls( | 154 void SetDefaultPresentationUrls( |
155 const std::vector<GURL>& presentation_urls) override; | 155 const std::vector<GURL>& presentation_urls) override; |
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; | 156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; |
157 void ListenForScreenAvailability(const GURL& url) override; | 157 void ListenForScreenAvailability(const GURL& url) override; |
158 void StopListeningForScreenAvailability(const GURL& url) override; | 158 void StopListeningForScreenAvailability(const GURL& url) override; |
159 void StartSession(const std::vector<GURL>& presentation_urls, | 159 void StartSession(const std::vector<GURL>& presentation_urls, |
160 const NewSessionCallback& callback) override; | 160 const NewSessionCallback& callback) override; |
161 void JoinSession(const std::vector<GURL>& presentation_urls, | 161 void JoinSession(const std::vector<GURL>& presentation_urls, |
162 const base::Optional<std::string>& presentation_id, | 162 const base::Optional<std::string>& presentation_id, |
163 const NewSessionCallback& callback) override; | 163 const NewSessionCallback& callback) override; |
164 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, | 164 void SendConnectionMessage( |
165 blink::mojom::SessionMessagePtr session_message, | 165 blink::mojom::PresentationSessionInfoPtr session_info, |
166 const SendSessionMessageCallback& callback) override; | 166 blink::mojom::ConnectionMessagePtr connection_message, |
| 167 const SendConnectionMessageCallback& callback) override; |
167 void CloseConnection(const GURL& presentation_url, | 168 void CloseConnection(const GURL& presentation_url, |
168 const std::string& presentation_id) override; | 169 const std::string& presentation_id) override; |
169 void Terminate(const GURL& presentation_url, | 170 void Terminate(const GURL& presentation_url, |
170 const std::string& presentation_id) override; | 171 const std::string& presentation_id) override; |
171 void ListenForSessionMessages( | 172 void ListenForConnectionMessages( |
172 blink::mojom::PresentationSessionInfoPtr session) override; | 173 blink::mojom::PresentationSessionInfoPtr session) override; |
173 | 174 |
174 // Creates a binding between this object and |request|. | 175 // Creates a binding between this object and |request|. |
175 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 176 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
176 | 177 |
177 // WebContentsObserver override. | 178 // WebContentsObserver override. |
178 void DidNavigateAnyFrame( | 179 void DidNavigateAnyFrame( |
179 content::RenderFrameHost* render_frame_host, | 180 content::RenderFrameHost* render_frame_host, |
180 const content::LoadCommittedDetails& details, | 181 const content::LoadCommittedDetails& details, |
181 const content::FrameNavigateParams& params) override; | 182 const content::FrameNavigateParams& params) override; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 void OnSendMessageCallback(bool sent); | 223 void OnSendMessageCallback(bool sent); |
223 | 224 |
224 // Calls to |delegate_| to start listening for state changes for |connection|. | 225 // Calls to |delegate_| to start listening for state changes for |connection|. |
225 // State changes will be returned via |OnConnectionStateChanged|. Change | 226 // State changes will be returned via |OnConnectionStateChanged|. Change |
226 // |connection|'s state to 'connected' after listening. | 227 // |connection|'s state to 'connected' after listening. |
227 void ListenForConnectionStateChangeAndChangeState( | 228 void ListenForConnectionStateChangeAndChangeState( |
228 const PresentationSessionInfo& connection); | 229 const PresentationSessionInfo& connection); |
229 | 230 |
230 // Passed to embedder's implementation of PresentationServiceDelegate for | 231 // Passed to embedder's implementation of PresentationServiceDelegate for |
231 // later invocation when session messages arrive. | 232 // later invocation when session messages arrive. |
232 void OnSessionMessages( | 233 void OnConnectionMessages( |
233 const content::PresentationSessionInfo& session, | 234 const content::PresentationSessionInfo& session, |
234 const ScopedVector<PresentationSessionMessage>& messages, | 235 const ScopedVector<PresentationConnectionMessage>& messages, |
235 bool pass_ownership); | 236 bool pass_ownership); |
236 | 237 |
237 // Associates a JoinSession |callback| with a unique request ID and | 238 // Associates a JoinSession |callback| with a unique request ID and |
238 // stores it in a map. | 239 // stores it in a map. |
239 // Returns a positive value on success. | 240 // Returns a positive value on success. |
240 int RegisterJoinSessionCallback(const NewSessionCallback& callback); | 241 int RegisterJoinSessionCallback(const NewSessionCallback& callback); |
241 | 242 |
242 // Invoked by the embedder's PresentationServiceDelegate when a | 243 // Invoked by the embedder's PresentationServiceDelegate when a |
243 // PresentationConnection's state has changed. | 244 // PresentationConnection's state has changed. |
244 void OnConnectionStateChanged( | 245 void OnConnectionStateChanged( |
(...skipping 24 matching lines...) Expand all Loading... |
269 | 270 |
270 // For JoinSession requests. | 271 // For JoinSession requests. |
271 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>> | 272 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>> |
272 pending_join_session_cbs_; | 273 pending_join_session_cbs_; |
273 | 274 |
274 // RAII binding of |this| to an Presentation interface request. | 275 // RAII binding of |this| to an Presentation interface request. |
275 // The binding is removed when binding_ is cleared or goes out of scope. | 276 // The binding is removed when binding_ is cleared or goes out of scope. |
276 std::unique_ptr<mojo::Binding<blink::mojom::PresentationService>> binding_; | 277 std::unique_ptr<mojo::Binding<blink::mojom::PresentationService>> binding_; |
277 | 278 |
278 // There can be only one send message request at a time. | 279 // There can be only one send message request at a time. |
279 std::unique_ptr<SendSessionMessageCallback> send_message_callback_; | 280 std::unique_ptr<SendConnectionMessageCallback> send_message_callback_; |
280 | 281 |
281 std::unique_ptr<SessionMessagesCallback> on_session_messages_callback_; | 282 std::unique_ptr<ConnectionMessagesCallback> on_connection_messages_callback_; |
282 | 283 |
283 // ID of the RenderFrameHost this object is associated with. | 284 // ID of the RenderFrameHost this object is associated with. |
284 int render_process_id_; | 285 int render_process_id_; |
285 int render_frame_id_; | 286 int render_frame_id_; |
286 | 287 |
287 // NOTE: Weak pointers must be invalidated before all other member variables. | 288 // NOTE: Weak pointers must be invalidated before all other member variables. |
288 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 289 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
289 | 290 |
290 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 291 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
291 }; | 292 }; |
292 | 293 |
293 } // namespace content | 294 } // namespace content |
294 | 295 |
295 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 296 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |