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 namespace { |
17 | 18 |
18 namespace content { | 19 #if defined(ENABLE_EXTENSIONS) |
19 class WebContents; | 20 const extensions::Extension* GetExtensionForOrigin(Profile* profile, |
21 const GURL& security_origin) { | |
22 if (!security_origin.SchemeIs(extensions::kExtensionScheme)) | |
23 return NULL; | |
24 | |
25 ExtensionService* extensions_service = | |
26 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
27 const extensions::Extension* extension = | |
28 extensions_service->extensions()->GetByID(security_origin.host()); | |
29 DCHECK(extension); | |
30 return extension; | |
20 } | 31 } |
32 #endif | |
33 | |
34 } // namespace | |
21 | 35 |
22 void RequestMediaAccessPermission( | 36 void RequestMediaAccessPermission( |
23 content::WebContents* web_contents, | 37 content::WebContents* web_contents, |
24 Profile* profile, | 38 Profile* profile, |
25 const content::MediaStreamRequest& request, | 39 const content::MediaStreamRequest& request, |
26 const content::MediaResponseCallback& callback) { | 40 const content::MediaResponseCallback& callback) { |
27 const extensions::Extension* extension = NULL; | 41 const extensions::Extension* extension = NULL; |
28 #if defined(ENABLE_EXTENSIONS) | 42 #if defined(ENABLE_EXTENSIONS) |
29 GURL origin(request.security_origin); | 43 extension = GetExtensionForOrigin(profile, 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 | 44 #endif |
37 | |
38 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 45 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
39 web_contents, request, callback, extension); | 46 web_contents, request, callback, extension); |
40 } | 47 } |
48 | |
49 bool CheckMediaAccessPermission(content::WebContents* web_contents, | |
50 const GURL& security_origin, | |
51 content::MediaStreamType type) { | |
52 const extensions::Extension* extension = NULL; | |
sky
2014/09/16 16:33:25
If ENABLE_EXTENSIONS is false, why are you passing
Henrik Grunell
2014/09/16 17:14:15
Do you think yet another function is better or did
| |
53 #if defined(ENABLE_EXTENSIONS) | |
54 Profile* profile = | |
55 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
56 extension = GetExtensionForOrigin(profile, security_origin); | |
57 #endif | |
58 return MediaCaptureDevicesDispatcher::GetInstance() | |
59 ->CheckMediaAccessPermission( | |
60 web_contents, security_origin, type, extension); | |
61 } | |
OLD | NEW |