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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 class IssuesObserver; | 32 class IssuesObserver; |
33 class MediaRoute; | 33 class MediaRoute; |
34 class MediaRouter; | 34 class MediaRouter; |
35 class MediaRouterDialogCallbacks; | 35 class MediaRouterDialogCallbacks; |
36 class MediaRouterMojoImpl; | 36 class MediaRouterMojoImpl; |
37 class MediaRouterWebUIMessageHandler; | 37 class MediaRouterWebUIMessageHandler; |
38 class MediaRoutesObserver; | 38 class MediaRoutesObserver; |
39 class MediaSink; | 39 class MediaSink; |
40 class MediaSinksObserver; | 40 class MediaSinksObserver; |
41 class CreatePresentationConnectionRequest; | 41 class CreatePresentationSessionRequest; |
42 | 42 |
43 // Implements the chrome://media-router user interface. | 43 // Implements the chrome://media-router user interface. |
44 class MediaRouterUI : public ConstrainedWebDialogUI, | 44 class MediaRouterUI |
45 public QueryResultManager::Observer, | 45 : public ConstrainedWebDialogUI, |
46 public PresentationServiceDelegateImpl:: | 46 public QueryResultManager::Observer, |
47 DefaultPresentationRequestObserver { | 47 public PresentationServiceDelegateImpl::DefaultMediaSourceObserver { |
48 public: | 48 public: |
49 // |web_ui| owns this object and is used to initialize the base class. | 49 // |web_ui| owns this object and is used to initialize the base class. |
50 explicit MediaRouterUI(content::WebUI* web_ui); | 50 explicit MediaRouterUI(content::WebUI* web_ui); |
51 ~MediaRouterUI() override; | 51 ~MediaRouterUI() override; |
52 | 52 |
53 // Initializes internal state (e.g. starts listening for MediaSinks) for | 53 // Initializes internal state (e.g. starts listening for MediaSinks) for |
54 // targeting the default MediaSource (if any) of the initiator tab that owns | 54 // targeting the default MediaSource (if any) of the initiator tab that owns |
55 // |delegate|, as well as mirroring sources of that tab. | 55 // |delegate|, as well as mirroring sources of that tab. |
56 // The contents of the UI will change as the default MediaSource changes. | 56 // The contents of the UI will change as the default MediaSource changes. |
57 // If there is a default MediaSource, then DEFAULT MediaCastMode will be | 57 // If there is a default MediaSource, then DEFAULT MediaCastMode will be |
(...skipping 14 matching lines...) Expand all Loading... |
72 // Init* methods can only be called once. | 72 // Init* methods can only be called once. |
73 // |initiator|: Reference to the WebContents that initiated the dialog. | 73 // |initiator|: Reference to the WebContents that initiated the dialog. |
74 // Must not be null. | 74 // Must not be null. |
75 // |delegate|: PresentationServiceDelegateImpl of the initiator tab. | 75 // |delegate|: PresentationServiceDelegateImpl of the initiator tab. |
76 // Must not be null. | 76 // Must not be null. |
77 // |presentation_request|: The presentation request. This instance will take | 77 // |presentation_request|: The presentation request. This instance will take |
78 // ownership of it. Must not be null. | 78 // ownership of it. Must not be null. |
79 void InitWithPresentationSessionRequest( | 79 void InitWithPresentationSessionRequest( |
80 content::WebContents* initiator, | 80 content::WebContents* initiator, |
81 const base::WeakPtr<PresentationServiceDelegateImpl>& delegate, | 81 const base::WeakPtr<PresentationServiceDelegateImpl>& delegate, |
82 scoped_ptr<CreatePresentationConnectionRequest> presentation_request); | 82 scoped_ptr<CreatePresentationSessionRequest> presentation_request); |
83 | 83 |
84 // Closes the media router UI. | 84 // Closes the media router UI. |
85 void Close(); | 85 void Close(); |
86 | 86 |
87 // Notifies this instance that the UI has been initialized. | 87 // Notifies this instance that the UI has been initialized. |
88 void UIInitialized(); | 88 void UIInitialized(); |
89 | 89 |
90 // Requests a route be created from the source mapped to | 90 // Requests a route be created from the source mapped to |
91 // |cast_mode|, to the sink given by |sink_id|. | 91 // |cast_mode|, to the sink given by |sink_id|. |
92 // Returns true if a route request is successfully submitted. | 92 // Returns true if a route request is successfully submitted. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // requests. | 156 // requests. |
157 void OnRouteResponseReceived(const int route_request_id, | 157 void OnRouteResponseReceived(const int route_request_id, |
158 const MediaSink::Id& sink_id, | 158 const MediaSink::Id& sink_id, |
159 const MediaRoute* route, | 159 const MediaRoute* route, |
160 const std::string& presentation_id, | 160 const std::string& presentation_id, |
161 const std::string& error); | 161 const std::string& error); |
162 | 162 |
163 // Creates and sends an issue if route creation times out. | 163 // Creates and sends an issue if route creation times out. |
164 void RouteCreationTimeout(); | 164 void RouteCreationTimeout(); |
165 | 165 |
166 // Initializes the dialog with mirroring sources derived from |initiator|. | 166 // Sets the source host name to be displayed in the UI. |
167 void InitCommon(content::WebContents* initiator); | 167 // Gets cast modes from |query_result_manager_| and forwards it to UI. |
| 168 // One of the Init* functions must have been called before. |
| 169 void UpdateSourceHostAndCastModes(const GURL& frame_url); |
168 | 170 |
169 // PresentationServiceDelegateImpl::DefaultPresentationObserver | 171 // Initializes the dialog with mirroring sources derived from |initiator|, |
170 void OnDefaultPresentationChanged( | 172 // and optional |default_source| and |default_frame_url| if any. |
171 const PresentationRequest& presentation_request) override; | 173 void InitCommon(content::WebContents* initiator, |
172 void OnDefaultPresentationRemoved() override; | 174 const MediaSource& default_source, |
| 175 const GURL& default_frame_url); |
173 | 176 |
174 // Updates the set of supported cast modes and sends the updated set to | 177 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver |
175 // |handler_|. | 178 void OnDefaultMediaSourceChanged(const MediaSource& source, |
176 void UpdateCastModes(); | 179 const GURL& frame_url) override; |
177 | 180 |
178 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 181 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
179 // only after it has deleted |this|. | 182 // only after it has deleted |this|. |
180 MediaRouterWebUIMessageHandler* handler_; | 183 MediaRouterWebUIMessageHandler* handler_; |
181 | 184 |
182 // These are non-null while this instance is registered to receive | 185 // These are non-null while this instance is registered to receive |
183 // updates from them. | 186 // updates from them. |
184 scoped_ptr<IssuesObserver> issues_observer_; | 187 scoped_ptr<IssuesObserver> issues_observer_; |
185 scoped_ptr<MediaRoutesObserver> routes_observer_; | 188 scoped_ptr<MediaRoutesObserver> routes_observer_; |
186 | 189 |
(...skipping 11 matching lines...) Expand all Loading... |
198 | 201 |
199 std::vector<MediaSinkWithCastModes> sinks_; | 202 std::vector<MediaSinkWithCastModes> sinks_; |
200 std::vector<MediaRoute> routes_; | 203 std::vector<MediaRoute> routes_; |
201 CastModeSet cast_modes_; | 204 CastModeSet cast_modes_; |
202 GURL frame_url_; | 205 GURL frame_url_; |
203 | 206 |
204 scoped_ptr<QueryResultManager> query_result_manager_; | 207 scoped_ptr<QueryResultManager> query_result_manager_; |
205 | 208 |
206 // If set, then the result of the next presentation route request will | 209 // If set, then the result of the next presentation route request will |
207 // be handled by this object. | 210 // be handled by this object. |
208 scoped_ptr<CreatePresentationConnectionRequest> create_session_request_; | 211 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; |
209 | |
210 // Set to the presentation request corresponding to the presentation cast | |
211 // mode, if supported. Otherwise set to nullptr. | |
212 scoped_ptr<PresentationRequest> presentation_request_; | |
213 | 212 |
214 // It's possible for PresentationServiceDelegateImpl to be destroyed before | 213 // It's possible for PresentationServiceDelegateImpl to be destroyed before |
215 // this class. | 214 // this class. |
216 // (e.g. if a tab with the UI open is closed, then the tab WebContents will | 215 // (e.g. if a tab with the UI open is closed, then the tab WebContents will |
217 // be destroyed first momentarily before the UI WebContents). | 216 // be destroyed first momentarily before the UI WebContents). |
218 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to | 217 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to |
219 // handle this. | 218 // handle this. |
220 // TODO(imcheng): hold a weak ptr to an abstract type instead. | 219 // TODO(imcheng): hold a weak ptr to an abstract type instead. |
221 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; | 220 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; |
222 | 221 |
223 content::WebContents* initiator_; | 222 content::WebContents* initiator_; |
224 | 223 |
225 // Pointer to the MediaRouter for this instance's BrowserContext. | 224 // Pointer to the MediaRouter for this instance's BrowserContext. |
226 MediaRouterMojoImpl* router_; | 225 MediaRouterMojoImpl* router_; |
227 | 226 |
228 // Timer used to implement a timeout on a create route request. | 227 // Timer used to implement a timeout on a create route request. |
229 base::OneShotTimer route_creation_timer_; | 228 base::OneShotTimer route_creation_timer_; |
230 | 229 |
231 // NOTE: Weak pointers must be invalidated before all other member variables. | 230 // NOTE: Weak pointers must be invalidated before all other member variables. |
232 // Therefore |weak_factory_| must be placed at the end. | 231 // Therefore |weak_factory_| must be placed at the end. |
233 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 232 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
234 | 233 |
235 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 234 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
236 }; | 235 }; |
237 | 236 |
238 } // namespace media_router | 237 } // namespace media_router |
239 | 238 |
240 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 239 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |