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" | |
18 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 17 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
19 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
20 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" | 19 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" |
21 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" | 20 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" |
22 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" | 21 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" |
23 #include "chrome/common/media_router/issue.h" | 22 #include "chrome/common/media_router/issue.h" |
24 #include "chrome/common/media_router/media_source.h" | 23 #include "chrome/common/media_router/media_source.h" |
25 #include "content/public/browser/web_ui_data_source.h" | 24 #include "content/public/browser/web_ui_data_source.h" |
26 #include "third_party/icu/source/common/unicode/uversion.h" | 25 #include "third_party/icu/source/common/unicode/uversion.h" |
27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // ownership of it. Must not be null. | 88 // ownership of it. Must not be null. |
90 void InitWithPresentationSessionRequest( | 89 void InitWithPresentationSessionRequest( |
91 content::WebContents* initiator, | 90 content::WebContents* initiator, |
92 PresentationServiceDelegateImpl* delegate, | 91 PresentationServiceDelegateImpl* delegate, |
93 std::unique_ptr<CreatePresentationConnectionRequest> | 92 std::unique_ptr<CreatePresentationConnectionRequest> |
94 presentation_request); | 93 presentation_request); |
95 | 94 |
96 // Closes the media router UI. | 95 // Closes the media router UI. |
97 void Close(); | 96 void Close(); |
98 | 97 |
99 // Notifies this instance that the UI has been initialized. | 98 // Notifies this instance that the UI has been initialized. Marked virtual for |
| 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. | 131 // mirroring. Marked virtual for tests. |
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. | 135 // mode is MediaCastMode::DESKTOP_MIRROR. Marked virtual for tests. |
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. |
149 virtual const std::set<MediaCastMode>& cast_modes() const; | 150 virtual const std::set<MediaCastMode>& cast_modes() const; |
150 const std::unordered_map<MediaRoute::Id, MediaCastMode>& | 151 const std::unordered_map<MediaRoute::Id, MediaCastMode>& |
151 routes_and_cast_modes() const { | 152 routes_and_cast_modes() const { |
152 return routes_and_cast_modes_; | 153 return routes_and_cast_modes_; |
153 } | 154 } |
154 const content::WebContents* initiator() const { return initiator_; } | 155 const content::WebContents* initiator() const { return initiator_; } |
155 | 156 |
| 157 // Marked virtual for tests. |
156 virtual const std::string& GetRouteProviderExtensionId() const; | 158 virtual const std::string& GetRouteProviderExtensionId() const; |
157 | 159 |
158 // Called to track UI metrics. | 160 // Called to track UI metrics. |
159 void SetUIInitializationTimer(const base::Time& start_time); | 161 void SetUIInitializationTimer(const base::Time& start_time); |
160 void OnUIInitiallyLoaded(); | 162 void OnUIInitiallyLoaded(); |
161 void OnUIInitialDataReceived(); | 163 void OnUIInitialDataReceived(); |
162 | 164 |
163 void UpdateMaxDialogHeight(int height); | 165 void UpdateMaxDialogHeight(int height); |
164 | 166 |
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 | |
177 void InitForTest(MediaRouter* router, | 167 void InitForTest(MediaRouter* router, |
178 content::WebContents* initiator, | 168 content::WebContents* initiator, |
179 MediaRouterWebUIMessageHandler* handler, | 169 MediaRouterWebUIMessageHandler* handler, |
180 std::unique_ptr<CreatePresentationConnectionRequest> | 170 std::unique_ptr<CreatePresentationConnectionRequest> |
181 create_session_request); | 171 create_session_request); |
182 | 172 |
183 private: | 173 private: |
184 friend class MediaRouterUITest; | |
185 | |
186 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 174 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); | 175 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); |
188 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); | 176 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); |
189 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); | 177 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); |
190 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 178 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
191 UIMediaRoutesObserverAssignsCurrentCastModes); | 179 UIMediaRoutesObserverAssignsCurrentCastModes); |
192 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 180 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
193 UIMediaRoutesObserverSkipsUnavailableCastModes); | 181 UIMediaRoutesObserverSkipsUnavailableCastModes); |
194 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 182 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
195 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 183 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
196 GetExtensionNameEmptyWhenNotInstalled); | 184 GetExtensionNameEmptyWhenNotInstalled); |
197 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 185 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
198 GetExtensionNameEmptyWhenNotExtensionURL); | 186 GetExtensionNameEmptyWhenNotExtensionURL); |
199 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
200 RouteCreationTimeoutForPresentation); | 188 RouteCreationTimeoutForPresentation); |
201 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); | 189 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); | |
205 | 190 |
206 class UIIssuesObserver; | 191 class UIIssuesObserver; |
207 | 192 |
208 class UIMediaRoutesObserver : public MediaRoutesObserver { | 193 class UIMediaRoutesObserver : public MediaRoutesObserver { |
209 public: | 194 public: |
210 using RoutesUpdatedCallback = | 195 using RoutesUpdatedCallback = |
211 base::Callback<void(const std::vector<MediaRoute>&, | 196 base::Callback<void(const std::vector<MediaRoute>&, |
212 const std::vector<MediaRoute::Id>&)>; | 197 const std::vector<MediaRoute::Id>&)>; |
213 UIMediaRoutesObserver(MediaRouter* router, | 198 UIMediaRoutesObserver(MediaRouter* router, |
214 const MediaSource::Id& source_id, | 199 const MediaSource::Id& source_id, |
215 const RoutesUpdatedCallback& callback); | 200 const RoutesUpdatedCallback& callback); |
216 ~UIMediaRoutesObserver() override; | 201 ~UIMediaRoutesObserver() override; |
217 | 202 |
218 // MediaRoutesObserver | 203 // MediaRoutesObserver |
219 void OnRoutesUpdated( | 204 void OnRoutesUpdated( |
220 const std::vector<MediaRoute>& routes, | 205 const std::vector<MediaRoute>& routes, |
221 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | 206 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
222 | 207 |
223 private: | 208 private: |
224 // Callback to the owning MediaRouterUI instance. | 209 // Callback to the owning MediaRouterUI instance. |
225 RoutesUpdatedCallback callback_; | 210 RoutesUpdatedCallback callback_; |
226 | 211 |
227 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 212 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
228 }; | 213 }; |
229 | 214 |
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 | |
247 static std::string GetExtensionName(const GURL& url, | 215 static std::string GetExtensionName(const GURL& url, |
248 extensions::ExtensionRegistry* registry); | 216 extensions::ExtensionRegistry* registry); |
249 | 217 |
250 // QueryResultManager::Observer | 218 // QueryResultManager::Observer |
251 void OnResultsUpdated( | 219 void OnResultsUpdated( |
252 const std::vector<MediaSinkWithCastModes>& sinks) override; | 220 const std::vector<MediaSinkWithCastModes>& sinks) override; |
253 | 221 |
254 // Called by |issues_observer_| when the top issue has changed. | 222 // Called by |issues_observer_| when the top issue has changed. |
255 // If the UI is already initialized, notifies |handler_| to update the UI. | 223 // If the UI is already initialized, notifies |handler_| to update the UI. |
256 // Ignored if the UI is not yet initialized. | 224 // Ignored if the UI is not yet initialized. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 void UpdateRoutesToCastModesMapping(); | 284 void UpdateRoutesToCastModesMapping(); |
317 | 285 |
318 // Returns the default presentation request's frame URL if there is one. | 286 // Returns the default presentation request's frame URL if there is one. |
319 // Otherwise returns an empty GURL. | 287 // Otherwise returns an empty GURL. |
320 GURL GetFrameURL() const; | 288 GURL GetFrameURL() const; |
321 | 289 |
322 // Returns the serialized origin for |initiator_|, or the serialization of an | 290 // Returns the serialized origin for |initiator_|, or the serialization of an |
323 // opaque origin ("null") if |initiator_| is not set. | 291 // opaque origin ("null") if |initiator_| is not set. |
324 std::string GetSerializedInitiatorOrigin() const; | 292 std::string GetSerializedInitiatorOrigin() const; |
325 | 293 |
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 | |
334 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 294 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
335 // only after it has deleted |this|. | 295 // only after it has deleted |this|. |
336 MediaRouterWebUIMessageHandler* handler_ = nullptr; | 296 MediaRouterWebUIMessageHandler* handler_ = nullptr; |
337 | 297 |
338 // These are non-null while this instance is registered to receive | 298 // These are non-null while this instance is registered to receive |
339 // updates from them. | 299 // updates from them. |
340 std::unique_ptr<IssuesObserver> issues_observer_; | 300 std::unique_ptr<IssuesObserver> issues_observer_; |
341 std::unique_ptr<MediaRoutesObserver> routes_observer_; | 301 std::unique_ptr<MediaRoutesObserver> routes_observer_; |
342 | 302 |
343 // Set to true by |handler_| when the UI has been initialized. | 303 // Set to true by |handler_| when the UI has been initialized. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 341 |
382 content::WebContents* initiator_; | 342 content::WebContents* initiator_; |
383 | 343 |
384 // Pointer to the MediaRouter for this instance's BrowserContext. | 344 // Pointer to the MediaRouter for this instance's BrowserContext. |
385 MediaRouter* router_; | 345 MediaRouter* router_; |
386 | 346 |
387 // The start time for UI initialization metrics timer. When a dialog has been | 347 // The start time for UI initialization metrics timer. When a dialog has been |
388 // been painted and initialized with initial data, this should be cleared. | 348 // been painted and initialized with initial data, this should be cleared. |
389 base::Time start_time_; | 349 base::Time start_time_; |
390 | 350 |
391 // The observer for the route controller. Notifies |handler_| of media status | |
392 // updates. | |
393 std::unique_ptr<UIMediaRouteControllerObserver> route_controller_observer_; | |
394 | |
395 // NOTE: Weak pointers must be invalidated before all other member variables. | 351 // NOTE: Weak pointers must be invalidated before all other member variables. |
396 // Therefore |weak_factory_| must be placed at the end. | 352 // Therefore |weak_factory_| must be placed at the end. |
397 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 353 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
398 | 354 |
399 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 355 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
400 }; | 356 }; |
401 | 357 |
402 } // namespace media_router | 358 } // namespace media_router |
403 | 359 |
404 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 360 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |