Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4407)

Unified Diff: chrome/browser/media/media_permission.cc

Issue 1318173002: Integrate MediaPermission with PermissionManager by using PermissionContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/media_permission.cc
diff --git a/chrome/browser/media/media_permission.cc b/chrome/browser/media/media_permission.cc
index d09f8c80b52693c1cf9ed00e1a760862df785fa3..60c47e3899c6c4081e549663011a33460ad1a572 100644
--- a/chrome/browser/media/media_permission.cc
+++ b/chrome/browser/media/media_permission.cc
@@ -8,10 +8,46 @@
#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 "content/public/browser/permission_manager.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
+namespace {
raymes 2015/08/31 01:51:45 nit: newline below
guoweis_left_chromium 2015/09/01 07:08:51 Done.
+ContentSetting PermissionStatusToContentSetting(
+ content::PermissionStatus status) {
+ switch (status) {
+ case content::PERMISSION_STATUS_GRANTED:
+ return CONTENT_SETTING_ALLOW;
+ case content::PERMISSION_STATUS_DENIED:
+ return CONTENT_SETTING_BLOCK;
+ case content::PERMISSION_STATUS_ASK:
+ return CONTENT_SETTING_ASK;
+ }
+
+ NOTREACHED();
+ return CONTENT_SETTING_BLOCK;
+}
+
+content::PermissionType ContentSettingsTypeToPermission(
+ ContentSettingsType content_setting) {
+ switch (content_setting) {
+ case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
+ return content::PermissionType::AUDIO_RECORDING;
+ case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
+ return content::PermissionType::VIDEO_RECORDING;
+ default:
+ // This will hit the NOTREACHED below.
+ break;
+ }
+
+ NOTREACHED() << "Unexpected content setting for permission "
+ << static_cast<int>(content_setting);
+ return content::PermissionType::NUM;
+}
+
+} // namespace
+
MediaPermission::MediaPermission(ContentSettingsType content_type,
content::MediaStreamRequestType request_type,
const GURL& origin,
@@ -53,39 +89,18 @@ ContentSetting MediaPermission::GetPermissionStatusWithDeviceRequired(
}
ContentSetting MediaPermission::GetStoredContentSetting() const {
mlamouri (slow - plz ping) 2015/08/28 10:51:35 Could you change MediaPermission::GetStoredContent
raymes 2015/08/29 00:09:02 This unfortunately comes as a result of doing a pa
raymes 2015/08/31 01:51:45 It's probably possible to do some refactoring in M
mlamouri (slow - plz ping) 2015/08/31 13:09:58 Hmmm, my comment was only applying to GetStoredCon
- // 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_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
- policy_name = prefs::kAudioCaptureAllowed;
- urls_policy_name = prefs::kAudioCaptureAllowedUrls;
- } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
- policy_name = prefs::kVideoCaptureAllowed;
- urls_policy_name = prefs::kVideoCaptureAllowedUrls;
- } else {
- NOTREACHED();
+ ContentSetting setting = CONTENT_SETTING_BLOCK;
+ if (profile_) {
mlamouri (slow - plz ping) 2015/08/28 10:51:35 Why are you checking for |profile_| while the prev
guoweis_left_chromium 2015/09/01 07:08:51 Done.
+ content::PermissionManager* permission_manager =
+ profile_->GetPermissionManager();
+ if (permission_manager) {
mlamouri (slow - plz ping) 2015/08/28 10:51:35 Maybe: if (!permission_manager) return CONTENT_S
guoweis_left_chromium 2015/09/01 07:08:51 Done.
+ setting = PermissionStatusToContentSetting(
+ permission_manager->GetPermissionStatus(
+ ContentSettingsTypeToPermission(content_type_), origin_,
+ origin_));
mlamouri (slow - plz ping) 2015/08/28 10:51:35 Shouldn't you take into account the embedder?
raymes 2015/08/29 00:09:02 Mounir, you should read my replies :) As I mention
mlamouri (slow - plz ping) 2015/08/31 13:09:58 I remember your comment. Though, I would prefer th
raymes 2015/08/31 23:32:49 Ahh, sorry, that makes sense and I agree with you.
guoweis_left_chromium 2015/09/01 07:08:51 Done.
+ }
}
- MediaStreamDevicePolicy policy =
- GetDevicePolicy(profile_, 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);
- // Check the content setting.
- ContentSetting setting =
- profile_->GetHostContentSettingsMap()->GetContentSetting(
- origin_, origin_, content_type_,
- content_settings::ResourceIdentifier());
-
- if (setting == CONTENT_SETTING_DEFAULT)
- return CONTENT_SETTING_ASK;
-
// TODO(raymes): This is here for safety to ensure that we always ask the user
// even if a content setting is set to "allow" if the origin is insecure. In
// reality we shouldn't really need to check this here as we should respect
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698