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

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

Issue 896173002: Clean-up refactoring of chrome_content_browser_client to use GetPermissionContext consistently. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linker Created 5 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 (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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 624
625 PermissionContextBase* GetPermissionContext(Profile* profile, 625 PermissionContextBase* GetPermissionContext(Profile* profile,
626 content::PermissionType permission) { 626 content::PermissionType permission) {
627 switch (permission) { 627 switch (permission) {
628 case content::PERMISSION_MIDI_SYSEX: 628 case content::PERMISSION_MIDI_SYSEX:
629 return MidiPermissionContextFactory::GetForProfile(profile); 629 return MidiPermissionContextFactory::GetForProfile(profile);
630 case content::PERMISSION_NOTIFICATIONS: 630 case content::PERMISSION_NOTIFICATIONS:
631 #if defined(ENABLE_NOTIFICATIONS) 631 #if defined(ENABLE_NOTIFICATIONS)
632 return DesktopNotificationServiceFactory::GetForProfile(profile); 632 return DesktopNotificationServiceFactory::GetForProfile(profile);
633 #else 633 #else
634 NOTIMPLEMENTED(); 634 NOTIMPLEMENTED();
Peter Beverloo 2015/02/04 14:56:53 While unrelated to this change, there's a missing
timvolodine 2015/02/04 16:15:37 good catch! done.
635 #endif 635 #endif
636 case content::PERMISSION_GEOLOCATION: 636 case content::PERMISSION_GEOLOCATION:
637 return GeolocationPermissionContextFactory::GetForProfile(profile); 637 return GeolocationPermissionContextFactory::GetForProfile(profile);
638 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: 638 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
639 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 639 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
640 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile( 640 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
641 profile); 641 profile);
642 #else 642 #else
643 NOTIMPLEMENTED(); 643 NOTIMPLEMENTED();
644 break; 644 break;
645 #endif 645 #endif
646 case content::PERMISSION_PUSH_MESSAGING: 646 case content::PERMISSION_PUSH_MESSAGING:
647 return gcm::PushMessagingPermissionContextFactory::GetForProfile(profile); 647 return gcm::PushMessagingPermissionContextFactory::GetForProfile(profile);
648 case content::PERMISSION_NUM: 648 case content::PERMISSION_NUM:
649 NOTREACHED() << "Invalid RequestPermission for " << permission; 649 NOTREACHED() << "Invalid RequestPermission for " << permission;
650 break; 650 break;
651 } 651 }
652 return nullptr; 652 return nullptr;
653 } 653 }
654 654
655 // Helper method to translate from Permissions to ContentSettings
656 ContentSettingsType PermissionToContentSetting(
657 content::PermissionType permission) {
658 switch (permission) {
659 case content::PERMISSION_MIDI_SYSEX:
660 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
661 case content::PERMISSION_PUSH_MESSAGING:
662 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
663 case content::PERMISSION_NOTIFICATIONS:
664 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
665 case content::PERMISSION_GEOLOCATION:
666 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
667 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
668 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
669 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
670 #endif
671 default:
672 NOTREACHED() << "Unknown content setting for permission " << permission;
673 return CONTENT_SETTINGS_TYPE_DEFAULT;
674 }
675 }
676
655 } // namespace 677 } // namespace
656 678
657 namespace chrome { 679 namespace chrome {
658 680
659 ChromeContentBrowserClient::ChromeContentBrowserClient() 681 ChromeContentBrowserClient::ChromeContentBrowserClient()
660 : prerender_tracker_(NULL), 682 : prerender_tracker_(NULL),
661 weak_factory_(this) { 683 weak_factory_(this) {
662 #if defined(ENABLE_PLUGINS) 684 #if defined(ENABLE_PLUGINS)
663 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) 685 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i)
664 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); 686 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]);
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 1923
1902 void ChromeContentBrowserClient::RequestPermission( 1924 void ChromeContentBrowserClient::RequestPermission(
1903 content::PermissionType permission, 1925 content::PermissionType permission,
1904 content::WebContents* web_contents, 1926 content::WebContents* web_contents,
1905 int bridge_id, 1927 int bridge_id,
1906 const GURL& requesting_frame, 1928 const GURL& requesting_frame,
1907 bool user_gesture, 1929 bool user_gesture,
1908 const base::Callback<void(bool)>& result_callback) { 1930 const base::Callback<void(bool)>& result_callback) {
1909 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1931 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1910 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1932 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1911 Profile* profile =
1912 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1913
1914 const PermissionRequestID request_id(render_process_id, 1933 const PermissionRequestID request_id(render_process_id,
1915 render_view_id, 1934 render_view_id,
1916 bridge_id, 1935 bridge_id,
1917 requesting_frame); 1936 requesting_frame);
1937 Profile* profile =
1938 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1939 PermissionContextBase* context = GetPermissionContext(profile, permission);
1918 1940
1919 switch (permission) { 1941 if (!context)
1920 case content::PERMISSION_MIDI_SYSEX: 1942 return;
1921 MidiPermissionContextFactory::GetForProfile(profile) 1943
1922 ->RequestPermission(web_contents, 1944 context->RequestPermission(web_contents, request_id, requesting_frame,
1923 request_id, 1945 user_gesture, result_callback);
1924 requesting_frame,
1925 user_gesture,
1926 result_callback);
1927 break;
1928 case content::PERMISSION_NOTIFICATIONS:
1929 #if defined(ENABLE_NOTIFICATIONS)
1930 DesktopNotificationServiceFactory::GetForProfile(profile)
1931 ->RequestNotificationPermission(web_contents,
1932 request_id,
1933 requesting_frame,
1934 user_gesture,
1935 result_callback);
1936 #else
1937 NOTIMPLEMENTED();
1938 #endif
1939 break;
1940 case content::PERMISSION_GEOLOCATION:
1941 GeolocationPermissionContextFactory::GetForProfile(profile)
1942 ->RequestPermission(web_contents,
1943 request_id,
1944 requesting_frame.GetOrigin(),
1945 user_gesture,
1946 result_callback);
1947 break;
1948 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
1949 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1950 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
1951 ->RequestPermission(web_contents,
1952 request_id,
1953 requesting_frame.GetOrigin(),
1954 user_gesture,
1955 result_callback);
1956 #else
1957 NOTIMPLEMENTED();
1958 #endif
1959 break;
1960 case content::PERMISSION_PUSH_MESSAGING:
1961 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile)
1962 ->RequestPermission(web_contents,
1963 request_id,
1964 requesting_frame.GetOrigin(),
1965 user_gesture,
1966 result_callback);
1967 break;
1968 case content::PERMISSION_NUM:
1969 NOTREACHED() << "Invalid RequestPermission for " << permission;
1970 break;
1971 }
1972 } 1946 }
1973 1947
1974 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus( 1948 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus(
1975 content::PermissionType permission, 1949 content::PermissionType permission,
1976 content::BrowserContext* browser_context, 1950 content::BrowserContext* browser_context,
1977 const GURL& requesting_origin, 1951 const GURL& requesting_origin,
1978 const GURL& embedding_origin) { 1952 const GURL& embedding_origin) {
1979 DCHECK(browser_context); 1953 DCHECK(browser_context);
1980 Profile* profile = Profile::FromBrowserContext(browser_context); 1954 Profile* profile = Profile::FromBrowserContext(browser_context);
1981 PermissionContextBase* context = GetPermissionContext(profile, permission); 1955 PermissionContextBase* context = GetPermissionContext(profile, permission);
(...skipping 22 matching lines...) Expand all
2004 embedding_origin.GetOrigin()); 1978 embedding_origin.GetOrigin());
2005 } 1979 }
2006 1980
2007 void ChromeContentBrowserClient::CancelPermissionRequest( 1981 void ChromeContentBrowserClient::CancelPermissionRequest(
2008 content::PermissionType permission, 1982 content::PermissionType permission,
2009 content::WebContents* web_contents, 1983 content::WebContents* web_contents,
2010 int bridge_id, 1984 int bridge_id,
2011 const GURL& requesting_frame) { 1985 const GURL& requesting_frame) {
2012 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1986 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
2013 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1987 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
2014
2015 const PermissionRequestID request_id(render_process_id, 1988 const PermissionRequestID request_id(render_process_id,
2016 render_view_id, 1989 render_view_id,
2017 bridge_id, 1990 bridge_id,
2018 requesting_frame); 1991 requesting_frame);
2019 Profile* profile = 1992 Profile* profile =
2020 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1993 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2021 switch (permission) { 1994 PermissionContextBase* context = GetPermissionContext(profile, permission);
2022 case content::PERMISSION_MIDI_SYSEX: 1995 if (!context)
2023 MidiPermissionContextFactory::GetForProfile(profile) 1996 return;
2024 ->CancelPermissionRequest(web_contents, request_id); 1997 context->CancelPermissionRequest(web_contents, request_id);
2025 break;
2026 case content::PERMISSION_NOTIFICATIONS:
2027 #if defined(ENABLE_NOTIFICATIONS)
2028 DesktopNotificationServiceFactory::GetForProfile(profile)
2029 ->CancelPermissionRequest(web_contents, request_id);
2030 #else
2031 NOTIMPLEMENTED();
2032 #endif
2033 break;
2034 case content::PERMISSION_GEOLOCATION:
2035 GeolocationPermissionContextFactory::GetForProfile(profile)
2036 ->CancelPermissionRequest(web_contents, request_id);
2037 break;
2038 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
2039 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
2040 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
2041 ->CancelPermissionRequest(web_contents, request_id);
2042 #else
2043 NOTIMPLEMENTED();
2044 #endif
2045 break;
2046 case content::PERMISSION_PUSH_MESSAGING:
2047 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission;
2048 break;
2049 case content::PERMISSION_NUM:
2050 NOTREACHED() << "Invalid CancelPermission for " << permission;
2051 break;
2052 }
2053 }
2054
2055 // Helper method to translate from Permissions to ContentSettings
2056 static ContentSettingsType PermissionToContentSetting(
2057 content::PermissionType permission) {
2058 switch (permission) {
2059 case content::PERMISSION_MIDI_SYSEX:
2060 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
2061 case content::PERMISSION_PUSH_MESSAGING:
2062 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
2063 case content::PERMISSION_NOTIFICATIONS:
2064 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
2065 case content::PERMISSION_GEOLOCATION:
2066 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
2067 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
2068 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
2069 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
2070 #endif
2071 default:
2072 NOTREACHED() << "Unknown content setting for permission " << permission;
2073 return CONTENT_SETTINGS_TYPE_DEFAULT;
2074 }
2075 } 1998 }
2076 1999
2077 void ChromeContentBrowserClient::RegisterPermissionUsage( 2000 void ChromeContentBrowserClient::RegisterPermissionUsage(
2078 content::PermissionType permission, 2001 content::PermissionType permission,
2079 content::WebContents* web_contents, 2002 content::WebContents* web_contents,
2080 const GURL& frame_url, 2003 const GURL& frame_url,
2081 const GURL& main_frame_url) { 2004 const GURL& main_frame_url) {
2082 Profile::FromBrowserContext(web_contents->GetBrowserContext()) 2005 Profile::FromBrowserContext(web_contents->GetBrowserContext())
2083 ->GetHostContentSettingsMap() 2006 ->GetHostContentSettingsMap()
2084 ->UpdateLastUsage( 2007 ->UpdateLastUsage(
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 switches::kDisableWebRtcEncryption, 2587 switches::kDisableWebRtcEncryption,
2665 }; 2588 };
2666 to_command_line->CopySwitchesFrom(from_command_line, 2589 to_command_line->CopySwitchesFrom(from_command_line,
2667 kWebRtcDevSwitchNames, 2590 kWebRtcDevSwitchNames,
2668 arraysize(kWebRtcDevSwitchNames)); 2591 arraysize(kWebRtcDevSwitchNames));
2669 } 2592 }
2670 } 2593 }
2671 #endif // defined(ENABLE_WEBRTC) 2594 #endif // defined(ENABLE_WEBRTC)
2672 2595
2673 } // namespace chrome 2596 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698