Chromium Code Reviews| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // Marked virtual for tests. | 158 // Marked virtual for tests. |
| 158 virtual const std::string& GetRouteProviderExtensionId() const; | 159 virtual const std::string& GetRouteProviderExtensionId() const; |
| 159 | 160 |
| 160 // Called to track UI metrics. | 161 // Called to track UI metrics. |
| 161 void SetUIInitializationTimer(const base::Time& start_time); | 162 void SetUIInitializationTimer(const base::Time& start_time); |
| 162 void OnUIInitiallyLoaded(); | 163 void OnUIInitiallyLoaded(); |
| 163 void OnUIInitialDataReceived(); | 164 void OnUIInitialDataReceived(); |
| 164 | 165 |
| 165 void UpdateMaxDialogHeight(int height); | 166 void UpdateMaxDialogHeight(int height); |
| 166 | 167 |
| 168 // Sends media commands to |route_controller_| if it is set. Marked virtual | |
| 169 // for tests. | |
| 170 virtual void PlayRoute(); | |
|
imcheng
2017/04/22 00:22:51
These are duplicated method signatures from MediaR
takumif
2017/04/24 20:59:23
I realized that we should sanitize the arguments f
imcheng
2017/04/26 21:48:39
I would have the MessageHandler parse/validate the
takumif
2017/04/27 03:04:17
Okay, making the MessageHandler call the controlle
| |
| 171 virtual void PauseRoute(); | |
| 172 virtual void SeekRoute(base::TimeDelta time); | |
| 173 virtual void SetRouteMute(bool mute); | |
| 174 virtual void SetRouteVolume(float volume); | |
| 175 | |
| 176 // Gets a reference to the MediaRouteController for |route_id| and | |
| 177 // instantiates an observer for media status updates for the route. Marked | |
| 178 // virtual for tests. | |
| 179 virtual void OnUIDetailsViewOpened(MediaRoute::Id route_id); | |
| 180 // Resets |route_controller_| and |route_status_observer_|. Marked virtual for | |
| 181 // tests. | |
| 182 virtual void OnUIDetailsViewClosed(); | |
| 183 | |
| 167 void InitForTest(MediaRouter* router, | 184 void InitForTest(MediaRouter* router, |
| 168 content::WebContents* initiator, | 185 content::WebContents* initiator, |
| 169 MediaRouterWebUIMessageHandler* handler, | 186 MediaRouterWebUIMessageHandler* handler, |
| 170 std::unique_ptr<CreatePresentationConnectionRequest> | 187 std::unique_ptr<CreatePresentationConnectionRequest> |
| 171 create_session_request); | 188 create_session_request); |
| 172 | 189 |
| 173 private: | 190 private: |
| 191 friend class MediaRouterUITest; | |
| 192 | |
| 174 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 193 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
| 175 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); | 194 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); |
| 176 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); | 195 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); |
| 177 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); | 196 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); |
| 178 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 197 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 179 UIMediaRoutesObserverAssignsCurrentCastModes); | 198 UIMediaRoutesObserverAssignsCurrentCastModes); |
| 180 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 199 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 181 UIMediaRoutesObserverSkipsUnavailableCastModes); | 200 UIMediaRoutesObserverSkipsUnavailableCastModes); |
| 182 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 201 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
| 183 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 202 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 184 GetExtensionNameEmptyWhenNotInstalled); | 203 GetExtensionNameEmptyWhenNotInstalled); |
| 185 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 204 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 186 GetExtensionNameEmptyWhenNotExtensionURL); | 205 GetExtensionNameEmptyWhenNotExtensionURL); |
| 187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 206 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 188 RouteCreationTimeoutForPresentation); | 207 RouteCreationTimeoutForPresentation); |
| 189 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); | 208 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); |
| 209 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, OpenAndCloseUIDetailsView); | |
| 210 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaCommands); | |
| 211 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaStatusUpdate); | |
| 212 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, IsValidRouteId); | |
| 190 | 213 |
| 191 class UIIssuesObserver; | 214 class UIIssuesObserver; |
| 192 | 215 |
| 193 class UIMediaRoutesObserver : public MediaRoutesObserver { | 216 class UIMediaRoutesObserver : public MediaRoutesObserver { |
| 194 public: | 217 public: |
| 195 using RoutesUpdatedCallback = | 218 using RoutesUpdatedCallback = |
| 196 base::Callback<void(const std::vector<MediaRoute>&, | 219 base::Callback<void(const std::vector<MediaRoute>&, |
| 197 const std::vector<MediaRoute::Id>&)>; | 220 const std::vector<MediaRoute::Id>&)>; |
| 198 UIMediaRoutesObserver(MediaRouter* router, | 221 UIMediaRoutesObserver(MediaRouter* router, |
| 199 const MediaSource::Id& source_id, | 222 const MediaSource::Id& source_id, |
| 200 const RoutesUpdatedCallback& callback); | 223 const RoutesUpdatedCallback& callback); |
| 201 ~UIMediaRoutesObserver() override; | 224 ~UIMediaRoutesObserver() override; |
| 202 | 225 |
| 203 // MediaRoutesObserver | 226 // MediaRoutesObserver |
| 204 void OnRoutesUpdated( | 227 void OnRoutesUpdated( |
| 205 const std::vector<MediaRoute>& routes, | 228 const std::vector<MediaRoute>& routes, |
| 206 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | 229 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
| 207 | 230 |
| 208 private: | 231 private: |
| 209 // Callback to the owning MediaRouterUI instance. | 232 // Callback to the owning MediaRouterUI instance. |
| 210 RoutesUpdatedCallback callback_; | 233 RoutesUpdatedCallback callback_; |
| 211 | 234 |
| 212 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 235 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
| 213 }; | 236 }; |
| 214 | 237 |
| 238 class UIMediaRouteControllerObserver : public MediaRouteController::Observer { | |
| 239 public: | |
| 240 explicit UIMediaRouteControllerObserver( | |
| 241 MediaRouterUI* ui, | |
| 242 scoped_refptr<MediaRouteController> controller); | |
| 243 ~UIMediaRouteControllerObserver() override; | |
| 244 | |
| 245 // MediaRouteController::Observer | |
| 246 void OnMediaStatusUpdated(const MediaStatus& status) override; | |
| 247 void OnControllerInvalidated() override; | |
| 248 | |
| 249 private: | |
| 250 MediaRouterUI* ui_; | |
| 251 | |
| 252 DISALLOW_COPY_AND_ASSIGN(UIMediaRouteControllerObserver); | |
| 253 }; | |
| 254 | |
| 215 static std::string GetExtensionName(const GURL& url, | 255 static std::string GetExtensionName(const GURL& url, |
| 216 extensions::ExtensionRegistry* registry); | 256 extensions::ExtensionRegistry* registry); |
| 217 | 257 |
| 218 // QueryResultManager::Observer | 258 // QueryResultManager::Observer |
| 219 void OnResultsUpdated( | 259 void OnResultsUpdated( |
| 220 const std::vector<MediaSinkWithCastModes>& sinks) override; | 260 const std::vector<MediaSinkWithCastModes>& sinks) override; |
| 221 | 261 |
| 222 // Called by |issues_observer_| when the top issue has changed. | 262 // Called by |issues_observer_| when the top issue has changed. |
| 223 // If the UI is already initialized, notifies |handler_| to update the UI. | 263 // If the UI is already initialized, notifies |handler_| to update the UI. |
| 224 // Ignored if the UI is not yet initialized. | 264 // Ignored if the UI is not yet initialized. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 void UpdateRoutesToCastModesMapping(); | 324 void UpdateRoutesToCastModesMapping(); |
| 285 | 325 |
| 286 // Returns the default presentation request's frame URL if there is one. | 326 // Returns the default presentation request's frame URL if there is one. |
| 287 // Otherwise returns an empty GURL. | 327 // Otherwise returns an empty GURL. |
| 288 GURL GetFrameURL() const; | 328 GURL GetFrameURL() const; |
| 289 | 329 |
| 290 // Returns the serialized origin for |initiator_|, or the serialization of an | 330 // Returns the serialized origin for |initiator_|, or the serialization of an |
| 291 // opaque origin ("null") if |initiator_| is not set. | 331 // opaque origin ("null") if |initiator_| is not set. |
| 292 std::string GetSerializedInitiatorOrigin() const; | 332 std::string GetSerializedInitiatorOrigin() const; |
| 293 | 333 |
| 334 // Returns true if |routes_| contains a route with |route_id|. | |
| 335 bool IsValidRouteId(const MediaRoute::Id& route_id) const; | |
| 336 | |
| 337 // Destroys the route controller observer. Called when the route controller is | |
| 338 // invalidated. | |
| 339 void OnRouteControllerInvalidated(); | |
| 340 | |
| 294 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 341 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
| 295 // only after it has deleted |this|. | 342 // only after it has deleted |this|. |
| 296 MediaRouterWebUIMessageHandler* handler_ = nullptr; | 343 MediaRouterWebUIMessageHandler* handler_ = nullptr; |
| 297 | 344 |
| 298 // These are non-null while this instance is registered to receive | 345 // These are non-null while this instance is registered to receive |
| 299 // updates from them. | 346 // updates from them. |
| 300 std::unique_ptr<IssuesObserver> issues_observer_; | 347 std::unique_ptr<IssuesObserver> issues_observer_; |
| 301 std::unique_ptr<MediaRoutesObserver> routes_observer_; | 348 std::unique_ptr<MediaRoutesObserver> routes_observer_; |
| 302 | 349 |
| 303 // Set to true by |handler_| when the UI has been initialized. | 350 // 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 | 388 |
| 342 content::WebContents* initiator_; | 389 content::WebContents* initiator_; |
| 343 | 390 |
| 344 // Pointer to the MediaRouter for this instance's BrowserContext. | 391 // Pointer to the MediaRouter for this instance's BrowserContext. |
| 345 MediaRouter* router_; | 392 MediaRouter* router_; |
| 346 | 393 |
| 347 // The start time for UI initialization metrics timer. When a dialog has been | 394 // 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. | 395 // been painted and initialized with initial data, this should be cleared. |
| 349 base::Time start_time_; | 396 base::Time start_time_; |
| 350 | 397 |
| 398 // The observer for the route controller. Notifies |handler_| of media status | |
| 399 // updates. | |
| 400 std::unique_ptr<UIMediaRouteControllerObserver> route_controller_observer_; | |
| 401 | |
| 351 // NOTE: Weak pointers must be invalidated before all other member variables. | 402 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 352 // Therefore |weak_factory_| must be placed at the end. | 403 // Therefore |weak_factory_| must be placed at the end. |
| 353 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 404 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
| 354 | 405 |
| 355 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 406 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
| 356 }; | 407 }; |
| 357 | 408 |
| 358 } // namespace media_router | 409 } // namespace media_router |
| 359 | 410 |
| 360 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 411 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| OLD | NEW |