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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
89 ReceiveSessionMessagesAfterReset); | 89 ReceiveSessionMessagesAfterReset); |
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 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | |
99 SetPresentationConnection); | |
100 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | |
101 ReceiverPresentationServiceDelegate); | |
98 | 102 |
99 // Maximum number of pending JoinSession requests at any given time. | 103 // Maximum number of pending JoinSession requests at any given time. |
100 static const int kMaxNumQueuedSessionRequests = 10; | 104 static const int kMaxNumQueuedSessionRequests = 10; |
101 | 105 |
102 using SessionMessagesCallback = | 106 using SessionMessagesCallback = |
103 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; | 107 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; |
104 using SendSessionMessageCallback = base::Callback<void(bool)>; | 108 using SendSessionMessageCallback = base::Callback<void(bool)>; |
105 | 109 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 110 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 111 // this is created when PresentationRequest.getAvailability() is resolved. |
(...skipping 28 matching lines...) Expand all Loading... | |
136 blink::mojom::PresentationErrorPtr error); | 140 blink::mojom::PresentationErrorPtr error); |
137 | 141 |
138 private: | 142 private: |
139 NewSessionCallback callback_; | 143 NewSessionCallback callback_; |
140 | 144 |
141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); | 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); |
142 }; | 146 }; |
143 | 147 |
144 // |render_frame_host|: The RFH this instance is associated with. | 148 // |render_frame_host|: The RFH this instance is associated with. |
145 // |web_contents|: The WebContents to observe. | 149 // |web_contents|: The WebContents to observe. |
146 // |delegate|: Where Presentation API requests are delegated to. Not owned | 150 // |controller_delegate|: Where Presentation API requests are delegated to in |
151 // controller frame. Set to null if current frame is receiver frame. Not owned | |
mark a. foltz
2016/12/02 22:09:05
nit: s/null/nullptr/ here and below
zhaobin
2016/12/03 00:34:26
Done.
| |
152 // by this class. | |
153 // |receiver_delegate|: Where Presentation API requests are delegated to in | |
154 // receiver frame. Set to null if current frame is controller frame. Not owned | |
147 // by this class. | 155 // by this class. |
148 PresentationServiceImpl( | 156 PresentationServiceImpl( |
149 RenderFrameHost* render_frame_host, | 157 RenderFrameHost* render_frame_host, |
150 WebContents* web_contents, | 158 WebContents* web_contents, |
151 PresentationServiceDelegate* delegate); | 159 ControllerPresentationServiceDelegate* controller_delegate, |
160 ReceiverPresentationServiceDelegate* receiver_delegate); | |
152 | 161 |
153 // PresentationService implementation. | 162 // PresentationService implementation. |
154 void SetDefaultPresentationUrls( | 163 void SetDefaultPresentationUrls( |
155 const std::vector<GURL>& presentation_urls) override; | 164 const std::vector<GURL>& presentation_urls) override; |
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; | 165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; |
157 void ListenForScreenAvailability(const GURL& url) override; | 166 void ListenForScreenAvailability(const GURL& url) override; |
158 void StopListeningForScreenAvailability(const GURL& url) override; | 167 void StopListeningForScreenAvailability(const GURL& url) override; |
159 void StartSession(const std::vector<GURL>& presentation_urls, | 168 void StartSession(const std::vector<GURL>& presentation_urls, |
160 const NewSessionCallback& callback) override; | 169 const NewSessionCallback& callback) override; |
161 void JoinSession(const std::vector<GURL>& presentation_urls, | 170 void JoinSession(const std::vector<GURL>& presentation_urls, |
162 const base::Optional<std::string>& presentation_id, | 171 const base::Optional<std::string>& presentation_id, |
163 const NewSessionCallback& callback) override; | 172 const NewSessionCallback& callback) override; |
164 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, | 173 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, |
165 blink::mojom::SessionMessagePtr session_message, | 174 blink::mojom::SessionMessagePtr session_message, |
166 const SendSessionMessageCallback& callback) override; | 175 const SendSessionMessageCallback& callback) override; |
167 void CloseConnection(const GURL& presentation_url, | 176 void CloseConnection(const GURL& presentation_url, |
168 const std::string& presentation_id) override; | 177 const std::string& presentation_id) override; |
169 void Terminate(const GURL& presentation_url, | 178 void Terminate(const GURL& presentation_url, |
170 const std::string& presentation_id) override; | 179 const std::string& presentation_id) override; |
171 void ListenForSessionMessages( | 180 void ListenForSessionMessages( |
172 blink::mojom::PresentationSessionInfoPtr session) override; | 181 blink::mojom::PresentationSessionInfoPtr session) override; |
182 void SetPresentationConnection( | |
183 blink::mojom::PresentationSessionInfoPtr session, | |
184 blink::mojom::PresentationConnectionPtr connection) override; | |
173 | 185 |
174 // Creates a binding between this object and |request|. | 186 // Creates a binding between this object and |request|. |
175 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 187 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
176 | 188 |
177 // WebContentsObserver override. | 189 // WebContentsObserver override. |
178 void DidNavigateAnyFrame( | 190 void DidNavigateAnyFrame( |
179 content::RenderFrameHost* render_frame_host, | 191 content::RenderFrameHost* render_frame_host, |
180 const content::LoadCommittedDetails& details, | 192 const content::LoadCommittedDetails& details, |
181 const content::FrameNavigateParams& params) override; | 193 const content::FrameNavigateParams& params) override; |
182 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 194 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 int request_session_id, | 232 int request_session_id, |
221 const PresentationError& error); | 233 const PresentationError& error); |
222 void OnSendMessageCallback(bool sent); | 234 void OnSendMessageCallback(bool sent); |
223 | 235 |
224 // Calls to |delegate_| to start listening for state changes for |connection|. | 236 // Calls to |delegate_| to start listening for state changes for |connection|. |
225 // State changes will be returned via |OnConnectionStateChanged|. Change | 237 // State changes will be returned via |OnConnectionStateChanged|. Change |
226 // |connection|'s state to 'connected' after listening. | 238 // |connection|'s state to 'connected' after listening. |
227 void ListenForConnectionStateChangeAndChangeState( | 239 void ListenForConnectionStateChangeAndChangeState( |
228 const PresentationSessionInfo& connection); | 240 const PresentationSessionInfo& connection); |
229 | 241 |
230 // Passed to embedder's implementation of PresentationServiceDelegate for | |
231 // later invocation when session messages arrive. | |
232 void OnSessionMessages( | 242 void OnSessionMessages( |
233 const content::PresentationSessionInfo& session, | 243 const content::PresentationSessionInfo& session, |
234 const ScopedVector<PresentationSessionMessage>& messages, | 244 const ScopedVector<PresentationSessionMessage>& messages, |
235 bool pass_ownership); | 245 bool pass_ownership); |
236 | 246 |
247 // A callback registered to OffscreenPresentationManager when | |
248 // the PresentationServiceImpl for the presentation receiver is initialized. | |
249 // Calls |client_| to create a new PresentationConnection on receiver page. | |
250 void OnReceiverConnectionAvailable( | |
251 const content::PresentationSessionInfo& session_info, | |
252 PresentationConnectionPtr controller_connection); | |
253 | |
237 // Associates a JoinSession |callback| with a unique request ID and | 254 // Associates a JoinSession |callback| with a unique request ID and |
238 // stores it in a map. | 255 // stores it in a map. |
239 // Returns a positive value on success. | 256 // Returns a positive value on success. |
240 int RegisterJoinSessionCallback(const NewSessionCallback& callback); | 257 int RegisterJoinSessionCallback(const NewSessionCallback& callback); |
241 | 258 |
242 // Invoked by the embedder's PresentationServiceDelegate when a | 259 // Invoked by the embedder's PresentationServiceDelegate when a |
243 // PresentationConnection's state has changed. | 260 // PresentationConnection's state has changed. |
244 void OnConnectionStateChanged( | 261 void OnConnectionStateChanged( |
245 const PresentationSessionInfo& connection, | 262 const PresentationSessionInfo& connection, |
246 const PresentationConnectionStateChangeInfo& info); | 263 const PresentationConnectionStateChangeInfo& info); |
247 | 264 |
248 // Returns true if this object is associated with |render_frame_host|. | 265 // Returns true if this object is associated with |render_frame_host|. |
249 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; | 266 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; |
250 | 267 |
251 // Embedder-specific delegate to forward Presentation requests to. | 268 // Returns |controller_delegate| if current frame is controller frame; Returns |
252 // May be null if embedder does not support Presentation API. | 269 // |receiver_delegate| if current frame is receiver frame. |
253 PresentationServiceDelegate* delegate_; | 270 PresentationServiceDelegate* GetPresentationServiceDelegate(); |
271 | |
272 // Embedder-specific delegate for controller to forward Presentation requests | |
273 // to. Must be nullptr if current page is receiver page or | |
274 // embedder does not support Presentation API . | |
275 ControllerPresentationServiceDelegate* controller_delegate_; | |
276 | |
277 // Embedder-specific delegate for receiver to forward Presentation requests | |
278 // to. Must be nullptr if current page is receiver page or | |
279 // embedder does not support Presentation API. | |
280 ReceiverPresentationServiceDelegate* receiver_delegate_; | |
254 | 281 |
255 // Proxy to the PresentationServiceClient to send results (e.g., screen | 282 // Proxy to the PresentationServiceClient to send results (e.g., screen |
256 // availability) to. | 283 // availability) to. |
257 blink::mojom::PresentationServiceClientPtr client_; | 284 blink::mojom::PresentationServiceClientPtr client_; |
258 | 285 |
259 std::vector<GURL> default_presentation_urls_; | 286 std::vector<GURL> default_presentation_urls_; |
260 | 287 |
261 using ScreenAvailabilityListenerMap = | 288 using ScreenAvailabilityListenerMap = |
262 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; | 289 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; |
263 ScreenAvailabilityListenerMap screen_availability_listeners_; | 290 ScreenAvailabilityListenerMap screen_availability_listeners_; |
(...skipping 22 matching lines...) Expand all Loading... | |
286 | 313 |
287 // NOTE: Weak pointers must be invalidated before all other member variables. | 314 // NOTE: Weak pointers must be invalidated before all other member variables. |
288 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 315 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
289 | 316 |
290 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 317 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
291 }; | 318 }; |
292 | 319 |
293 } // namespace content | 320 } // namespace content |
294 | 321 |
295 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 322 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |