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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/media_utils.h"
7 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/web_contents.h"
11 #if defined(ENABLE_EXTENSIONS)
12 #include "extensions/browser/extension_registry.h"
13 #include "extensions/common/constants.h"
18 #if defined(ENABLE_EXTENSIONS)
19 const extensions::Extension
* GetExtensionForOrigin(Profile
* profile
,
20 const GURL
& security_origin
) {
21 if (!security_origin
.SchemeIs(extensions::kExtensionScheme
))
24 const extensions::Extension
* extension
=
25 extensions::ExtensionRegistry::Get(profile
)->enabled_extensions().GetByID(
26 security_origin
.host());
34 void RequestMediaAccessPermission(
35 content::WebContents
* web_contents
,
37 const content::MediaStreamRequest
& request
,
38 const content::MediaResponseCallback
& callback
) {
39 const extensions::Extension
* extension
= NULL
;
40 #if defined(ENABLE_EXTENSIONS)
41 extension
= GetExtensionForOrigin(profile
, request
.security_origin
);
43 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
44 web_contents
, request
, callback
, extension
);
47 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
48 const GURL
& security_origin
,
49 content::MediaStreamType type
) {
50 #if defined(ENABLE_EXTENSIONS)
52 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
53 const extensions::Extension
* extension
=
54 GetExtensionForOrigin(profile
, security_origin
);
56 return MediaCaptureDevicesDispatcher::GetInstance()
57 ->CheckMediaAccessPermission(
58 web_contents
, security_origin
, type
, extension
);
60 return MediaCaptureDevicesDispatcher::GetInstance()
61 ->CheckMediaAccessPermission(web_contents
, security_origin
, type
);
63 return MediaCaptureDevicesDispatcher::GetInstance()
64 ->CheckMediaAccessPermission(web_contents
, security_origin
, type
);