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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
13 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory
.h" | 13 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory
.h" |
14 #include "chrome/browser/extensions/event_names.h" | 14 #include "chrome/browser/extensions/event_names.h" |
15 #include "chrome/browser/extensions/extension_renderer_state.h" | 15 #include "chrome/browser/extensions/extension_renderer_state.h" |
16 #include "chrome/browser/extensions/tab_helper.h" | |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/sessions/session_tab_helper.h" | 17 #include "chrome/browser/sessions/session_tab_helper.h" |
19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/permissions/permissions_data.h" |
23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_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 | 27 |
28 using extensions::api::tab_capture::MediaStreamConstraint; | 28 using extensions::api::tab_capture::MediaStreamConstraint; |
29 | 29 |
30 namespace TabCapture = extensions::api::tab_capture; | 30 namespace TabCapture = extensions::api::tab_capture; |
31 namespace GetCapturedTabs = TabCapture::GetCapturedTabs; | 31 namespace GetCapturedTabs = TabCapture::GetCapturedTabs; |
32 | 32 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 content::WebContents* target_contents = | 66 content::WebContents* target_contents = |
67 target_browser->tab_strip_model()->GetActiveWebContents(); | 67 target_browser->tab_strip_model()->GetActiveWebContents(); |
68 if (!target_contents) { | 68 if (!target_contents) { |
69 error_ = kFindingTabError; | 69 error_ = kFindingTabError; |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 const Extension* extension = GetExtension(); | 73 const Extension* extension = GetExtension(); |
74 const std::string& extension_id = extension->id(); | 74 const std::string& extension_id = extension->id(); |
75 | 75 |
| 76 const int tab_id = SessionID::IdForTab(target_contents); |
| 77 |
76 // Make sure either we have been granted permission to capture through an | 78 // Make sure either we have been granted permission to capture through an |
77 // extension icon click or our extension is whitelisted. | 79 // extension icon click or our extension is whitelisted. |
78 if (!TabHelper::FromWebContents(target_contents)-> | 80 if (!PermissionsData::HasAPIPermissionForTab( |
79 active_tab_permission_granter()->IsGranted(extension) && | 81 extension, tab_id, APIPermission::kTabCaptureForTab) && |
80 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 82 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
81 switches::kWhitelistedExtensionID) != extension_id && | 83 switches::kWhitelistedExtensionID) != extension_id && |
82 !FeatureProvider::GetByName("permission")->GetFeature("tabCapture")-> | 84 !FeatureProvider::GetByName("permission")->GetFeature("tabCapture")-> |
83 IsIdInWhitelist(extension_id)) { | 85 IsIdInWhitelist(extension_id)) { |
84 error_ = kGrantError; | 86 error_ = kGrantError; |
85 return false; | 87 return false; |
86 } | 88 } |
87 | 89 |
88 content::RenderViewHost* const rvh = target_contents->GetRenderViewHost(); | 90 content::RenderViewHost* const rvh = target_contents->GetRenderViewHost(); |
89 int render_process_id = rvh->GetProcess()->GetID(); | 91 int render_process_id = rvh->GetProcess()->GetID(); |
90 int routing_id = rvh->GetRoutingID(); | 92 int routing_id = rvh->GetRoutingID(); |
91 int tab_id = SessionTabHelper::FromWebContents(target_contents)-> | |
92 session_id().id(); | |
93 | 93 |
94 // Create a constraints vector. We will modify all the constraints in this | 94 // Create a constraints vector. We will modify all the constraints in this |
95 // vector to append our chrome specific constraints. | 95 // vector to append our chrome specific constraints. |
96 std::vector<MediaStreamConstraint*> constraints; | 96 std::vector<MediaStreamConstraint*> constraints; |
97 bool has_audio = params->options.audio.get() && *params->options.audio.get(); | 97 bool has_audio = params->options.audio.get() && *params->options.audio.get(); |
98 bool has_video = params->options.video.get() && *params->options.video.get(); | 98 bool has_video = params->options.video.get() && *params->options.video.get(); |
99 | 99 |
100 if (!has_audio && !has_video) { | 100 if (!has_audio && !has_video) { |
101 error_ = kNoAudioOrVideo; | 101 error_ = kNoAudioOrVideo; |
102 return false; | 102 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 info->tab_id = it->first; | 162 info->tab_id = it->first; |
163 info->status = it->second; | 163 info->status = it->second; |
164 list->Append(info->ToValue().release()); | 164 list->Append(info->ToValue().release()); |
165 } | 165 } |
166 | 166 |
167 SetResult(list); | 167 SetResult(list); |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 } // namespace extensions | 171 } // namespace extensions |
OLD | NEW |