Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / media_utils.cc
blob4520a19c2e0d739e67e302e43d8aaeeac440d9e0
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"
14 #endif
16 namespace {
18 #if defined(ENABLE_EXTENSIONS)
19 const extensions::Extension* GetExtensionForOrigin(Profile* profile,
20 const GURL& security_origin) {
21 if (!security_origin.SchemeIs(extensions::kExtensionScheme))
22 return NULL;
24 const extensions::Extension* extension =
25 extensions::ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(
26 security_origin.host());
27 DCHECK(extension);
28 return extension;
30 #endif
32 } // namespace
34 void RequestMediaAccessPermission(
35 content::WebContents* web_contents,
36 Profile* profile,
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);
42 #endif
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)
51 Profile* profile =
52 Profile::FromBrowserContext(web_contents->GetBrowserContext());
53 const extensions::Extension* extension =
54 GetExtensionForOrigin(profile, security_origin);
55 if (extension) {
56 return MediaCaptureDevicesDispatcher::GetInstance()
57 ->CheckMediaAccessPermission(
58 web_contents, security_origin, type, extension);
60 return MediaCaptureDevicesDispatcher::GetInstance()
61 ->CheckMediaAccessPermission(web_contents, security_origin, type);
62 #else
63 return MediaCaptureDevicesDispatcher::GetInstance()
64 ->CheckMediaAccessPermission(web_contents, security_origin, type);
65 #endif