Chromium Code Reviews| Index: chrome/browser/media/media_stream_device_permission_context.cc |
| diff --git a/chrome/browser/media/media_stream_device_permission_context.cc b/chrome/browser/media/media_stream_device_permission_context.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..431a3caaff5dd9733cf25f0e11b867ee44c5cf5f |
| --- /dev/null |
| +++ b/chrome/browser/media/media_stream_device_permission_context.cc |
| @@ -0,0 +1,82 @@ |
| +// 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/media_stream_device_permission_context.h" |
| +#include "chrome/browser/media/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" |
| + |
| +MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( |
| + Profile* profile, |
| + const ContentSettingsType content_settings_type) |
| + : PermissionContextBase(profile, 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::RequestPermission( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + bool user_gesture, |
| + const BrowserPermissionCallback& callback) { |
| + NOTREACHED() << "RequestPermission is not implemented"; |
| + callback.Run(CONTENT_SETTING_BLOCK); |
| +} |
| + |
| +ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatus( |
| + 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) { |
|
palmer
2015/09/01 18:31:04
I wonder if this would be more clear/obvious as a
guoweis_left_chromium
2015/09/01 19:36:33
This class could only be used with 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); |
| + |
| + if (policy == ALWAYS_DENY) |
|
palmer
2015/09/01 18:31:04
Same here, switching over the enum seems better.
guoweis_left_chromium
2015/09/01 19:36:33
Done.
|
| + return CONTENT_SETTING_BLOCK; |
| + |
| + if (policy == ALWAYS_ALLOW) |
| + return CONTENT_SETTING_ALLOW; |
| + |
| + DCHECK_EQ(POLICY_NOT_SET, policy); |
| + // Check the content setting. |
| + ContentSetting setting = PermissionContextBase::GetPermissionStatus( |
| + requesting_origin, embedding_origin); |
| + |
| + return setting == CONTENT_SETTING_DEFAULT ? CONTENT_SETTING_ASK : setting; |
| +} |
| + |
| +void MediaStreamDevicePermissionContext::ResetPermission( |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin) { |
| + NOTREACHED() << "ResetPermission is not implemented"; |
| +} |
| + |
| +void MediaStreamDevicePermissionContext::CancelPermissionRequest( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id) { |
| + NOTREACHED() << "CancelPermissionRequest is not implemented"; |
| +} |
| + |
| +bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
| + // Flash currently doesn't require secure origin to use mic/camera. If we |
| + // return true here, it'll break the use case like http://tinychat.com. |
| + return false; |
| +} |