Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / media_stream_device_permission_context.cc
blob17022371a46a00a6fb3ef9072ee89a04b7a8e6ea
1 // Copyright 2015 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/media/media_stream_device_permission_context.h"
6 #include "chrome/browser/media/media_stream_device_permissions.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/pref_names.h"
9 #include "components/content_settings/core/browser/host_content_settings_map.h"
10 #include "components/content_settings/core/common/content_settings.h"
11 #include "content/public/common/url_constants.h"
12 #include "extensions/common/constants.h"
14 MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext(
15 Profile* profile,
16 const ContentSettingsType content_settings_type)
17 : PermissionContextBase(profile, content_settings_type),
18 content_settings_type_(content_settings_type) {
19 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
20 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
23 MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {}
25 void MediaStreamDevicePermissionContext::RequestPermission(
26 content::WebContents* web_contents,
27 const PermissionRequestID& id,
28 const GURL& requesting_frame,
29 bool user_gesture,
30 const BrowserPermissionCallback& callback) {
31 NOTREACHED() << "RequestPermission is not implemented";
32 callback.Run(CONTENT_SETTING_BLOCK);
35 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatus(
36 const GURL& requesting_origin,
37 const GURL& embedding_origin) const {
38 return GetPermissionStatusInternal(requesting_origin, embedding_origin,
39 false);
42 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusForPepper(
43 const GURL& requesting_origin,
44 const GURL& embedding_origin) const {
45 return GetPermissionStatusInternal(requesting_origin, embedding_origin, true);
48 void MediaStreamDevicePermissionContext::ResetPermission(
49 const GURL& requesting_origin,
50 const GURL& embedding_origin) {
51 NOTREACHED() << "ResetPermission is not implemented";
54 void MediaStreamDevicePermissionContext::CancelPermissionRequest(
55 content::WebContents* web_contents,
56 const PermissionRequestID& id) {
57 NOTREACHED() << "CancelPermissionRequest is not implemented";
60 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal(
61 const GURL& requesting_origin,
62 const GURL& embedding_origin,
63 bool is_pepper_request) const {
64 // TODO(raymes): Merge this policy check into content settings
65 // crbug.com/244389.
66 const char* policy_name = nullptr;
67 const char* urls_policy_name = nullptr;
68 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
69 policy_name = prefs::kAudioCaptureAllowed;
70 urls_policy_name = prefs::kAudioCaptureAllowedUrls;
71 } else {
72 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
73 policy_name = prefs::kVideoCaptureAllowed;
74 urls_policy_name = prefs::kVideoCaptureAllowedUrls;
77 MediaStreamDevicePolicy policy = GetDevicePolicy(
78 profile(), requesting_origin, policy_name, urls_policy_name);
80 switch (policy) {
81 case ALWAYS_DENY:
82 return CONTENT_SETTING_BLOCK;
83 case ALWAYS_ALLOW:
84 return CONTENT_SETTING_ALLOW;
85 default:
86 DCHECK_EQ(POLICY_NOT_SET, policy);
89 // Check the content setting. TODO(raymes): currently mic/camera permission
90 // doesn't consider the embedder.
91 ContentSetting setting = PermissionContextBase::GetPermissionStatus(
92 requesting_origin, requesting_origin);
94 if (setting == CONTENT_SETTING_DEFAULT)
95 setting = CONTENT_SETTING_ASK;
97 // TODO(raymes): This is here for safety to ensure that we always ask the user
98 // even if a content setting is set to "allow" if the origin is insecure. In
99 // reality we shouldn't really need to check this here as we should respect
100 // the user's content setting. The problem is that pepper requests allow
101 // insecure origins to be persisted. We should stop allowing this, do some
102 // sort of migration and remove this check. See crbug.com/512301.
103 if (!ShouldPersistContentSetting(setting, requesting_origin,
104 is_pepper_request) &&
105 !requesting_origin.SchemeIs(extensions::kExtensionScheme) &&
106 !requesting_origin.SchemeIs(content::kChromeUIScheme) &&
107 !requesting_origin.SchemeIs(content::kChromeDevToolsScheme)) {
108 return CONTENT_SETTING_ASK;
111 return setting;
114 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const {
115 // Flash currently doesn't require secure origin to use mic/camera. If we
116 // return true here, it'll break the use case like http://tinychat.com. Please
117 // see crbug.com/512301.
118 return false;