Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc

Issue 1228863005: [MediaRouter] The minimal change to make everything build on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the include for MediaRouterDialogControllerImpl Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" 10 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" 13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "components/web_modal/web_contents_modal_dialog_host.h" 15 #include "components/web_modal/web_contents_modal_dialog_host.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_details.h" 18 #include "content/public/browser/navigation_details.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_delegate.h" 24 #include "content/public/browser/web_contents_delegate.h"
25 #include "ui/web_dialogs/web_dialog_delegate.h" 25 #include "ui/web_dialogs/web_dialog_delegate.h"
26 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" 26 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
27 #include "url/gurl.h" 27 #include "url/gurl.h"
28 28
29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(media_router::MediaRouterDialogController); 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
30 media_router::MediaRouterDialogControllerImpl);
30 31
31 using content::LoadCommittedDetails; 32 using content::LoadCommittedDetails;
32 using content::NavigationController; 33 using content::NavigationController;
33 using content::WebContents; 34 using content::WebContents;
34 using content::WebUIMessageHandler; 35 using content::WebUIMessageHandler;
35 using ui::WebDialogDelegate; 36 using ui::WebDialogDelegate;
36 37
37 namespace { 38 namespace {
38 const int kMaxHeight = 260; 39 const int kMaxHeight = 260;
39 #if !defined(OS_MACOSX) 40 #if !defined(OS_MACOSX)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 *size = gfx::Size(kWidth, kMaxHeight); 104 *size = gfx::Size(kWidth, kMaxHeight);
104 #else 105 #else
105 // size is not used because the dialog is auto-resizeable. 106 // size is not used because the dialog is auto-resizeable.
106 *size = gfx::Size(); 107 *size = gfx::Size();
107 #endif 108 #endif
108 } 109 }
109 110
110 } // namespace 111 } // namespace
111 112
112 // static 113 // static
113 MediaRouterDialogController* 114 MediaRouterDialogControllerImpl*
114 MediaRouterDialogController::GetOrCreateForWebContents( 115 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(
115 WebContents* web_contents) { 116 WebContents* web_contents) {
116 DCHECK(web_contents); 117 DCHECK(web_contents);
117 // This call does nothing if the controller already exists. 118 // This call does nothing if the controller already exists.
118 MediaRouterDialogController::CreateForWebContents(web_contents); 119 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents);
119 return MediaRouterDialogController::FromWebContents(web_contents); 120 return MediaRouterDialogControllerImpl::FromWebContents(web_contents);
120 } 121 }
121 122
122 class MediaRouterDialogController::DialogWebContentsObserver 123 class MediaRouterDialogControllerImpl::DialogWebContentsObserver
123 : public content::WebContentsObserver { 124 : public content::WebContentsObserver {
124 public: 125 public:
125 DialogWebContentsObserver( 126 DialogWebContentsObserver(
126 WebContents* web_contents, 127 WebContents* web_contents,
127 MediaRouterDialogController* dialog_controller) 128 MediaRouterDialogControllerImpl* dialog_controller)
128 : content::WebContentsObserver(web_contents), 129 : content::WebContentsObserver(web_contents),
129 dialog_controller_(dialog_controller) { 130 dialog_controller_(dialog_controller) {
130 } 131 }
131 132
132 private: 133 private:
133 void WebContentsDestroyed() override { 134 void WebContentsDestroyed() override {
134 // The dialog is already closed. No need to call Close() again. 135 // The dialog is already closed. No need to call Close() again.
135 // NOTE: |this| is deleted after Reset() returns. 136 // NOTE: |this| is deleted after Reset() returns.
136 dialog_controller_->Reset(); 137 dialog_controller_->Reset();
137 } 138 }
138 139
139 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) 140 void NavigationEntryCommitted(const LoadCommittedDetails& load_details)
140 override { 141 override {
141 dialog_controller_->OnDialogNavigated(load_details); 142 dialog_controller_->OnDialogNavigated(load_details);
142 } 143 }
143 144
144 void RenderProcessGone(base::TerminationStatus status) override { 145 void RenderProcessGone(base::TerminationStatus status) override {
145 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. 146 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
146 dialog_controller_->CloseMediaRouterDialog(); 147 dialog_controller_->CloseMediaRouterDialog();
147 } 148 }
148 149
149 MediaRouterDialogController* const dialog_controller_; 150 MediaRouterDialogControllerImpl* const dialog_controller_;
150 }; 151 };
151 152
152 class MediaRouterDialogController::InitiatorWebContentsObserver 153 class MediaRouterDialogControllerImpl::InitiatorWebContentsObserver
153 : public content::WebContentsObserver { 154 : public content::WebContentsObserver {
154 public: 155 public:
155 InitiatorWebContentsObserver( 156 InitiatorWebContentsObserver(
156 WebContents* web_contents, 157 WebContents* web_contents,
157 MediaRouterDialogController* dialog_controller) 158 MediaRouterDialogControllerImpl* dialog_controller)
158 : content::WebContentsObserver(web_contents), 159 : content::WebContentsObserver(web_contents),
159 dialog_controller_(dialog_controller) { 160 dialog_controller_(dialog_controller) {
160 } 161 }
161 162
162 private: 163 private:
163 void WebContentsDestroyed() override { 164 void WebContentsDestroyed() override {
164 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. 165 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
165 dialog_controller_->CloseMediaRouterDialog(); 166 dialog_controller_->CloseMediaRouterDialog();
166 } 167 }
167 168
168 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) 169 void NavigationEntryCommitted(const LoadCommittedDetails& load_details)
169 override { 170 override {
170 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. 171 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
171 dialog_controller_->CloseMediaRouterDialog(); 172 dialog_controller_->CloseMediaRouterDialog();
172 } 173 }
173 174
174 void RenderProcessGone(base::TerminationStatus status) override { 175 void RenderProcessGone(base::TerminationStatus status) override {
175 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. 176 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
176 dialog_controller_->CloseMediaRouterDialog(); 177 dialog_controller_->CloseMediaRouterDialog();
177 } 178 }
178 179
179 MediaRouterDialogController* const dialog_controller_; 180 MediaRouterDialogControllerImpl* const dialog_controller_;
180 }; 181 };
181 182
182 MediaRouterDialogController::MediaRouterDialogController( 183 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl(
183 WebContents* web_contents) 184 WebContents* web_contents)
184 : initiator_(web_contents), 185 : initiator_(web_contents),
185 media_router_dialog_pending_(false) { 186 media_router_dialog_pending_(false) {
186 DCHECK(initiator_); 187 DCHECK(initiator_);
187 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 188 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
188 } 189 }
189 190
190 MediaRouterDialogController::~MediaRouterDialogController() { 191 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() {
191 DCHECK(thread_checker_.CalledOnValidThread()); 192 DCHECK(thread_checker_.CalledOnValidThread());
192 } 193 }
193 194
194 WebContents* MediaRouterDialogController::ShowMediaRouterDialog() { 195 WebContents* MediaRouterDialogControllerImpl::ShowMediaRouterDialog() {
195 DCHECK(thread_checker_.CalledOnValidThread()); 196 DCHECK(thread_checker_.CalledOnValidThread());
196 197
197 // Get the media router dialog for |initiator|, or create a new dialog 198 // Get the media router dialog for |initiator|, or create a new dialog
198 // if not found. 199 // if not found.
199 WebContents* media_router_dialog = GetMediaRouterDialog(); 200 WebContents* media_router_dialog = GetMediaRouterDialog();
200 if (!media_router_dialog) { 201 if (!media_router_dialog) {
201 CreateMediaRouterDialog(); 202 CreateMediaRouterDialog();
202 return GetMediaRouterDialog(); 203 return GetMediaRouterDialog();
203 } 204 }
204 205
205 // Show the initiator holding the existing media router dialog. 206 // Show the initiator holding the existing media router dialog.
206 initiator_->GetDelegate()->ActivateContents(initiator_); 207 initiator_->GetDelegate()->ActivateContents(initiator_);
207 return media_router_dialog; 208 return media_router_dialog;
208 } 209 }
209 210
210 WebContents* MediaRouterDialogController::ShowMediaRouterDialogForPresentation( 211 bool MediaRouterDialogControllerImpl::ShowMediaRouterDialogForPresentation(
211 scoped_ptr<CreatePresentationSessionRequest> request) { 212 scoped_ptr<CreatePresentationSessionRequest> request) {
212 DCHECK(thread_checker_.CalledOnValidThread()); 213 DCHECK(thread_checker_.CalledOnValidThread());
213 214
214 // Get the media router dialog for |initiator|, or create a new dialog 215 // Get the media router dialog for |initiator|, or create a new dialog
215 // if not found. 216 // if not found.
216 WebContents* media_router_dialog = GetMediaRouterDialog(); 217 WebContents* media_router_dialog = GetMediaRouterDialog();
217 if (!media_router_dialog) { 218 if (!media_router_dialog) {
218 CreateMediaRouterDialog(); 219 CreateMediaRouterDialog();
219 media_router_dialog = GetMediaRouterDialog(); 220 media_router_dialog = GetMediaRouterDialog();
220 presentation_request_ = request.Pass(); 221 presentation_request_ = request.Pass();
221 return media_router_dialog; 222 return true;
222 } 223 }
223 224
224 // Show the initiator holding the existing media router dialog. 225 // Show the initiator holding the existing media router dialog.
225 initiator_->GetDelegate()->ActivateContents(initiator_); 226 initiator_->GetDelegate()->ActivateContents(initiator_);
226 return nullptr; 227 return false;
227 } 228 }
228 229
229 WebContents* MediaRouterDialogController::GetMediaRouterDialog() const { 230 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const {
230 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
231 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr; 232 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr;
232 } 233 }
233 234
234 void MediaRouterDialogController::CloseMediaRouterDialog() { 235 void MediaRouterDialogControllerImpl::CloseMediaRouterDialog() {
235 DCHECK(thread_checker_.CalledOnValidThread()); 236 DCHECK(thread_checker_.CalledOnValidThread());
236 DCHECK(initiator_observer_.get()); 237 DCHECK(initiator_observer_.get());
237 WebContents* media_router_dialog = GetMediaRouterDialog(); 238 WebContents* media_router_dialog = GetMediaRouterDialog();
238 CHECK(media_router_dialog); 239 CHECK(media_router_dialog);
239 Reset(); 240 Reset();
240 241
241 content::WebUI* web_ui = media_router_dialog->GetWebUI(); 242 content::WebUI* web_ui = media_router_dialog->GetWebUI();
242 if (web_ui) { 243 if (web_ui) {
243 MediaRouterUI* media_router_ui = 244 MediaRouterUI* media_router_ui =
244 static_cast<MediaRouterUI*>(web_ui->GetController()); 245 static_cast<MediaRouterUI*>(web_ui->GetController());
245 if (media_router_ui) 246 if (media_router_ui)
246 media_router_ui->Close(); 247 media_router_ui->Close();
247 } 248 }
248 } 249 }
249 250
250 void MediaRouterDialogController::CreateMediaRouterDialog() { 251 void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() {
251 DCHECK(!initiator_observer_.get()); 252 DCHECK(!initiator_observer_.get());
252 DCHECK(!dialog_observer_.get()); 253 DCHECK(!dialog_observer_.get());
253 254
254 Profile* profile = 255 Profile* profile =
255 Profile::FromBrowserContext(initiator_->GetBrowserContext()); 256 Profile::FromBrowserContext(initiator_->GetBrowserContext());
256 DCHECK(profile); 257 DCHECK(profile);
257 258
258 WebDialogDelegate* web_dialog_delegate = new MediaRouterDialogDelegate; 259 WebDialogDelegate* web_dialog_delegate = new MediaRouterDialogDelegate;
259 260
260 // |web_dialog_delegate|'s owner is |constrained_delegate|. 261 // |web_dialog_delegate|'s owner is |constrained_delegate|.
(...skipping 21 matching lines...) Expand all
282 WebContents* media_router_dialog = constrained_delegate->GetWebContents(); 283 WebContents* media_router_dialog = constrained_delegate->GetWebContents();
283 284
284 media_router_dialog_pending_ = true; 285 media_router_dialog_pending_ = true;
285 286
286 initiator_observer_.reset(new InitiatorWebContentsObserver( 287 initiator_observer_.reset(new InitiatorWebContentsObserver(
287 initiator_, this)); 288 initiator_, this));
288 dialog_observer_.reset(new DialogWebContentsObserver( 289 dialog_observer_.reset(new DialogWebContentsObserver(
289 media_router_dialog, this)); 290 media_router_dialog, this));
290 } 291 }
291 292
292 void MediaRouterDialogController::Reset() { 293 void MediaRouterDialogControllerImpl::Reset() {
293 DCHECK(thread_checker_.CalledOnValidThread()); 294 DCHECK(thread_checker_.CalledOnValidThread());
294 DCHECK(initiator_observer_.get()); 295 DCHECK(initiator_observer_.get());
295 DCHECK(dialog_observer_.get()); 296 DCHECK(dialog_observer_.get());
296 initiator_observer_.reset(); 297 initiator_observer_.reset();
297 dialog_observer_.reset(); 298 dialog_observer_.reset();
298 presentation_request_.reset(); 299 presentation_request_.reset();
299 } 300 }
300 301
301 void MediaRouterDialogController::OnDialogNavigated( 302 void MediaRouterDialogControllerImpl::OnDialogNavigated(
302 const content::LoadCommittedDetails& details) { 303 const content::LoadCommittedDetails& details) {
303 DCHECK(thread_checker_.CalledOnValidThread()); 304 DCHECK(thread_checker_.CalledOnValidThread());
304 WebContents* media_router_dialog = GetMediaRouterDialog(); 305 WebContents* media_router_dialog = GetMediaRouterDialog();
305 CHECK(media_router_dialog); 306 CHECK(media_router_dialog);
306 ui::PageTransition transition_type = details.entry->GetTransitionType(); 307 ui::PageTransition transition_type = details.entry->GetTransitionType();
307 content::NavigationType nav_type = details.type; 308 content::NavigationType nav_type = details.type;
308 309
309 // New |media_router_dialog| is created. 310 // New |media_router_dialog| is created.
310 DCHECK(media_router_dialog_pending_); 311 DCHECK(media_router_dialog_pending_);
311 DCHECK(transition_type == ui::PAGE_TRANSITION_AUTO_TOPLEVEL && 312 DCHECK(transition_type == ui::PAGE_TRANSITION_AUTO_TOPLEVEL &&
312 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) 313 nav_type == content::NAVIGATION_TYPE_NEW_PAGE)
313 << "transition_type: " << transition_type << ", " 314 << "transition_type: " << transition_type << ", "
314 << "nav_type: " << nav_type; 315 << "nav_type: " << nav_type;
315 316
316 media_router_dialog_pending_ = false; 317 media_router_dialog_pending_ = false;
317 318
318 PopulateDialog(media_router_dialog); 319 PopulateDialog(media_router_dialog);
319 } 320 }
320 321
321 void MediaRouterDialogController::PopulateDialog( 322 void MediaRouterDialogControllerImpl::PopulateDialog(
322 content::WebContents* media_router_dialog) { 323 content::WebContents* media_router_dialog) {
323 DCHECK(media_router_dialog); 324 DCHECK(media_router_dialog);
324 DCHECK(initiator_observer_); 325 DCHECK(initiator_observer_);
325 if (!initiator_observer_) { 326 if (!initiator_observer_) {
326 Reset(); 327 Reset();
327 return; 328 return;
328 } 329 }
329 content::WebContents* initiator = initiator_observer_->web_contents(); 330 content::WebContents* initiator = initiator_observer_->web_contents();
330 DCHECK(initiator); 331 DCHECK(initiator);
331 if (!initiator || !media_router_dialog->GetWebUI()) { 332 if (!initiator || !media_router_dialog->GetWebUI()) {
(...skipping 17 matching lines...) Expand all
349 ->GetWeakPtr(); 350 ->GetWeakPtr();
350 media_router_ui->InitWithDefaultMediaSource(delegate); 351 media_router_ui->InitWithDefaultMediaSource(delegate);
351 } else { 352 } else {
352 media_router_ui->InitWithPresentationSessionRequest( 353 media_router_ui->InitWithPresentationSessionRequest(
353 initiator, presentation_request_.Pass()); 354 initiator, presentation_request_.Pass());
354 } 355 }
355 } 356 }
356 357
357 } // namespace media_router 358 } // namespace media_router
358 359
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698