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

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views.cc

Issue 529293002: Fix DesktopMediaPickerViews to handle background parent_web_contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/desktop_media_picker_views.h" 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "chrome/browser/media/desktop_media_list.h" 8 #include "chrome/browser/media/desktop_media_list.h"
9 #include "chrome/browser/ui/ash/ash_util.h" 9 #include "chrome/browser/ui/ash/ash_util.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
12 #include "components/web_modal/popup_manager.h" 12 #include "components/web_modal/popup_manager.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_delegate.h"
14 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
15 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/events/event_constants.h" 18 #include "ui/events/event_constants.h"
17 #include "ui/events/keycodes/keyboard_codes.h" 19 #include "ui/events/keycodes/keyboard_codes.h"
18 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
19 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
20 #include "ui/views/background.h" 22 #include "ui/views/background.h"
21 #include "ui/views/bubble/bubble_frame_view.h" 23 #include "ui/views/bubble/bubble_frame_view.h"
22 #include "ui/views/controls/image_view.h" 24 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 void DesktopMediaListView::OnSourceThumbnailChanged(int index) { 353 void DesktopMediaListView::OnSourceThumbnailChanged(int index) {
352 const DesktopMediaList::Source& source = media_list_->GetSource(index); 354 const DesktopMediaList::Source& source = media_list_->GetSource(index);
353 DesktopMediaSourceView* source_view = 355 DesktopMediaSourceView* source_view =
354 static_cast<DesktopMediaSourceView*>(child_at(index)); 356 static_cast<DesktopMediaSourceView*>(child_at(index));
355 source_view->SetThumbnail(source.thumbnail); 357 source_view->SetThumbnail(source.thumbnail);
356 } 358 }
357 359
358 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( 360 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
359 content::WebContents* parent_web_contents, 361 content::WebContents* parent_web_contents,
360 gfx::NativeWindow context, 362 gfx::NativeWindow context,
361 gfx::NativeWindow parent_window,
362 DesktopMediaPickerViews* parent, 363 DesktopMediaPickerViews* parent,
363 const base::string16& app_name, 364 const base::string16& app_name,
364 const base::string16& target_name, 365 const base::string16& target_name,
365 scoped_ptr<DesktopMediaList> media_list) 366 scoped_ptr<DesktopMediaList> media_list)
366 : parent_(parent), 367 : parent_(parent),
367 app_name_(app_name), 368 app_name_(app_name),
368 label_(new views::Label()), 369 label_(new views::Label()),
369 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), 370 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()),
370 list_view_(new DesktopMediaListView(this, media_list.Pass())) { 371 list_view_(new DesktopMediaListView(this, media_list.Pass())) {
371 if (app_name == target_name) { 372 if (app_name == target_name) {
372 label_->SetText( 373 label_->SetText(
373 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 374 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
374 } else { 375 } else {
375 label_->SetText(l10n_util::GetStringFUTF16( 376 label_->SetText(l10n_util::GetStringFUTF16(
376 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 377 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
377 } 378 }
378 label_->SetMultiLine(true); 379 label_->SetMultiLine(true);
379 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 380 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
380 AddChildView(label_); 381 AddChildView(label_);
381 382
382 scroll_view_->SetContents(list_view_); 383 scroll_view_->SetContents(list_view_);
383 scroll_view_->ClipHeightTo( 384 scroll_view_->ClipHeightTo(
384 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); 385 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2));
385 AddChildView(scroll_view_); 386 AddChildView(scroll_view_);
386 387
387 // If |parent_web_contents| is set, the picker will be shown modal to the 388 // If |parent_web_contents| is set and it's not a background page then the
388 // web contents. Otherwise, a new dialog widget inside |parent_window| will be 389 // picker will be shown modal to the web contents. Otherwise the picker is
389 // created for the picker. Note that |parent_window| may also be NULL if 390 // shown in a separate window.
390 // parent web contents is not set. In this case the picker will be parented
391 // by a root window.
392 views::Widget* widget = NULL; 391 views::Widget* widget = NULL;
393 if (parent_web_contents) 392 bool modal_dialog =
393 parent_web_contents &&
394 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
395 if (modal_dialog) {
394 widget = CreateWebModalDialogViews(this, parent_web_contents); 396 widget = CreateWebModalDialogViews(this, parent_web_contents);
395 else 397 } else {
396 widget = DialogDelegate::CreateDialogWidget(this, context, parent_window); 398 widget = DialogDelegate::CreateDialogWidget(this, context, NULL);
399 }
397 400
398 // DesktopMediaList needs to know the ID of the picker window which 401 // If the picker is not modal to the calling web contents then it is displayed
399 // matches the ID it gets from the OS. Depending on the OS and configuration 402 // in its own top-level window, so in that case it needs to be filtered out of
400 // we get this ID differently. 403 // the list of top-level windows available for capture, and to achieve that
404 // the Id is passed to DesktopMediaList.
401 DesktopMediaID::Id dialog_window_id = 0; 405 DesktopMediaID::Id dialog_window_id = 0;
402 406 if (!modal_dialog) {
403 // If there is |parent_window| or |parent_web_contents|, the picker window
404 // is embedded in the parent and does not have its own native window id, so we
405 // do not filter in that case.
406 if (!parent_window && !parent_web_contents) {
407 #if defined(USE_ASH) 407 #if defined(USE_ASH)
408 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { 408 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) {
409 dialog_window_id = 409 dialog_window_id =
410 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; 410 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id;
411 DCHECK_NE(dialog_window_id, 0); 411 DCHECK_NE(dialog_window_id, 0);
412 } 412 }
413 #endif 413 #endif
414 414
415 if (dialog_window_id == 0) { 415 if (dialog_window_id == 0) {
416 dialog_window_id = AcceleratedWidgetToDesktopMediaId( 416 dialog_window_id = AcceleratedWidgetToDesktopMediaId(
417 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); 417 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
418 } 418 }
419 } 419 }
420 420
421 list_view_->StartUpdating(dialog_window_id); 421 list_view_->StartUpdating(dialog_window_id);
422 422
423 if (parent_web_contents) { 423 if (modal_dialog) {
424 web_modal::PopupManager* popup_manager = 424 web_modal::PopupManager* popup_manager =
425 web_modal::PopupManager::FromWebContents(parent_web_contents); 425 web_modal::PopupManager::FromWebContents(parent_web_contents);
426 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), 426 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(),
427 parent_web_contents); 427 parent_web_contents);
428 } else { 428 } else {
429 widget->Show(); 429 widget->Show();
430 } 430 }
431 } 431 }
432 432
433 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} 433 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 548
549 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, 549 void DesktopMediaPickerViews::Show(content::WebContents* web_contents,
550 gfx::NativeWindow context, 550 gfx::NativeWindow context,
551 gfx::NativeWindow parent, 551 gfx::NativeWindow parent,
552 const base::string16& app_name, 552 const base::string16& app_name,
553 const base::string16& target_name, 553 const base::string16& target_name,
554 scoped_ptr<DesktopMediaList> media_list, 554 scoped_ptr<DesktopMediaList> media_list,
555 const DoneCallback& done_callback) { 555 const DoneCallback& done_callback) {
556 callback_ = done_callback; 556 callback_ = done_callback;
557 dialog_ = new DesktopMediaPickerDialogView( 557 dialog_ = new DesktopMediaPickerDialogView(
558 web_contents, context, parent, this, app_name, target_name, 558 web_contents, context, this, app_name, target_name, media_list.Pass());
559 media_list.Pass());
560 } 559 }
561 560
562 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { 561 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
563 // Once this method is called the |dialog_| will close and destroy itself. 562 // Once this method is called the |dialog_| will close and destroy itself.
564 dialog_->DetachParent(); 563 dialog_->DetachParent();
565 dialog_ = NULL; 564 dialog_ = NULL;
566 565
567 DCHECK(!callback_.is_null()); 566 DCHECK(!callback_.is_null());
568 567
569 // Notify the |callback_| asynchronously because it may need to destroy 568 // Notify the |callback_| asynchronously because it may need to destroy
570 // DesktopMediaPicker. 569 // DesktopMediaPicker.
571 content::BrowserThread::PostTask( 570 content::BrowserThread::PostTask(
572 content::BrowserThread::UI, FROM_HERE, 571 content::BrowserThread::UI, FROM_HERE,
573 base::Bind(callback_, source)); 572 base::Bind(callback_, source));
574 callback_.Reset(); 573 callback_.Reset();
575 } 574 }
576 575
577 // static 576 // static
578 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 577 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
579 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 578 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
580 } 579 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.h ('k') | chrome/browser/ui/views/desktop_media_picker_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698