| 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> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 "Extension has not been invoked for the current page (see activeTab " | 44 "Extension has not been invoked for the current page (see activeTab " |
| 45 "permission). Chrome pages cannot be captured."; | 45 "permission). Chrome pages cannot be captured."; |
| 46 | 46 |
| 47 // Keys/values for media stream constraints. | 47 // Keys/values for media stream constraints. |
| 48 const char kMediaStreamSource[] = "chromeMediaSource"; | 48 const char kMediaStreamSource[] = "chromeMediaSource"; |
| 49 const char kMediaStreamSourceId[] = "chromeMediaSourceId"; | 49 const char kMediaStreamSourceId[] = "chromeMediaSourceId"; |
| 50 const char kMediaStreamSourceTab[] = "tab"; | 50 const char kMediaStreamSourceTab[] = "tab"; |
| 51 | 51 |
| 52 // Whitelisted extensions that do not check for a browser action grant because | 52 // Whitelisted extensions that do not check for a browser action grant because |
| 53 // they provide API's. | 53 // they provide API's. |
| 54 const char* const whitelisted_extensions[] = { | 54 const char* const kWhitelist[] = { |
| 55 "enhhojjnijigcajfphajepfemndkmdlo", // Dev | 55 "enhhojjnijigcajfphajepfemndkmdlo", // Dev |
| 56 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester | 56 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester |
| 57 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging | 57 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging |
| 58 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary | 58 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary |
| 59 "F155646B5D1CA545F7E1E4E20D573DFDD44C2540", // Trusted Tester (public) | 59 "F155646B5D1CA545F7E1E4E20D573DFDD44C2540", // Trusted Tester (public) |
| 60 "16CA7A47AAE4BE49B1E75A6B960C3875E945B264" // Release | 60 "16CA7A47AAE4BE49B1E75A6B960C3875E945B264" // Release |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 86 | 86 |
| 87 // Make sure either we have been granted permission to capture through an | 87 // Make sure either we have been granted permission to capture through an |
| 88 // extension icon click or our extension is whitelisted. | 88 // extension icon click or our extension is whitelisted. |
| 89 if (!extension()->permissions_data()->HasAPIPermissionForTab( | 89 if (!extension()->permissions_data()->HasAPIPermissionForTab( |
| 90 SessionTabHelper::IdForTab(target_contents), | 90 SessionTabHelper::IdForTab(target_contents), |
| 91 APIPermission::kTabCaptureForTab) && | 91 APIPermission::kTabCaptureForTab) && |
| 92 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 92 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 93 switches::kWhitelistedExtensionID) != extension_id && | 93 switches::kWhitelistedExtensionID) != extension_id && |
| 94 !SimpleFeature::IsIdInList( | 94 !SimpleFeature::IsIdInList( |
| 95 extension_id, | 95 extension_id, |
| 96 std::set<std::string>( | 96 std::set<std::string>(kWhitelist, |
| 97 whitelisted_extensions, | 97 kWhitelist + arraysize(kWhitelist)))) { |
| 98 whitelisted_extensions + arraysize(whitelisted_extensions)))) { | |
| 99 error_ = kGrantError; | 98 error_ = kGrantError; |
| 100 return false; | 99 return false; |
| 101 } | 100 } |
| 102 | 101 |
| 103 // Create a constraints vector. We will modify all the constraints in this | 102 // Create a constraints vector. We will modify all the constraints in this |
| 104 // vector to append our chrome specific constraints. | 103 // vector to append our chrome specific constraints. |
| 105 std::vector<MediaStreamConstraint*> constraints; | 104 std::vector<MediaStreamConstraint*> constraints; |
| 106 bool has_audio = params->options.audio.get() && *params->options.audio.get(); | 105 bool has_audio = params->options.audio.get() && *params->options.audio.get(); |
| 107 bool has_video = params->options.video.get() && *params->options.video.get(); | 106 bool has_video = params->options.video.get() && *params->options.video.get(); |
| 108 | 107 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 134 main_frame->GetRoutingID()); | 133 main_frame->GetRoutingID()); |
| 135 | 134 |
| 136 // Append chrome specific tab constraints. | 135 // Append chrome specific tab constraints. |
| 137 for (std::vector<MediaStreamConstraint*>::iterator it = constraints.begin(); | 136 for (std::vector<MediaStreamConstraint*>::iterator it = constraints.begin(); |
| 138 it != constraints.end(); ++it) { | 137 it != constraints.end(); ++it) { |
| 139 base::DictionaryValue* constraint = &(*it)->mandatory.additional_properties; | 138 base::DictionaryValue* constraint = &(*it)->mandatory.additional_properties; |
| 140 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); | 139 constraint->SetString(kMediaStreamSource, kMediaStreamSourceTab); |
| 141 constraint->SetString(kMediaStreamSourceId, device_id); | 140 constraint->SetString(kMediaStreamSourceId, device_id); |
| 142 } | 141 } |
| 143 | 142 |
| 144 extensions::TabCaptureRegistry* registry = | 143 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); |
| 145 extensions::TabCaptureRegistry::Get(GetProfile()); | |
| 146 if (!registry->AddRequest(target_contents, extension_id)) { | 144 if (!registry->AddRequest(target_contents, extension_id)) { |
| 147 error_ = kCapturingSameTab; | 145 error_ = kCapturingSameTab; |
| 148 return false; | 146 return false; |
| 149 } | 147 } |
| 150 | 148 |
| 151 // Copy the result from our modified input parameters. This will be | 149 // Copy the result from our modified input parameters. This will be |
| 152 // intercepted by custom bindings which will build and send the special | 150 // intercepted by custom bindings which will build and send the special |
| 153 // WebRTC user media request. | 151 // WebRTC user media request. |
| 154 base::DictionaryValue* result = new base::DictionaryValue(); | 152 base::DictionaryValue* result = new base::DictionaryValue(); |
| 155 result->MergeDictionary(params->options.ToValue().get()); | 153 result->MergeDictionary(params->options.ToValue().get()); |
| 156 | 154 |
| 157 SetResult(result); | 155 SetResult(result); |
| 158 return true; | 156 return true; |
| 159 } | 157 } |
| 160 | 158 |
| 161 bool TabCaptureGetCapturedTabsFunction::RunSync() { | 159 bool TabCaptureGetCapturedTabsFunction::RunSync() { |
| 162 extensions::TabCaptureRegistry* registry = | 160 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); |
| 163 extensions::TabCaptureRegistry::Get(GetProfile()); | |
| 164 base::ListValue* const list = new base::ListValue(); | 161 base::ListValue* const list = new base::ListValue(); |
| 165 if (registry) | 162 if (registry) |
| 166 registry->GetCapturedTabs(extension()->id(), list); | 163 registry->GetCapturedTabs(extension()->id(), list); |
| 167 SetResult(list); | 164 SetResult(list); |
| 168 return true; | 165 return true; |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace extensions | 168 } // namespace extensions |
| OLD | NEW |