| 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 CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 struct PresentationInfo; | 31 struct PresentationInfo; |
| 32 } // namespace content | 32 } // namespace content |
| 33 | 33 |
| 34 namespace url { | 34 namespace url { |
| 35 class Origin; | 35 class Origin; |
| 36 } // namespace url | 36 } // namespace url |
| 37 | 37 |
| 38 namespace media_router { | 38 namespace media_router { |
| 39 | 39 |
| 40 class MediaRoute; | 40 class MediaRoute; |
| 41 class PresentationFrameManager; | 41 class PresentationFrame; |
| 42 class RouteRequestResult; | 42 class RouteRequestResult; |
| 43 | 43 |
| 44 // Implementation of PresentationServiceDelegate that interfaces an instance of | 44 // Implementation of PresentationServiceDelegate that interfaces an instance of |
| 45 // WebContents with the Chrome Media Router. It uses the Media Router to handle | 45 // WebContents with the Chrome Media Router. It uses the Media Router to handle |
| 46 // presentation API calls forwarded from PresentationServiceImpl. In addition, | 46 // presentation API calls forwarded from PresentationServiceImpl. In addition, |
| 47 // it also provides default presentation URL that is required for creating | 47 // it also provides default presentation URL that is required for creating |
| 48 // browser-initiated presentations. It is scoped to the lifetime of a | 48 // browser-initiated presentations. It is scoped to the lifetime of a |
| 49 // WebContents, and is managed by the associated WebContents. | 49 // WebContents, and is managed by the associated WebContents. |
| 50 class PresentationServiceDelegateImpl | 50 class PresentationServiceDelegateImpl |
| 51 : public content::WebContentsUserData<PresentationServiceDelegateImpl>, | 51 : public content::WebContentsUserData<PresentationServiceDelegateImpl>, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const RouteRequestResult& result); | 140 const RouteRequestResult& result); |
| 141 | 141 |
| 142 // Adds / removes an observer for listening to default PresentationRequest | 142 // Adds / removes an observer for listening to default PresentationRequest |
| 143 // changes. This class does not own |observer|. When |observer| is about to | 143 // changes. This class does not own |observer|. When |observer| is about to |
| 144 // be destroyed, |RemoveDefaultPresentationRequestObserver| must be called. | 144 // be destroyed, |RemoveDefaultPresentationRequestObserver| must be called. |
| 145 void AddDefaultPresentationRequestObserver( | 145 void AddDefaultPresentationRequestObserver( |
| 146 DefaultPresentationRequestObserver* observer); | 146 DefaultPresentationRequestObserver* observer); |
| 147 void RemoveDefaultPresentationRequestObserver( | 147 void RemoveDefaultPresentationRequestObserver( |
| 148 DefaultPresentationRequestObserver* observer); | 148 DefaultPresentationRequestObserver* observer); |
| 149 | 149 |
| 150 // Gets the default presentation request for the owning tab WebContents. It | 150 // Gets the default presentation request for the owning WebContents. It |
| 151 // is an error to call this method if the default presentation request does | 151 // is an error to call this method if the default presentation request does |
| 152 // not exist. | 152 // not exist. |
| 153 PresentationRequest GetDefaultPresentationRequest() const; | 153 PresentationRequest GetDefaultPresentationRequest() const; |
| 154 | 154 |
| 155 // Returns true if there is a default presentation request for the owning tab | 155 // Returns true if there is a default presentation request for the owning tab |
| 156 // WebContents. | 156 // WebContents. |
| 157 bool HasDefaultPresentationRequest() const; | 157 bool HasDefaultPresentationRequest() const; |
| 158 | 158 |
| 159 // Returns the WebContents that owns this instance. | 159 // Returns the WebContents that owns this instance. |
| 160 content::WebContents* web_contents() const { return web_contents_; } | 160 content::WebContents* web_contents() const { return web_contents_; } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 179 DefaultPresentationUrlCallback); | 179 DefaultPresentationUrlCallback); |
| 180 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, | 180 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, |
| 181 TestCloseConnectionForOffscreenPresentation); | 181 TestCloseConnectionForOffscreenPresentation); |
| 182 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, | 182 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, |
| 183 ConnectToOffscreenPresentation); | 183 ConnectToOffscreenPresentation); |
| 184 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, | 184 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, |
| 185 ConnectToPresentation); | 185 ConnectToPresentation); |
| 186 | 186 |
| 187 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents); | 187 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents); |
| 188 | 188 |
| 189 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does | 189 PresentationFrame* GetOrAddPresentationFrame( |
| 190 // not have a persentation URL, returns the tab mirroring MediaSource. | 190 const RenderFrameHostId& render_frame_host_id); |
| 191 MediaSource GetMediaSourceFromListener( | |
| 192 content::PresentationScreenAvailabilityListener* listener); | |
| 193 | 191 |
| 194 void OnJoinRouteResponse( | 192 void OnJoinRouteResponse( |
| 195 int render_process_id, | 193 int render_process_id, |
| 196 int render_frame_id, | 194 int render_frame_id, |
| 197 const GURL& presentation_url, | 195 const GURL& presentation_url, |
| 198 const std::string& presentation_id, | 196 const std::string& presentation_id, |
| 199 content::PresentationConnectionCallback success_cb, | 197 content::PresentationConnectionCallback success_cb, |
| 200 content::PresentationConnectionErrorCallback error_cb, | 198 content::PresentationConnectionErrorCallback error_cb, |
| 201 const RouteRequestResult& result); | 199 const RouteRequestResult& result); |
| 202 | 200 |
| 203 void OnStartPresentationSucceeded( | 201 void OnStartPresentationSucceeded( |
| 204 int render_process_id, | 202 int render_process_id, |
| 205 int render_frame_id, | 203 int render_frame_id, |
| 206 content::PresentationConnectionCallback success_cb, | 204 content::PresentationConnectionCallback success_cb, |
| 207 const content::PresentationInfo& new_presentation_info, | 205 const content::PresentationInfo& new_presentation_info, |
| 208 const MediaRoute& route); | 206 const MediaRoute& route); |
| 209 | 207 |
| 208 // Notifies the PresentationFrame of |render_frame_host_id| that a |
| 209 // presentation and its corresponding MediaRoute has been created. |
| 210 // The PresentationFrame will be created if it does not already exist. |
| 211 // This must be called before |ConnectToPresentation()|. |
| 212 void AddPresentation(const RenderFrameHostId& render_frame_host_id, |
| 213 const content::PresentationInfo& presentation_info, |
| 214 const MediaRoute& route); |
| 215 |
| 216 // Notifies the PresentationFrame of |render_frame_host_id| that a |
| 217 // presentation and its corresponding MediaRoute has been removed. |
| 218 void RemovePresentation(const RenderFrameHostId& render_frame_host_id, |
| 219 const std::string& presentation_id); |
| 220 |
| 221 // Sets the default presentation request for the owning WebContents and |
| 222 // notifies observers of changes. |
| 223 void SetDefaultPresentationRequest( |
| 224 const PresentationRequest& default_presentation_request); |
| 225 |
| 226 // Clears the default presentation request for the owning WebContents and |
| 227 // notifies observers of changes. Also resets |
| 228 // |default_presentation_started_callback_|. |
| 229 void ClearDefaultPresentationRequest(); |
| 230 |
| 231 // Returns |true| if the given frame is the main frame of the associated |
| 232 // WebContents. |
| 233 // NOTE: This method will be removed in an upcoming patch. |
| 234 bool IsMainFrame(const RenderFrameHostId& render_frame_host_id) const; |
| 235 |
| 236 // Returns the ID of the route corresponding to |presentation_id| in the given |
| 237 // frame, or empty if no such route exist. |
| 238 MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 239 const std::string& presentation_id) const; |
| 240 |
| 210 #if !defined(OS_ANDROID) | 241 #if !defined(OS_ANDROID) |
| 211 // Returns true if auto-join requests should be cancelled for |origin|. | 242 // Returns true if auto-join requests should be cancelled for |origin|. |
| 212 bool ShouldCancelAutoJoinForOrigin(const url::Origin& origin) const; | 243 bool ShouldCancelAutoJoinForOrigin(const url::Origin& origin) const; |
| 213 #endif | 244 #endif |
| 214 | 245 |
| 215 // References to the WebContents that owns this instance, and associated | 246 // References to the WebContents that owns this instance, and associated |
| 216 // browser profile's MediaRouter instance. | 247 // browser profile's MediaRouter instance. |
| 217 content::WebContents* const web_contents_; | 248 content::WebContents* const web_contents_; |
| 218 MediaRouter* router_; | 249 MediaRouter* router_; |
| 219 | 250 |
| 220 std::unique_ptr<PresentationFrameManager> frame_manager_; | 251 // References to the observers listening for changes to the default |
| 252 // presentation of the associated WebContents. |
| 253 base::ObserverList<DefaultPresentationRequestObserver> |
| 254 default_presentation_request_observers_; |
| 255 |
| 256 // Default presentation request for the owning WebContents. |
| 257 std::unique_ptr<PresentationRequest> default_presentation_request_; |
| 258 |
| 259 // Callback to invoke when the default presentation has started. |
| 260 content::DefaultPresentationConnectionCallback |
| 261 default_presentation_started_callback_; |
| 262 |
| 263 // Maps a frame identifier to a PresentationFrame object for frames |
| 264 // that are using Presentation API. |
| 265 std::unordered_map<RenderFrameHostId, |
| 266 std::unique_ptr<PresentationFrame>, |
| 267 RenderFrameHostIdHasher> |
| 268 presentation_frames_; |
| 269 |
| 221 PresentationServiceDelegateObservers observers_; | 270 PresentationServiceDelegateObservers observers_; |
| 222 | 271 |
| 223 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; | 272 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; |
| 224 | 273 |
| 225 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); | 274 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); |
| 226 }; | 275 }; |
| 227 | 276 |
| 228 } // namespace media_router | 277 } // namespace media_router |
| 229 | 278 |
| 230 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ | 279 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ |
| OLD | NEW |