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