Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 11198044: Make tab capture media stream requests verify that the request came from extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: refactor media access permission helper Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/shell_window.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/public/common/renderer_preferences.h" 44 #include "content/public/common/renderer_preferences.h"
45 #include "third_party/skia/include/core/SkRegion.h" 45 #include "third_party/skia/include/core/SkRegion.h"
46 46
47 using content::BrowserThread; 47 using content::BrowserThread;
48 using content::ConsoleMessageLevel; 48 using content::ConsoleMessageLevel;
49 using content::RenderViewHost; 49 using content::RenderViewHost;
50 using content::ResourceDispatcherHost; 50 using content::ResourceDispatcherHost;
51 using content::SiteInstance; 51 using content::SiteInstance;
52 using content::WebContents; 52 using content::WebContents;
53 using extensions::APIPermission; 53 using extensions::APIPermission;
54 using extensions::RequestMediaAccessPermissionHelper;
54 55
55 namespace { 56 namespace {
56 const int kDefaultWidth = 512; 57 const int kDefaultWidth = 512;
57 const int kDefaultHeight = 384; 58 const int kDefaultHeight = 384;
58 59
59 void SuspendRenderViewHost(RenderViewHost* rvh) { 60 void SuspendRenderViewHost(RenderViewHost* rvh) {
60 DCHECK(rvh); 61 DCHECK(rvh);
61 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 62 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
62 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute, 63 base::Bind(&ResourceDispatcherHost::BlockRequestsForRoute,
63 base::Unretained(ResourceDispatcherHost::Get()), 64 base::Unretained(ResourceDispatcherHost::Get()),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 registrar_.RemoveAll(); 188 registrar_.RemoveAll();
188 189
189 // Remove shutdown prevention. 190 // Remove shutdown prevention.
190 browser::EndKeepAlive(); 191 browser::EndKeepAlive();
191 } 192 }
192 193
193 void ShellWindow::RequestMediaAccessPermission( 194 void ShellWindow::RequestMediaAccessPermission(
194 content::WebContents* web_contents, 195 content::WebContents* web_contents,
195 const content::MediaStreamRequest* request, 196 const content::MediaStreamRequest* request,
196 const content::MediaResponseCallback& callback) { 197 const content::MediaResponseCallback& callback) {
197 content::MediaStreamDevices devices; 198 RequestMediaAccessPermissionHelper::AuthorizeRequest(
198 199 request,
199 // Auto-accept the first audio device and the first video device from the 200 callback,
200 // request when the appropriate API permissions exist. 201 extension()->HasAPIPermission(APIPermission::kAudioCapture),
201 bool accepted_an_audio_device = false; 202 extension()->HasAPIPermission(APIPermission::kVideoCapture),
202 bool accepted_a_video_device = false; 203 extension()->HasAPIPermission(APIPermission::kTabCapture));
203 for (content::MediaStreamDeviceMap::const_iterator it =
204 request->devices.begin();
205 it != request->devices.end(); ++it) {
206 if (!accepted_an_audio_device &&
207 content::IsAudioMediaType(it->first) &&
208 extension()->HasAPIPermission(APIPermission::kAudioCapture) &&
209 !it->second.empty()) {
210 devices.push_back(it->second.front());
211 accepted_an_audio_device = true;
212 } else if (!accepted_a_video_device &&
213 content::IsVideoMediaType(it->first) &&
214 extension()->HasAPIPermission(APIPermission::kVideoCapture) &&
215 !it->second.empty()) {
216 devices.push_back(it->second.front());
217 accepted_a_video_device = true;
218 }
219 }
220
221 callback.Run(devices);
222 } 204 }
223 205
224 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, 206 WebContents* ShellWindow::OpenURLFromTab(WebContents* source,
225 const content::OpenURLParams& params) { 207 const content::OpenURLParams& params) {
226 DCHECK(source == web_contents_); 208 DCHECK(source == web_contents_);
227 209
228 // Don't allow the current tab to be navigated. It would be nice to map all 210 // Don't allow the current tab to be navigated. It would be nice to map all
229 // anchor tags (even those without target="_blank") to new tabs, but right 211 // anchor tags (even those without target="_blank") to new tabs, but right
230 // now we can't distinguish between those and <meta> refreshes or window.href 212 // now we can't distinguish between those and <meta> refreshes or window.href
231 // navigations, which we don't want to allow. 213 // navigations, which we don't want to allow.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 const extensions::DraggableRegion& region = *iter; 470 const extensions::DraggableRegion& region = *iter;
489 sk_region->op( 471 sk_region->op(
490 region.bounds.x(), 472 region.bounds.x(),
491 region.bounds.y(), 473 region.bounds.y(),
492 region.bounds.right(), 474 region.bounds.right(),
493 region.bounds.bottom(), 475 region.bounds.bottom(),
494 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 476 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
495 } 477 }
496 return sk_region; 478 return sk_region;
497 } 479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698