OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 #if defined(ENABLE_NOTIFICATIONS) |
| 1915 case content::PERMISSION_NOTIFICATIONS: |
| 1916 DesktopNotificationServiceFactory::GetForProfile(profile) |
| 1917 ->RequestNotificationPermission(web_contents, |
| 1918 request_id, |
| 1919 requesting_frame, |
| 1920 user_gesture, |
| 1921 result_callback); |
| 1922 break; |
| 1923 #else |
| 1924 NOTIMPLEMENTED(); |
| 1925 #endif |
| 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 #if defined(OS_ANDROID) |
| 1935 case content::PERMISSION_PROTECTED_MEDIA: |
| 1936 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile) |
| 1937 ->RequestProtectedMediaIdentifierPermission( |
| 1938 web_contents, requesting_frame, result_callback); |
| 1939 break; |
| 1940 #endif |
| 1941 default: |
| 1942 LOG(WARNING) << "Permission not available " << permission; |
| 1943 } |
1938 } | 1944 } |
1939 | 1945 |
1940 void ChromeContentBrowserClient::CancelGeolocationPermissionRequest( | 1946 void ChromeContentBrowserClient::CancelPermissionRequest( |
| 1947 content::PermissionType permission, |
1941 content::WebContents* web_contents, | 1948 content::WebContents* web_contents, |
1942 int bridge_id, | 1949 int bridge_id, |
1943 const GURL& requesting_frame) { | 1950 const GURL& requesting_frame) { |
1944 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 1951 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
1945 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 1952 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
1946 | 1953 |
1947 const PermissionRequestID request_id(render_process_id, | 1954 const PermissionRequestID request_id(render_process_id, |
1948 render_view_id, | 1955 render_view_id, |
1949 bridge_id, | 1956 bridge_id, |
1950 requesting_frame); | 1957 requesting_frame); |
1951 GeolocationPermissionContextFactory::GetForProfile( | 1958 Profile* profile = |
1952 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> | 1959 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
1953 CancelPermissionRequest(web_contents, request_id); | 1960 switch (permission) { |
| 1961 case content::PERMISSION_MIDI_SYSEX: |
| 1962 MidiPermissionContextFactory::GetForProfile(profile) |
| 1963 ->CancelPermissionRequest(web_contents, request_id); |
| 1964 break; |
| 1965 #if defined(ENABLE_NOTIFICATIONS) |
| 1966 case content::PERMISSION_NOTIFICATIONS: |
| 1967 DesktopNotificationServiceFactory::GetForProfile(profile) |
| 1968 ->CancelPermissionRequest(web_contents, request_id); |
| 1969 #else |
| 1970 NOTIMPLEMENTED(); |
| 1971 break; |
| 1972 #endif |
| 1973 case content::PERMISSION_GEOLOCATION: |
| 1974 GeolocationPermissionContextFactory::GetForProfile(profile) |
| 1975 ->CancelPermissionRequest(web_contents, request_id); |
| 1976 break; |
| 1977 #if defined(OS_ANDROID) |
| 1978 case content::PERMISSION_PROTECTED_MEDIA: |
| 1979 ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile) |
| 1980 ->CancelProtectedMediaIdentifierPermissionRequests( |
| 1981 render_process_id, render_view_id, requesting_frame); |
| 1982 break; |
| 1983 #endif |
| 1984 default: |
| 1985 LOG(WARNING) << "Permission not available " << permission; |
| 1986 } |
1954 } | 1987 } |
1955 | 1988 |
1956 void ChromeContentBrowserClient::RequestMidiSysExPermission( | 1989 // Helper method to translate from Permissions to ContentSettings |
1957 content::WebContents* web_contents, | 1990 static ContentSettingsType PermissionToContentSetting( |
1958 int bridge_id, | 1991 content::PermissionType permission) { |
1959 const GURL& requesting_frame, | 1992 switch (permission) { |
1960 bool user_gesture, | 1993 case content::PERMISSION_MIDI_SYSEX: |
1961 base::Callback<void(bool)> result_callback, | 1994 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX; |
1962 base::Closure* cancel_callback) { | 1995 case content::PERMISSION_NOTIFICATIONS: |
1963 MidiPermissionContext* context = | 1996 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
1964 MidiPermissionContextFactory::GetForProfile( | 1997 case content::PERMISSION_GEOLOCATION: |
1965 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 1998 return CONTENT_SETTINGS_TYPE_GEOLOCATION; |
1966 int renderer_id = web_contents->GetRenderProcessHost()->GetID(); | 1999 #if defined(OS_ANDROID) |
1967 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 2000 case content::PERMISSION_PROTECTED_MEDIA: |
1968 const PermissionRequestID id(renderer_id, render_view_id, bridge_id, GURL()); | 2001 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER; |
1969 | 2002 #endif |
1970 context->RequestPermission(web_contents, id, requesting_frame, | 2003 default: |
1971 user_gesture, result_callback); | 2004 NOTREACHED() << "Unknown content setting for permission " << permission; |
| 2005 return CONTENT_SETTINGS_TYPE_DEFAULT; |
| 2006 } |
1972 } | 2007 } |
1973 | 2008 |
1974 void ChromeContentBrowserClient::DidUseGeolocationPermission( | 2009 void ChromeContentBrowserClient::RegisterPermissionUsage( |
| 2010 content::PermissionType permission, |
1975 content::WebContents* web_contents, | 2011 content::WebContents* web_contents, |
1976 const GURL& frame_url, | 2012 const GURL& frame_url, |
1977 const GURL& main_frame_url) { | 2013 const GURL& main_frame_url) { |
1978 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 2014 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
1979 ->GetHostContentSettingsMap() | 2015 ->GetHostContentSettingsMap() |
1980 ->UpdateLastUsage( | 2016 ->UpdateLastUsage( |
1981 frame_url, main_frame_url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 2017 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 } | 2018 } |
2002 | 2019 |
2003 bool ChromeContentBrowserClient::CanCreateWindow( | 2020 bool ChromeContentBrowserClient::CanCreateWindow( |
2004 const GURL& opener_url, | 2021 const GURL& opener_url, |
2005 const GURL& opener_top_level_frame_url, | 2022 const GURL& opener_top_level_frame_url, |
2006 const GURL& source_origin, | 2023 const GURL& source_origin, |
2007 WindowContainerType container_type, | 2024 WindowContainerType container_type, |
2008 const GURL& target_url, | 2025 const GURL& target_url, |
2009 const content::Referrer& referrer, | 2026 const content::Referrer& referrer, |
2010 WindowOpenDisposition disposition, | 2027 WindowOpenDisposition disposition, |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 switches::kDisableWebRtcEncryption, | 2627 switches::kDisableWebRtcEncryption, |
2611 }; | 2628 }; |
2612 to_command_line->CopySwitchesFrom(from_command_line, | 2629 to_command_line->CopySwitchesFrom(from_command_line, |
2613 kWebRtcDevSwitchNames, | 2630 kWebRtcDevSwitchNames, |
2614 arraysize(kWebRtcDevSwitchNames)); | 2631 arraysize(kWebRtcDevSwitchNames)); |
2615 } | 2632 } |
2616 } | 2633 } |
2617 #endif // defined(ENABLE_WEBRTC) | 2634 #endif // defined(ENABLE_WEBRTC) |
2618 | 2635 |
2619 } // namespace chrome | 2636 } // namespace chrome |
OLD | NEW |