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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 class WebContents; | 26 class WebContents; |
27 } // namespace content | 27 } // namespace content |
28 | 28 |
29 namespace media_router { | 29 namespace media_router { |
30 | 30 |
31 class IssuesObserver; | 31 class IssuesObserver; |
32 class MediaRoute; | 32 class MediaRoute; |
33 class MediaRouter; | 33 class MediaRouter; |
| 34 class MediaRouterDialogCallbacks; |
34 class MediaRouterWebUIMessageHandler; | 35 class MediaRouterWebUIMessageHandler; |
35 class MediaRoutesObserver; | 36 class MediaRoutesObserver; |
36 class MediaSink; | 37 class MediaSink; |
37 class MediaSinksObserver; | 38 class MediaSinksObserver; |
38 class CreateSessionRequest; | 39 class CreateSessionRequest; |
39 | 40 |
40 // Implements the chrome://media-router user interface. | 41 // Implements the chrome://media-router user interface. |
41 class MediaRouterUI | 42 class MediaRouterUI |
42 : public ConstrainedWebDialogUI, | 43 : public ConstrainedWebDialogUI, |
43 public QueryResultManager::Observer, | 44 public QueryResultManager::Observer, |
44 public PresentationServiceDelegateImpl::DefaultMediaSourceObserver { | 45 public PresentationServiceDelegateImpl::DefaultMediaSourceObserver { |
45 public: | 46 public: |
46 // |web_ui| owns this object and is used to initialize the base class. | 47 // |web_ui| owns this object and is used to initialize the base class. |
47 explicit MediaRouterUI(content::WebUI* web_ui); | 48 explicit MediaRouterUI(content::WebUI* web_ui); |
48 ~MediaRouterUI() override; | 49 ~MediaRouterUI() override; |
49 | 50 |
50 // Initializes internal state (e.g. starts listening for MediaSinks) for | 51 // Initializes internal state (e.g. starts listening for MediaSinks) for |
51 // targeting the default MediaSource (if any) of the tab. The contents of the | 52 // targeting the default MediaSource (if any) of the initiator tab as |
52 // UI will change as the default MediaSource changes. If there is a default | 53 // determined by |delegate|, as well as mirroring sources of that tab. |
53 // MediaSource, then DEFAULT MediaCastMode will be added to |cast_modes_|. | 54 // The contents of the UI will change as the default MediaSource changes. |
54 // |source_manager|: PresentationServiceDelegateImpl of the initiator tab. | 55 // If there is a default MediaSource, then DEFAULT MediaCastMode will be |
55 // Must not be null. | 56 // added to |cast_modes_|. |
56 // Can only be called once. | 57 // Init* methods can only be called once. |
| 58 // |delegate|: PresentationServiceDelegateImpl of the initiator tab. |
| 59 // Must not be null. |
| 60 // |dialog_callbacks|: The set of callbacks to be invoked by the UI as a |
| 61 // result of certain operations. Must not be null. |
57 // TODO(imcheng): Replace use of impl with an intermediate abstract | 62 // TODO(imcheng): Replace use of impl with an intermediate abstract |
58 // interface. | 63 // interface. |
59 void InitWithDefaultMediaSource(PresentationServiceDelegateImpl* delegate); | 64 void InitWithDefaultMediaSource( |
| 65 const base::WeakPtr<PresentationServiceDelegateImpl>& delegate, |
| 66 MediaRouterDialogCallbacks* dialog_callbacks); |
60 | 67 |
61 // Initializes internal state targeting the presentation specified in | 68 // Initializes internal state targeting the presentation specified in |
62 // |request|. Also sets up mirroring sources based on |initiator|. | 69 // the CreateSessionRequest in |dialog_callbacks|. |
| 70 // Also sets up mirroring sources based on |initiator|. |
63 // This is different from |InitWithDefaultMediaSource| in that it does not | 71 // This is different from |InitWithDefaultMediaSource| in that it does not |
64 // listen for default media source changes, as the UI is fixed to the source | 72 // listen for default media source changes, as the UI is fixed to the source |
65 // in |request|. | 73 // in |request|. |
| 74 // Init* methods can only be called once. |
| 75 // |intiator|: Reference to the WebContents that initiated the dialog. |
| 76 // Must not be null. |
| 77 // |dialog_callbacks|: The set of callbacks to be invoked by the UI as a |
| 78 // result of certain operations. Must not be null, and |
| 79 // must contain a CreateSessionRequest. |
66 void InitWithPresentationSessionRequest( | 80 void InitWithPresentationSessionRequest( |
67 const content::WebContents* initiator, | 81 const content::WebContents* initiator, |
68 scoped_ptr<CreateSessionRequest> request); | 82 MediaRouterDialogCallbacks* dialog_callbacks); |
69 | 83 |
70 // Closes the media router UI. | 84 // Closes the media router UI. |
71 void Close(); | 85 void Close(); |
72 | 86 |
73 // Notifies this instance that the UI has been initialized. | 87 // Notifies this instance that the UI has been initialized. |
74 void UIInitialized(); | 88 void UIInitialized(); |
75 | 89 |
76 // Requests a route be created from the source determined by the preferred | 90 // Requests a route be created from the source determined by the preferred |
77 // MediaCastMode, to the sink given by |sink_id|. | 91 // MediaCastMode, to the sink given by |sink_id|. |
78 // The preferred cast mode is determined from the set of currently supported | 92 // The preferred cast mode is determined from the set of currently supported |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Called by |issues_observer_| when the top issue has changed. | 132 // Called by |issues_observer_| when the top issue has changed. |
119 // If the UI is already initialized, notifies |handler_| to update the UI. | 133 // If the UI is already initialized, notifies |handler_| to update the UI. |
120 // Ignored if the UI is not yet initialized. | 134 // Ignored if the UI is not yet initialized. |
121 void SetIssue(const Issue* issue); | 135 void SetIssue(const Issue* issue); |
122 | 136 |
123 // Called by |routes_observer_| when the set of active routes has changed. | 137 // Called by |routes_observer_| when the set of active routes has changed. |
124 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); | 138 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); |
125 | 139 |
126 // Callback passed to MediaRouter to receive response to route creation | 140 // Callback passed to MediaRouter to receive response to route creation |
127 // requests. | 141 // requests. |
128 void OnRouteResponseReceived(scoped_ptr<MediaRoute> route, | 142 void OnRouteResponseReceived(const MediaRoute* route, |
129 const std::string& error); | 143 const std::string& error); |
130 | 144 |
131 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 145 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
132 | 146 |
133 // Sets the source host name to be displayed in the UI. | 147 // Sets the source host name to be displayed in the UI. |
134 // Gets cast modes from |query_result_manager_| and forwards it to UI. | 148 // Gets cast modes from |query_result_manager_| and forwards it to UI. |
135 // One of the Init* functions must have been called before. | 149 // One of the Init* functions must have been called before. |
136 void UpdateSourceHostAndCastModes(const GURL& frame_url); | 150 void UpdateSourceHostAndCastModes(const GURL& frame_url); |
137 | 151 |
138 // Initializes the dialog with mirroring sources derived from |initiator|, | 152 // Initializes the dialog with mirroring sources derived from |initiator|, |
139 // and optional |default_source| and |default_frame_url| if any. | 153 // and optional |default_source| and |default_frame_url| if any. |
140 void InitCommon(const content::WebContents* initiator, | 154 void InitCommon(const content::WebContents* initiator, |
141 const MediaSource& default_source, | 155 const MediaSource& default_source, |
142 const GURL& default_frame_url); | 156 const GURL& default_frame_url, |
143 | 157 MediaRouterDialogCallbacks* dialog_callbacks); |
144 // Invoke presentation callbacks based on |route| and |error| if the dialog | |
145 // was created for Presentation API. | |
146 void HandleRouteResponseForPresentation(const MediaRoute* route, | |
147 const std::string& error); | |
148 | 158 |
149 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver | 159 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver |
150 void OnDefaultMediaSourceChanged(const MediaSource& source, | 160 void OnDefaultMediaSourceChanged(const MediaSource& source, |
151 const GURL& frame_url) override; | 161 const GURL& frame_url) override; |
152 | 162 |
153 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 163 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
154 // only after it has deleted |this|. | 164 // only after it has deleted |this|. |
155 MediaRouterWebUIMessageHandler* handler_; | 165 MediaRouterWebUIMessageHandler* handler_; |
156 | 166 |
157 // These are non-null while this instance is registered to receive | 167 // These are non-null while this instance is registered to receive |
158 // updates from them. | 168 // updates from them. |
159 scoped_ptr<IssuesObserver> issues_observer_; | 169 scoped_ptr<IssuesObserver> issues_observer_; |
160 scoped_ptr<MediaRoutesObserver> routes_observer_; | 170 scoped_ptr<MediaRoutesObserver> routes_observer_; |
161 | 171 |
162 // Set to true by |handler_| when the UI has been initialized. | 172 // Set to true by |handler_| when the UI has been initialized. |
163 bool ui_initialized_; | 173 bool ui_initialized_; |
164 | 174 |
165 // Set to |true| if there is a pending route request for this UI. | 175 // Set to |true| if there is a pending route request for this UI. |
166 bool has_pending_route_request_; | 176 bool has_pending_route_request_; |
167 | 177 |
168 bool requesting_route_for_default_source_; | 178 bool requesting_route_for_default_source_; |
169 | 179 |
170 std::vector<MediaSinkWithCastModes> sinks_; | 180 std::vector<MediaSinkWithCastModes> sinks_; |
171 std::vector<MediaRoute> routes_; | 181 std::vector<MediaRoute> routes_; |
172 CastModeSet cast_modes_; | 182 CastModeSet cast_modes_; |
173 GURL frame_url_; | 183 GURL frame_url_; |
174 | 184 |
175 scoped_ptr<QueryResultManager> query_result_manager_; | 185 scoped_ptr<QueryResultManager> query_result_manager_; |
176 | 186 |
177 // Only set if the UI is created as a result of Presentation API. | |
178 scoped_ptr<CreateSessionRequest> presentation_session_request_; | |
179 | |
180 // It's possible for PresentationServiceDelegateImpl to be destroyed before | 187 // It's possible for PresentationServiceDelegateImpl to be destroyed before |
181 // this class. | 188 // this class. |
182 // (e.g. if a tab with the UI open is closed, then the tab WebContents will | 189 // (e.g. if a tab with the UI open is closed, then the tab WebContents will |
183 // be destroyed first momentarily before the UI WebContents). | 190 // be destroyed first momentarily before the UI WebContents). |
184 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to | 191 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to |
185 // handle this. | 192 // handle this. |
186 // TODO(imcheng): hold a weak ptr to an abstract type instead. | 193 // TODO(imcheng): hold a weak ptr to an abstract type instead. |
187 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; | 194 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; |
188 | 195 |
| 196 MediaRouterDialogCallbacks* dialog_callbacks_; |
| 197 |
189 const content::WebContents* initiator_; | 198 const content::WebContents* initiator_; |
190 | 199 |
191 // Cached pointer to the MediaRouter for this instance's BrowserContext. | 200 // Cached pointer to the MediaRouter for this instance's BrowserContext. |
192 MediaRouter* router_; | 201 MediaRouter* router_; |
193 | 202 |
194 // NOTE: Weak pointers must be invalidated before all other member variables. | 203 // NOTE: Weak pointers must be invalidated before all other member variables. |
195 // Therefore |weak_factory_| must be placed at the end. | 204 // Therefore |weak_factory_| must be placed at the end. |
196 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 205 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
197 | 206 |
198 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 207 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
199 }; | 208 }; |
200 | 209 |
201 } // namespace media_router | 210 } // namespace media_router |
202 | 211 |
203 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 212 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |