OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Tab Capture API. | 5 // Implements the Chrome Extensions Tab Capture API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" | 7 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 16 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
17 #include "chrome/browser/extensions/extension_renderer_state.h" | 17 #include "chrome/browser/extensions/extension_renderer_state.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "content/public/browser/render_frame_host.h" | |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | |
25 #include "extensions/common/features/feature.h" | 25 #include "extensions/common/features/feature.h" |
26 #include "extensions/common/features/feature_provider.h" | 26 #include "extensions/common/features/feature_provider.h" |
27 #include "extensions/common/features/simple_feature.h" | 27 #include "extensions/common/features/simple_feature.h" |
28 #include "extensions/common/permissions/permissions_data.h" | 28 #include "extensions/common/permissions/permissions_data.h" |
29 #include "extensions/common/switches.h" | 29 #include "extensions/common/switches.h" |
30 | 30 |
31 using extensions::api::tab_capture::MediaStreamConstraint; | 31 using extensions::api::tab_capture::MediaStreamConstraint; |
32 | 32 |
33 namespace TabCapture = extensions::api::tab_capture; | 33 namespace TabCapture = extensions::api::tab_capture; |
34 namespace GetCapturedTabs = TabCapture::GetCapturedTabs; | 34 namespace GetCapturedTabs = TabCapture::GetCapturedTabs; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 switches::kWhitelistedExtensionID) != extension_id && | 95 switches::kWhitelistedExtensionID) != extension_id && |
96 !SimpleFeature::IsIdInList( | 96 !SimpleFeature::IsIdInList( |
97 extension_id, | 97 extension_id, |
98 std::set<std::string>( | 98 std::set<std::string>( |
99 whitelisted_extensions, | 99 whitelisted_extensions, |
100 whitelisted_extensions + arraysize(whitelisted_extensions)))) { | 100 whitelisted_extensions + arraysize(whitelisted_extensions)))) { |
101 error_ = kGrantError; | 101 error_ = kGrantError; |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 content::RenderViewHost* const rvh = target_contents->GetRenderViewHost(); | |
106 int render_process_id = rvh->GetProcess()->GetID(); | |
107 int routing_id = rvh->GetRoutingID(); | |
108 | |
109 // Create a constraints vector. We will modify all the constraints in this | 105 // Create a constraints vector. We will modify all the constraints in this |
110 // vector to append our chrome specific constraints. | 106 // vector to append our chrome specific constraints. |
111 std::vector<MediaStreamConstraint*> constraints; | 107 std::vector<MediaStreamConstraint*> constraints; |
112 bool has_audio = params->options.audio.get() && *params->options.audio.get(); | 108 bool has_audio = params->options.audio.get() && *params->options.audio.get(); |
113 bool has_video = params->options.video.get() && *params->options.video.get(); | 109 bool has_video = params->options.video.get() && *params->options.video.get(); |
114 | 110 |
115 if (!has_audio && !has_video) { | 111 if (!has_audio && !has_video) { |
116 error_ = kNoAudioOrVideo; | 112 error_ = kNoAudioOrVideo; |
117 return false; | 113 return false; |
118 } | 114 } |
119 | 115 |
120 if (has_audio) { | 116 if (has_audio) { |
121 if (!params->options.audio_constraints.get()) | 117 if (!params->options.audio_constraints.get()) |
122 params->options.audio_constraints.reset(new MediaStreamConstraint); | 118 params->options.audio_constraints.reset(new MediaStreamConstraint); |
123 | 119 |
124 constraints.push_back(params->options.audio_constraints.get()); | 120 constraints.push_back(params->options.audio_constraints.get()); |
125 } | 121 } |
126 if (has_video) { | 122 if (has_video) { |
127 if (!params->options.video_constraints.get()) | 123 if (!params->options.video_constraints.get()) |
128 params->options.video_constraints.reset(new MediaStreamConstraint); | 124 params->options.video_constraints.reset(new MediaStreamConstraint); |
129 | 125 |
130 constraints.push_back(params->options.video_constraints.get()); | 126 constraints.push_back(params->options.video_constraints.get()); |
131 } | 127 } |
132 | 128 |
133 // Device id we use for Tab Capture. | 129 // Device id we use for Tab Capture. |
134 std::string device_id = | 130 content::RenderFrameHost* const main_frame = target_contents->GetMainFrame(); |
135 base::StringPrintf("%i:%i", render_process_id, routing_id); | 131 // TODO(miu): We should instead use a "randomly generated device ID" scheme, |
132 // like that employed by the desktop capture API. http://crbug.com/163100 | |
133 const std::string device_id = base::StringPrintf( | |
134 "web-contents-media-stream://%i:%i", | |
ncarter (slow)
2014/07/10 01:17:51
Does introducing the scheme here fix a bug? How is
miu
2014/07/10 22:16:11
It addresses crbug.com/163100. There isn't really
ncarter (slow)
2014/07/11 22:32:24
Acknowledged.
| |
135 main_frame->GetProcess()->GetID(), | |
136 main_frame->GetRoutingID()); | |
136 | 137 |
137 // Append chrome specific tab constraints. | 138 // Append chrome specific tab constraints. |
138 for (std::vector<MediaStreamConstraint*>::iterator it = constraints.begin(); | 139 for (std::vector<MediaStreamConstraint*>::iterator it = constraints.begin(); |
139 it != constraints.end(); ++it) { | 140 it != constraints.end(); ++it) { |
140 base::DictionaryValue* constraint = &(*it)->mandatory.additional_properties; | 141 base::DictionaryValue* constraint = &(*it)->mandatory.additional_properties; |
141 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); | 142 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); |
142 constraint->SetString(kMediaStreamSourceId, device_id); | 143 constraint->SetString(kMediaStreamSourceId, device_id); |
143 } | 144 } |
144 | 145 |
145 extensions::TabCaptureRegistry* registry = | 146 extensions::TabCaptureRegistry* registry = |
146 extensions::TabCaptureRegistry::Get(GetProfile()); | 147 extensions::TabCaptureRegistry::Get(GetProfile()); |
147 if (!registry->AddRequest(render_process_id, | 148 if (!registry->AddRequest(target_contents, |
148 routing_id, | |
149 extension_id, | 149 extension_id, |
150 tab_id, | 150 tab_id, |
151 tab_capture::TAB_CAPTURE_STATE_NONE)) { | 151 tab_capture::TAB_CAPTURE_STATE_NONE)) { |
152 error_ = kCapturingSameTab; | 152 error_ = kCapturingSameTab; |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 // Copy the result from our modified input parameters. This will be | 156 // Copy the result from our modified input parameters. This will be |
157 // intercepted by custom bindings which will build and send the special | 157 // intercepted by custom bindings which will build and send the special |
158 // WebRTC user media request. | 158 // WebRTC user media request. |
(...skipping 18 matching lines...) Expand all Loading... | |
177 info->tab_id = it->first; | 177 info->tab_id = it->first; |
178 info->status = it->second; | 178 info->status = it->second; |
179 list->Append(info->ToValue().release()); | 179 list->Append(info->ToValue().release()); |
180 } | 180 } |
181 | 181 |
182 SetResult(list); | 182 SetResult(list); |
183 return true; | 183 return true; |
184 } | 184 } |
185 | 185 |
186 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |