OLD | NEW |
---|---|
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/extensions/api/desktop_capture/desktop_capture_api.h" | 5 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" |
6 | 6 |
7 #include "ash/shell.h" | |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
11 #include "chrome/browser/media/desktop_media_list_ash.h" | 12 #include "chrome/browser/media/desktop_media_list_ash.h" |
12 #include "chrome/browser/media/desktop_streams_registry.h" | 13 #include "chrome/browser/media/desktop_streams_registry.h" |
13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 14 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
14 #include "chrome/browser/media/native_desktop_media_list.h" | 15 #include "chrome/browser/media/native_desktop_media_list.h" |
15 #include "chrome/browser/ui/ash/ash_util.h" | 16 #include "chrome/browser/ui/ash/ash_util.h" |
17 #include "chrome/browser/ui/host_desktop.h" | |
16 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/api/tabs.h" | 19 #include "chrome/common/extensions/api/tabs.h" |
18 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
21 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
22 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" | 24 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" |
23 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 25 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
24 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" | 26 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" |
25 | 27 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &request_id_)); | 83 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &request_id_)); |
82 args_->Remove(0, NULL); | 84 args_->Remove(0, NULL); |
83 | 85 |
84 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params = | 86 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params = |
85 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_); | 87 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_); |
86 EXTENSION_FUNCTION_VALIDATE(params.get()); | 88 EXTENSION_FUNCTION_VALIDATE(params.get()); |
87 | 89 |
88 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( | 90 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( |
89 render_view_host()->GetProcess()->GetID(), request_id_, this); | 91 render_view_host()->GetProcess()->GetID(), request_id_, this); |
90 | 92 |
91 gfx::NativeWindow parent_window; | 93 gfx::NativeWindow parent_window = NULL; |
92 content::RenderViewHost* render_view; | 94 content::RenderViewHost* render_view = NULL; |
95 content::WebContents* web_contents = NULL; | |
93 base::string16 target_name; | 96 base::string16 target_name; |
94 if (params->target_tab) { | 97 if (params->target_tab) { |
95 if (!params->target_tab->url) { | 98 if (!params->target_tab->url) { |
96 error_ = kNoUrlError; | 99 error_ = kNoUrlError; |
97 return false; | 100 return false; |
98 } | 101 } |
99 origin_ = GURL(*(params->target_tab->url)).GetOrigin(); | 102 origin_ = GURL(*(params->target_tab->url)).GetOrigin(); |
100 | 103 |
101 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 104 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
102 switches::kAllowHttpScreenCapture) && | 105 switches::kAllowHttpScreenCapture) && |
103 !origin_.SchemeIsSecure()) { | 106 !origin_.SchemeIsSecure()) { |
104 error_ = kTabUrlNotSecure; | 107 error_ = kTabUrlNotSecure; |
105 return false; | 108 return false; |
106 } | 109 } |
107 target_name = base::UTF8ToUTF16(origin_.SchemeIsSecure() ? | 110 target_name = base::UTF8ToUTF16(origin_.SchemeIsSecure() ? |
108 net::GetHostAndOptionalPort(origin_) : origin_.spec()); | 111 net::GetHostAndOptionalPort(origin_) : origin_.spec()); |
109 | 112 |
110 if (!params->target_tab->id) { | 113 if (!params->target_tab->id) { |
111 error_ = kNoTabIdError; | 114 error_ = kNoTabIdError; |
112 return false; | 115 return false; |
113 } | 116 } |
114 | 117 |
115 content::WebContents* web_contents = NULL; | |
116 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), | 118 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), |
117 true, NULL, NULL, &web_contents, NULL)) { | 119 true, NULL, NULL, &web_contents, NULL)) { |
118 error_ = kInvalidTabIdError; | 120 error_ = kInvalidTabIdError; |
119 return false; | 121 return false; |
120 } | 122 } |
121 | 123 |
122 GURL current_origin_ = | 124 GURL current_origin_ = |
123 web_contents->GetLastCommittedURL().GetOrigin(); | 125 web_contents->GetLastCommittedURL().GetOrigin(); |
124 if (current_origin_ != origin_) { | 126 if (current_origin_ != origin_) { |
125 error_ = kTabUrlChangedError; | 127 error_ = kTabUrlChangedError; |
126 return false; | 128 return false; |
127 } | 129 } |
128 | 130 |
129 // Register to be notified when the tab is closed. | 131 // Register to be notified when the tab is closed. |
130 Observe(web_contents); | 132 Observe(web_contents); |
131 | 133 |
132 render_view = web_contents->GetRenderViewHost(); | 134 render_view = web_contents->GetRenderViewHost(); |
133 parent_window = web_contents->GetTopLevelNativeWindow(); | 135 parent_window = web_contents->GetTopLevelNativeWindow(); |
134 } else { | 136 } else { |
135 origin_ = GetExtension()->url(); | 137 origin_ = GetExtension()->url(); |
136 target_name = base::UTF8ToUTF16(GetExtension()->name()); | 138 target_name = base::UTF8ToUTF16(GetExtension()->name()); |
137 render_view = render_view_host(); | 139 render_view = render_view_host(); |
138 parent_window = | 140 |
139 GetAssociatedWebContents()->GetTopLevelNativeWindow(); | 141 web_contents = GetAssociatedWebContents(); |
142 if (web_contents) { | |
143 parent_window = web_contents->GetTopLevelNativeWindow(); | |
144 } else { | |
145 #if defined(USE_ASH) | |
146 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | |
147 parent_window = ash::Shell::GetPrimaryRootWindow(); | |
sky
2014/06/03 22:07:20
Why is the primary root the right one here? And as
tbarzic
2014/06/03 22:25:33
the primary root is used only when there is no web
| |
148 #endif | |
149 } | |
140 } | 150 } |
151 | |
141 render_process_id_ = render_view->GetProcess()->GetID(); | 152 render_process_id_ = render_view->GetProcess()->GetID(); |
142 render_view_id_ = render_view->GetRoutingID(); | 153 render_view_id_ = render_view->GetRoutingID(); |
143 | 154 |
144 bool show_screens = false; | 155 bool show_screens = false; |
145 bool show_windows = false; | 156 bool show_windows = false; |
146 | 157 |
147 for (std::vector<api::desktop_capture::DesktopCaptureSourceType>::iterator | 158 for (std::vector<api::desktop_capture::DesktopCaptureSourceType>::iterator |
148 it = params->sources.begin(); it != params->sources.end(); ++it) { | 159 it = params->sources.begin(); it != params->sources.end(); ++it) { |
149 switch (*it) { | 160 switch (*it) { |
150 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_NONE: | 161 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_NONE: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 212 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
202 picker_ = DesktopMediaPicker::Create(); | 213 picker_ = DesktopMediaPicker::Create(); |
203 #else | 214 #else |
204 error_ = "Desktop Capture API is not yet implemented for this platform."; | 215 error_ = "Desktop Capture API is not yet implemented for this platform."; |
205 return false; | 216 return false; |
206 #endif | 217 #endif |
207 } | 218 } |
208 DesktopMediaPicker::DoneCallback callback = base::Bind( | 219 DesktopMediaPicker::DoneCallback callback = base::Bind( |
209 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); | 220 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); |
210 | 221 |
211 picker_->Show(web_contents(), | 222 picker_->Show(web_contents, |
212 parent_window, parent_window, | 223 parent_window, parent_window, |
213 base::UTF8ToUTF16(GetExtension()->name()), | 224 base::UTF8ToUTF16(GetExtension()->name()), |
214 target_name, | 225 target_name, |
215 media_list.Pass(), callback); | 226 media_list.Pass(), callback); |
216 return true; | 227 return true; |
217 } | 228 } |
218 | 229 |
219 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed() { | 230 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed() { |
220 Cancel(); | 231 Cancel(); |
221 } | 232 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 | 303 |
293 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, | 304 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, |
294 int request_id) { | 305 int request_id) { |
295 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); | 306 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); |
296 if (it != requests_.end()) | 307 if (it != requests_.end()) |
297 it->second->Cancel(); | 308 it->second->Cancel(); |
298 } | 309 } |
299 | 310 |
300 | 311 |
301 } // namespace extensions | 312 } // namespace extensions |
OLD | NEW |