| 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_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class WebContents; | 26 class WebContents; |
| 27 } // namespace content | 27 } // namespace content |
| 28 | 28 |
| 29 namespace media_router { | 29 namespace media_router { |
| 30 | 30 |
| 31 class IssuesObserver; | 31 class IssuesObserver; |
| 32 class MediaRoute; | 32 class MediaRoute; |
| 33 class MediaRouter; | 33 class MediaRouter; |
| 34 class MediaRouterDialogCallbacks; |
| 34 class MediaRouterWebUIMessageHandler; | 35 class MediaRouterWebUIMessageHandler; |
| 35 class MediaRoutesObserver; | 36 class MediaRoutesObserver; |
| 36 class MediaSink; | 37 class MediaSink; |
| 37 class MediaSinksObserver; | 38 class MediaSinksObserver; |
| 38 class CreateSessionRequest; | 39 class CreateSessionRequest; |
| 39 | 40 |
| 40 // Implements the chrome://media-router user interface. | 41 // Implements the chrome://media-router user interface. |
| 41 class MediaRouterUI | 42 class MediaRouterUI |
| 42 : public ConstrainedWebDialogUI, | 43 : public ConstrainedWebDialogUI, |
| 43 public QueryResultManager::Observer, | 44 public QueryResultManager::Observer, |
| 44 public PresentationServiceDelegateImpl::DefaultMediaSourceObserver { | 45 public PresentationServiceDelegateImpl::DefaultMediaSourceObserver { |
| 45 public: | 46 public: |
| 46 // |web_ui| owns this object and is used to initialize the base class. | 47 // |web_ui| owns this object and is used to initialize the base class. |
| 47 explicit MediaRouterUI(content::WebUI* web_ui); | 48 explicit MediaRouterUI(content::WebUI* web_ui); |
| 48 ~MediaRouterUI() override; | 49 ~MediaRouterUI() override; |
| 49 | 50 |
| 50 // Initializes internal state (e.g. starts listening for MediaSinks) for | 51 // Initializes internal state (e.g. starts listening for MediaSinks) for |
| 51 // targeting the default MediaSource (if any) of the tab. The contents of the | 52 // targeting the default MediaSource (if any) of the initiator tab that owns |
| 52 // UI will change as the default MediaSource changes. If there is a default | 53 // |delegate|, as well as mirroring sources of that tab. |
| 53 // MediaSource, then DEFAULT MediaCastMode will be added to |cast_modes_|. | 54 // The contents of the UI will change as the default MediaSource changes. |
| 54 // |source_manager|: PresentationServiceDelegateImpl of the initiator tab. | 55 // If there is a default MediaSource, then DEFAULT MediaCastMode will be |
| 55 // Must not be null. | 56 // added to |cast_modes_|. |
| 56 // Can only be called once. | 57 // Init* methods can only be called once. |
| 58 // |delegate|: PresentationServiceDelegateImpl of the initiator tab. |
| 59 // Must not be null. |
| 57 // TODO(imcheng): Replace use of impl with an intermediate abstract | 60 // TODO(imcheng): Replace use of impl with an intermediate abstract |
| 58 // interface. | 61 // interface. |
| 59 void InitWithDefaultMediaSource(PresentationServiceDelegateImpl* delegate); | 62 void InitWithDefaultMediaSource( |
| 63 const base::WeakPtr<PresentationServiceDelegateImpl>& delegate); |
| 60 | 64 |
| 61 // Initializes internal state targeting the presentation specified in | 65 // Initializes internal state targeting the presentation specified in |
| 62 // |request|. Also sets up mirroring sources based on |initiator|. | 66 // |request|. Also sets up mirroring sources based on |initiator|. |
| 63 // This is different from |InitWithDefaultMediaSource| in that it does not | 67 // This is different from |InitWithDefaultMediaSource| in that it does not |
| 64 // listen for default media source changes, as the UI is fixed to the source | 68 // listen for default media source changes, as the UI is fixed to the source |
| 65 // in |request|. | 69 // in |request|. |
| 70 // Init* methods can only be called once. |
| 71 // |initiator|: Reference to the WebContents that initiated the dialog. |
| 72 // Must not be null. |
| 73 // |presentation_request|: The presentation request. This instance will take |
| 74 // ownership of it. Must not be null. |
| 66 void InitWithPresentationSessionRequest( | 75 void InitWithPresentationSessionRequest( |
| 67 const content::WebContents* initiator, | 76 content::WebContents* initiator, |
| 68 scoped_ptr<CreateSessionRequest> request); | 77 scoped_ptr<CreateSessionRequest> presentation_request); |
| 69 | 78 |
| 70 // Closes the media router UI. | 79 // Closes the media router UI. |
| 71 void Close(); | 80 void Close(); |
| 72 | 81 |
| 73 // Notifies this instance that the UI has been initialized. | 82 // Notifies this instance that the UI has been initialized. |
| 74 void UIInitialized(); | 83 void UIInitialized(); |
| 75 | 84 |
| 76 // Requests a route be created from the source determined by the preferred | 85 // Requests a route be created from the source determined by the preferred |
| 77 // MediaCastMode, to the sink given by |sink_id|. | 86 // MediaCastMode, to the sink given by |sink_id|. |
| 78 // The preferred cast mode is determined from the set of currently supported | 87 // The preferred cast mode is determined from the set of currently supported |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 139 |
| 131 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 140 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
| 132 | 141 |
| 133 // Sets the source host name to be displayed in the UI. | 142 // Sets the source host name to be displayed in the UI. |
| 134 // Gets cast modes from |query_result_manager_| and forwards it to UI. | 143 // Gets cast modes from |query_result_manager_| and forwards it to UI. |
| 135 // One of the Init* functions must have been called before. | 144 // One of the Init* functions must have been called before. |
| 136 void UpdateSourceHostAndCastModes(const GURL& frame_url); | 145 void UpdateSourceHostAndCastModes(const GURL& frame_url); |
| 137 | 146 |
| 138 // Initializes the dialog with mirroring sources derived from |initiator|, | 147 // Initializes the dialog with mirroring sources derived from |initiator|, |
| 139 // and optional |default_source| and |default_frame_url| if any. | 148 // and optional |default_source| and |default_frame_url| if any. |
| 140 void InitCommon(const content::WebContents* initiator, | 149 void InitCommon(content::WebContents* initiator, |
| 141 const MediaSource& default_source, | 150 const MediaSource& default_source, |
| 142 const GURL& default_frame_url); | 151 const GURL& default_frame_url); |
| 143 | 152 |
| 144 // Invoke presentation callbacks based on |route| and |error| if the dialog | |
| 145 // was created for Presentation API. | |
| 146 void HandleRouteResponseForPresentation(const MediaRoute* route, | |
| 147 const std::string& error); | |
| 148 | |
| 149 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver | 153 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver |
| 150 void OnDefaultMediaSourceChanged(const MediaSource& source, | 154 void OnDefaultMediaSourceChanged(const MediaSource& source, |
| 151 const GURL& frame_url) override; | 155 const GURL& frame_url) override; |
| 152 | 156 |
| 153 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 157 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
| 154 // only after it has deleted |this|. | 158 // only after it has deleted |this|. |
| 155 MediaRouterWebUIMessageHandler* handler_; | 159 MediaRouterWebUIMessageHandler* handler_; |
| 156 | 160 |
| 157 // These are non-null while this instance is registered to receive | 161 // These are non-null while this instance is registered to receive |
| 158 // updates from them. | 162 // updates from them. |
| 159 scoped_ptr<IssuesObserver> issues_observer_; | 163 scoped_ptr<IssuesObserver> issues_observer_; |
| 160 scoped_ptr<MediaRoutesObserver> routes_observer_; | 164 scoped_ptr<MediaRoutesObserver> routes_observer_; |
| 161 | 165 |
| 162 // Set to true by |handler_| when the UI has been initialized. | 166 // Set to true by |handler_| when the UI has been initialized. |
| 163 bool ui_initialized_; | 167 bool ui_initialized_; |
| 164 | 168 |
| 165 // Set to |true| if there is a pending route request for this UI. | 169 // Set to |true| if there is a pending route request for this UI. |
| 166 bool has_pending_route_request_; | 170 bool has_pending_route_request_; |
| 167 | 171 |
| 168 bool requesting_route_for_default_source_; | 172 bool requesting_route_for_default_source_; |
| 169 | 173 |
| 170 std::vector<MediaSinkWithCastModes> sinks_; | 174 std::vector<MediaSinkWithCastModes> sinks_; |
| 171 std::vector<MediaRoute> routes_; | 175 std::vector<MediaRoute> routes_; |
| 172 CastModeSet cast_modes_; | 176 CastModeSet cast_modes_; |
| 173 GURL frame_url_; | 177 GURL frame_url_; |
| 174 | 178 |
| 175 scoped_ptr<QueryResultManager> query_result_manager_; | 179 scoped_ptr<QueryResultManager> query_result_manager_; |
| 176 | 180 |
| 177 // Only set if the UI is created as a result of Presentation API. | 181 // If set, then the result of the next presentation route request will |
| 178 scoped_ptr<CreateSessionRequest> presentation_session_request_; | 182 // be handled by this object. |
| 183 scoped_ptr<CreateSessionRequest> presentation_request_; |
| 179 | 184 |
| 180 // It's possible for PresentationServiceDelegateImpl to be destroyed before | 185 // It's possible for PresentationServiceDelegateImpl to be destroyed before |
| 181 // this class. | 186 // this class. |
| 182 // (e.g. if a tab with the UI open is closed, then the tab WebContents will | 187 // (e.g. if a tab with the UI open is closed, then the tab WebContents will |
| 183 // be destroyed first momentarily before the UI WebContents). | 188 // be destroyed first momentarily before the UI WebContents). |
| 184 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to | 189 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to |
| 185 // handle this. | 190 // handle this. |
| 186 // TODO(imcheng): hold a weak ptr to an abstract type instead. | 191 // TODO(imcheng): hold a weak ptr to an abstract type instead. |
| 187 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; | 192 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; |
| 188 | 193 |
| 189 const content::WebContents* initiator_; | 194 content::WebContents* initiator_; |
| 190 | 195 |
| 191 // Cached pointer to the MediaRouter for this instance's BrowserContext. | 196 // Cached pointer to the MediaRouter for this instance's BrowserContext. |
| 192 MediaRouter* router_; | 197 MediaRouter* router_; |
| 193 | 198 |
| 194 // NOTE: Weak pointers must be invalidated before all other member variables. | 199 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 195 // Therefore |weak_factory_| must be placed at the end. | 200 // Therefore |weak_factory_| must be placed at the end. |
| 196 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 201 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
| 197 | 202 |
| 198 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 203 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
| 199 }; | 204 }; |
| 200 | 205 |
| 201 } // namespace media_router | 206 } // namespace media_router |
| 202 | 207 |
| 203 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 208 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| OLD | NEW |