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

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

Issue 1958293002: Revert "Desktop Capture Picker New UI: Non Mac Structure Change" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "desktop_media_picker_views_deprecated.h"
6
7 #include <stddef.h>
8 #include <utility>
9
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h"
14 #include "chrome/browser/media/combined_desktop_media_list.h"
15 #include "chrome/browser/media/desktop_media_list.h"
16 #include "chrome/browser/ui/ash/ash_util.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "components/constrained_window/constrained_window_views.h"
20 #include "components/web_modal/web_contents_modal_dialog_manager.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents_delegate.h"
24 #include "grit/components_strings.h"
25 #include "ui/aura/window_tree_host.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/events/event_constants.h"
28 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/native_theme/native_theme.h"
31 #include "ui/views/background.h"
32 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/checkbox.h"
34 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/scroll_view.h"
37 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_client_view.h"
41 #include "ui/wm/core/shadow_types.h"
42
43 using content::DesktopMediaID;
44
45 namespace {
46
47 const int kThumbnailWidth = 160;
48 const int kThumbnailHeight = 100;
49 const int kThumbnailMargin = 10;
50 const int kLabelHeight = 40;
51 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth;
52 const int kListItemHeight =
53 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight;
54 const int kListColumns = 3;
55 const int kTotalListWidth = kListColumns * kListItemWidth;
56
57 const int kDesktopMediaSourceViewGroupId = 1;
58
59 const char kDesktopMediaSourceViewClassName[] =
60 "DesktopMediaPicker_DesktopMediaSourceView";
61
62 DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId(
63 gfx::AcceleratedWidget accelerated_widget) {
64 #if defined(OS_WIN)
65 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget);
66 #else
67 return static_cast<DesktopMediaID::Id>(accelerated_widget);
68 #endif
69 }
70
71 int GetMediaListViewHeightForRows(size_t rows) {
72 return kListItemHeight * rows;
73 }
74
75 } // namespace
76
77 namespace deprecated {
78
79 DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent,
80 DesktopMediaID source_id)
81 : parent_(parent),
82 source_id_(source_id),
83 image_view_(new views::ImageView()),
84 label_(new views::Label()),
85 selected_(false) {
86 AddChildView(image_view_);
87 AddChildView(label_);
88 SetFocusBehavior(FocusBehavior::ALWAYS);
89 }
90
91 DesktopMediaSourceView::~DesktopMediaSourceView() {}
92
93 void DesktopMediaSourceView::SetName(const base::string16& name) {
94 label_->SetText(name);
95 }
96
97 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) {
98 image_view_->SetImage(thumbnail);
99 }
100
101 void DesktopMediaSourceView::SetSelected(bool selected) {
102 if (selected == selected_)
103 return;
104 selected_ = selected;
105
106 if (selected) {
107 // Unselect all other sources.
108 Views neighbours;
109 parent()->GetViewsInGroup(GetGroup(), &neighbours);
110 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
111 if (*i != this) {
112 DCHECK_EQ((*i)->GetClassName(), kDesktopMediaSourceViewClassName);
113 DesktopMediaSourceView* source_view =
114 static_cast<DesktopMediaSourceView*>(*i);
115 source_view->SetSelected(false);
116 }
117 }
118
119 const SkColor bg_color = GetNativeTheme()->GetSystemColor(
120 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
121 set_background(views::Background::CreateSolidBackground(bg_color));
122
123 parent_->OnSelectionChanged();
124 } else {
125 set_background(NULL);
126 }
127
128 SchedulePaint();
129 }
130
131 const char* DesktopMediaSourceView::GetClassName() const {
132 return kDesktopMediaSourceViewClassName;
133 }
134
135 void DesktopMediaSourceView::Layout() {
136 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, kThumbnailWidth,
137 kThumbnailHeight);
138 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin,
139 kThumbnailWidth, kLabelHeight);
140 }
141
142 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
143 Views neighbours;
144 parent()->GetViewsInGroup(group, &neighbours);
145 if (neighbours.empty())
146 return NULL;
147
148 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
149 DCHECK_EQ((*i)->GetClassName(), kDesktopMediaSourceViewClassName);
150 DesktopMediaSourceView* source_view =
151 static_cast<DesktopMediaSourceView*>(*i);
152 if (source_view->selected_)
153 return source_view;
154 }
155 return NULL;
156 }
157
158 bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
159 return false;
160 }
161
162 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
163 View::OnPaint(canvas);
164 if (HasFocus()) {
165 gfx::Rect bounds(GetLocalBounds());
166 bounds.Inset(kThumbnailMargin / 2, kThumbnailMargin / 2);
167 canvas->DrawFocusRect(bounds);
168 }
169 }
170
171 void DesktopMediaSourceView::OnFocus() {
172 View::OnFocus();
173 SetSelected(true);
174 ScrollRectToVisible(gfx::Rect(size()));
175 // We paint differently when focused.
176 SchedulePaint();
177 }
178
179 void DesktopMediaSourceView::OnBlur() {
180 View::OnBlur();
181 // We paint differently when focused.
182 SchedulePaint();
183 }
184
185 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
186 if (event.GetClickCount() == 1) {
187 RequestFocus();
188 } else if (event.GetClickCount() == 2) {
189 RequestFocus();
190 parent_->OnDoubleClick();
191 }
192 return true;
193 }
194
195 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
196 if (event->type() == ui::ET_GESTURE_TAP &&
197 event->details().tap_count() == 2) {
198 RequestFocus();
199 parent_->OnDoubleClick();
200 event->SetHandled();
201 return;
202 }
203
204 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused
205 // on the long tap (when the tap gesture starts).
206 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
207 RequestFocus();
208 event->SetHandled();
209 }
210 }
211
212 DesktopMediaListView::DesktopMediaListView(
213 DesktopMediaPickerDialogView* parent,
214 std::unique_ptr<DesktopMediaList> media_list)
215 : parent_(parent), media_list_(std::move(media_list)), weak_factory_(this) {
216 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight));
217 SetFocusBehavior(FocusBehavior::ALWAYS);
218 }
219
220 DesktopMediaListView::~DesktopMediaListView() {}
221
222 void DesktopMediaListView::StartUpdating(DesktopMediaID dialog_window_id) {
223 media_list_->SetViewDialogWindowId(dialog_window_id);
224 media_list_->StartUpdating(this);
225 }
226
227 void DesktopMediaListView::OnSelectionChanged() {
228 parent_->OnSelectionChanged();
229 }
230
231 void DesktopMediaListView::OnDoubleClick() {
232 parent_->OnDoubleClick();
233 }
234
235 DesktopMediaSourceView* DesktopMediaListView::GetSelection() {
236 for (int i = 0; i < child_count(); ++i) {
237 DesktopMediaSourceView* source_view =
238 static_cast<DesktopMediaSourceView*>(child_at(i));
239 DCHECK_EQ(source_view->GetClassName(), kDesktopMediaSourceViewClassName);
240 if (source_view->is_selected())
241 return source_view;
242 }
243 return NULL;
244 }
245
246 gfx::Size DesktopMediaListView::GetPreferredSize() const {
247 int total_rows = (child_count() + kListColumns - 1) / kListColumns;
248 return gfx::Size(kTotalListWidth, GetMediaListViewHeightForRows(total_rows));
249 }
250
251 void DesktopMediaListView::Layout() {
252 int x = 0;
253 int y = 0;
254
255 for (int i = 0; i < child_count(); ++i) {
256 if (x + kListItemWidth > kTotalListWidth) {
257 x = 0;
258 y += kListItemHeight;
259 }
260
261 View* source_view = child_at(i);
262 source_view->SetBounds(x, y, kListItemWidth, kListItemHeight);
263
264 x += kListItemWidth;
265 }
266
267 y += kListItemHeight;
268 SetSize(gfx::Size(kTotalListWidth, y));
269 }
270
271 bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) {
272 int position_increment = 0;
273 switch (event.key_code()) {
274 case ui::VKEY_UP:
275 position_increment = -kListColumns;
276 break;
277 case ui::VKEY_DOWN:
278 position_increment = kListColumns;
279 break;
280 case ui::VKEY_LEFT:
281 position_increment = -1;
282 break;
283 case ui::VKEY_RIGHT:
284 position_increment = 1;
285 break;
286 default:
287 return false;
288 }
289
290 if (position_increment != 0) {
291 DesktopMediaSourceView* selected = GetSelection();
292 DesktopMediaSourceView* new_selected = NULL;
293
294 if (selected) {
295 int index = GetIndexOf(selected);
296 int new_index = index + position_increment;
297 if (new_index >= child_count())
298 new_index = child_count() - 1;
299 else if (new_index < 0)
300 new_index = 0;
301 if (index != new_index) {
302 new_selected =
303 static_cast<DesktopMediaSourceView*>(child_at(new_index));
304 }
305 } else if (has_children()) {
306 new_selected = static_cast<DesktopMediaSourceView*>(child_at(0));
307 }
308
309 if (new_selected) {
310 GetFocusManager()->SetFocusedView(new_selected);
311 }
312
313 return true;
314 }
315
316 return false;
317 }
318
319 void DesktopMediaListView::OnSourceAdded(DesktopMediaList* list, int index) {
320 const DesktopMediaList::Source& source = media_list_->GetSource(index);
321 DesktopMediaSourceView* source_view =
322 new DesktopMediaSourceView(this, source.id);
323 source_view->SetName(source.name);
324 source_view->SetGroup(kDesktopMediaSourceViewGroupId);
325 AddChildViewAt(source_view, index);
326
327 PreferredSizeChanged();
328
329 if (child_count() % kListColumns == 1)
330 parent_->OnMediaListRowsChanged();
331
332 std::string autoselect_source =
333 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
334 switches::kAutoSelectDesktopCaptureSource);
335 if (!autoselect_source.empty() &&
336 base::ASCIIToUTF16(autoselect_source) == source.name) {
337 // Select, then accept and close the dialog when we're done adding sources.
338 source_view->OnFocus();
339 content::BrowserThread::PostTask(
340 content::BrowserThread::UI, FROM_HERE,
341 base::Bind(&DesktopMediaListView::AcceptSelection,
342 weak_factory_.GetWeakPtr()));
343 }
344 }
345
346 void DesktopMediaListView::OnSourceRemoved(DesktopMediaList* list, int index) {
347 DesktopMediaSourceView* view =
348 static_cast<DesktopMediaSourceView*>(child_at(index));
349 DCHECK(view);
350 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName);
351 bool was_selected = view->is_selected();
352 RemoveChildView(view);
353 delete view;
354
355 if (was_selected)
356 OnSelectionChanged();
357
358 PreferredSizeChanged();
359
360 if (child_count() % kListColumns == 0)
361 parent_->OnMediaListRowsChanged();
362 }
363
364 void DesktopMediaListView::OnSourceMoved(DesktopMediaList* list,
365 int old_index,
366 int new_index) {
367 DesktopMediaSourceView* view =
368 static_cast<DesktopMediaSourceView*>(child_at(old_index));
369 ReorderChildView(view, new_index);
370 PreferredSizeChanged();
371 }
372
373 void DesktopMediaListView::OnSourceNameChanged(DesktopMediaList* list,
374 int index) {
375 const DesktopMediaList::Source& source = media_list_->GetSource(index);
376 DesktopMediaSourceView* source_view =
377 static_cast<DesktopMediaSourceView*>(child_at(index));
378 source_view->SetName(source.name);
379 }
380
381 void DesktopMediaListView::OnSourceThumbnailChanged(DesktopMediaList* list,
382 int index) {
383 const DesktopMediaList::Source& source = media_list_->GetSource(index);
384 DesktopMediaSourceView* source_view =
385 static_cast<DesktopMediaSourceView*>(child_at(index));
386 source_view->SetThumbnail(source.thumbnail);
387 }
388
389 void DesktopMediaListView::AcceptSelection() {
390 OnSelectionChanged();
391 OnDoubleClick();
392 }
393
394 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
395 content::WebContents* parent_web_contents,
396 gfx::NativeWindow context,
397 DesktopMediaPickerViews* parent,
398 const base::string16& app_name,
399 const base::string16& target_name,
400 std::unique_ptr<DesktopMediaList> screen_list,
401 std::unique_ptr<DesktopMediaList> window_list,
402 std::unique_ptr<DesktopMediaList> tab_list,
403 bool request_audio)
404 : parent_(parent),
405 app_name_(app_name),
406 description_label_(new views::Label()),
407 audio_share_checkbox_(nullptr),
408 audio_share_checked_(true),
409 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) {
410 std::vector<std::unique_ptr<DesktopMediaList>> media_lists;
411 if (screen_list)
412 media_lists.push_back(std::move(screen_list));
413 if (window_list)
414 media_lists.push_back(std::move(window_list));
415 if (tab_list)
416 media_lists.push_back(std::move(tab_list));
417
418 std::unique_ptr<DesktopMediaList> media_list;
419 if (media_lists.size() > 1)
420 media_list.reset(new CombinedDesktopMediaList(media_lists));
421 else
422 media_list = std::move(media_lists[0]);
423
424 DCHECK(media_list != nullptr);
425 sources_list_view_ = new DesktopMediaListView(this, std::move(media_list));
426
427 // TODO(estade): we should be getting the inside-border spacing by default as
428 // a DialogDelegateView subclass, via default BubbleFrameView content margins.
429 SetLayoutManager(new views::BoxLayout(
430 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew,
431 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing));
432
433 if (app_name == target_name) {
434 description_label_->SetText(
435 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
436 } else {
437 description_label_->SetText(l10n_util::GetStringFUTF16(
438 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
439 }
440 description_label_->SetMultiLine(true);
441 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
442 AddChildView(description_label_);
443
444 sources_scroll_view_->SetContents(sources_list_view_);
445 sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1),
446 GetMediaListViewHeightForRows(2));
447 AddChildView(sources_scroll_view_);
448
449 if (request_audio) {
450 audio_share_checkbox_ = new views::Checkbox(
451 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
452 AddChildView(audio_share_checkbox_);
453 audio_share_checkbox_->SetEnabled(false);
454 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
455 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
456 }
457
458 // If |parent_web_contents| is set and it's not a background page then the
459 // picker will be shown modal to the web contents. Otherwise the picker is
460 // shown in a separate window.
461 views::Widget* widget = NULL;
462 bool modal_dialog =
463 parent_web_contents &&
464 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
465 if (modal_dialog) {
466 widget =
467 constrained_window::ShowWebModalDialogViews(this, parent_web_contents);
468 } else {
469 widget = DialogDelegate::CreateDialogWidget(this, context, NULL);
470 widget->Show();
471 }
472
473 // If the picker is not modal to the calling web contents then it is displayed
474 // in its own top-level window, so in that case it needs to be filtered out of
475 // the list of top-level windows available for capture, and to achieve that
476 // the Id is passed to DesktopMediaList.
477 DesktopMediaID dialog_window_id;
478 if (!modal_dialog) {
479 dialog_window_id = DesktopMediaID::RegisterAuraWindow(
480 DesktopMediaID::TYPE_WINDOW, widget->GetNativeWindow());
481
482 bool is_ash_window = false;
483 #if defined(USE_ASH)
484 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow());
485 #endif
486
487 // Set native window ID if the windows is outside Ash.
488 if (!is_ash_window) {
489 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
490 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
491 }
492 }
493
494 sources_list_view_->StartUpdating(dialog_window_id);
495 }
496
497 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
498
499 void DesktopMediaPickerDialogView::DetachParent() {
500 parent_ = NULL;
501 }
502
503 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
504 static const size_t kDialogViewWidth = 600;
505 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth));
506 }
507
508 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
509 return ui::MODAL_TYPE_CHILD;
510 }
511
512 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
513 return l10n_util::GetStringFUTF16(
514 IDS_DESKTOP_MEDIA_PICKER_TITLE_DEPRECATED, app_name_);
515 }
516
517 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
518 ui::DialogButton button) const {
519 if (button == ui::DIALOG_BUTTON_OK)
520 return sources_list_view_->GetSelection() != NULL;
521 return true;
522 }
523
524 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
525 return sources_list_view_;
526 }
527
528 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
529 ui::DialogButton button) const {
530 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK
531 ? IDS_DESKTOP_MEDIA_PICKER_SHARE
532 : IDS_CANCEL);
533 }
534
535 bool DesktopMediaPickerDialogView::Accept() {
536 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
537
538 // Ok button should only be enabled when a source is selected.
539 DCHECK(selection);
540 DesktopMediaID source = selection->source_id();
541 source.audio_share = audio_share_checkbox_ &&
542 audio_share_checkbox_->enabled() &&
543 audio_share_checkbox_->checked();
544
545 // If the media source is an tab, activate it.
546 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
547 content::WebContents* tab = content::WebContents::FromRenderFrameHost(
548 content::RenderFrameHost::FromID(
549 source.web_contents_id.render_process_id,
550 source.web_contents_id.main_render_frame_id));
551 if (tab)
552 tab->GetDelegate()->ActivateContents(tab);
553 }
554
555 if (parent_)
556 parent_->NotifyDialogResult(source);
557
558 // Return true to close the window.
559 return true;
560 }
561
562 void DesktopMediaPickerDialogView::DeleteDelegate() {
563 // If the dialog is being closed then notify the parent about it.
564 if (parent_)
565 parent_->NotifyDialogResult(DesktopMediaID());
566 delete this;
567 }
568
569 void DesktopMediaPickerDialogView::OnSelectionChanged() {
570 GetDialogClientView()->UpdateDialogButtons();
571
572 // Disable the checkbox if we cannot support audio for the selected source.
573 if (audio_share_checkbox_) {
574 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
575
576 DesktopMediaID source;
577 if (selection)
578 source = selection->source_id();
579
580 if (source.type == DesktopMediaID::TYPE_SCREEN ||
581 source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
582 if (!audio_share_checkbox_->enabled()) {
583 audio_share_checkbox_->SetEnabled(true);
584 audio_share_checkbox_->SetChecked(audio_share_checked_);
585 }
586 audio_share_checkbox_->SetTooltipText(base::string16());
587 } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
588 if (audio_share_checkbox_->enabled()) {
589 audio_share_checkbox_->SetEnabled(false);
590 audio_share_checked_ = audio_share_checkbox_->checked();
591 audio_share_checkbox_->SetChecked(false);
592 }
593 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
594 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
595 } else {
596 NOTREACHED();
597 }
598 }
599 }
600
601 void DesktopMediaPickerDialogView::OnDoubleClick() {
602 // This will call Accept() and close the dialog.
603 GetDialogClientView()->AcceptWindow();
604 }
605
606 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
607 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
608
609 int new_height = widget_bound.height() - sources_scroll_view_->height() +
610 sources_scroll_view_->GetPreferredSize().height();
611
612 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
613 }
614
615 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
616 const {
617 return sources_list_view_;
618 }
619
620 DesktopMediaSourceView*
621 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
622 if (sources_list_view_->child_count() <= index)
623 return NULL;
624
625 return reinterpret_cast<DesktopMediaSourceView*>(
626 sources_list_view_->child_at(index));
627 }
628
629 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {}
630
631 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
632 if (dialog_) {
633 dialog_->DetachParent();
634 dialog_->GetWidget()->Close();
635 }
636 }
637
638 void DesktopMediaPickerViews::Show(
639 content::WebContents* web_contents,
640 gfx::NativeWindow context,
641 gfx::NativeWindow parent,
642 const base::string16& app_name,
643 const base::string16& target_name,
644 std::unique_ptr<DesktopMediaList> screen_list,
645 std::unique_ptr<DesktopMediaList> window_list,
646 std::unique_ptr<DesktopMediaList> tab_list,
647 bool request_audio,
648 const DoneCallback& done_callback) {
649 callback_ = done_callback;
650 dialog_ = new DesktopMediaPickerDialogView(
651 web_contents, context, this, app_name, target_name,
652 std::move(screen_list), std::move(window_list), std::move(tab_list),
653 request_audio);
654 }
655
656 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
657 // Once this method is called the |dialog_| will close and destroy itself.
658 dialog_->DetachParent();
659 dialog_ = NULL;
660
661 DCHECK(!callback_.is_null());
662
663 // Notify the |callback_| asynchronously because it may need to destroy
664 // DesktopMediaPicker.
665 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
666 base::Bind(callback_, source));
667 callback_.Reset();
668 }
669
670 } // namespace deprecated
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698