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

Side by Side Diff: chrome/browser/media/webrtc/media_permission.cc

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media/webrtc/media_permission.h" 5 #include "chrome/browser/media/webrtc/media_permission.h"
6 6
7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
9 #include "chrome/browser/permissions/permission_context_base.h" 9 #include "chrome/browser/permissions/permission_context_base.h"
10 #include "chrome/browser/permissions/permission_manager.h" 10 #include "chrome/browser/permissions/permission_manager.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/permission_manager.h" 13 #include "content/public/browser/permission_manager.h"
14 #include "content/public/browser/permission_type.h"
15 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
16 #include "extensions/common/constants.h" 15 #include "extensions/common/constants.h"
17 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
18 17
19 namespace {
20
21 content::PermissionType ContentSettingsTypeToPermission(
22 ContentSettingsType content_setting) {
23 if (content_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
24 return content::PermissionType::AUDIO_CAPTURE;
25 } else {
26 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_setting);
27 return content::PermissionType::VIDEO_CAPTURE;
28 }
29 }
30
31 } // namespace
32
33 MediaPermission::MediaPermission(ContentSettingsType content_type, 18 MediaPermission::MediaPermission(ContentSettingsType content_type,
34 const GURL& requesting_origin, 19 const GURL& requesting_origin,
35 const GURL& embedding_origin, 20 const GURL& embedding_origin,
36 Profile* profile) 21 Profile* profile)
37 : content_type_(content_type), 22 : content_type_(content_type),
38 requesting_origin_(requesting_origin), 23 requesting_origin_(requesting_origin),
39 embedding_origin_(embedding_origin), 24 embedding_origin_(embedding_origin),
40 profile_(profile) {} 25 profile_(profile) {}
41 26
42 ContentSetting MediaPermission::GetPermissionStatus( 27 ContentSetting MediaPermission::GetPermissionStatus(
43 content::MediaStreamRequestResult* denial_reason) const { 28 content::MediaStreamRequestResult* denial_reason) const {
44 // Deny the request if the security origin is empty, this happens with 29 // Deny the request if the security origin is empty, this happens with
45 // file access without |--allow-file-access-from-files| flag. 30 // file access without |--allow-file-access-from-files| flag.
46 if (requesting_origin_.is_empty()) { 31 if (requesting_origin_.is_empty()) {
47 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; 32 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN;
48 return CONTENT_SETTING_BLOCK; 33 return CONTENT_SETTING_BLOCK;
49 } 34 }
50 35
51 content::PermissionType permission_type =
52 ContentSettingsTypeToPermission(content_type_);
53 PermissionManager* permission_manager = PermissionManager::Get(profile_); 36 PermissionManager* permission_manager = PermissionManager::Get(profile_);
54 37
55 // Find out if the kill switch is on. Set the denial reason to kill switch. 38 // Find out if the kill switch is on. Set the denial reason to kill switch.
56 if (permission_manager->IsPermissionKillSwitchOn(permission_type)) { 39 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) {
57 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; 40 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON;
58 return CONTENT_SETTING_BLOCK; 41 return CONTENT_SETTING_BLOCK;
59 } 42 }
60 43
61 // Check policy and content settings. 44 // Check policy and content settings.
62 blink::mojom::PermissionStatus status = 45 blink::mojom::PermissionStatus status =
63 permission_manager->GetPermissionStatus( 46 permission_manager->GetPermissionStatus(
64 permission_type, requesting_origin_, embedding_origin_); 47 content_type_, requesting_origin_, embedding_origin_);
65 switch (status) { 48 switch (status) {
66 case blink::mojom::PermissionStatus::DENIED: 49 case blink::mojom::PermissionStatus::DENIED:
67 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 50 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
68 return CONTENT_SETTING_BLOCK; 51 return CONTENT_SETTING_BLOCK;
69 case blink::mojom::PermissionStatus::ASK: 52 case blink::mojom::PermissionStatus::ASK:
70 return CONTENT_SETTING_ASK; 53 return CONTENT_SETTING_ASK;
71 case blink::mojom::PermissionStatus::GRANTED: 54 case blink::mojom::PermissionStatus::GRANTED:
72 return CONTENT_SETTING_ALLOW; 55 return CONTENT_SETTING_ALLOW;
73 } 56 }
74 57
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return false; 93 return false;
111 94
112 // Note: we check device_id before dereferencing devices. If the requested 95 // Note: we check device_id before dereferencing devices. If the requested
113 // device id is non-empty, then the corresponding device list must not be 96 // device id is non-empty, then the corresponding device list must not be
114 // NULL. 97 // NULL.
115 if (!device_id.empty() && !devices->FindById(device_id)) 98 if (!device_id.empty() && !devices->FindById(device_id))
116 return false; 99 return false;
117 100
118 return true; 101 return true;
119 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698