| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h" |
| #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/content_settings/core/browser/host_content_settings_map.h" |
| #include "components/content_settings/core/common/content_settings.h" |
| #include "content/public/common/content_features.h" |
| #include "content/public/common/url_constants.h" |
| #include "extensions/common/constants.h" |
| |
| namespace { |
| |
| blink::FeaturePolicyFeature GetFeaturePolicyFeature(ContentSettingsType type) { |
| if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
| return blink::FeaturePolicyFeature::kMicrophone; |
| |
| DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, type); |
| return blink::FeaturePolicyFeature::kCamera; |
| } |
| |
| } // namespace |
| |
| MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( |
| Profile* profile, |
| const ContentSettingsType content_settings_type) |
| : PermissionContextBase(profile, |
| content_settings_type, |
| GetFeaturePolicyFeature(content_settings_type)), |
| content_settings_type_(content_settings_type) { |
| DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| } |
| |
| MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {} |
| |
| void MediaStreamDevicePermissionContext::DecidePermission( |
| content::WebContents* web_contents, |
| const PermissionRequestID& id, |
| const GURL& requesting_origin, |
| const GURL& embedding_origin, |
| bool user_gesture, |
| const BrowserPermissionCallback& callback) { |
| PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
| embedding_origin, user_gesture, |
| callback); |
| } |
| |
| ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal( |
| content::RenderFrameHost* render_frame_host, |
| const GURL& requesting_origin, |
| const GURL& embedding_origin) const { |
| // TODO(raymes): Merge this policy check into content settings |
| // crbug.com/244389. |
| const char* policy_name = nullptr; |
| const char* urls_policy_name = nullptr; |
| if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| policy_name = prefs::kAudioCaptureAllowed; |
| urls_policy_name = prefs::kAudioCaptureAllowedUrls; |
| } else { |
| DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| policy_name = prefs::kVideoCaptureAllowed; |
| urls_policy_name = prefs::kVideoCaptureAllowedUrls; |
| } |
| |
| MediaStreamDevicePolicy policy = GetDevicePolicy( |
| profile(), requesting_origin, policy_name, urls_policy_name); |
| |
| switch (policy) { |
| case ALWAYS_DENY: |
| return CONTENT_SETTING_BLOCK; |
| case ALWAYS_ALLOW: |
| return CONTENT_SETTING_ALLOW; |
| default: |
| DCHECK_EQ(POLICY_NOT_SET, policy); |
| } |
| |
| // Check the content setting. TODO(raymes): currently mic/camera permission |
| // doesn't consider the embedder. |
| ContentSetting setting = PermissionContextBase::GetPermissionStatusInternal( |
| render_frame_host, requesting_origin, requesting_origin); |
| |
| if (setting == CONTENT_SETTING_DEFAULT) |
| setting = CONTENT_SETTING_ASK; |
| |
| return setting; |
| } |
| |
| void MediaStreamDevicePermissionContext::ResetPermission( |
| const GURL& requesting_origin, |
| const GURL& embedding_origin) { |
| NOTREACHED() << "ResetPermission is not implemented"; |
| } |
| |
| bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
| return true; |
| } |