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

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

Issue 622793002: Group the different permission related methods in the content api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #include "components/signin/core/common/profile_management_switches.h" 101 #include "components/signin/core/common/profile_management_switches.h"
102 #include "components/translate/core/common/translate_switches.h" 102 #include "components/translate/core/common/translate_switches.h"
103 #include "content/public/browser/browser_child_process_host.h" 103 #include "content/public/browser/browser_child_process_host.h"
104 #include "content/public/browser/browser_main_parts.h" 104 #include "content/public/browser/browser_main_parts.h"
105 #include "content/public/browser/browser_ppapi_host.h" 105 #include "content/public/browser/browser_ppapi_host.h"
106 #include "content/public/browser/browser_thread.h" 106 #include "content/public/browser/browser_thread.h"
107 #include "content/public/browser/browser_url_handler.h" 107 #include "content/public/browser/browser_url_handler.h"
108 #include "content/public/browser/child_process_data.h" 108 #include "content/public/browser/child_process_data.h"
109 #include "content/public/browser/child_process_security_policy.h" 109 #include "content/public/browser/child_process_security_policy.h"
110 #include "content/public/browser/desktop_notification_delegate.h" 110 #include "content/public/browser/desktop_notification_delegate.h"
111 #include "content/public/browser/permission_type.h"
111 #include "content/public/browser/render_frame_host.h" 112 #include "content/public/browser/render_frame_host.h"
112 #include "content/public/browser/render_process_host.h" 113 #include "content/public/browser/render_process_host.h"
113 #include "content/public/browser/render_view_host.h" 114 #include "content/public/browser/render_view_host.h"
114 #include "content/public/browser/resource_context.h" 115 #include "content/public/browser/resource_context.h"
115 #include "content/public/browser/site_instance.h" 116 #include "content/public/browser/site_instance.h"
116 #include "content/public/browser/web_contents.h" 117 #include "content/public/browser/web_contents.h"
117 #include "content/public/common/child_process_host.h" 118 #include "content/public/common/child_process_host.h"
118 #include "content/public/common/content_descriptors.h" 119 #include "content/public/common/content_descriptors.h"
119 #include "content/public/common/show_desktop_notification_params.h" 120 #include "content/public/common/show_desktop_notification_params.h"
120 #include "content/public/common/url_utils.h" 121 #include "content/public/common/url_utils.h"
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 int render_process_id, 1811 int render_process_id,
1811 int render_frame_id) { 1812 int render_frame_id) {
1812 chrome::SSLAddCertificate(cert_type, cert_data, cert_size, 1813 chrome::SSLAddCertificate(cert_type, cert_data, cert_size,
1813 render_process_id, render_frame_id); 1814 render_process_id, render_frame_id);
1814 } 1815 }
1815 1816
1816 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { 1817 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1817 return MediaCaptureDevicesDispatcher::GetInstance(); 1818 return MediaCaptureDevicesDispatcher::GetInstance();
1818 } 1819 }
1819 1820
1820 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1821 const GURL& source_origin,
1822 content::RenderFrameHost* render_frame_host,
1823 const base::Callback<void(blink::WebNotificationPermission)>& callback) {
1824 #if defined(ENABLE_NOTIFICATIONS)
1825 // Skip showing the infobar if the request comes from an extension, and that
1826 // extension has the 'notify' permission. (If the extension does not have the
1827 // permission, the user will still be prompted.)
1828 Profile* profile = Profile::FromBrowserContext(
1829 render_frame_host->GetSiteInstance()->GetBrowserContext());
1830 DesktopNotificationService* notification_service =
1831 DesktopNotificationServiceFactory::GetForProfile(profile);
1832 WebContents* web_contents = WebContents::FromRenderFrameHost(
1833 render_frame_host);
1834 int render_process_id = render_frame_host->GetProcess()->GetID();
1835 const PermissionRequestID request_id(render_process_id,
1836 web_contents->GetRoutingID(),
1837 -1 /* bridge id */,
1838 GURL());
1839
1840 notification_service->RequestNotificationPermission(
1841 web_contents,
1842 request_id,
1843 source_origin,
1844 // TODO(peter): plumb user_gesture over IPC
1845 true,
1846 callback);
1847
1848 #else
1849 NOTIMPLEMENTED();
1850 #endif
1851 }
1852
1853 blink::WebNotificationPermission 1821 blink::WebNotificationPermission
1854 ChromeContentBrowserClient::CheckDesktopNotificationPermission( 1822 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1855 const GURL& source_origin, 1823 const GURL& source_origin,
1856 content::ResourceContext* context, 1824 content::ResourceContext* context,
1857 int render_process_id) { 1825 int render_process_id) {
1858 #if defined(ENABLE_NOTIFICATIONS) 1826 #if defined(ENABLE_NOTIFICATIONS)
1859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1860 1828
1861 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1829 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1862 #if defined(ENABLE_EXTENSIONS) 1830 #if defined(ENABLE_EXTENSIONS)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 service->ShowDesktopNotification( 1879 service->ShowDesktopNotification(
1912 params, render_frame_host, delegate.Pass(), cancel_callback); 1880 params, render_frame_host, delegate.Pass(), cancel_callback);
1913 1881
1914 profile->GetHostContentSettingsMap()->UpdateLastUsage( 1882 profile->GetHostContentSettingsMap()->UpdateLastUsage(
1915 params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 1883 params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
1916 #else 1884 #else
1917 NOTIMPLEMENTED(); 1885 NOTIMPLEMENTED();
1918 #endif 1886 #endif
1919 } 1887 }
1920 1888
1921 void ChromeContentBrowserClient::RequestGeolocationPermission( 1889 void ChromeContentBrowserClient::RequestPermission(
1890 content::PermissionType permission,
1922 content::WebContents* web_contents, 1891 content::WebContents* web_contents,
1923 int bridge_id, 1892 int bridge_id,
1924 const GURL& requesting_frame, 1893 const GURL& requesting_frame,
1925 bool user_gesture, 1894 bool user_gesture,
1926 const base::Callback<void(bool)>& result_callback) { 1895 const base::Callback<void(bool)>& result_callback) {
1927 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1896 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1928 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1897 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1898 Profile* profile =
1899 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1929 1900
1930 const PermissionRequestID request_id(render_process_id, 1901 const PermissionRequestID request_id(render_process_id,
1931 render_view_id, 1902 render_view_id,
1932 bridge_id, 1903 bridge_id,
1933 requesting_frame); 1904 requesting_frame);
1934 GeolocationPermissionContextFactory::GetForProfile( 1905
1935 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> 1906 switch (permission) {
1936 RequestPermission(web_contents, request_id, 1907 case content::PERMISSION_MIDI_SYSEX:
1937 requesting_frame.GetOrigin(), user_gesture, 1908 MidiPermissionContextFactory::GetForProfile(profile)
1938 result_callback); 1909 ->RequestPermission(web_contents,
1910 request_id,
1911 requesting_frame,
1912 user_gesture,
1913 result_callback);
1914 break;
1915 case content::PERMISSION_NOTIFICATIONS:
1916 #if defined(ENABLE_NOTIFICATIONS)
1917 DesktopNotificationServiceFactory::GetForProfile(profile)
1918 ->RequestNotificationPermission(web_contents,
1919 request_id,
1920 requesting_frame,
1921 user_gesture,
1922 result_callback);
1923 #else
1924 NOTIMPLEMENTED();
1925 #endif
1926 break;
1927 case content::PERMISSION_GEOLOCATION:
1928 GeolocationPermissionContextFactory::GetForProfile(profile)
1929 ->RequestPermission(web_contents,
1930 request_id,
1931 requesting_frame.GetOrigin(),
1932 user_gesture,
1933 result_callback);
1934 break;
1935 case content::PERMISSION_PROTECTED_MEDIA:
1936 #if defined(OS_ANDROID)
1937 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
1938 ->RequestProtectedMediaIdentifierPermission(
1939 web_contents, requesting_frame, result_callback);
1940 #else
1941 NOTIMPLEMENTED();
1942 #endif
1943 break;
1944 case content::PERMISSION_PUSH_MESSAGING:
1945 // Push messaging does not require this flow as it goes directly through
1946 // the push service implementation so there is no reason to
1947 // implement it here.
1948 NOTIMPLEMENTED() << "RequestPermission not implemented for "
1949 << permission;
1950 break;
1951 case content::PERMISSION_NUM:
1952 NOTREACHED() << "Invalid RequestPermission for " << permission;
1953 break;
1954 }
1939 } 1955 }
1940 1956
1941 void ChromeContentBrowserClient::CancelGeolocationPermissionRequest( 1957 void ChromeContentBrowserClient::CancelPermissionRequest(
1958 content::PermissionType permission,
1942 content::WebContents* web_contents, 1959 content::WebContents* web_contents,
1943 int bridge_id, 1960 int bridge_id,
1944 const GURL& requesting_frame) { 1961 const GURL& requesting_frame) {
1945 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1962 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1946 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1963 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1947 1964
1948 const PermissionRequestID request_id(render_process_id, 1965 const PermissionRequestID request_id(render_process_id,
1949 render_view_id, 1966 render_view_id,
1950 bridge_id, 1967 bridge_id,
1951 requesting_frame); 1968 requesting_frame);
1952 GeolocationPermissionContextFactory::GetForProfile( 1969 Profile* profile =
1953 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> 1970 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1954 CancelPermissionRequest(web_contents, request_id); 1971 switch (permission) {
1972 case content::PERMISSION_MIDI_SYSEX:
1973 MidiPermissionContextFactory::GetForProfile(profile)
1974 ->CancelPermissionRequest(web_contents, request_id);
1975 break;
1976 case content::PERMISSION_NOTIFICATIONS:
1977 #if defined(ENABLE_NOTIFICATIONS)
1978 DesktopNotificationServiceFactory::GetForProfile(profile)
1979 ->CancelPermissionRequest(web_contents, request_id);
1980 #else
1981 NOTIMPLEMENTED();
1982 #endif
1983 break;
1984 case content::PERMISSION_GEOLOCATION:
1985 GeolocationPermissionContextFactory::GetForProfile(profile)
1986 ->CancelPermissionRequest(web_contents, request_id);
1987 break;
1988 case content::PERMISSION_PROTECTED_MEDIA:
1989 #if defined(OS_ANDROID)
1990 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
1991 ->CancelProtectedMediaIdentifierPermissionRequests(
1992 render_process_id, render_view_id, requesting_frame);
1993 #else
1994 NOTIMPLEMENTED();
1995 #endif
1996 break;
1997 case content::PERMISSION_PUSH_MESSAGING:
1998 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission;
1999 break;
2000 case content::PERMISSION_NUM:
2001 NOTREACHED() << "Invalid CancelPermission for " << permission;
2002 break;
2003 }
1955 } 2004 }
1956 2005
1957 void ChromeContentBrowserClient::RequestMidiSysExPermission( 2006 // Helper method to translate from Permissions to ContentSettings
1958 content::WebContents* web_contents, 2007 static ContentSettingsType PermissionToContentSetting(
1959 int bridge_id, 2008 content::PermissionType permission) {
1960 const GURL& requesting_frame, 2009 switch (permission) {
1961 bool user_gesture, 2010 case content::PERMISSION_MIDI_SYSEX:
1962 base::Callback<void(bool)> result_callback, 2011 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
1963 base::Closure* cancel_callback) { 2012 case content::PERMISSION_NOTIFICATIONS:
1964 MidiPermissionContext* context = 2013 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
1965 MidiPermissionContextFactory::GetForProfile( 2014 case content::PERMISSION_GEOLOCATION:
1966 Profile::FromBrowserContext(web_contents->GetBrowserContext())); 2015 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
1967 int renderer_id = web_contents->GetRenderProcessHost()->GetID(); 2016 #if defined(OS_ANDROID)
1968 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 2017 case content::PERMISSION_PROTECTED_MEDIA:
1969 const PermissionRequestID id(renderer_id, render_view_id, bridge_id, GURL()); 2018 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
1970 2019 #endif
1971 context->RequestPermission(web_contents, id, requesting_frame, 2020 default:
1972 user_gesture, result_callback); 2021 NOTREACHED() << "Unknown content setting for permission " << permission;
2022 return CONTENT_SETTINGS_TYPE_DEFAULT;
2023 }
1973 } 2024 }
1974 2025
1975 void ChromeContentBrowserClient::DidUseGeolocationPermission( 2026 void ChromeContentBrowserClient::RegisterPermissionUsage(
2027 content::PermissionType permission,
1976 content::WebContents* web_contents, 2028 content::WebContents* web_contents,
1977 const GURL& frame_url, 2029 const GURL& frame_url,
1978 const GURL& main_frame_url) { 2030 const GURL& main_frame_url) {
1979 Profile::FromBrowserContext(web_contents->GetBrowserContext()) 2031 Profile::FromBrowserContext(web_contents->GetBrowserContext())
1980 ->GetHostContentSettingsMap() 2032 ->GetHostContentSettingsMap()
1981 ->UpdateLastUsage( 2033 ->UpdateLastUsage(
1982 frame_url, main_frame_url, CONTENT_SETTINGS_TYPE_GEOLOCATION); 2034 frame_url, main_frame_url, PermissionToContentSetting(permission));
1983 }
1984
1985 void ChromeContentBrowserClient::RequestProtectedMediaIdentifierPermission(
1986 content::WebContents* web_contents,
1987 const GURL& origin,
1988 base::Callback<void(bool)> result_callback,
1989 base::Closure* cancel_callback) {
1990 #if defined(OS_ANDROID)
1991 ProtectedMediaIdentifierPermissionContext* context =
1992 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
1993 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
1994 context->RequestProtectedMediaIdentifierPermission(web_contents,
1995 origin,
1996 result_callback,
1997 cancel_callback);
1998 #else
1999 NOTIMPLEMENTED();
2000 result_callback.Run(false);
2001 #endif // defined(OS_ANDROID)
2002 } 2035 }
2003 2036
2004 bool ChromeContentBrowserClient::CanCreateWindow( 2037 bool ChromeContentBrowserClient::CanCreateWindow(
2005 const GURL& opener_url, 2038 const GURL& opener_url,
2006 const GURL& opener_top_level_frame_url, 2039 const GURL& opener_top_level_frame_url,
2007 const GURL& source_origin, 2040 const GURL& source_origin,
2008 WindowContainerType container_type, 2041 WindowContainerType container_type,
2009 const GURL& target_url, 2042 const GURL& target_url,
2010 const content::Referrer& referrer, 2043 const content::Referrer& referrer,
2011 WindowOpenDisposition disposition, 2044 WindowOpenDisposition disposition,
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 switches::kDisableWebRtcEncryption, 2644 switches::kDisableWebRtcEncryption,
2612 }; 2645 };
2613 to_command_line->CopySwitchesFrom(from_command_line, 2646 to_command_line->CopySwitchesFrom(from_command_line,
2614 kWebRtcDevSwitchNames, 2647 kWebRtcDevSwitchNames,
2615 arraysize(kWebRtcDevSwitchNames)); 2648 arraysize(kWebRtcDevSwitchNames));
2616 } 2649 }
2617 } 2650 }
2618 #endif // defined(ENABLE_WEBRTC) 2651 #endif // defined(ENABLE_WEBRTC)
2619 2652
2620 } // namespace chrome 2653 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698