Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 13 #include "chrome/browser/media/desktop_media_list_ash.h" | 14 #include "chrome/browser/media/desktop_media_list_ash.h" |
| 14 #include "chrome/browser/media/desktop_streams_registry.h" | 15 #include "chrome/browser/media/desktop_streams_registry.h" |
| 15 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 16 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 16 #include "chrome/browser/media/native_desktop_media_list.h" | 17 #include "chrome/browser/media/native_desktop_media_list.h" |
| 17 #include "chrome/browser/ui/ash/ash_util.h" | 18 #include "chrome/browser/ui/ash/ash_util.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "extensions/common/switches.h" | |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" | 23 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 24 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
| 23 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" | 25 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 const char kInvalidSourceNameError[] = "Invalid source type specified."; | 31 const char kInvalidSourceNameError[] = "Invalid source type specified."; |
| 30 const char kEmptySourcesListError[] = | 32 const char kEmptySourcesListError[] = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 const std::vector<api::desktop_capture::DesktopCaptureSourceType>& sources, | 72 const std::vector<api::desktop_capture::DesktopCaptureSourceType>& sources, |
| 71 content::WebContents* web_contents, | 73 content::WebContents* web_contents, |
| 72 const GURL& origin, | 74 const GURL& origin, |
| 73 const base::string16 target_name) { | 75 const base::string16 target_name) { |
| 74 // Register to be notified when the tab is closed. | 76 // Register to be notified when the tab is closed. |
| 75 Observe(web_contents); | 77 Observe(web_contents); |
| 76 | 78 |
| 77 bool show_screens = false; | 79 bool show_screens = false; |
| 78 bool show_windows = false; | 80 bool show_windows = false; |
| 79 | 81 |
| 82 bool request_audio = false; | |
| 83 | |
| 80 for (auto source_type : sources) { | 84 for (auto source_type : sources) { |
| 81 switch (source_type) { | 85 switch (source_type) { |
| 82 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_NONE: | 86 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_NONE: |
| 83 error_ = kInvalidSourceNameError; | 87 error_ = kInvalidSourceNameError; |
| 84 return false; | 88 return false; |
| 85 | 89 |
| 86 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_SCREEN: | 90 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_SCREEN: |
| 87 show_screens = true; | 91 show_screens = true; |
| 88 break; | 92 break; |
| 89 | 93 |
| 90 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_WINDOW: | 94 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_WINDOW: |
| 91 show_windows = true; | 95 show_windows = true; |
| 92 break; | 96 break; |
| 93 | 97 |
| 94 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_TAB: | 98 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_TAB: |
| 95 error_ = kTabCaptureNotSupportedError; | 99 error_ = kTabCaptureNotSupportedError; |
| 96 return false; | 100 return false; |
| 101 | |
| 102 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_AUDIO: | |
| 103 bool has_flag = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
|
Ken Rockot(use gerrit already)
2016/02/03 14:22:25
nit: i don't think there's a need to introduce has
qiangchen
2016/02/03 17:41:41
I think it is better to put it behind the flag, un
| |
| 104 extensions::switches::kEnableDesktopCaptureAudio); | |
| 105 request_audio = has_flag; | |
| 106 break; | |
| 97 } | 107 } |
| 98 } | 108 } |
| 99 | 109 |
| 100 if (!show_screens && !show_windows) { | 110 if (!show_screens && !show_windows) { |
| 101 error_ = kEmptySourcesListError; | 111 error_ = kEmptySourcesListError; |
| 102 return false; | 112 return false; |
| 103 } | 113 } |
| 104 | 114 |
| 105 const gfx::NativeWindow parent_window = | 115 const gfx::NativeWindow parent_window = |
| 106 web_contents->GetTopLevelNativeWindow(); | 116 web_contents->GetTopLevelNativeWindow(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 error_ = "Desktop Capture API is not yet implemented for this platform."; | 148 error_ = "Desktop Capture API is not yet implemented for this platform."; |
| 139 return false; | 149 return false; |
| 140 #endif | 150 #endif |
| 141 } | 151 } |
| 142 DesktopMediaPicker::DoneCallback callback = base::Bind( | 152 DesktopMediaPicker::DoneCallback callback = base::Bind( |
| 143 &DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults, | 153 &DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults, |
| 144 this); | 154 this); |
| 145 | 155 |
| 146 picker_->Show(web_contents, parent_window, parent_window, | 156 picker_->Show(web_contents, parent_window, parent_window, |
| 147 base::UTF8ToUTF16(extension()->name()), target_name, | 157 base::UTF8ToUTF16(extension()->name()), target_name, |
| 148 std::move(media_list), callback); | 158 std::move(media_list), request_audio, callback); |
| 149 origin_ = origin; | 159 origin_ = origin; |
| 150 return true; | 160 return true; |
| 151 } | 161 } |
| 152 | 162 |
| 153 void DesktopCaptureChooseDesktopMediaFunctionBase::WebContentsDestroyed() { | 163 void DesktopCaptureChooseDesktopMediaFunctionBase::WebContentsDestroyed() { |
| 154 Cancel(); | 164 Cancel(); |
| 155 } | 165 } |
| 156 | 166 |
| 157 void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults( | 167 void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults( |
| 158 content::DesktopMediaID source) { | 168 content::DesktopMediaID source) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 239 |
| 230 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, | 240 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, |
| 231 int request_id) { | 241 int request_id) { |
| 232 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); | 242 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); |
| 233 if (it != requests_.end()) | 243 if (it != requests_.end()) |
| 234 it->second->Cancel(); | 244 it->second->Cancel(); |
| 235 } | 245 } |
| 236 | 246 |
| 237 | 247 |
| 238 } // namespace extensions | 248 } // namespace extensions |
| OLD | NEW |