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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 const char kInvalidSourceNameError[] = "Invalid source type specified."; | 30 const char kInvalidSourceNameError[] = "Invalid source type specified."; |
31 const char kEmptySourcesListError[] = | 31 const char kEmptySourcesListError[] = |
32 "At least one source type must be specified."; | 32 "At least one source type must be specified."; |
33 const char kTabCaptureNotSupportedError[] = "Tab capture is not supported yet."; | 33 const char kTabCaptureNotSupportedError[] = "Tab capture is not supported yet."; |
34 const char kNoTabIdError[] = "targetTab doesn't have id field set."; | 34 const char kNoTabIdError[] = "targetTab doesn't have id field set."; |
35 const char kNoUrlError[] = "targetTab doesn't have URL field set."; | 35 const char kNoUrlError[] = "targetTab doesn't have URL field set."; |
36 const char kInvalidTabIdError[] = "Invalid tab specified."; | 36 const char kInvalidTabIdError[] = "Invalid tab specified."; |
37 const char kTabUrlChangedError[] = "URL for the specified tab has changed."; | 37 const char kTabUrlChangedError[] = "URL for the specified tab has changed."; |
38 const char kTabUrlNotSecure[] = | 38 const char kTabUrlNotSecure[] = |
39 "URL scheme for the specified tab is not secure."; | 39 "URL scheme for the specified tab is not secure."; |
40 const char kNoTabsAvailableError[] = "No tabs available."; | |
40 | 41 |
41 DesktopCaptureChooseDesktopMediaFunction::PickerFactory* g_picker_factory = | 42 DesktopCaptureChooseDesktopMediaFunction::PickerFactory* g_picker_factory = |
42 NULL; | 43 NULL; |
43 | 44 |
44 } // namespace | 45 } // namespace |
45 | 46 |
46 // static | 47 // static |
47 void DesktopCaptureChooseDesktopMediaFunction::SetPickerFactoryForTests( | 48 void DesktopCaptureChooseDesktopMediaFunction::SetPickerFactoryForTests( |
48 PickerFactory* factory) { | 49 PickerFactory* factory) { |
49 g_picker_factory = factory; | 50 g_picker_factory = factory; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 args_->Remove(0, NULL); | 83 args_->Remove(0, NULL); |
83 | 84 |
84 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params = | 85 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params = |
85 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_); | 86 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_); |
86 EXTENSION_FUNCTION_VALIDATE(params.get()); | 87 EXTENSION_FUNCTION_VALIDATE(params.get()); |
87 | 88 |
88 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( | 89 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( |
89 render_view_host()->GetProcess()->GetID(), request_id_, this); | 90 render_view_host()->GetProcess()->GetID(), request_id_, this); |
90 | 91 |
91 gfx::NativeWindow parent_window; | 92 gfx::NativeWindow parent_window; |
92 content::RenderViewHost* render_view; | 93 content::RenderViewHost* render_view = NULL; |
94 content::WebContents* web_contents = NULL; | |
93 base::string16 target_name; | 95 base::string16 target_name; |
94 if (params->target_tab) { | 96 if (params->target_tab) { |
95 if (!params->target_tab->url) { | 97 if (!params->target_tab->url) { |
96 error_ = kNoUrlError; | 98 error_ = kNoUrlError; |
97 return false; | 99 return false; |
98 } | 100 } |
99 origin_ = GURL(*(params->target_tab->url)).GetOrigin(); | 101 origin_ = GURL(*(params->target_tab->url)).GetOrigin(); |
100 | 102 |
101 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 103 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
102 switches::kAllowHttpScreenCapture) && | 104 switches::kAllowHttpScreenCapture) && |
103 !origin_.SchemeIsSecure()) { | 105 !origin_.SchemeIsSecure()) { |
104 error_ = kTabUrlNotSecure; | 106 error_ = kTabUrlNotSecure; |
105 return false; | 107 return false; |
106 } | 108 } |
107 target_name = base::UTF8ToUTF16(origin_.SchemeIsSecure() ? | 109 target_name = base::UTF8ToUTF16(origin_.SchemeIsSecure() ? |
108 net::GetHostAndOptionalPort(origin_) : origin_.spec()); | 110 net::GetHostAndOptionalPort(origin_) : origin_.spec()); |
109 | 111 |
110 if (!params->target_tab->id) { | 112 if (!params->target_tab->id) { |
111 error_ = kNoTabIdError; | 113 error_ = kNoTabIdError; |
112 return false; | 114 return false; |
113 } | 115 } |
114 | 116 |
115 content::WebContents* web_contents = NULL; | |
116 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), | 117 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), |
117 true, NULL, NULL, &web_contents, NULL)) { | 118 true, NULL, NULL, &web_contents, NULL)) { |
118 error_ = kInvalidTabIdError; | 119 error_ = kInvalidTabIdError; |
119 return false; | 120 return false; |
120 } | 121 } |
121 | 122 |
122 GURL current_origin_ = | 123 GURL current_origin_ = |
123 web_contents->GetLastCommittedURL().GetOrigin(); | 124 web_contents->GetLastCommittedURL().GetOrigin(); |
124 if (current_origin_ != origin_) { | 125 if (current_origin_ != origin_) { |
125 error_ = kTabUrlChangedError; | 126 error_ = kTabUrlChangedError; |
126 return false; | 127 return false; |
127 } | 128 } |
128 | 129 |
129 // Register to be notified when the tab is closed. | 130 // Register to be notified when the tab is closed. |
130 Observe(web_contents); | 131 Observe(web_contents); |
131 | 132 |
132 render_view = web_contents->GetRenderViewHost(); | 133 render_view = web_contents->GetRenderViewHost(); |
133 parent_window = web_contents->GetTopLevelNativeWindow(); | 134 parent_window = web_contents->GetTopLevelNativeWindow(); |
134 } else { | 135 } else { |
135 origin_ = GetExtension()->url(); | 136 origin_ = GetExtension()->url(); |
136 target_name = base::UTF8ToUTF16(GetExtension()->name()); | 137 target_name = base::UTF8ToUTF16(GetExtension()->name()); |
137 render_view = render_view_host(); | 138 render_view = render_view_host(); |
138 parent_window = | 139 |
139 GetAssociatedWebContents()->GetTopLevelNativeWindow(); | 140 web_contents = GetAssociatedWebContents(); |
141 if (!web_contents) { | |
142 error_ = kNoTabsAvailableError; | |
zel
2014/05/28 04:06:34
I still think we could support this scenario as we
Sergey Ulanov
2014/06/01 01:31:38
I agree. I think in this case we should pass null
tbarzic
2014/06/03 01:18:51
We still need to select the parent_window to use i
| |
143 return false; | |
144 } | |
145 | |
146 parent_window = web_contents->GetTopLevelNativeWindow(); | |
140 } | 147 } |
148 | |
141 render_process_id_ = render_view->GetProcess()->GetID(); | 149 render_process_id_ = render_view->GetProcess()->GetID(); |
142 render_view_id_ = render_view->GetRoutingID(); | 150 render_view_id_ = render_view->GetRoutingID(); |
143 | 151 |
144 bool show_screens = false; | 152 bool show_screens = false; |
145 bool show_windows = false; | 153 bool show_windows = false; |
146 | 154 |
147 for (std::vector<api::desktop_capture::DesktopCaptureSourceType>::iterator | 155 for (std::vector<api::desktop_capture::DesktopCaptureSourceType>::iterator |
148 it = params->sources.begin(); it != params->sources.end(); ++it) { | 156 it = params->sources.begin(); it != params->sources.end(); ++it) { |
149 switch (*it) { | 157 switch (*it) { |
150 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_NONE: | 158 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) | 209 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
202 picker_ = DesktopMediaPicker::Create(); | 210 picker_ = DesktopMediaPicker::Create(); |
203 #else | 211 #else |
204 error_ = "Desktop Capture API is not yet implemented for this platform."; | 212 error_ = "Desktop Capture API is not yet implemented for this platform."; |
205 return false; | 213 return false; |
206 #endif | 214 #endif |
207 } | 215 } |
208 DesktopMediaPicker::DoneCallback callback = base::Bind( | 216 DesktopMediaPicker::DoneCallback callback = base::Bind( |
209 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); | 217 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); |
210 | 218 |
211 picker_->Show(web_contents(), | 219 picker_->Show(web_contents, |
212 parent_window, parent_window, | 220 parent_window, parent_window, |
213 base::UTF8ToUTF16(GetExtension()->name()), | 221 base::UTF8ToUTF16(GetExtension()->name()), |
214 target_name, | 222 target_name, |
215 media_list.Pass(), callback); | 223 media_list.Pass(), callback); |
216 return true; | 224 return true; |
217 } | 225 } |
218 | 226 |
219 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed() { | 227 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed() { |
220 Cancel(); | 228 Cancel(); |
221 } | 229 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 | 300 |
293 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, | 301 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, |
294 int request_id) { | 302 int request_id) { |
295 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); | 303 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); |
296 if (it != requests_.end()) | 304 if (it != requests_.end()) |
297 it->second->Cancel(); | 305 it->second->Cancel(); |
298 } | 306 } |
299 | 307 |
300 | 308 |
301 } // namespace extensions | 309 } // namespace extensions |
OLD | NEW |