| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 if (!msc) | 167 if (!msc) |
| 168 continue; | 168 continue; |
| 169 base::DictionaryValue* constraint = &msc->mandatory.additional_properties; | 169 base::DictionaryValue* constraint = &msc->mandatory.additional_properties; |
| 170 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); | 170 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); |
| 171 constraint->SetString(kMediaStreamSourceId, device_id); | 171 constraint->SetString(kMediaStreamSourceId, device_id); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace | 175 } // namespace |
| 176 | 176 |
| 177 const char* const kBetaChromecastExtensionId = | |
| 178 "dliochdbjfkdbacpmhlcpmleaejidimm"; | |
| 179 const char* const kStableChromecastExtensionId = | |
| 180 "boadgeojelhgndaghljhdicfkmllpafd"; | |
| 181 | |
| 182 // Whitelisted extensions that do not check for a browser action grant because | 177 // Whitelisted extensions that do not check for a browser action grant because |
| 183 // they provide API's. If there are additional extension ids that need | 178 // they provide API's. If there are additional extension ids that need |
| 184 // whitelisting and are *not* the Chromecast extension, add them to a new | 179 // whitelisting and are *not* the Media Router extension, add them to a new |
| 185 // kWhitelist array. | 180 // kWhitelist array. |
| 186 // | 181 const char* const kMediaRouterExtensionIds[] = { |
| 187 // This list is also used by CastConfigDelegateChromeos to find official Cast | |
| 188 // extensions. | |
| 189 const char* const kChromecastExtensionIds[] = { | |
| 190 "enhhojjnijigcajfphajepfemndkmdlo", // Dev | 182 "enhhojjnijigcajfphajepfemndkmdlo", // Dev |
| 191 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging | |
| 192 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary | |
| 193 kBetaChromecastExtensionId, // Google Cast Beta | |
| 194 kStableChromecastExtensionId, // Google Cast Stable | |
| 195 "hlgmmjhlnlapooncikdpiiokdjcdpjme", // Test cast extension | |
| 196 }; | |
| 197 | |
| 198 const char* const kMediaRouterExtensionIds[] = { | |
| 199 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Stable | 183 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Stable |
| 200 "ekpaaapppgpmolpcldedioblbkmijaca", // Beta | |
| 201 }; | 184 }; |
| 202 | 185 |
| 203 ExtensionFunction::ResponseAction TabCaptureCaptureFunction::Run() { | 186 ExtensionFunction::ResponseAction TabCaptureCaptureFunction::Run() { |
| 204 std::unique_ptr<api::tab_capture::Capture::Params> params = | 187 std::unique_ptr<api::tab_capture::Capture::Params> params = |
| 205 TabCapture::Capture::Params::Create(*args_); | 188 TabCapture::Capture::Params::Create(*args_); |
| 206 EXTENSION_FUNCTION_VALIDATE(params); | 189 EXTENSION_FUNCTION_VALIDATE(params); |
| 207 | 190 |
| 208 // Figure out the active WebContents and retrieve the needed ids. | 191 // Figure out the active WebContents and retrieve the needed ids. |
| 209 Browser* target_browser = chrome::FindAnyBrowser( | 192 Browser* target_browser = chrome::FindAnyBrowser( |
| 210 Profile::FromBrowserContext(browser_context()), include_incognito()); | 193 Profile::FromBrowserContext(browser_context()), include_incognito()); |
| 211 if (!target_browser) | 194 if (!target_browser) |
| 212 return RespondNow(Error(kFindingTabError)); | 195 return RespondNow(Error(kFindingTabError)); |
| 213 | 196 |
| 214 content::WebContents* target_contents = | 197 content::WebContents* target_contents = |
| 215 target_browser->tab_strip_model()->GetActiveWebContents(); | 198 target_browser->tab_strip_model()->GetActiveWebContents(); |
| 216 if (!target_contents) | 199 if (!target_contents) |
| 217 return RespondNow(Error(kFindingTabError)); | 200 return RespondNow(Error(kFindingTabError)); |
| 218 | 201 |
| 219 const std::string& extension_id = extension()->id(); | 202 const std::string& extension_id = extension()->id(); |
| 220 | 203 |
| 221 // Make sure either we have been granted permission to capture through an | 204 // Make sure either we have been granted permission to capture through an |
| 222 // extension icon click or our extension is whitelisted. | 205 // extension icon click or our extension is whitelisted. |
| 223 if (!extension()->permissions_data()->HasAPIPermissionForTab( | 206 if (!extension()->permissions_data()->HasAPIPermissionForTab( |
| 224 SessionTabHelper::IdForTab(target_contents), | 207 SessionTabHelper::IdForTab(target_contents), |
| 225 APIPermission::kTabCaptureForTab) && | 208 APIPermission::kTabCaptureForTab) && |
| 226 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 209 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 227 switches::kWhitelistedExtensionID) != extension_id && | 210 switches::kWhitelistedExtensionID) != extension_id && |
| 228 !SimpleFeature::IsIdInArray(extension_id, kChromecastExtensionIds, | |
| 229 arraysize(kChromecastExtensionIds)) && | |
| 230 !SimpleFeature::IsIdInArray(extension_id, kMediaRouterExtensionIds, | 211 !SimpleFeature::IsIdInArray(extension_id, kMediaRouterExtensionIds, |
| 231 arraysize(kMediaRouterExtensionIds))) { | 212 arraysize(kMediaRouterExtensionIds))) { |
| 232 return RespondNow(Error(kGrantError)); | 213 return RespondNow(Error(kGrantError)); |
| 233 } | 214 } |
| 234 | 215 |
| 235 if (!OptionsSpecifyAudioOrVideo(params->options)) | 216 if (!OptionsSpecifyAudioOrVideo(params->options)) |
| 236 return RespondNow(Error(kNoAudioOrVideo)); | 217 return RespondNow(Error(kNoAudioOrVideo)); |
| 237 | 218 |
| 238 TabCaptureRegistry* registry = TabCaptureRegistry::Get(browser_context()); | 219 TabCaptureRegistry* registry = TabCaptureRegistry::Get(browser_context()); |
| 239 if (!registry->AddRequest(target_contents, extension_id, false)) { | 220 if (!registry->AddRequest(target_contents, extension_id, false)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 EXTENSION_FUNCTION_VALIDATE(params); | 252 EXTENSION_FUNCTION_VALIDATE(params); |
| 272 | 253 |
| 273 // Make sure the extension is whitelisted for using this API, regardless of | 254 // Make sure the extension is whitelisted for using this API, regardless of |
| 274 // Chrome channel. | 255 // Chrome channel. |
| 275 // | 256 // |
| 276 // TODO(miu): Use _api_features.json and extensions::Feature library instead. | 257 // TODO(miu): Use _api_features.json and extensions::Feature library instead. |
| 277 // http://crbug.com/537732 | 258 // http://crbug.com/537732 |
| 278 const bool is_whitelisted_extension = | 259 const bool is_whitelisted_extension = |
| 279 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 260 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 280 switches::kWhitelistedExtensionID) == extension()->id() || | 261 switches::kWhitelistedExtensionID) == extension()->id() || |
| 281 SimpleFeature::IsIdInArray(extension()->id(), kChromecastExtensionIds, | |
| 282 arraysize(kChromecastExtensionIds)) || | |
| 283 SimpleFeature::IsIdInArray(extension()->id(), kMediaRouterExtensionIds, | 262 SimpleFeature::IsIdInArray(extension()->id(), kMediaRouterExtensionIds, |
| 284 arraysize(kMediaRouterExtensionIds)); | 263 arraysize(kMediaRouterExtensionIds)); |
| 285 if (!is_whitelisted_extension) | 264 if (!is_whitelisted_extension) |
| 286 return RespondNow(Error(kNotWhitelistedForOffscreenTabApi)); | 265 return RespondNow(Error(kNotWhitelistedForOffscreenTabApi)); |
| 287 | 266 |
| 288 const GURL start_url(params->start_url); | 267 const GURL start_url(params->start_url); |
| 289 if (!IsAcceptableOffscreenTabUrl(start_url)) | 268 if (!IsAcceptableOffscreenTabUrl(start_url)) |
| 290 return RespondNow(Error(kInvalidStartUrl)); | 269 return RespondNow(Error(kInvalidStartUrl)); |
| 291 | 270 |
| 292 if (!OptionsSpecifyAudioOrVideo(params->options)) | 271 if (!OptionsSpecifyAudioOrVideo(params->options)) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 342 } |
| 364 } | 343 } |
| 365 | 344 |
| 366 // No maximum size was provided, so just return the default size bounded by | 345 // No maximum size was provided, so just return the default size bounded by |
| 367 // the minimum size. | 346 // the minimum size. |
| 368 return gfx::Size(std::max(kDefaultWidth, min_size.width()), | 347 return gfx::Size(std::max(kDefaultWidth, min_size.width()), |
| 369 std::max(kDefaultHeight, min_size.height())); | 348 std::max(kDefaultHeight, min_size.height())); |
| 370 } | 349 } |
| 371 | 350 |
| 372 } // namespace extensions | 351 } // namespace extensions |
| OLD | NEW |