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..1f46738da9cd7898eebaec70bf9cd71595535e30 |
| --- /dev/null |
| +++ b/chrome/browser/media/media_stream_device_permission_context.cc |
| @@ -0,0 +1,85 @@ |
| +// 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" |
| + |
| +MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( |
| + Profile* profile, |
| + const ContentSettingsType permission_type) |
| + : PermissionContextBase(profile, permission_type) { |
| + CHECK(permission_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| + permission_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| +} |
| + |
| +MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {} |
| + |
| +bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
|
raymes
2015/08/26 03:07:36
Please keep functions in the same order as the hea
guoweis_left_chromium
2015/08/26 22:29:57
Done.
|
| + return true; |
| +} |
| + |
| +void MediaStreamDevicePermissionContext::RequestPermission( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + bool user_gesture, |
| + const BrowserPermissionCallback& callback) { |
| + CHECK(0) << "RequestPermission is not implemented"; |
|
raymes
2015/08/26 03:07:36
We would typically use NOTREACHED() here. (and bel
guoweis_left_chromium
2015/08/26 22:29:57
Done.
|
| +} |
| + |
| +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) { |
| + policy_name = prefs::kAudioCaptureAllowed; |
| + urls_policy_name = prefs::kAudioCaptureAllowedUrls; |
| + } else if (content_settings_type() == |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| + policy_name = prefs::kVideoCaptureAllowed; |
| + urls_policy_name = prefs::kVideoCaptureAllowedUrls; |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + // TODO(guoweis): why are we using embedding_origin? |
|
raymes
2015/08/26 03:07:36
You tell me: why are we using embedding origin :)?
mlamouri (slow - plz ping)
2015/08/26 13:49:34
If embedder.com has an iframe to website.com and w
guoweis_left_chromium
2015/08/26 22:29:57
Done.
|
| + MediaStreamDevicePolicy policy = GetDevicePolicy( |
| + profile(), embedding_origin, policy_name, urls_policy_name); |
| + |
| + if (policy == ALWAYS_DENY) |
| + return CONTENT_SETTING_BLOCK; |
| + |
| + if (policy == ALWAYS_ALLOW) |
| + return CONTENT_SETTING_ALLOW; |
| + |
| + DCHECK(policy == POLICY_NOT_SET); |
|
raymes
2015/08/26 03:07:36
DCHECK_EQ
guoweis_left_chromium
2015/08/26 22:29:57
Done.
|
| + // Check the content setting. |
| + ContentSetting setting = |
| + profile()->GetHostContentSettingsMap()->GetContentSetting( |
| + requesting_origin, embedding_origin, content_settings_type(), |
|
raymes
2015/08/26 03:07:36
This should use requesting_origin, requesting_orig
mlamouri (slow - plz ping)
2015/08/26 13:49:34
Could you just call PermissionContextBase::GetPerm
guoweis_left_chromium
2015/08/26 22:29:57
Done.
raymes
2015/08/27 05:54:18
This will break the current behavior for the media
|
| + content_settings::ResourceIdentifier()); |
| + |
| + if (setting == CONTENT_SETTING_DEFAULT) |
| + return CONTENT_SETTING_ASK; |
| + |
| + return setting; |
| +} |
| + |
| +void MediaStreamDevicePermissionContext::ResetPermission( |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin) { |
| + CHECK(0) << "ResetPermission is not implemented"; |
| +} |
| + |
| +void MediaStreamDevicePermissionContext::CancelPermissionRequest( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id) { |
| + CHECK(0) << "CancelPermissionRequest is not implemented"; |
| +} |