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

Unified Diff: chrome/browser/ui/views/desktop_media_picker_views.cc

Issue 378273003: Add command-line flag for tests to bypass the screenshare window picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using PostTask and weak pointers instead Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/desktop_media_picker_views.cc
diff --git a/chrome/browser/ui/views/desktop_media_picker_views.cc b/chrome/browser/ui/views/desktop_media_picker_views.cc
index fb73e5a934c547f8994fa1efa1772040c4f92ee0..07bc20214338d800d1add38df395c4f4222414c9 100644
--- a/chrome/browser/ui/views/desktop_media_picker_views.cc
+++ b/chrome/browser/ui/views/desktop_media_picker_views.cc
@@ -5,10 +5,14 @@
#include "chrome/browser/ui/views/desktop_media_picker_views.h"
#include "base/callback.h"
+#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/media/desktop_media_list.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
+#include "chrome/common/chrome_switches.h"
#include "components/web_modal/popup_manager.h"
+#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "ui/aura/window_tree_host.h"
@@ -59,6 +63,35 @@ int GetMediaListViewHeightForRows(size_t rows) {
return kListItemHeight * rows;
}
+static bool ShouldAutoSelectSource(const DesktopMediaList::Source& source) {
Peter Kasting 2014/08/13 17:17:50 Nit: "static" unnecessary (you're already in an an
phoglund_chromium 2014/08/14 13:16:24 Done. Inlining worked out pretty nicely with your
+ std::string desired_source =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kAutoSelectDesktopCaptureSource);
+ if (desired_source.empty())
+ return false;
+
+ return desired_source == base::UTF16ToASCII(source.name);
Peter Kasting 2014/08/13 17:17:50 Nit: Shorter: return !desired_source.empty() &&
phoglund_chromium 2014/08/14 13:16:24 Done.
+}
+
+class AutoSelectTask: public base::RefCounted<AutoSelectTask> {
Peter Kasting 2014/08/13 17:17:50 Does this really need to be refcounted? Seems lik
phoglund_chromium 2014/08/14 13:16:24 Nope, went with jiayl's solution instead.
+ public:
+ explicit AutoSelectTask(const base::WeakPtr<DesktopMediaListView>& list_view)
+ : list_view_(list_view) {}
+
+ void AcceptSelectedSource() {
+ if (list_view_) {
+ list_view_->OnSelectionChanged();
+ list_view_->OnDoubleClick();
+ }
+ }
+
+ private:
+ friend class base::RefCounted<AutoSelectTask>;
+ ~AutoSelectTask() {}
+
+ base::WeakPtr<DesktopMediaListView> list_view_;
+};
Peter Kasting 2014/08/13 17:17:50 Nit: DISALLOW_COPY_AND_ASSIGN
phoglund_chromium 2014/08/14 13:16:24 Acknowledged.
+
} // namespace
DesktopMediaSourceView::DesktopMediaSourceView(
@@ -199,7 +232,8 @@ DesktopMediaListView::DesktopMediaListView(
DesktopMediaPickerDialogView* parent,
scoped_ptr<DesktopMediaList> media_list)
: parent_(parent),
- media_list_(media_list.Pass()) {
+ media_list_(media_list.Pass()),
+ weak_factory_(this) {
media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight));
}
@@ -314,6 +348,18 @@ void DesktopMediaListView::OnSourceAdded(int index) {
if (child_count() % kListColumns == 1)
parent_->OnMediaListRowsChanged();
+
+ if (ShouldAutoSelectSource(source)) {
+ // Focusing on the element will select it.
+ source_view->OnFocus();
+
+ // Accept and close the dialog when we're done adding sources.
+ scoped_refptr<AutoSelectTask> task(
+ new AutoSelectTask(weak_factory_.GetWeakPtr()));
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&AutoSelectTask::AcceptSelectedSource, task));
jiayl 2014/08/13 17:32:42 AutoSelectTask is not needed. You can just do Pos
phoglund_chromium 2014/08/14 13:16:24 So PostTask is smart enough to check the weak poin
+ }
}
void DesktopMediaListView::OnSourceRemoved(int index) {
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698