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 <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
17 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 18 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 19 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
19 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" | 20 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" |
20 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" | 21 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" |
21 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" | 22 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" |
22 #include "chrome/common/media_router/issue.h" | 23 #include "chrome/common/media_router/issue.h" |
23 #include "chrome/common/media_router/media_source.h" | 24 #include "chrome/common/media_router/media_source.h" |
24 #include "content/public/browser/web_ui_data_source.h" | 25 #include "content/public/browser/web_ui_data_source.h" |
25 #include "third_party/icu/source/common/unicode/uversion.h" | 26 #include "third_party/icu/source/common/unicode/uversion.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // ownership of it. Must not be null. | 89 // ownership of it. Must not be null. |
89 void InitWithPresentationSessionRequest( | 90 void InitWithPresentationSessionRequest( |
90 content::WebContents* initiator, | 91 content::WebContents* initiator, |
91 PresentationServiceDelegateImpl* delegate, | 92 PresentationServiceDelegateImpl* delegate, |
92 std::unique_ptr<CreatePresentationConnectionRequest> | 93 std::unique_ptr<CreatePresentationConnectionRequest> |
93 presentation_request); | 94 presentation_request); |
94 | 95 |
95 // Closes the media router UI. | 96 // Closes the media router UI. |
96 void Close(); | 97 void Close(); |
97 | 98 |
98 // Notifies this instance that the UI has been initialized. Marked virtual for | 99 // Notifies this instance that the UI has been initialized. |
99 // tests. | |
100 virtual void UIInitialized(); | 100 virtual void UIInitialized(); |
101 | 101 |
102 // Requests a route be created from the source mapped to | 102 // Requests a route be created from the source mapped to |
103 // |cast_mode|, to the sink given by |sink_id|. | 103 // |cast_mode|, to the sink given by |sink_id|. |
104 // Returns true if a route request is successfully submitted. | 104 // Returns true if a route request is successfully submitted. |
105 // |OnRouteResponseReceived()| will be invoked when the route request | 105 // |OnRouteResponseReceived()| will be invoked when the route request |
106 // completes. | 106 // completes. |
107 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 107 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
108 | 108 |
109 // Calls MediaRouter to join the given route. | 109 // Calls MediaRouter to join the given route. |
(...skipping 11 matching lines...) Expand all Loading... |
121 | 121 |
122 // Calls MediaRouter to search route providers for sinks matching | 122 // Calls MediaRouter to search route providers for sinks matching |
123 // |search_criteria| with the source that is currently associated with | 123 // |search_criteria| with the source that is currently associated with |
124 // |cast_mode|. The user's domain |domain| is also used. | 124 // |cast_mode|. The user's domain |domain| is also used. |
125 void SearchSinksAndCreateRoute(const MediaSink::Id& sink_id, | 125 void SearchSinksAndCreateRoute(const MediaSink::Id& sink_id, |
126 const std::string& search_criteria, | 126 const std::string& search_criteria, |
127 const std::string& domain, | 127 const std::string& domain, |
128 MediaCastMode cast_mode); | 128 MediaCastMode cast_mode); |
129 | 129 |
130 // Returns true if the cast mode last chosen for the current origin is tab | 130 // Returns true if the cast mode last chosen for the current origin is tab |
131 // mirroring. Marked virtual for tests. | 131 // mirroring. |
132 virtual bool UserSelectedTabMirroringForCurrentOrigin() const; | 132 virtual bool UserSelectedTabMirroringForCurrentOrigin() const; |
133 | 133 |
134 // Records the cast mode selection for the current origin, unless the cast | 134 // Records the cast mode selection for the current origin, unless the cast |
135 // mode is MediaCastMode::DESKTOP_MIRROR. Marked virtual for tests. | 135 // mode is MediaCastMode::DESKTOP_MIRROR. |
136 virtual void RecordCastModeSelection(MediaCastMode cast_mode); | 136 virtual void RecordCastModeSelection(MediaCastMode cast_mode); |
137 | 137 |
138 // Returns the hostname of the default source's parent frame URL. | 138 // Returns the hostname of the default source's parent frame URL. |
139 std::string GetPresentationRequestSourceName() const; | 139 std::string GetPresentationRequestSourceName() const; |
140 std::string GetTruncatedPresentationRequestSourceName() const; | 140 std::string GetTruncatedPresentationRequestSourceName() const; |
141 bool HasPendingRouteRequest() const { | 141 bool HasPendingRouteRequest() const { |
142 return current_route_request_id_ != -1; | 142 return current_route_request_id_ != -1; |
143 } | 143 } |
144 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } | 144 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } |
145 const std::vector<MediaRoute>& routes() const { return routes_; } | 145 const std::vector<MediaRoute>& routes() const { return routes_; } |
146 const std::vector<MediaRoute::Id>& joinable_route_ids() const { | 146 const std::vector<MediaRoute::Id>& joinable_route_ids() const { |
147 return joinable_route_ids_; | 147 return joinable_route_ids_; |
148 } | 148 } |
149 // Marked virtual for tests. | |
150 virtual const std::set<MediaCastMode>& cast_modes() const; | 149 virtual const std::set<MediaCastMode>& cast_modes() const; |
151 const std::unordered_map<MediaRoute::Id, MediaCastMode>& | 150 const std::unordered_map<MediaRoute::Id, MediaCastMode>& |
152 routes_and_cast_modes() const { | 151 routes_and_cast_modes() const { |
153 return routes_and_cast_modes_; | 152 return routes_and_cast_modes_; |
154 } | 153 } |
155 const content::WebContents* initiator() const { return initiator_; } | 154 const content::WebContents* initiator() const { return initiator_; } |
156 | 155 |
157 // Marked virtual for tests. | |
158 virtual const std::string& GetRouteProviderExtensionId() const; | 156 virtual const std::string& GetRouteProviderExtensionId() const; |
159 | 157 |
160 // Called to track UI metrics. | 158 // Called to track UI metrics. |
161 void SetUIInitializationTimer(const base::Time& start_time); | 159 void SetUIInitializationTimer(const base::Time& start_time); |
162 void OnUIInitiallyLoaded(); | 160 void OnUIInitiallyLoaded(); |
163 void OnUIInitialDataReceived(); | 161 void OnUIInitialDataReceived(); |
164 | 162 |
165 void UpdateMaxDialogHeight(int height); | 163 void UpdateMaxDialogHeight(int height); |
166 | 164 |
| 165 // Gets the route controller currently in use by the UI. Returns a nullptr if |
| 166 // none is in use. |
| 167 virtual const MediaRouteController* GetMediaRouteController() const; |
| 168 |
| 169 // Called when a media controller UI surface is created. Creates an observer |
| 170 // for the MediaRouteController for |route_id| to listen for media status |
| 171 // updates. |
| 172 virtual void OnMediaControllerUIAvailable(const MediaRoute::Id& route_id); |
| 173 // Called when a media controller UI surface is closed. Resets the observer |
| 174 // for MediaRouteController. |
| 175 virtual void OnMediaControllerUIClosed(); |
| 176 |
167 void InitForTest(MediaRouter* router, | 177 void InitForTest(MediaRouter* router, |
168 content::WebContents* initiator, | 178 content::WebContents* initiator, |
169 MediaRouterWebUIMessageHandler* handler, | 179 MediaRouterWebUIMessageHandler* handler, |
170 std::unique_ptr<CreatePresentationConnectionRequest> | 180 std::unique_ptr<CreatePresentationConnectionRequest> |
171 create_session_request); | 181 create_session_request); |
172 | 182 |
173 private: | 183 private: |
| 184 friend class MediaRouterUITest; |
| 185 |
174 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 186 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
175 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); | 187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); |
176 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); | 188 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); |
177 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); | 189 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); |
178 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 190 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
179 UIMediaRoutesObserverAssignsCurrentCastModes); | 191 UIMediaRoutesObserverAssignsCurrentCastModes); |
180 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 192 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
181 UIMediaRoutesObserverSkipsUnavailableCastModes); | 193 UIMediaRoutesObserverSkipsUnavailableCastModes); |
182 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 194 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
183 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 195 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
184 GetExtensionNameEmptyWhenNotInstalled); | 196 GetExtensionNameEmptyWhenNotInstalled); |
185 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 197 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
186 GetExtensionNameEmptyWhenNotExtensionURL); | 198 GetExtensionNameEmptyWhenNotExtensionURL); |
187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 199 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
188 RouteCreationTimeoutForPresentation); | 200 RouteCreationTimeoutForPresentation); |
189 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); | 201 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); |
| 202 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, OpenAndCloseUIDetailsView); |
| 203 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaCommands); |
| 204 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaStatusUpdate); |
190 | 205 |
191 class UIIssuesObserver; | 206 class UIIssuesObserver; |
192 | 207 |
193 class UIMediaRoutesObserver : public MediaRoutesObserver { | 208 class UIMediaRoutesObserver : public MediaRoutesObserver { |
194 public: | 209 public: |
195 using RoutesUpdatedCallback = | 210 using RoutesUpdatedCallback = |
196 base::Callback<void(const std::vector<MediaRoute>&, | 211 base::Callback<void(const std::vector<MediaRoute>&, |
197 const std::vector<MediaRoute::Id>&)>; | 212 const std::vector<MediaRoute::Id>&)>; |
198 UIMediaRoutesObserver(MediaRouter* router, | 213 UIMediaRoutesObserver(MediaRouter* router, |
199 const MediaSource::Id& source_id, | 214 const MediaSource::Id& source_id, |
200 const RoutesUpdatedCallback& callback); | 215 const RoutesUpdatedCallback& callback); |
201 ~UIMediaRoutesObserver() override; | 216 ~UIMediaRoutesObserver() override; |
202 | 217 |
203 // MediaRoutesObserver | 218 // MediaRoutesObserver |
204 void OnRoutesUpdated( | 219 void OnRoutesUpdated( |
205 const std::vector<MediaRoute>& routes, | 220 const std::vector<MediaRoute>& routes, |
206 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | 221 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
207 | 222 |
208 private: | 223 private: |
209 // Callback to the owning MediaRouterUI instance. | 224 // Callback to the owning MediaRouterUI instance. |
210 RoutesUpdatedCallback callback_; | 225 RoutesUpdatedCallback callback_; |
211 | 226 |
212 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 227 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
213 }; | 228 }; |
214 | 229 |
| 230 class UIMediaRouteControllerObserver : public MediaRouteController::Observer { |
| 231 public: |
| 232 explicit UIMediaRouteControllerObserver( |
| 233 MediaRouterUI* ui, |
| 234 scoped_refptr<MediaRouteController> controller); |
| 235 ~UIMediaRouteControllerObserver() override; |
| 236 |
| 237 // MediaRouteController::Observer |
| 238 void OnMediaStatusUpdated(const MediaStatus& status) override; |
| 239 void OnControllerInvalidated() override; |
| 240 |
| 241 private: |
| 242 MediaRouterUI* ui_; |
| 243 |
| 244 DISALLOW_COPY_AND_ASSIGN(UIMediaRouteControllerObserver); |
| 245 }; |
| 246 |
215 static std::string GetExtensionName(const GURL& url, | 247 static std::string GetExtensionName(const GURL& url, |
216 extensions::ExtensionRegistry* registry); | 248 extensions::ExtensionRegistry* registry); |
217 | 249 |
218 // QueryResultManager::Observer | 250 // QueryResultManager::Observer |
219 void OnResultsUpdated( | 251 void OnResultsUpdated( |
220 const std::vector<MediaSinkWithCastModes>& sinks) override; | 252 const std::vector<MediaSinkWithCastModes>& sinks) override; |
221 | 253 |
222 // Called by |issues_observer_| when the top issue has changed. | 254 // Called by |issues_observer_| when the top issue has changed. |
223 // If the UI is already initialized, notifies |handler_| to update the UI. | 255 // If the UI is already initialized, notifies |handler_| to update the UI. |
224 // Ignored if the UI is not yet initialized. | 256 // Ignored if the UI is not yet initialized. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void UpdateRoutesToCastModesMapping(); | 316 void UpdateRoutesToCastModesMapping(); |
285 | 317 |
286 // Returns the default presentation request's frame URL if there is one. | 318 // Returns the default presentation request's frame URL if there is one. |
287 // Otherwise returns an empty GURL. | 319 // Otherwise returns an empty GURL. |
288 GURL GetFrameURL() const; | 320 GURL GetFrameURL() const; |
289 | 321 |
290 // Returns the serialized origin for |initiator_|, or the serialization of an | 322 // Returns the serialized origin for |initiator_|, or the serialization of an |
291 // opaque origin ("null") if |initiator_| is not set. | 323 // opaque origin ("null") if |initiator_| is not set. |
292 std::string GetSerializedInitiatorOrigin() const; | 324 std::string GetSerializedInitiatorOrigin() const; |
293 | 325 |
| 326 // Destroys the route controller observer. Called when the route controller is |
| 327 // invalidated. |
| 328 void OnRouteControllerInvalidated(); |
| 329 |
| 330 // Called by the internal route controller observer. Notifies the message |
| 331 // handler of a media status update for the route currently shown in the UI. |
| 332 void UpdateMediaRouteStatus(const MediaStatus& status); |
| 333 |
294 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 334 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
295 // only after it has deleted |this|. | 335 // only after it has deleted |this|. |
296 MediaRouterWebUIMessageHandler* handler_ = nullptr; | 336 MediaRouterWebUIMessageHandler* handler_ = nullptr; |
297 | 337 |
298 // These are non-null while this instance is registered to receive | 338 // These are non-null while this instance is registered to receive |
299 // updates from them. | 339 // updates from them. |
300 std::unique_ptr<IssuesObserver> issues_observer_; | 340 std::unique_ptr<IssuesObserver> issues_observer_; |
301 std::unique_ptr<MediaRoutesObserver> routes_observer_; | 341 std::unique_ptr<MediaRoutesObserver> routes_observer_; |
302 | 342 |
303 // Set to true by |handler_| when the UI has been initialized. | 343 // Set to true by |handler_| when the UI has been initialized. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 381 |
342 content::WebContents* initiator_; | 382 content::WebContents* initiator_; |
343 | 383 |
344 // Pointer to the MediaRouter for this instance's BrowserContext. | 384 // Pointer to the MediaRouter for this instance's BrowserContext. |
345 MediaRouter* router_; | 385 MediaRouter* router_; |
346 | 386 |
347 // The start time for UI initialization metrics timer. When a dialog has been | 387 // The start time for UI initialization metrics timer. When a dialog has been |
348 // been painted and initialized with initial data, this should be cleared. | 388 // been painted and initialized with initial data, this should be cleared. |
349 base::Time start_time_; | 389 base::Time start_time_; |
350 | 390 |
| 391 // The observer for the route controller. Notifies |handler_| of media status |
| 392 // updates. |
| 393 std::unique_ptr<UIMediaRouteControllerObserver> route_controller_observer_; |
| 394 |
351 // NOTE: Weak pointers must be invalidated before all other member variables. | 395 // NOTE: Weak pointers must be invalidated before all other member variables. |
352 // Therefore |weak_factory_| must be placed at the end. | 396 // Therefore |weak_factory_| must be placed at the end. |
353 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 397 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
354 | 398 |
355 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 399 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
356 }; | 400 }; |
357 | 401 |
358 } // namespace media_router | 402 } // namespace media_router |
359 | 403 |
360 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 404 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |