| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "chrome/browser/media/router/media_router.h" | 18 #include "chrome/browser/media/router/media_router.h" |
| 19 #include "chrome/browser/media/router/media_source.h" | 19 #include "chrome/browser/media/router/media_source.h" |
| 20 #include "chrome/browser/media/router/presentation_request.h" | 20 #include "chrome/browser/media/router/presentation_request.h" |
| 21 #include "chrome/browser/media/router/presentation_service_delegate_observers.h" | 21 #include "chrome/browser/media/router/presentation_service_delegate_observers.h" |
| 22 #include "chrome/browser/media/router/render_frame_host_id.h" | 22 #include "chrome/browser/media/router/render_frame_host_id.h" |
| 23 #include "content/public/browser/presentation_service_delegate.h" | 23 #include "content/public/browser/presentation_service_delegate.h" |
| 24 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
| 25 #include "content/public/browser/web_contents_user_data.h" | 25 #include "content/public/browser/web_contents_user_data.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 class PresentationScreenAvailabilityListener; | 28 class PresentationScreenAvailabilityListener; |
| 29 class WebContents; | 29 class WebContents; |
| 30 struct PresentationSessionInfo; | |
| 31 struct PresentationConnectionMessage; | 30 struct PresentationConnectionMessage; |
| 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 PresentationFrameManager; |
| 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 sessions. It is scoped to the lifetime of a WebContents, | 48 // browser-initiated presentations. It is scoped to the lifetime of a |
| 49 // 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>, |
| 52 public content::ControllerPresentationServiceDelegate { | 52 public content::ControllerPresentationServiceDelegate { |
| 53 public: | 53 public: |
| 54 // Observer interface for listening to default presentation request | 54 // Observer interface for listening to default presentation request |
| 55 // changes for the WebContents. | 55 // changes for the WebContents. |
| 56 class DefaultPresentationRequestObserver { | 56 class DefaultPresentationRequestObserver { |
| 57 public: | 57 public: |
| 58 virtual ~DefaultPresentationRequestObserver() = default; | 58 virtual ~DefaultPresentationRequestObserver() = default; |
| 59 | 59 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 88 content::PresentationScreenAvailabilityListener* listener) override; | 88 content::PresentationScreenAvailabilityListener* listener) override; |
| 89 void RemoveScreenAvailabilityListener( | 89 void RemoveScreenAvailabilityListener( |
| 90 int render_process_id, | 90 int render_process_id, |
| 91 int render_frame_id, | 91 int render_frame_id, |
| 92 content::PresentationScreenAvailabilityListener* listener) override; | 92 content::PresentationScreenAvailabilityListener* listener) override; |
| 93 void Reset(int render_process_id, int render_frame_id) override; | 93 void Reset(int render_process_id, int render_frame_id) override; |
| 94 void SetDefaultPresentationUrls( | 94 void SetDefaultPresentationUrls( |
| 95 int render_process_id, | 95 int render_process_id, |
| 96 int render_frame_id, | 96 int render_frame_id, |
| 97 const std::vector<GURL>& default_presentation_urls, | 97 const std::vector<GURL>& default_presentation_urls, |
| 98 const content::PresentationSessionStartedCallback& callback) override; | 98 const content::PresentationConnectionCallback& callback) override; |
| 99 void StartSession( | 99 void StartPresentation( |
| 100 int render_process_id, | 100 int render_process_id, |
| 101 int render_frame_id, | 101 int render_frame_id, |
| 102 const std::vector<GURL>& presentation_urls, | 102 const std::vector<GURL>& presentation_urls, |
| 103 const content::PresentationSessionStartedCallback& success_cb, | 103 const content::PresentationConnectionCallback& success_cb, |
| 104 const content::PresentationSessionErrorCallback& error_cb) override; | 104 const content::PresentationConnectionErrorCallback& error_cb) override; |
| 105 void JoinSession( | 105 void ReconnectPresentation( |
| 106 int render_process_id, | 106 int render_process_id, |
| 107 int render_frame_id, | 107 int render_frame_id, |
| 108 const std::vector<GURL>& presentation_urls, | 108 const std::vector<GURL>& presentation_urls, |
| 109 const std::string& presentation_id, | 109 const std::string& presentation_id, |
| 110 const content::PresentationSessionStartedCallback& success_cb, | 110 const content::PresentationConnectionCallback& success_cb, |
| 111 const content::PresentationSessionErrorCallback& error_cb) override; | 111 const content::PresentationConnectionErrorCallback& error_cb) override; |
| 112 void CloseConnection(int render_process_id, | 112 void CloseConnection(int render_process_id, |
| 113 int render_frame_id, | 113 int render_frame_id, |
| 114 const std::string& presentation_id) override; | 114 const std::string& presentation_id) override; |
| 115 void Terminate(int render_process_id, | 115 void Terminate(int render_process_id, |
| 116 int render_frame_id, | 116 int render_frame_id, |
| 117 const std::string& presentation_id) override; | 117 const std::string& presentation_id) override; |
| 118 void ListenForConnectionMessages( | 118 void ListenForConnectionMessages( |
| 119 int render_process_id, | 119 int render_process_id, |
| 120 int render_frame_id, | 120 int render_frame_id, |
| 121 const content::PresentationSessionInfo& session, | 121 const content::PresentationInfo& presentation_info, |
| 122 const content::PresentationConnectionMessageCallback& message_cb) | 122 const content::PresentationConnectionMessageCallback& message_cb) |
| 123 override; | 123 override; |
| 124 void SendMessage(int render_process_id, | 124 void SendMessage(int render_process_id, |
| 125 int render_frame_id, | 125 int render_frame_id, |
| 126 const content::PresentationSessionInfo& session, | 126 const content::PresentationInfo& presentation_info, |
| 127 content::PresentationConnectionMessage message, | 127 content::PresentationConnectionMessage message, |
| 128 const SendMessageCallback& send_message_cb) override; | 128 const SendMessageCallback& send_message_cb) override; |
| 129 void ListenForConnectionStateChange( | 129 void ListenForConnectionStateChange( |
| 130 int render_process_id, | 130 int render_process_id, |
| 131 int render_frame_id, | 131 int render_frame_id, |
| 132 const content::PresentationSessionInfo& connection, | 132 const content::PresentationInfo& connection, |
| 133 const content::PresentationConnectionStateChangedCallback& | 133 const content::PresentationConnectionStateChangedCallback& |
| 134 state_changed_cb) override; | 134 state_changed_cb) override; |
| 135 void ConnectToPresentation( | 135 void ConnectToPresentation( |
| 136 int render_process_id, | 136 int render_process_id, |
| 137 int render_frame_id, | 137 int render_frame_id, |
| 138 const content::PresentationSessionInfo& session, | 138 const content::PresentationInfo& presentation_info, |
| 139 content::PresentationConnectionPtr controller_connection_ptr, | 139 content::PresentationConnectionPtr controller_connection_ptr, |
| 140 content::PresentationConnectionRequest receiver_connection_request) | 140 content::PresentationConnectionRequest receiver_connection_request) |
| 141 override; | 141 override; |
| 142 | 142 |
| 143 // Callback invoked when a default PresentationRequest is started from a | 143 // Callback invoked when a default PresentationRequest is started from a |
| 144 // browser-initiated dialog. | 144 // browser-initiated dialog. |
| 145 void OnRouteResponse(const PresentationRequest& request, | 145 void OnRouteResponse(const PresentationRequest& request, |
| 146 const RouteRequestResult& result); | 146 const RouteRequestResult& result); |
| 147 | 147 |
| 148 // Adds / removes an observer for listening to default PresentationRequest | 148 // Adds / removes an observer for listening to default PresentationRequest |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does | 191 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does |
| 192 // not have a persentation URL, returns the tab mirroring MediaSource. | 192 // not have a persentation URL, returns the tab mirroring MediaSource. |
| 193 MediaSource GetMediaSourceFromListener( | 193 MediaSource GetMediaSourceFromListener( |
| 194 content::PresentationScreenAvailabilityListener* listener); | 194 content::PresentationScreenAvailabilityListener* listener); |
| 195 | 195 |
| 196 void OnJoinRouteResponse( | 196 void OnJoinRouteResponse( |
| 197 int render_process_id, | 197 int render_process_id, |
| 198 int render_frame_id, | 198 int render_frame_id, |
| 199 const GURL& presentation_url, | 199 const GURL& presentation_url, |
| 200 const std::string& presentation_id, | 200 const std::string& presentation_id, |
| 201 const content::PresentationSessionStartedCallback& success_cb, | 201 const content::PresentationConnectionCallback& success_cb, |
| 202 const content::PresentationSessionErrorCallback& error_cb, | 202 const content::PresentationConnectionErrorCallback& error_cb, |
| 203 const RouteRequestResult& result); | 203 const RouteRequestResult& result); |
| 204 | 204 |
| 205 void OnStartSessionSucceeded( | 205 void OnStartPresentationSucceeded( |
| 206 int render_process_id, | 206 int render_process_id, |
| 207 int render_frame_id, | 207 int render_frame_id, |
| 208 const content::PresentationSessionStartedCallback& success_cb, | 208 const content::PresentationConnectionCallback& success_cb, |
| 209 const content::PresentationSessionInfo& new_session, | 209 const content::PresentationInfo& new_presentation_info, |
| 210 const MediaRoute& route); | 210 const MediaRoute& route); |
| 211 | 211 |
| 212 #if !defined(OS_ANDROID) | 212 #if !defined(OS_ANDROID) |
| 213 // Returns true if auto-join requests should be cancelled for |origin|. | 213 // Returns true if auto-join requests should be cancelled for |origin|. |
| 214 bool ShouldCancelAutoJoinForOrigin(const url::Origin& origin) const; | 214 bool ShouldCancelAutoJoinForOrigin(const url::Origin& origin) const; |
| 215 #endif | 215 #endif |
| 216 | 216 |
| 217 // References to the WebContents that owns this instance, and associated | 217 // References to the WebContents that owns this instance, and associated |
| 218 // browser profile's MediaRouter instance. | 218 // browser profile's MediaRouter instance. |
| 219 content::WebContents* const web_contents_; | 219 content::WebContents* const web_contents_; |
| 220 MediaRouter* router_; | 220 MediaRouter* router_; |
| 221 | 221 |
| 222 std::unique_ptr<PresentationFrameManager> frame_manager_; | 222 std::unique_ptr<PresentationFrameManager> frame_manager_; |
| 223 PresentationServiceDelegateObservers observers_; | 223 PresentationServiceDelegateObservers observers_; |
| 224 | 224 |
| 225 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; | 225 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; |
| 226 | 226 |
| 227 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); | 227 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 } // namespace media_router | 230 } // namespace media_router |
| 231 | 231 |
| 232 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ | 232 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ |
| OLD | NEW |