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 // Creates an observer for the MediaRouteController for |route_id| to listen | |
170 // for media status updates. | |
mark a. foltz
2017/05/01 21:28:43
This documentation describes the implementation bu
takumif
2017/05/02 21:37:37
Done.
| |
171 virtual void OnMediaControllerUIAvailable(const MediaRoute::Id& route_id); | |
172 // Resets the observer for MediaRouteController. | |
mark a. foltz
2017/05/01 21:28:43
Similar comment here.
takumif
2017/05/02 21:37:37
Done.
| |
173 virtual void OnMediaControllerUIClosed(); | |
174 | |
167 void InitForTest(MediaRouter* router, | 175 void InitForTest(MediaRouter* router, |
168 content::WebContents* initiator, | 176 content::WebContents* initiator, |
169 MediaRouterWebUIMessageHandler* handler, | 177 MediaRouterWebUIMessageHandler* handler, |
170 std::unique_ptr<CreatePresentationConnectionRequest> | 178 std::unique_ptr<CreatePresentationConnectionRequest> |
171 create_session_request); | 179 create_session_request); |
172 | 180 |
173 private: | 181 private: |
182 friend class MediaRouterUITest; | |
183 | |
174 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 184 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
175 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); | 185 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortSinksByIconType); |
176 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); | 186 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayRoutes); |
177 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); | 187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, FilterNonDisplayJoinableRoutes); |
178 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 188 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
179 UIMediaRoutesObserverAssignsCurrentCastModes); | 189 UIMediaRoutesObserverAssignsCurrentCastModes); |
180 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 190 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
181 UIMediaRoutesObserverSkipsUnavailableCastModes); | 191 UIMediaRoutesObserverSkipsUnavailableCastModes); |
182 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 192 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
183 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 193 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
184 GetExtensionNameEmptyWhenNotInstalled); | 194 GetExtensionNameEmptyWhenNotInstalled); |
185 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 195 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
186 GetExtensionNameEmptyWhenNotExtensionURL); | 196 GetExtensionNameEmptyWhenNotExtensionURL); |
187 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 197 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
188 RouteCreationTimeoutForPresentation); | 198 RouteCreationTimeoutForPresentation); |
189 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); | 199 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); |
200 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, OpenAndCloseUIDetailsView); | |
201 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaCommands); | |
202 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SendMediaStatusUpdate); | |
190 | 203 |
191 class UIIssuesObserver; | 204 class UIIssuesObserver; |
192 | 205 |
193 class UIMediaRoutesObserver : public MediaRoutesObserver { | 206 class UIMediaRoutesObserver : public MediaRoutesObserver { |
194 public: | 207 public: |
195 using RoutesUpdatedCallback = | 208 using RoutesUpdatedCallback = |
196 base::Callback<void(const std::vector<MediaRoute>&, | 209 base::Callback<void(const std::vector<MediaRoute>&, |
197 const std::vector<MediaRoute::Id>&)>; | 210 const std::vector<MediaRoute::Id>&)>; |
198 UIMediaRoutesObserver(MediaRouter* router, | 211 UIMediaRoutesObserver(MediaRouter* router, |
199 const MediaSource::Id& source_id, | 212 const MediaSource::Id& source_id, |
200 const RoutesUpdatedCallback& callback); | 213 const RoutesUpdatedCallback& callback); |
201 ~UIMediaRoutesObserver() override; | 214 ~UIMediaRoutesObserver() override; |
202 | 215 |
203 // MediaRoutesObserver | 216 // MediaRoutesObserver |
204 void OnRoutesUpdated( | 217 void OnRoutesUpdated( |
205 const std::vector<MediaRoute>& routes, | 218 const std::vector<MediaRoute>& routes, |
206 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | 219 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
207 | 220 |
208 private: | 221 private: |
209 // Callback to the owning MediaRouterUI instance. | 222 // Callback to the owning MediaRouterUI instance. |
210 RoutesUpdatedCallback callback_; | 223 RoutesUpdatedCallback callback_; |
211 | 224 |
212 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 225 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
213 }; | 226 }; |
214 | 227 |
228 class UIMediaRouteControllerObserver : public MediaRouteController::Observer { | |
229 public: | |
230 explicit UIMediaRouteControllerObserver( | |
231 MediaRouterUI* ui, | |
232 scoped_refptr<MediaRouteController> controller); | |
233 ~UIMediaRouteControllerObserver() override; | |
234 | |
235 // MediaRouteController::Observer | |
236 void OnMediaStatusUpdated(const MediaStatus& status) override; | |
237 void OnControllerInvalidated() override; | |
238 | |
239 private: | |
240 MediaRouterUI* ui_; | |
241 | |
242 DISALLOW_COPY_AND_ASSIGN(UIMediaRouteControllerObserver); | |
243 }; | |
244 | |
215 static std::string GetExtensionName(const GURL& url, | 245 static std::string GetExtensionName(const GURL& url, |
216 extensions::ExtensionRegistry* registry); | 246 extensions::ExtensionRegistry* registry); |
217 | 247 |
218 // QueryResultManager::Observer | 248 // QueryResultManager::Observer |
219 void OnResultsUpdated( | 249 void OnResultsUpdated( |
220 const std::vector<MediaSinkWithCastModes>& sinks) override; | 250 const std::vector<MediaSinkWithCastModes>& sinks) override; |
221 | 251 |
222 // Called by |issues_observer_| when the top issue has changed. | 252 // Called by |issues_observer_| when the top issue has changed. |
223 // If the UI is already initialized, notifies |handler_| to update the UI. | 253 // If the UI is already initialized, notifies |handler_| to update the UI. |
224 // Ignored if the UI is not yet initialized. | 254 // Ignored if the UI is not yet initialized. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 void UpdateRoutesToCastModesMapping(); | 314 void UpdateRoutesToCastModesMapping(); |
285 | 315 |
286 // Returns the default presentation request's frame URL if there is one. | 316 // Returns the default presentation request's frame URL if there is one. |
287 // Otherwise returns an empty GURL. | 317 // Otherwise returns an empty GURL. |
288 GURL GetFrameURL() const; | 318 GURL GetFrameURL() const; |
289 | 319 |
290 // Returns the serialized origin for |initiator_|, or the serialization of an | 320 // Returns the serialized origin for |initiator_|, or the serialization of an |
291 // opaque origin ("null") if |initiator_| is not set. | 321 // opaque origin ("null") if |initiator_| is not set. |
292 std::string GetSerializedInitiatorOrigin() const; | 322 std::string GetSerializedInitiatorOrigin() const; |
293 | 323 |
324 // Destroys the route controller observer. Called when the route controller is | |
325 // invalidated. | |
326 void OnRouteControllerInvalidated(); | |
327 | |
294 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 328 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
295 // only after it has deleted |this|. | 329 // only after it has deleted |this|. |
296 MediaRouterWebUIMessageHandler* handler_ = nullptr; | 330 MediaRouterWebUIMessageHandler* handler_ = nullptr; |
297 | 331 |
298 // These are non-null while this instance is registered to receive | 332 // These are non-null while this instance is registered to receive |
299 // updates from them. | 333 // updates from them. |
300 std::unique_ptr<IssuesObserver> issues_observer_; | 334 std::unique_ptr<IssuesObserver> issues_observer_; |
301 std::unique_ptr<MediaRoutesObserver> routes_observer_; | 335 std::unique_ptr<MediaRoutesObserver> routes_observer_; |
302 | 336 |
303 // Set to true by |handler_| when the UI has been initialized. | 337 // 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 | 375 |
342 content::WebContents* initiator_; | 376 content::WebContents* initiator_; |
343 | 377 |
344 // Pointer to the MediaRouter for this instance's BrowserContext. | 378 // Pointer to the MediaRouter for this instance's BrowserContext. |
345 MediaRouter* router_; | 379 MediaRouter* router_; |
346 | 380 |
347 // The start time for UI initialization metrics timer. When a dialog has been | 381 // 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. | 382 // been painted and initialized with initial data, this should be cleared. |
349 base::Time start_time_; | 383 base::Time start_time_; |
350 | 384 |
385 // The observer for the route controller. Notifies |handler_| of media status | |
386 // updates. | |
387 std::unique_ptr<UIMediaRouteControllerObserver> route_controller_observer_; | |
388 | |
351 // NOTE: Weak pointers must be invalidated before all other member variables. | 389 // NOTE: Weak pointers must be invalidated before all other member variables. |
352 // Therefore |weak_factory_| must be placed at the end. | 390 // Therefore |weak_factory_| must be placed at the end. |
353 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 391 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
354 | 392 |
355 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 393 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
356 }; | 394 }; |
357 | 395 |
358 } // namespace media_router | 396 } // namespace media_router |
359 | 397 |
360 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 398 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |