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

Side by Side Diff: chrome/browser/extensions/api/desktop_capture/desktop_capture_base.cc

Issue 1880693002: Desktop Capture Picker New UI: Preliminary Refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/extensions/api/desktop_capture/desktop_capture_base.h" 5 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_base.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/media/combined_desktop_media_list.h"
16 #include "chrome/browser/media/desktop_media_list_ash.h" 15 #include "chrome/browser/media/desktop_media_list_ash.h"
17 #include "chrome/browser/media/desktop_streams_registry.h" 16 #include "chrome/browser/media/desktop_streams_registry.h"
18 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
19 #include "chrome/browser/media/native_desktop_media_list.h" 18 #include "chrome/browser/media/native_desktop_media_list.h"
20 #include "chrome/browser/media/tab_desktop_media_list.h" 19 #include "chrome/browser/media/tab_desktop_media_list.h"
21 #include "chrome/browser/ui/ash/ash_util.h" 20 #include "chrome/browser/ui/ash/ash_util.h"
22 #include "chrome/common/channel_info.h" 21 #include "chrome/common/channel_info.h"
23 #include "components/version_info/version_info.h" 22 #include "components/version_info/version_info.h"
24 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 119 }
121 } 120 }
122 121
123 if (!show_screens && !show_windows && !show_tabs) { 122 if (!show_screens && !show_windows && !show_tabs) {
124 error_ = kEmptySourcesListError; 123 error_ = kEmptySourcesListError;
125 return false; 124 return false;
126 } 125 }
127 126
128 const gfx::NativeWindow parent_window = 127 const gfx::NativeWindow parent_window =
129 web_contents->GetTopLevelNativeWindow(); 128 web_contents->GetTopLevelNativeWindow();
130 std::unique_ptr<DesktopMediaList> media_list; 129 std::unique_ptr<DesktopMediaList> screen_list;
130 std::unique_ptr<DesktopMediaList> window_list;
131 std::unique_ptr<DesktopMediaList> tab_list;
131 if (g_picker_factory) { 132 if (g_picker_factory) {
132 media_list = g_picker_factory->CreateModel(show_screens, show_windows, 133 std::vector<std::unique_ptr<DesktopMediaList>> media_lists;
133 show_tabs, request_audio); 134 media_lists = g_picker_factory->CreateModel(show_screens, show_windows,
msw 2016/04/13 00:04:02 nit: combine this assignment statement with the de
qiangchen 2016/04/14 17:08:40 Done.
135 show_tabs, request_audio);
136 screen_list = std::move(media_lists[0]);
137 window_list = std::move(media_lists[1]);
138 tab_list = std::move(media_lists[2]);
134 picker_ = g_picker_factory->CreatePicker(); 139 picker_ = g_picker_factory->CreatePicker();
135 } else { 140 } else {
136 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; 141 // Create a screens list.
137 // Create a screens/windows list and push it into media_lists. 142 if (show_screens) {
138 if (show_screens || show_windows) {
139 #if defined(USE_ASH) 143 #if defined(USE_ASH)
140 if (chrome::IsNativeWindowInAsh(parent_window)) { 144 if (chrome::IsNativeWindowInAsh(parent_window)) {
141 media_lists.push_back(base::WrapUnique(new DesktopMediaListAsh( 145 screen_list = base::WrapUnique(
142 (show_screens ? DesktopMediaListAsh::SCREENS : 0) | 146 new DesktopMediaListAsh(DesktopMediaListAsh::SCREENS));
143 (show_windows ? DesktopMediaListAsh::WINDOWS : 0))));
144 } 147 }
145 #endif 148 #endif
146 if (media_lists.empty()) { 149 if (!screen_list) {
147 webrtc::DesktopCaptureOptions options = 150 webrtc::DesktopCaptureOptions options =
148 webrtc::DesktopCaptureOptions::CreateDefault(); 151 webrtc::DesktopCaptureOptions::CreateDefault();
149 options.set_disable_effects(false); 152 options.set_disable_effects(false);
150 std::unique_ptr<webrtc::ScreenCapturer> screen_capturer( 153 std::unique_ptr<webrtc::ScreenCapturer> screen_capturer(
151 show_screens ? webrtc::ScreenCapturer::Create(options) : NULL); 154 webrtc::ScreenCapturer::Create(options));
155
156 screen_list = base::WrapUnique(
157 new NativeDesktopMediaList(std::move(screen_capturer), nullptr));
158 }
159 }
160
161 // Create a windows list.
162 if (show_windows) {
163 #if defined(USE_ASH)
164 if (chrome::IsNativeWindowInAsh(parent_window)) {
165 window_list = base::WrapUnique(
166 new DesktopMediaListAsh(DesktopMediaListAsh::WINDOWS));
167 }
168 #endif
169 if (!window_list) {
170 webrtc::DesktopCaptureOptions options =
171 webrtc::DesktopCaptureOptions::CreateDefault();
172 options.set_disable_effects(false);
152 std::unique_ptr<webrtc::WindowCapturer> window_capturer( 173 std::unique_ptr<webrtc::WindowCapturer> window_capturer(
153 show_windows ? webrtc::WindowCapturer::Create(options) : NULL); 174 webrtc::WindowCapturer::Create(options));
154 175
155 media_lists.push_back(base::WrapUnique(new NativeDesktopMediaList( 176 window_list = base::WrapUnique(
156 std::move(screen_capturer), std::move(window_capturer)))); 177 new NativeDesktopMediaList(nullptr, std::move(window_capturer)));
157 } 178 }
158 } 179 }
159 180
160 if (show_tabs) 181 if (show_tabs)
161 media_lists.push_back(base::WrapUnique(new TabDesktopMediaList())); 182 tab_list = base::WrapUnique(new TabDesktopMediaList());
162 183
163 DCHECK(!media_lists.empty()); 184 DCHECK(screen_list || window_list || tab_list);
164
165 if (media_lists.size() == 1) {
166 media_list = std::move(media_lists[0]);
167 } else {
168 media_list.reset(new CombinedDesktopMediaList(media_lists));
169 }
170 185
171 // DesktopMediaPicker is implemented only for Windows, OSX and 186 // DesktopMediaPicker is implemented only for Windows, OSX and
172 // Aura Linux builds. 187 // Aura Linux builds.
173 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) 188 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
174 picker_ = DesktopMediaPicker::Create(); 189 picker_ = DesktopMediaPicker::Create();
175 #else 190 #else
176 error_ = "Desktop Capture API is not yet implemented for this platform."; 191 error_ = "Desktop Capture API is not yet implemented for this platform.";
177 return false; 192 return false;
178 #endif 193 #endif
179 } 194 }
180 195
181 DesktopMediaPicker::DoneCallback callback = base::Bind( 196 DesktopMediaPicker::DoneCallback callback = base::Bind(
182 &DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults, 197 &DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults,
183 this); 198 this);
184 199
185 picker_->Show(web_contents, parent_window, parent_window, 200 picker_->Show(web_contents, parent_window, parent_window,
186 base::UTF8ToUTF16(extension()->name()), target_name, 201 base::UTF8ToUTF16(extension()->name()), target_name,
187 std::move(media_list), request_audio, callback); 202 std::move(screen_list), std::move(window_list),
203 std::move(tab_list), request_audio, callback);
188 origin_ = origin; 204 origin_ = origin;
189 return true; 205 return true;
190 } 206 }
191 207
192 void DesktopCaptureChooseDesktopMediaFunctionBase::WebContentsDestroyed() { 208 void DesktopCaptureChooseDesktopMediaFunctionBase::WebContentsDestroyed() {
193 Cancel(); 209 Cancel();
194 } 210 }
195 211
196 void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults( 212 void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults(
197 content::DesktopMediaID source) { 213 content::DesktopMediaID source) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 284
269 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, 285 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id,
270 int request_id) { 286 int request_id) {
271 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); 287 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id));
272 if (it != requests_.end()) 288 if (it != requests_.end())
273 it->second->Cancel(); 289 it->second->Cancel();
274 } 290 }
275 291
276 292
277 } // namespace extensions 293 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698