OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_utils.h" | 5 #include "chrome/browser/ui/media_utils.h" |
6 | 6 |
7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "content/public/browser/web_contents.h" | |
9 | 10 |
10 #if defined(ENABLE_EXTENSIONS) | 11 #if defined(ENABLE_EXTENSIONS) |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
12 #include "extensions/browser/extension_system.h" | 13 #include "extensions/browser/extension_system.h" |
13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
14 #endif | 15 #endif |
15 | 16 |
16 class Profile; | 17 class Profile; |
17 | 18 |
18 namespace content { | 19 namespace { |
19 class WebContents; | 20 |
21 const extensions::Extension* GetExtensionForOrigin( | |
22 Profile* profile, | |
23 const GURL& security_origin) { | |
24 #if defined(ENABLE_EXTENSIONS) | |
sky
2014/09/12 16:19:14
How come you check ENABLE_EXTENSIONS here, but not
Henrik Grunell
2014/09/15 11:33:47
The ProcessMediaAccessRequest and CheckMediaAccess
| |
25 if (!security_origin.SchemeIs(extensions::kExtensionScheme)) | |
26 return NULL; | |
27 | |
28 ExtensionService* extensions_service = | |
29 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
30 const extensions::Extension* extension = | |
31 extensions_service->extensions()->GetByID(security_origin.host()); | |
32 DCHECK(extension); | |
33 return extension; | |
34 #else | |
35 return NULL; | |
36 #endif | |
20 } | 37 } |
21 | 38 |
39 } // namespace | |
40 | |
22 void RequestMediaAccessPermission( | 41 void RequestMediaAccessPermission( |
23 content::WebContents* web_contents, | 42 content::WebContents* web_contents, |
24 Profile* profile, | 43 Profile* profile, |
25 const content::MediaStreamRequest& request, | 44 const content::MediaStreamRequest& request, |
26 const content::MediaResponseCallback& callback) { | 45 const content::MediaResponseCallback& callback) { |
27 const extensions::Extension* extension = NULL; | 46 const extensions::Extension* extension = |
28 #if defined(ENABLE_EXTENSIONS) | 47 GetExtensionForOrigin(profile, request.security_origin); |
29 GURL origin(request.security_origin); | |
30 if (origin.SchemeIs(extensions::kExtensionScheme)) { | |
31 ExtensionService* extensions_service = | |
32 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
33 extension = extensions_service->extensions()->GetByID(origin.host()); | |
34 DCHECK(extension); | |
35 } | |
36 #endif | |
37 | |
38 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 48 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
39 web_contents, request, callback, extension); | 49 web_contents, request, callback, extension); |
40 } | 50 } |
51 | |
52 bool CheckMediaAccessPermission(content::WebContents* web_contents, | |
53 const GURL& security_origin, | |
54 content::MediaStreamType type) { | |
55 Profile* profile = | |
56 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
57 const extensions::Extension* extension = | |
58 GetExtensionForOrigin(profile, security_origin); | |
59 return MediaCaptureDevicesDispatcher::GetInstance() | |
60 ->CheckMediaAccessPermission( | |
61 web_contents, security_origin, type, extension); | |
62 } | |
OLD | NEW |