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 16 matching lines...) Expand all Loading... |
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; |
35 | 35 |
36 namespace extensions { | 36 namespace extensions { |
37 | |
38 namespace { | 37 namespace { |
39 | 38 |
40 const char kCapturingSameTab[] = "Cannot capture a tab with an active stream."; | 39 const char kCapturingSameTab[] = "Cannot capture a tab with an active stream."; |
41 const char kFindingTabError[] = "Error finding tab to capture."; | 40 const char kFindingTabError[] = "Error finding tab to capture."; |
42 const char kNoAudioOrVideo[] = "Capture failed. No audio or video requested."; | 41 const char kNoAudioOrVideo[] = "Capture failed. No audio or video requested."; |
43 const char kGrantError[] = | 42 const char kGrantError[] = |
44 "Extension has not been invoked for the current page (see activeTab " | 43 "Extension has not been invoked for the current page (see activeTab " |
45 "permission). Chrome pages cannot be captured."; | 44 "permission). Chrome pages cannot be captured."; |
46 | 45 |
47 // Keys/values for media stream constraints. | 46 // Keys/values for media stream constraints. |
48 const char kMediaStreamSource[] = "chromeMediaSource"; | 47 const char kMediaStreamSource[] = "chromeMediaSource"; |
49 const char kMediaStreamSourceId[] = "chromeMediaSourceId"; | 48 const char kMediaStreamSourceId[] = "chromeMediaSourceId"; |
50 const char kMediaStreamSourceTab[] = "tab"; | 49 const char kMediaStreamSourceTab[] = "tab"; |
51 | 50 |
| 51 } // namespace |
| 52 |
52 // Whitelisted extensions that do not check for a browser action grant because | 53 // Whitelisted extensions that do not check for a browser action grant because |
53 // they provide API's. | 54 // they provide API's. If there are additional extension ids that need |
54 const char* const kWhitelist[] = { | 55 // whitelisting and are *not* the Chromecast extension, add them to a new |
55 "enhhojjnijigcajfphajepfemndkmdlo", // Dev | 56 // kWhitelist array. |
56 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester | 57 const char* const kChromecastExtensionIds[] = { |
57 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging | 58 "enhhojjnijigcajfphajepfemndkmdlo", // Dev |
58 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary | 59 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Dogfood |
59 "F155646B5D1CA545F7E1E4E20D573DFDD44C2540", // Trusted Tester (public) | 60 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging |
60 "16CA7A47AAE4BE49B1E75A6B960C3875E945B264" // Release | 61 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary |
| 62 "dliochdbjfkdbacpmhlcpmleaejidimm", // Google Cast Beta |
| 63 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast Stable |
61 }; | 64 }; |
62 | 65 |
63 } // namespace | |
64 | |
65 bool TabCaptureCaptureFunction::RunSync() { | 66 bool TabCaptureCaptureFunction::RunSync() { |
66 scoped_ptr<api::tab_capture::Capture::Params> params = | 67 scoped_ptr<api::tab_capture::Capture::Params> params = |
67 TabCapture::Capture::Params::Create(*args_); | 68 TabCapture::Capture::Params::Create(*args_); |
68 EXTENSION_FUNCTION_VALIDATE(params.get()); | 69 EXTENSION_FUNCTION_VALIDATE(params.get()); |
69 | 70 |
70 // Figure out the active WebContents and retrieve the needed ids. | 71 // Figure out the active WebContents and retrieve the needed ids. |
71 Browser* target_browser = chrome::FindAnyBrowser( | 72 Browser* target_browser = chrome::FindAnyBrowser( |
72 GetProfile(), include_incognito(), chrome::GetActiveDesktop()); | 73 GetProfile(), include_incognito(), chrome::GetActiveDesktop()); |
73 if (!target_browser) { | 74 if (!target_browser) { |
74 error_ = kFindingTabError; | 75 error_ = kFindingTabError; |
75 return false; | 76 return false; |
76 } | 77 } |
77 | 78 |
78 content::WebContents* target_contents = | 79 content::WebContents* target_contents = |
79 target_browser->tab_strip_model()->GetActiveWebContents(); | 80 target_browser->tab_strip_model()->GetActiveWebContents(); |
80 if (!target_contents) { | 81 if (!target_contents) { |
81 error_ = kFindingTabError; | 82 error_ = kFindingTabError; |
82 return false; | 83 return false; |
83 } | 84 } |
84 | 85 |
85 const std::string& extension_id = extension()->id(); | 86 const std::string& extension_id = extension()->id(); |
86 | 87 |
87 // Make sure either we have been granted permission to capture through an | 88 // Make sure either we have been granted permission to capture through an |
88 // extension icon click or our extension is whitelisted. | 89 // extension icon click or our extension is whitelisted. |
89 if (!extension()->permissions_data()->HasAPIPermissionForTab( | 90 if (!extension()->permissions_data()->HasAPIPermissionForTab( |
90 SessionTabHelper::IdForTab(target_contents), | 91 SessionTabHelper::IdForTab(target_contents), |
91 APIPermission::kTabCaptureForTab) && | 92 APIPermission::kTabCaptureForTab) && |
92 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 93 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
93 switches::kWhitelistedExtensionID) != extension_id && | 94 switches::kWhitelistedExtensionID) != extension_id && |
94 !SimpleFeature::IsIdInArray( | 95 !SimpleFeature::IsIdInArray(extension_id, kChromecastExtensionIds, |
95 extension_id, kWhitelist, arraysize(kWhitelist))) { | 96 arraysize(kChromecastExtensionIds))) { |
96 error_ = kGrantError; | 97 error_ = kGrantError; |
97 return false; | 98 return false; |
98 } | 99 } |
99 | 100 |
100 // Create a constraints vector. We will modify all the constraints in this | 101 // Create a constraints vector. We will modify all the constraints in this |
101 // vector to append our chrome specific constraints. | 102 // vector to append our chrome specific constraints. |
102 std::vector<MediaStreamConstraint*> constraints; | 103 std::vector<MediaStreamConstraint*> constraints; |
103 bool has_audio = params->options.audio.get() && *params->options.audio.get(); | 104 bool has_audio = params->options.audio.get() && *params->options.audio.get(); |
104 bool has_video = params->options.video.get() && *params->options.video.get(); | 105 bool has_video = params->options.video.get() && *params->options.video.get(); |
105 | 106 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 bool TabCaptureGetCapturedTabsFunction::RunSync() { | 158 bool TabCaptureGetCapturedTabsFunction::RunSync() { |
158 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); | 159 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); |
159 base::ListValue* const list = new base::ListValue(); | 160 base::ListValue* const list = new base::ListValue(); |
160 if (registry) | 161 if (registry) |
161 registry->GetCapturedTabs(extension()->id(), list); | 162 registry->GetCapturedTabs(extension()->id(), list); |
162 SetResult(list); | 163 SetResult(list); |
163 return true; | 164 return true; |
164 } | 165 } |
165 | 166 |
166 } // namespace extensions | 167 } // namespace extensions |
OLD | NEW |