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

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: Created 6 years, 1 month 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 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 int render_process_id, 1810 int render_process_id,
1810 int render_frame_id) { 1811 int render_frame_id) {
1811 chrome::SSLAddCertificate(cert_type, cert_data, cert_size, 1812 chrome::SSLAddCertificate(cert_type, cert_data, cert_size,
1812 render_process_id, render_frame_id); 1813 render_process_id, render_frame_id);
1813 } 1814 }
1814 1815
1815 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { 1816 content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1816 return MediaCaptureDevicesDispatcher::GetInstance(); 1817 return MediaCaptureDevicesDispatcher::GetInstance();
1817 } 1818 }
1818 1819
1819 void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1820 const GURL& source_origin,
1821 content::RenderFrameHost* render_frame_host,
1822 const base::Callback<void(blink::WebNotificationPermission)>& callback) {
1823 #if defined(ENABLE_NOTIFICATIONS)
1824 // Skip showing the infobar if the request comes from an extension, and that
1825 // extension has the 'notify' permission. (If the extension does not have the
1826 // permission, the user will still be prompted.)
1827 Profile* profile = Profile::FromBrowserContext(
1828 render_frame_host->GetSiteInstance()->GetBrowserContext());
1829 DesktopNotificationService* notification_service =
1830 DesktopNotificationServiceFactory::GetForProfile(profile);
1831 WebContents* web_contents = WebContents::FromRenderFrameHost(
1832 render_frame_host);
1833 int render_process_id = render_frame_host->GetProcess()->GetID();
1834 const PermissionRequestID request_id(render_process_id,
1835 web_contents->GetRoutingID(),
1836 -1 /* bridge id */,
1837 GURL());
1838
1839 notification_service->RequestNotificationPermission(
1840 web_contents,
1841 request_id,
1842 source_origin,
1843 // TODO(peter): plumb user_gesture over IPC
1844 true,
1845 callback);
1846
1847 #else
1848 NOTIMPLEMENTED();
1849 #endif
1850 }
1851
1852 blink::WebNotificationPermission 1820 blink::WebNotificationPermission
1853 ChromeContentBrowserClient::CheckDesktopNotificationPermission( 1821 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
1854 const GURL& source_origin, 1822 const GURL& source_origin,
1855 content::ResourceContext* context, 1823 content::ResourceContext* context,
1856 int render_process_id) { 1824 int render_process_id) {
1857 #if defined(ENABLE_NOTIFICATIONS) 1825 #if defined(ENABLE_NOTIFICATIONS)
1858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1826 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1859 1827
1860 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1828 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1861 #if defined(ENABLE_EXTENSIONS) 1829 #if defined(ENABLE_EXTENSIONS)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 service->ShowDesktopNotification( 1878 service->ShowDesktopNotification(
1911 params, render_frame_host, delegate.Pass(), cancel_callback); 1879 params, render_frame_host, delegate.Pass(), cancel_callback);
1912 1880
1913 profile->GetHostContentSettingsMap()->UpdateLastUsage( 1881 profile->GetHostContentSettingsMap()->UpdateLastUsage(
1914 params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 1882 params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
1915 #else 1883 #else
1916 NOTIMPLEMENTED(); 1884 NOTIMPLEMENTED();
1917 #endif 1885 #endif
1918 } 1886 }
1919 1887
1920 void ChromeContentBrowserClient::RequestGeolocationPermission( 1888 void ChromeContentBrowserClient::RequestPermission(
1889 content::PermissionType permission,
1921 content::WebContents* web_contents, 1890 content::WebContents* web_contents,
1922 int bridge_id, 1891 int bridge_id,
1923 const GURL& requesting_frame, 1892 const GURL& requesting_frame,
1924 bool user_gesture, 1893 bool user_gesture,
1925 const base::Callback<void(bool)>& result_callback) { 1894 const base::Callback<void(bool)>& result_callback) {
1926 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1895 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1927 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1896 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1897 Profile* profile =
1898 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1928 1899
1929 const PermissionRequestID request_id(render_process_id, 1900 const PermissionRequestID request_id(render_process_id,
1930 render_view_id, 1901 render_view_id,
1931 bridge_id, 1902 bridge_id,
1932 requesting_frame); 1903 requesting_frame);
1933 GeolocationPermissionContextFactory::GetForProfile( 1904
1934 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> 1905 switch (permission) {
1935 RequestPermission(web_contents, request_id, 1906 case content::PERMISSION_MIDI_SYSEX:
1936 requesting_frame.GetOrigin(), user_gesture, 1907 MidiPermissionContextFactory::GetForProfile(profile)
1937 result_callback); 1908 ->RequestPermission(web_contents,
1909 request_id,
1910 requesting_frame,
1911 user_gesture,
1912 result_callback);
1913 break;
1914 case content::PERMISSION_NOTIFICATIONS:
1915 #if defined(ENABLE_NOTIFICATIONS)
1916 DesktopNotificationServiceFactory::GetForProfile(profile)
1917 ->RequestNotificationPermission(web_contents,
1918 request_id,
1919 requesting_frame,
1920 user_gesture,
1921 result_callback);
1922 #else
1923 NOTIMPLEMENTED();
1924 #endif
1925 break;
1926 case content::PERMISSION_GEOLOCATION:
1927 GeolocationPermissionContextFactory::GetForProfile(profile)
1928 ->RequestPermission(web_contents,
1929 request_id,
1930 requesting_frame.GetOrigin(),
1931 user_gesture,
1932 result_callback);
1933 break;
1934 case content::PERMISSION_PROTECTED_MEDIA:
1935 #if defined(OS_ANDROID)
1936 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
1937 ->RequestProtectedMediaIdentifierPermission(
1938 web_contents, requesting_frame, result_callback);
1939 #else
1940 NOTIMPLEMENTED();
1941 #endif
1942 break;
1943 case content::PERMISSION_PUSH_MESSAGING:
1944 // Push messaging does not require this flow
1945 // so there is no reason to implement it here.
Peter Beverloo 2014/10/24 14:37:28 This comment would be more useful if it would brie
Miguel Garcia 2014/10/24 16:05:32 Done.
1946 NOTIMPLEMENTED() << "RequestPermission not implemented for "
1947 << permission;
Peter Beverloo 2014/10/24 14:37:28 nit: "break;" as the last statement in this case.
Miguel Garcia 2014/10/24 16:05:32 Done.
1948 case content::PERMISSION_NUM:
1949 NOTREACHED() << "Invalid RequestPermission for " << permission;
Peter Beverloo 2014/10/24 14:37:28 nit: "break;" as the last statement in this case.
Miguel Garcia 2014/10/24 16:05:32 Done.
1950 }
1938 } 1951 }
1939 1952
1940 void ChromeContentBrowserClient::CancelGeolocationPermissionRequest( 1953 void ChromeContentBrowserClient::CancelPermissionRequest(
1954 content::PermissionType permission,
1941 content::WebContents* web_contents, 1955 content::WebContents* web_contents,
1942 int bridge_id, 1956 int bridge_id,
1943 const GURL& requesting_frame) { 1957 const GURL& requesting_frame) {
1944 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 1958 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
1945 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 1959 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
1946 1960
1947 const PermissionRequestID request_id(render_process_id, 1961 const PermissionRequestID request_id(render_process_id,
1948 render_view_id, 1962 render_view_id,
1949 bridge_id, 1963 bridge_id,
1950 requesting_frame); 1964 requesting_frame);
1951 GeolocationPermissionContextFactory::GetForProfile( 1965 Profile* profile =
1952 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> 1966 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1953 CancelPermissionRequest(web_contents, request_id); 1967 switch (permission) {
1968 case content::PERMISSION_MIDI_SYSEX:
1969 MidiPermissionContextFactory::GetForProfile(profile)
1970 ->CancelPermissionRequest(web_contents, request_id);
1971 break;
1972 case content::PERMISSION_NOTIFICATIONS:
1973 #if defined(ENABLE_NOTIFICATIONS)
1974 DesktopNotificationServiceFactory::GetForProfile(profile)
1975 ->CancelPermissionRequest(web_contents, request_id);
1976 #else
1977 NOTIMPLEMENTED();
1978 #endif
1979 break;
1980 case content::PERMISSION_GEOLOCATION:
1981 GeolocationPermissionContextFactory::GetForProfile(profile)
1982 ->CancelPermissionRequest(web_contents, request_id);
1983 break;
1984 case content::PERMISSION_PROTECTED_MEDIA:
1985 #if defined(OS_ANDROID)
1986 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
1987 ->CancelProtectedMediaIdentifierPermissionRequests(
1988 render_process_id, render_view_id, requesting_frame);
1989 #else
1990 NOTIMPLEMENTED();
1991 #endif
1992 break;
1993 case content::PERMISSION_PUSH_MESSAGING:
1994 NOTIMPLEMENTED() << "CancelPermission not implemented for " << permission;
1995 break;
1996 case content::PERMISSION_NUM:
1997 NOTREACHED() << "Invalid CancelPermission for " << permission;
1998 break;
1999 }
1954 } 2000 }
1955 2001
1956 void ChromeContentBrowserClient::RequestMidiSysExPermission( 2002 // Helper method to translate from Permissions to ContentSettings
1957 content::WebContents* web_contents, 2003 static ContentSettingsType PermissionToContentSetting(
1958 int bridge_id, 2004 content::PermissionType permission) {
1959 const GURL& requesting_frame, 2005 switch (permission) {
1960 bool user_gesture, 2006 case content::PERMISSION_MIDI_SYSEX:
1961 base::Callback<void(bool)> result_callback, 2007 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
1962 base::Closure* cancel_callback) { 2008 case content::PERMISSION_NOTIFICATIONS:
1963 MidiPermissionContext* context = 2009 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
1964 MidiPermissionContextFactory::GetForProfile( 2010 case content::PERMISSION_GEOLOCATION:
1965 Profile::FromBrowserContext(web_contents->GetBrowserContext())); 2011 return CONTENT_SETTINGS_TYPE_GEOLOCATION;
1966 int renderer_id = web_contents->GetRenderProcessHost()->GetID(); 2012 #if defined(OS_ANDROID)
1967 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 2013 case content::PERMISSION_PROTECTED_MEDIA:
1968 const PermissionRequestID id(renderer_id, render_view_id, bridge_id, GURL()); 2014 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
1969 2015 #endif
1970 context->RequestPermission(web_contents, id, requesting_frame, 2016 default:
1971 user_gesture, result_callback); 2017 NOTREACHED() << "Unknown content setting for permission " << permission;
2018 return CONTENT_SETTINGS_TYPE_DEFAULT;
2019 }
1972 } 2020 }
1973 2021
1974 void ChromeContentBrowserClient::DidUseGeolocationPermission( 2022 void ChromeContentBrowserClient::RegisterPermissionUsage(
2023 content::PermissionType permission,
1975 content::WebContents* web_contents, 2024 content::WebContents* web_contents,
1976 const GURL& frame_url, 2025 const GURL& frame_url,
1977 const GURL& main_frame_url) { 2026 const GURL& main_frame_url) {
1978 Profile::FromBrowserContext(web_contents->GetBrowserContext()) 2027 Profile::FromBrowserContext(web_contents->GetBrowserContext())
1979 ->GetHostContentSettingsMap() 2028 ->GetHostContentSettingsMap()
1980 ->UpdateLastUsage( 2029 ->UpdateLastUsage(
1981 frame_url, main_frame_url, CONTENT_SETTINGS_TYPE_GEOLOCATION); 2030 frame_url, main_frame_url, PermissionToContentSetting(permission));
1982 }
1983
1984 void ChromeContentBrowserClient::RequestProtectedMediaIdentifierPermission(
1985 content::WebContents* web_contents,
1986 const GURL& origin,
1987 base::Callback<void(bool)> result_callback,
1988 base::Closure* cancel_callback) {
1989 #if defined(OS_ANDROID)
1990 ProtectedMediaIdentifierPermissionContext* context =
1991 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
1992 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
1993 context->RequestProtectedMediaIdentifierPermission(web_contents,
1994 origin,
1995 result_callback,
1996 cancel_callback);
1997 #else
1998 NOTIMPLEMENTED();
1999 result_callback.Run(false);
2000 #endif // defined(OS_ANDROID)
2001 } 2031 }
2002 2032
2003 bool ChromeContentBrowserClient::CanCreateWindow( 2033 bool ChromeContentBrowserClient::CanCreateWindow(
2004 const GURL& opener_url, 2034 const GURL& opener_url,
2005 const GURL& opener_top_level_frame_url, 2035 const GURL& opener_top_level_frame_url,
2006 const GURL& source_origin, 2036 const GURL& source_origin,
2007 WindowContainerType container_type, 2037 WindowContainerType container_type,
2008 const GURL& target_url, 2038 const GURL& target_url,
2009 const content::Referrer& referrer, 2039 const content::Referrer& referrer,
2010 WindowOpenDisposition disposition, 2040 WindowOpenDisposition disposition,
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 switches::kDisableWebRtcEncryption, 2640 switches::kDisableWebRtcEncryption,
2611 }; 2641 };
2612 to_command_line->CopySwitchesFrom(from_command_line, 2642 to_command_line->CopySwitchesFrom(from_command_line,
2613 kWebRtcDevSwitchNames, 2643 kWebRtcDevSwitchNames,
2614 arraysize(kWebRtcDevSwitchNames)); 2644 arraysize(kWebRtcDevSwitchNames));
2615 } 2645 }
2616 } 2646 }
2617 #endif // defined(ENABLE_WEBRTC) 2647 #endif // defined(ENABLE_WEBRTC)
2618 2648
2619 } // namespace chrome 2649 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698