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

Side by Side Diff: chrome/browser/permissions/permission_manager.cc

Issue 2339093002: [HBD] Add Plugins permission type and PermissionContext (Closed)
Patch Set: Created 4 years, 3 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/permissions/permission_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
dominickn 2016/09/14 07:18:42 Nit: this should probably #include <memory> for st
raymes 2016/09/15 03:40:30 Done.
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/background_sync/background_sync_permission_context.h" 12 #include "chrome/browser/background_sync/background_sync_permission_context.h"
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/browser/media/midi_permission_context.h" 14 #include "chrome/browser/media/midi_permission_context.h"
15 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h" 15 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h"
16 #include "chrome/browser/notifications/notification_permission_context.h" 16 #include "chrome/browser/notifications/notification_permission_context.h"
17 #include "chrome/browser/permissions/permission_context_base.h" 17 #include "chrome/browser/permissions/permission_context_base.h"
18 #include "chrome/browser/permissions/permission_manager_factory.h" 18 #include "chrome/browser/permissions/permission_manager_factory.h"
19 #include "chrome/browser/permissions/permission_request_id.h" 19 #include "chrome/browser/permissions/permission_request_id.h"
20 #include "chrome/browser/permissions/permission_uma_util.h" 20 #include "chrome/browser/permissions/permission_uma_util.h"
21 #include "chrome/browser/plugins/plugins_permission_context.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/storage/durable_storage_permission_context.h" 23 #include "chrome/browser/storage/durable_storage_permission_context.h"
23 #include "chrome/browser/tab_contents/tab_util.h" 24 #include "chrome/browser/tab_contents/tab_util.h"
24 #include "chrome/common/features.h" 25 #include "chrome/common/features.h"
25 #include "components/content_settings/core/browser/host_content_settings_map.h" 26 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "content/public/browser/permission_type.h" 27 #include "content/public/browser/permission_type.h"
27 #include "content/public/browser/render_frame_host.h" 28 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 31
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return CONTENT_SETTINGS_TYPE_DURABLE_STORAGE; 93 return CONTENT_SETTINGS_TYPE_DURABLE_STORAGE;
93 case PermissionType::MIDI: 94 case PermissionType::MIDI:
94 // This will hit the NOTREACHED below. 95 // This will hit the NOTREACHED below.
95 break; 96 break;
96 case PermissionType::AUDIO_CAPTURE: 97 case PermissionType::AUDIO_CAPTURE:
97 return CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; 98 return CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC;
98 case PermissionType::VIDEO_CAPTURE: 99 case PermissionType::VIDEO_CAPTURE:
99 return CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; 100 return CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA;
100 case PermissionType::BACKGROUND_SYNC: 101 case PermissionType::BACKGROUND_SYNC:
101 return CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC; 102 return CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC;
103 case PermissionType::PLUGINS:
104 return CONTENT_SETTINGS_TYPE_PLUGINS;
102 case PermissionType::NUM: 105 case PermissionType::NUM:
103 // This will hit the NOTREACHED below. 106 // This will hit the NOTREACHED below.
104 break; 107 break;
105 } 108 }
106 109
107 NOTREACHED() << "Unknown content setting for permission " 110 NOTREACHED() << "Unknown content setting for permission "
108 << static_cast<int>(permission); 111 << static_cast<int>(permission);
109 return CONTENT_SETTINGS_TYPE_DEFAULT; 112 return CONTENT_SETTINGS_TYPE_DEFAULT;
110 } 113 }
111 114
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // static 215 // static
213 PermissionManager* PermissionManager::Get(Profile* profile) { 216 PermissionManager* PermissionManager::Get(Profile* profile) {
214 return PermissionManagerFactory::GetForProfile(profile); 217 return PermissionManagerFactory::GetForProfile(profile);
215 } 218 }
216 219
217 PermissionManager::PermissionManager(Profile* profile) 220 PermissionManager::PermissionManager(Profile* profile)
218 : profile_(profile), 221 : profile_(profile),
219 weak_ptr_factory_(this) { 222 weak_ptr_factory_(this) {
220 permission_contexts_[PermissionType::MIDI_SYSEX] = 223 permission_contexts_[PermissionType::MIDI_SYSEX] =
221 base::WrapUnique(new MidiPermissionContext(profile)); 224 base::WrapUnique(new MidiPermissionContext(profile));
222 permission_contexts_[PermissionType::PUSH_MESSAGING] = 225 permission_contexts_[PermissionType::PUSH_MESSAGING] =
dominickn 2016/09/14 07:18:43 base::WrapUnique is dispreferred in favour of base
raymes 2016/09/15 03:40:30 Done.
223 base::WrapUnique(new NotificationPermissionContext( 226 base::WrapUnique(new NotificationPermissionContext(
224 profile, PermissionType::PUSH_MESSAGING)); 227 profile, PermissionType::PUSH_MESSAGING));
225 permission_contexts_[PermissionType::NOTIFICATIONS] = 228 permission_contexts_[PermissionType::NOTIFICATIONS] =
226 base::WrapUnique(new NotificationPermissionContext( 229 base::WrapUnique(new NotificationPermissionContext(
227 profile, PermissionType::NOTIFICATIONS)); 230 profile, PermissionType::NOTIFICATIONS));
228 #if !BUILDFLAG(ANDROID_JAVA_UI) 231 #if !BUILDFLAG(ANDROID_JAVA_UI)
229 permission_contexts_[PermissionType::GEOLOCATION] = 232 permission_contexts_[PermissionType::GEOLOCATION] =
230 base::WrapUnique(new GeolocationPermissionContext(profile)); 233 base::WrapUnique(new GeolocationPermissionContext(profile));
231 #else 234 #else
232 permission_contexts_[PermissionType::GEOLOCATION] = 235 permission_contexts_[PermissionType::GEOLOCATION] =
233 base::WrapUnique(new GeolocationPermissionContextAndroid(profile)); 236 base::WrapUnique(new GeolocationPermissionContextAndroid(profile));
234 #endif 237 #endif
235 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 238 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
236 permission_contexts_[PermissionType::PROTECTED_MEDIA_IDENTIFIER] = 239 permission_contexts_[PermissionType::PROTECTED_MEDIA_IDENTIFIER] =
237 base::WrapUnique(new ProtectedMediaIdentifierPermissionContext(profile)); 240 base::WrapUnique(new ProtectedMediaIdentifierPermissionContext(profile));
238 #endif 241 #endif
239 permission_contexts_[PermissionType::DURABLE_STORAGE] = 242 permission_contexts_[PermissionType::DURABLE_STORAGE] =
240 base::WrapUnique(new DurableStoragePermissionContext(profile)); 243 base::WrapUnique(new DurableStoragePermissionContext(profile));
241 permission_contexts_[PermissionType::AUDIO_CAPTURE] = 244 permission_contexts_[PermissionType::AUDIO_CAPTURE] =
242 base::WrapUnique(new MediaStreamDevicePermissionContext( 245 base::WrapUnique(new MediaStreamDevicePermissionContext(
243 profile, content::PermissionType::AUDIO_CAPTURE, 246 profile, content::PermissionType::AUDIO_CAPTURE,
244 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 247 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
245 permission_contexts_[PermissionType::VIDEO_CAPTURE] = 248 permission_contexts_[PermissionType::VIDEO_CAPTURE] =
246 base::WrapUnique(new MediaStreamDevicePermissionContext( 249 base::WrapUnique(new MediaStreamDevicePermissionContext(
247 profile, content::PermissionType::VIDEO_CAPTURE, 250 profile, content::PermissionType::VIDEO_CAPTURE,
248 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 251 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
249 permission_contexts_[PermissionType::BACKGROUND_SYNC] = 252 permission_contexts_[PermissionType::BACKGROUND_SYNC] =
250 base::WrapUnique(new BackgroundSyncPermissionContext(profile)); 253 base::WrapUnique(new BackgroundSyncPermissionContext(profile));
254 permission_contexts_[PermissionType::PLUGINS] =
255 base::WrapUnique(new PluginsPermissionContext(profile));
251 } 256 }
252 257
253 PermissionManager::~PermissionManager() { 258 PermissionManager::~PermissionManager() {
254 if (!subscriptions_.IsEmpty()) 259 if (!subscriptions_.IsEmpty())
255 HostContentSettingsMapFactory::GetForProfile(profile_) 260 HostContentSettingsMapFactory::GetForProfile(profile_)
256 ->RemoveObserver(this); 261 ->RemoveObserver(this);
257 } 262 }
258 263
259 int PermissionManager::RequestPermission( 264 int PermissionManager::RequestPermission(
260 PermissionType permission, 265 PermissionType permission,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // Add the callback to |callbacks| which will be run after the loop to 478 // Add the callback to |callbacks| which will be run after the loop to
474 // prevent re-entrance issues. 479 // prevent re-entrance issues.
475 callbacks.push_back( 480 callbacks.push_back(
476 base::Bind(subscription->callback, 481 base::Bind(subscription->callback,
477 ContentSettingToPermissionStatus(new_value))); 482 ContentSettingToPermissionStatus(new_value)));
478 } 483 }
479 484
480 for (const auto& callback : callbacks) 485 for (const auto& callback : callbacks)
481 callback.Run(); 486 callback.Run();
482 } 487 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698