OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 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 |
| 12 MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( |
| 13 Profile* profile, |
| 14 const ContentSettingsType content_settings_type) |
| 15 : PermissionContextBase(profile, content_settings_type), |
| 16 content_settings_type_(content_settings_type) { |
| 17 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 18 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 19 } |
| 20 |
| 21 MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {} |
| 22 |
| 23 void MediaStreamDevicePermissionContext::RequestPermission( |
| 24 content::WebContents* web_contents, |
| 25 const PermissionRequestID& id, |
| 26 const GURL& requesting_frame, |
| 27 bool user_gesture, |
| 28 const BrowserPermissionCallback& callback) { |
| 29 NOTREACHED() << "RequestPermission is not implemented"; |
| 30 callback.Run(CONTENT_SETTING_BLOCK); |
| 31 } |
| 32 |
| 33 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatus( |
| 34 const GURL& requesting_origin, |
| 35 const GURL& embedding_origin) const { |
| 36 // TODO(raymes): Merge this policy check into content settings |
| 37 // crbug.com/244389. |
| 38 const char* policy_name = nullptr; |
| 39 const char* urls_policy_name = nullptr; |
| 40 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 41 policy_name = prefs::kAudioCaptureAllowed; |
| 42 urls_policy_name = prefs::kAudioCaptureAllowedUrls; |
| 43 } else { |
| 44 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 45 policy_name = prefs::kVideoCaptureAllowed; |
| 46 urls_policy_name = prefs::kVideoCaptureAllowedUrls; |
| 47 } |
| 48 |
| 49 MediaStreamDevicePolicy policy = GetDevicePolicy( |
| 50 profile(), requesting_origin, policy_name, urls_policy_name); |
| 51 |
| 52 switch (policy) { |
| 53 case ALWAYS_DENY: |
| 54 return CONTENT_SETTING_BLOCK; |
| 55 case ALWAYS_ALLOW: |
| 56 return CONTENT_SETTING_ALLOW; |
| 57 default: |
| 58 DCHECK_EQ(POLICY_NOT_SET, policy); |
| 59 } |
| 60 |
| 61 // Check the content setting. |
| 62 ContentSetting setting = PermissionContextBase::GetPermissionStatus( |
| 63 requesting_origin, embedding_origin); |
| 64 |
| 65 return setting == CONTENT_SETTING_DEFAULT ? CONTENT_SETTING_ASK : setting; |
| 66 } |
| 67 |
| 68 void MediaStreamDevicePermissionContext::ResetPermission( |
| 69 const GURL& requesting_origin, |
| 70 const GURL& embedding_origin) { |
| 71 NOTREACHED() << "ResetPermission is not implemented"; |
| 72 } |
| 73 |
| 74 void MediaStreamDevicePermissionContext::CancelPermissionRequest( |
| 75 content::WebContents* web_contents, |
| 76 const PermissionRequestID& id) { |
| 77 NOTREACHED() << "CancelPermissionRequest is not implemented"; |
| 78 } |
| 79 |
| 80 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
| 81 // Flash currently doesn't require secure origin to use mic/camera. If we |
| 82 // return true here, it'll break the use case like http://tinychat.com. Please |
| 83 // see crbug.com/512301. |
| 84 return false; |
| 85 } |
OLD | NEW |