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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 990303002: Implement PermissionService::GetNextPermissionChange. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_impl
Patch Set: review comments Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/browser_about_handler.h" 22 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h" 24 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h" 25 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h" 26 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h" 27 #include "chrome/browser/character_encoding.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h" 28 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h" 29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h" 30 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h" 31 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/permission_context.h"
33 #include "chrome/browser/content_settings/permission_observer.h"
34 #include "chrome/browser/content_settings/permission_observer_factory.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 35 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h" 36 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h" 37 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h" 38 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h" 39 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context.h" 40 #include "chrome/browser/geolocation/geolocation_permission_context.h"
38 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
39 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 41 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
40 #include "chrome/browser/media/midi_permission_context.h" 42 #include "chrome/browser/media/midi_permission_context.h"
41 #include "chrome/browser/media/midi_permission_context_factory.h"
42 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 43 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
43 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" 44 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
44 #include "chrome/browser/net/chrome_net_log.h" 45 #include "chrome/browser/net/chrome_net_log.h"
45 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 46 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
46 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 47 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
47 #include "chrome/browser/notifications/desktop_notification_service.h" 48 #include "chrome/browser/notifications/desktop_notification_service.h"
48 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
49 #include "chrome/browser/notifications/platform_notification_service_impl.h" 49 #include "chrome/browser/notifications/platform_notification_service_impl.h"
50 #include "chrome/browser/platform_util.h" 50 #include "chrome/browser/platform_util.h"
51 #include "chrome/browser/prerender/prerender_final_status.h" 51 #include "chrome/browser/prerender/prerender_final_status.h"
52 #include "chrome/browser/prerender/prerender_manager.h" 52 #include "chrome/browser/prerender/prerender_manager.h"
53 #include "chrome/browser/prerender/prerender_manager_factory.h" 53 #include "chrome/browser/prerender/prerender_manager_factory.h"
54 #include "chrome/browser/prerender/prerender_message_filter.h" 54 #include "chrome/browser/prerender/prerender_message_filter.h"
55 #include "chrome/browser/printing/printing_message_filter.h" 55 #include "chrome/browser/printing/printing_message_filter.h"
56 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 56 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
57 #include "chrome/browser/profiles/profile.h" 57 #include "chrome/browser/profiles/profile.h"
58 #include "chrome/browser/profiles/profile_io_data.h" 58 #include "chrome/browser/profiles/profile_io_data.h"
59 #include "chrome/browser/push_messaging/push_messaging_permission_context.h" 59 #include "chrome/browser/push_messaging/push_messaging_permission_context.h"
60 #include "chrome/browser/push_messaging/push_messaging_permission_context_factor y.h"
61 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 60 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
62 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" 61 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h"
63 #include "chrome/browser/search/instant_service.h" 62 #include "chrome/browser/search/instant_service.h"
64 #include "chrome/browser/search/instant_service_factory.h" 63 #include "chrome/browser/search/instant_service_factory.h"
65 #include "chrome/browser/search/search.h" 64 #include "chrome/browser/search/search.h"
66 #include "chrome/browser/search_engines/search_provider_install_state_message_fi lter.h" 65 #include "chrome/browser/search_engines/search_provider_install_state_message_fi lter.h"
67 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" 66 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
68 #include "chrome/browser/speech/tts_controller.h" 67 #include "chrome/browser/speech/tts_controller.h"
69 #include "chrome/browser/speech/tts_message_filter.h" 68 #include "chrome/browser/speech/tts_message_filter.h"
70 #include "chrome/browser/ssl/ssl_add_certificate.h" 69 #include "chrome/browser/ssl/ssl_add_certificate.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" 163 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
165 #include "chrome/browser/chrome_browser_main_android.h" 164 #include "chrome/browser/chrome_browser_main_android.h"
166 #include "chrome/common/descriptors_android.h" 165 #include "chrome/common/descriptors_android.h"
167 #include "components/crash/browser/crash_dump_manager_android.h" 166 #include "components/crash/browser/crash_dump_manager_android.h"
168 #elif defined(OS_POSIX) 167 #elif defined(OS_POSIX)
169 #include "chrome/browser/chrome_browser_main_posix.h" 168 #include "chrome/browser/chrome_browser_main_posix.h"
170 #endif 169 #endif
171 170
172 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 171 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
173 #include "chrome/browser/media/protected_media_identifier_permission_context.h" 172 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
174 #include "chrome/browser/media/protected_media_identifier_permission_context_fac tory.h"
175 #endif 173 #endif
176 174
177 #if defined(OS_POSIX) && !defined(OS_MACOSX) 175 #if defined(OS_POSIX) && !defined(OS_MACOSX)
178 #include "base/debug/leak_annotations.h" 176 #include "base/debug/leak_annotations.h"
179 #include "components/crash/app/breakpad_linux.h" 177 #include "components/crash/app/breakpad_linux.h"
180 #include "components/crash/browser/crash_handler_host_linux.h" 178 #include "components/crash/browser/crash_handler_host_linux.h"
181 #endif 179 #endif
182 180
183 #if defined(OS_ANDROID) 181 #if defined(OS_ANDROID)
184 #include "ui/base/ui_base_paths.h" 182 #include "ui/base/ui_base_paths.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 return content::PERMISSION_STATUS_ASK; 619 return content::PERMISSION_STATUS_ASK;
622 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: 620 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT:
623 case CONTENT_SETTING_DEFAULT: 621 case CONTENT_SETTING_DEFAULT:
624 case CONTENT_SETTING_NUM_SETTINGS: 622 case CONTENT_SETTING_NUM_SETTINGS:
625 break; 623 break;
626 } 624 }
627 NOTREACHED(); 625 NOTREACHED();
628 return content::PERMISSION_STATUS_DENIED; 626 return content::PERMISSION_STATUS_DENIED;
629 } 627 }
630 628
631 PermissionContextBase* GetPermissionContext(Profile* profile,
632 content::PermissionType permission) {
633 switch (permission) {
634 case content::PERMISSION_MIDI_SYSEX:
635 return MidiPermissionContextFactory::GetForProfile(profile);
636 case content::PERMISSION_NOTIFICATIONS:
637 #if defined(ENABLE_NOTIFICATIONS)
638 return DesktopNotificationServiceFactory::GetForProfile(profile);
639 #else
640 NOTIMPLEMENTED();
641 break;
642 #endif
643 case content::PERMISSION_GEOLOCATION:
644 return GeolocationPermissionContextFactory::GetForProfile(profile);
645 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
646 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
647 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
648 profile);
649 #else
650 NOTIMPLEMENTED();
651 break;
652 #endif
653 case content::PERMISSION_PUSH_MESSAGING:
654 return PushMessagingPermissionContextFactory::GetForProfile(profile);
655 case content::PERMISSION_NUM:
656 NOTREACHED() << "Invalid RequestPermission for " << permission;
657 break;
658 }
659 return nullptr;
660 }
661
662 // Helper method to translate from Permissions to ContentSettings 629 // Helper method to translate from Permissions to ContentSettings
663 ContentSettingsType PermissionToContentSetting( 630 ContentSettingsType PermissionToContentSetting(
664 content::PermissionType permission) { 631 content::PermissionType permission) {
665 switch (permission) { 632 switch (permission) {
666 case content::PERMISSION_MIDI_SYSEX: 633 case content::PERMISSION_MIDI_SYSEX:
667 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX; 634 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
668 case content::PERMISSION_PUSH_MESSAGING: 635 case content::PERMISSION_PUSH_MESSAGING:
669 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; 636 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
670 case content::PERMISSION_NOTIFICATIONS: 637 case content::PERMISSION_NOTIFICATIONS:
671 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; 638 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
672 case content::PERMISSION_GEOLOCATION: 639 case content::PERMISSION_GEOLOCATION:
673 return CONTENT_SETTINGS_TYPE_GEOLOCATION; 640 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
674 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 641 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
675 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: 642 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
676 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER; 643 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
677 #endif 644 #endif
678 default: 645 default:
679 NOTREACHED() << "Unknown content setting for permission " << permission; 646 NOTREACHED() << "Unknown content setting for permission " << permission;
680 return CONTENT_SETTINGS_TYPE_DEFAULT; 647 return CONTENT_SETTINGS_TYPE_DEFAULT;
681 } 648 }
682 } 649 }
683 650
684 void OnRequestPermission( 651 void PermissionStatusCallbackWrapper(
685 const base::Callback<void(content::PermissionStatus)>& callback, 652 const base::Callback<void(content::PermissionStatus)>& callback,
686 ContentSetting content_setting) { 653 ContentSetting content_setting) {
687 callback.Run(ContentSettingToPermissionStatus(content_setting)); 654 callback.Run(ContentSettingToPermissionStatus(content_setting));
688 } 655 }
689 656
690 } // namespace 657 } // namespace
691 658
692 namespace chrome { 659 namespace chrome {
693 660
694 ChromeContentBrowserClient::ChromeContentBrowserClient() 661 ChromeContentBrowserClient::ChromeContentBrowserClient()
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 bool user_gesture, 1906 bool user_gesture,
1940 const base::Callback<void(content::PermissionStatus)>& result_callback) { 1907 const base::Callback<void(content::PermissionStatus)>& result_callback) {
1941 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1908 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1942 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1909 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1943 const PermissionRequestID request_id(render_process_id, 1910 const PermissionRequestID request_id(render_process_id,
1944 render_view_id, 1911 render_view_id,
1945 bridge_id, 1912 bridge_id,
1946 requesting_frame); 1913 requesting_frame);
1947 Profile* profile = 1914 Profile* profile =
1948 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1915 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1949 PermissionContextBase* context = GetPermissionContext(profile, permission); 1916 PermissionContextBase* context =
1917 PermissionContext::Get(profile, PermissionToContentSetting(permission));
1950 1918
1951 if (!context) 1919 if (!context)
1952 return; 1920 return;
1953 1921
1954 context->RequestPermission(web_contents, request_id, requesting_frame, 1922 context->RequestPermission(web_contents, request_id, requesting_frame,
1955 user_gesture, 1923 user_gesture,
1956 base::Bind(&OnRequestPermission, result_callback)); 1924 base::Bind(&PermissionStatusCallbackWrapper,
1925 result_callback));
1957 } 1926 }
1958 1927
1959 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus( 1928 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus(
1960 content::PermissionType permission, 1929 content::PermissionType permission,
1961 content::BrowserContext* browser_context, 1930 content::BrowserContext* browser_context,
1962 const GURL& requesting_origin, 1931 const GURL& requesting_origin,
1963 const GURL& embedding_origin) { 1932 const GURL& embedding_origin) {
1964 DCHECK(browser_context); 1933 DCHECK(browser_context);
1965 Profile* profile = Profile::FromBrowserContext(browser_context); 1934 Profile* profile = Profile::FromBrowserContext(browser_context);
1966 PermissionContextBase* context = GetPermissionContext(profile, permission); 1935 PermissionContextBase* context =
1936 PermissionContext::Get(profile, PermissionToContentSetting(permission));
1967 1937
1968 if (!context) 1938 if (!context)
1969 return content::PERMISSION_STATUS_ASK; 1939 return content::PERMISSION_STATUS_ASK;
1970 1940
1971 return ContentSettingToPermissionStatus( 1941 return ContentSettingToPermissionStatus(
1972 context->GetPermissionStatus(requesting_origin.GetOrigin(), 1942 context->GetPermissionStatus(requesting_origin.GetOrigin(),
1973 embedding_origin.GetOrigin())); 1943 embedding_origin.GetOrigin()));
1974 } 1944 }
1975 1945
1946 int ChromeContentBrowserClient::SubscribePermissionStatusChange(
1947 content::PermissionType permission,
1948 content::BrowserContext* browser_context,
1949 const GURL& requesting_origin,
1950 const GURL& embedding_origin,
1951 const base::Callback<void(content::PermissionStatus)>& callback) {
1952 return PermissionObserverFactory::GetForProfile(
1953 Profile::FromBrowserContext(browser_context))
1954 ->Subscribe(PermissionToContentSetting(permission),
1955 requesting_origin,
1956 embedding_origin,
1957 base::Bind(&PermissionStatusCallbackWrapper,
1958 callback));
1959 }
1960
1961 void ChromeContentBrowserClient::UnsubscribePermissionStatusChange(
1962 content::BrowserContext* browser_context,
1963 int subscription_id) {
1964 PermissionObserverFactory::GetForProfile(
1965 Profile::FromBrowserContext(browser_context))
1966 ->Unsubscribe(subscription_id);
1967 }
1968
1976 void ChromeContentBrowserClient::ResetPermission( 1969 void ChromeContentBrowserClient::ResetPermission(
1977 content::PermissionType permission, 1970 content::PermissionType permission,
1978 content::BrowserContext* browser_context, 1971 content::BrowserContext* browser_context,
1979 const GURL& requesting_origin, 1972 const GURL& requesting_origin,
1980 const GURL& embedding_origin) { 1973 const GURL& embedding_origin) {
1981 DCHECK(browser_context); 1974 DCHECK(browser_context);
1982 Profile* profile = Profile::FromBrowserContext(browser_context); 1975 Profile* profile = Profile::FromBrowserContext(browser_context);
1983 PermissionContextBase* context = GetPermissionContext(profile, permission); 1976 PermissionContextBase* context =
1977 PermissionContext::Get(profile, PermissionToContentSetting(permission));
1984 1978
1985 if (!context) 1979 if (!context)
1986 return; 1980 return;
1987 1981
1988 context->ResetPermission(requesting_origin.GetOrigin(), 1982 context->ResetPermission(requesting_origin.GetOrigin(),
1989 embedding_origin.GetOrigin()); 1983 embedding_origin.GetOrigin());
1990 } 1984 }
1991 1985
1992 void ChromeContentBrowserClient::CancelPermissionRequest( 1986 void ChromeContentBrowserClient::CancelPermissionRequest(
1993 content::PermissionType permission, 1987 content::PermissionType permission,
1994 content::WebContents* web_contents, 1988 content::WebContents* web_contents,
1995 int bridge_id, 1989 int bridge_id,
1996 const GURL& requesting_frame) { 1990 const GURL& requesting_frame) {
1997 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1991 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1998 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1992 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1999 const PermissionRequestID request_id(render_process_id, 1993 const PermissionRequestID request_id(render_process_id,
2000 render_view_id, 1994 render_view_id,
2001 bridge_id, 1995 bridge_id,
2002 requesting_frame); 1996 requesting_frame);
2003 Profile* profile = 1997 Profile* profile =
2004 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1998 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2005 PermissionContextBase* context = GetPermissionContext(profile, permission); 1999 PermissionContextBase* context =
2000 PermissionContext::Get(profile, PermissionToContentSetting(permission));
2006 if (!context) 2001 if (!context)
2007 return; 2002 return;
2008 context->CancelPermissionRequest(web_contents, request_id); 2003 context->CancelPermissionRequest(web_contents, request_id);
2009 } 2004 }
2010 2005
2011 void ChromeContentBrowserClient::RegisterPermissionUsage( 2006 void ChromeContentBrowserClient::RegisterPermissionUsage(
2012 content::PermissionType permission, 2007 content::PermissionType permission,
2013 content::WebContents* web_contents, 2008 content::WebContents* web_contents,
2014 const GURL& frame_url, 2009 const GURL& frame_url,
2015 const GURL& main_frame_url) { 2010 const GURL& main_frame_url) {
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 switches::kDisableWebRtcEncryption, 2635 switches::kDisableWebRtcEncryption,
2641 }; 2636 };
2642 to_command_line->CopySwitchesFrom(from_command_line, 2637 to_command_line->CopySwitchesFrom(from_command_line,
2643 kWebRtcDevSwitchNames, 2638 kWebRtcDevSwitchNames,
2644 arraysize(kWebRtcDevSwitchNames)); 2639 arraysize(kWebRtcDevSwitchNames));
2645 } 2640 }
2646 } 2641 }
2647 #endif // defined(ENABLE_WEBRTC) 2642 #endif // defined(ENABLE_WEBRTC)
2648 2643
2649 } // namespace chrome 2644 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698