Chromium Code Reviews| 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(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 if (policy == ALWAYS_DENY) | |
| 53 return CONTENT_SETTING_BLOCK; | |
| 54 | |
| 55 if (policy == ALWAYS_ALLOW) | |
| 56 return CONTENT_SETTING_ALLOW; | |
| 57 | |
| 58 DCHECK_EQ(POLICY_NOT_SET, policy); | |
| 59 // Check the content setting. | |
| 60 ContentSetting setting = PermissionContextBase::GetPermissionStatus( | |
| 61 requesting_origin, embedding_origin); | |
| 62 | |
| 63 return setting == CONTENT_SETTING_DEFAULT ? CONTENT_SETTING_ASK : setting; | |
| 64 } | |
| 65 | |
| 66 void MediaStreamDevicePermissionContext::ResetPermission( | |
| 67 const GURL& requesting_origin, | |
| 68 const GURL& embedding_origin) { | |
| 69 NOTREACHED() << "ResetPermission is not implemented"; | |
| 70 } | |
| 71 | |
| 72 void MediaStreamDevicePermissionContext::CancelPermissionRequest( | |
| 73 content::WebContents* web_contents, | |
| 74 const PermissionRequestID& id) { | |
| 75 NOTREACHED() << "CancelPermissionRequest is not implemented"; | |
| 76 } | |
| 77 | |
| 78 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { | |
| 79 // Changing this once Flash also requires secure origin. | |
|
palmer
2015/08/28 01:44:21
I'm not sure what this comment means. Does it mean
mlamouri (slow - plz ping)
2015/08/28 10:56:21
+1.
Also, this is should be TODO($user) and point
guoweis_left_chromium
2015/08/28 16:16:20
My goal here is to refactor without introducing fu
| |
| 80 return false; | |
| 81 } | |
| OLD | NEW |