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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(); |
635 break; | |
635 #endif | 636 #endif |
636 case content::PERMISSION_GEOLOCATION: | 637 case content::PERMISSION_GEOLOCATION: |
637 return GeolocationPermissionContextFactory::GetForProfile(profile); | 638 return GeolocationPermissionContextFactory::GetForProfile(profile); |
638 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: | 639 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: |
639 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 640 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
640 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile( | 641 return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile( |
641 profile); | 642 profile); |
642 #else | 643 #else |
643 NOTIMPLEMENTED(); | 644 NOTIMPLEMENTED(); |
644 break; | 645 break; |
645 #endif | 646 #endif |
646 case content::PERMISSION_PUSH_MESSAGING: | 647 case content::PERMISSION_PUSH_MESSAGING: |
647 return gcm::PushMessagingPermissionContextFactory::GetForProfile(profile); | 648 return gcm::PushMessagingPermissionContextFactory::GetForProfile(profile); |
648 case content::PERMISSION_NUM: | 649 case content::PERMISSION_NUM: |
649 NOTREACHED() << "Invalid RequestPermission for " << permission; | 650 NOTREACHED() << "Invalid RequestPermission for " << permission; |
650 break; | 651 break; |
651 } | 652 } |
652 return nullptr; | 653 return nullptr; |
653 } | 654 } |
654 | 655 |
656 // Helper method to translate from Permissions to ContentSettings | |
657 ContentSettingsType PermissionToContentSetting( | |
Nico
2015/02/04 16:43:32
nit: feels like this could be somewhere in content
timvolodine
2015/02/05 18:19:04
ack, for now think we can keep it here as it's onl
| |
658 content::PermissionType permission) { | |
659 switch (permission) { | |
660 case content::PERMISSION_MIDI_SYSEX: | |
661 return CONTENT_SETTINGS_TYPE_MIDI_SYSEX; | |
662 case content::PERMISSION_PUSH_MESSAGING: | |
663 return CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; | |
664 case content::PERMISSION_NOTIFICATIONS: | |
665 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | |
666 case content::PERMISSION_GEOLOCATION: | |
667 return CONTENT_SETTINGS_TYPE_GEOLOCATION; | |
668 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
669 case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: | |
670 return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER; | |
671 #endif | |
672 default: | |
673 NOTREACHED() << "Unknown content setting for permission " << permission; | |
674 return CONTENT_SETTINGS_TYPE_DEFAULT; | |
675 } | |
676 } | |
677 | |
655 } // namespace | 678 } // namespace |
656 | 679 |
657 namespace chrome { | 680 namespace chrome { |
658 | 681 |
659 ChromeContentBrowserClient::ChromeContentBrowserClient() | 682 ChromeContentBrowserClient::ChromeContentBrowserClient() |
660 : prerender_tracker_(NULL), | 683 : prerender_tracker_(NULL), |
661 weak_factory_(this) { | 684 weak_factory_(this) { |
662 #if defined(ENABLE_PLUGINS) | 685 #if defined(ENABLE_PLUGINS) |
663 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) | 686 for (size_t i = 0; i < arraysize(kPredefinedAllowedDevChannelOrigins); ++i) |
664 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); | 687 allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1901 | 1924 |
1902 void ChromeContentBrowserClient::RequestPermission( | 1925 void ChromeContentBrowserClient::RequestPermission( |
1903 content::PermissionType permission, | 1926 content::PermissionType permission, |
1904 content::WebContents* web_contents, | 1927 content::WebContents* web_contents, |
1905 int bridge_id, | 1928 int bridge_id, |
1906 const GURL& requesting_frame, | 1929 const GURL& requesting_frame, |
1907 bool user_gesture, | 1930 bool user_gesture, |
1908 const base::Callback<void(bool)>& result_callback) { | 1931 const base::Callback<void(bool)>& result_callback) { |
1909 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 1932 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
1910 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 1933 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, | 1934 const PermissionRequestID request_id(render_process_id, |
1915 render_view_id, | 1935 render_view_id, |
1916 bridge_id, | 1936 bridge_id, |
1917 requesting_frame); | 1937 requesting_frame); |
1938 Profile* profile = | |
1939 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
1940 PermissionContextBase* context = GetPermissionContext(profile, permission); | |
1918 | 1941 |
1919 switch (permission) { | 1942 if (!context) |
1920 case content::PERMISSION_MIDI_SYSEX: | 1943 return; |
1921 MidiPermissionContextFactory::GetForProfile(profile) | 1944 |
1922 ->RequestPermission(web_contents, | 1945 context->RequestPermission(web_contents, request_id, requesting_frame, |
1923 request_id, | 1946 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 } | 1947 } |
1973 | 1948 |
1974 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus( | 1949 content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus( |
1975 content::PermissionType permission, | 1950 content::PermissionType permission, |
1976 content::BrowserContext* browser_context, | 1951 content::BrowserContext* browser_context, |
1977 const GURL& requesting_origin, | 1952 const GURL& requesting_origin, |
1978 const GURL& embedding_origin) { | 1953 const GURL& embedding_origin) { |
1979 DCHECK(browser_context); | 1954 DCHECK(browser_context); |
1980 Profile* profile = Profile::FromBrowserContext(browser_context); | 1955 Profile* profile = Profile::FromBrowserContext(browser_context); |
1981 PermissionContextBase* context = GetPermissionContext(profile, permission); | 1956 PermissionContextBase* context = GetPermissionContext(profile, permission); |
(...skipping 22 matching lines...) Expand all Loading... | |
2004 embedding_origin.GetOrigin()); | 1979 embedding_origin.GetOrigin()); |
2005 } | 1980 } |
2006 | 1981 |
2007 void ChromeContentBrowserClient::CancelPermissionRequest( | 1982 void ChromeContentBrowserClient::CancelPermissionRequest( |
2008 content::PermissionType permission, | 1983 content::PermissionType permission, |
2009 content::WebContents* web_contents, | 1984 content::WebContents* web_contents, |
2010 int bridge_id, | 1985 int bridge_id, |
2011 const GURL& requesting_frame) { | 1986 const GURL& requesting_frame) { |
2012 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 1987 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
2013 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 1988 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
2014 | |
2015 const PermissionRequestID request_id(render_process_id, | 1989 const PermissionRequestID request_id(render_process_id, |
2016 render_view_id, | 1990 render_view_id, |
2017 bridge_id, | 1991 bridge_id, |
2018 requesting_frame); | 1992 requesting_frame); |
2019 Profile* profile = | 1993 Profile* profile = |
2020 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1994 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
2021 switch (permission) { | 1995 PermissionContextBase* context = GetPermissionContext(profile, permission); |
2022 case content::PERMISSION_MIDI_SYSEX: | 1996 if (!context) |
2023 MidiPermissionContextFactory::GetForProfile(profile) | 1997 return; |
2024 ->CancelPermissionRequest(web_contents, request_id); | 1998 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 } | 1999 } |
2076 | 2000 |
2077 void ChromeContentBrowserClient::RegisterPermissionUsage( | 2001 void ChromeContentBrowserClient::RegisterPermissionUsage( |
2078 content::PermissionType permission, | 2002 content::PermissionType permission, |
2079 content::WebContents* web_contents, | 2003 content::WebContents* web_contents, |
2080 const GURL& frame_url, | 2004 const GURL& frame_url, |
2081 const GURL& main_frame_url) { | 2005 const GURL& main_frame_url) { |
2082 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 2006 Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
2083 ->GetHostContentSettingsMap() | 2007 ->GetHostContentSettingsMap() |
2084 ->UpdateLastUsage( | 2008 ->UpdateLastUsage( |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2664 switches::kDisableWebRtcEncryption, | 2588 switches::kDisableWebRtcEncryption, |
2665 }; | 2589 }; |
2666 to_command_line->CopySwitchesFrom(from_command_line, | 2590 to_command_line->CopySwitchesFrom(from_command_line, |
2667 kWebRtcDevSwitchNames, | 2591 kWebRtcDevSwitchNames, |
2668 arraysize(kWebRtcDevSwitchNames)); | 2592 arraysize(kWebRtcDevSwitchNames)); |
2669 } | 2593 } |
2670 } | 2594 } |
2671 #endif // defined(ENABLE_WEBRTC) | 2595 #endif // defined(ENABLE_WEBRTC) |
2672 | 2596 |
2673 } // namespace chrome | 2597 } // namespace chrome |
OLD | NEW |