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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 } | 715 } |
716 | 716 |
717 SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { | 717 SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
718 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 718 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
719 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 719 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
720 } | 720 } |
721 | 721 |
722 bool ChromeContentBrowserClient::AllowAppCache( | 722 bool ChromeContentBrowserClient::AllowAppCache( |
723 const GURL& manifest_url, | 723 const GURL& manifest_url, |
724 const GURL& first_party, | 724 const GURL& first_party, |
725 const content::ResourceContext& context) { | 725 content::ResourceContext* context) { |
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
727 ProfileIOData* io_data = | 727 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
728 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
729 return io_data->GetCookieSettings()-> | 728 return io_data->GetCookieSettings()-> |
730 IsSettingCookieAllowed(manifest_url, first_party); | 729 IsSettingCookieAllowed(manifest_url, first_party); |
731 } | 730 } |
732 | 731 |
733 bool ChromeContentBrowserClient::AllowGetCookie( | 732 bool ChromeContentBrowserClient::AllowGetCookie( |
734 const GURL& url, | 733 const GURL& url, |
735 const GURL& first_party, | 734 const GURL& first_party, |
736 const net::CookieList& cookie_list, | 735 const net::CookieList& cookie_list, |
737 const content::ResourceContext& context, | 736 content::ResourceContext* context, |
738 int render_process_id, | 737 int render_process_id, |
739 int render_view_id) { | 738 int render_view_id) { |
740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
741 ProfileIOData* io_data = | 740 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
742 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
743 bool allow = io_data->GetCookieSettings()-> | 741 bool allow = io_data->GetCookieSettings()-> |
744 IsReadingCookieAllowed(url, first_party); | 742 IsReadingCookieAllowed(url, first_party); |
745 | 743 |
746 BrowserThread::PostTask( | 744 BrowserThread::PostTask( |
747 BrowserThread::UI, FROM_HERE, | 745 BrowserThread::UI, FROM_HERE, |
748 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, | 746 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
749 render_view_id, url, cookie_list, !allow)); | 747 render_view_id, url, cookie_list, !allow)); |
750 return allow; | 748 return allow; |
751 } | 749 } |
752 | 750 |
753 bool ChromeContentBrowserClient::AllowSetCookie( | 751 bool ChromeContentBrowserClient::AllowSetCookie( |
754 const GURL& url, | 752 const GURL& url, |
755 const GURL& first_party, | 753 const GURL& first_party, |
756 const std::string& cookie_line, | 754 const std::string& cookie_line, |
757 const content::ResourceContext& context, | 755 content::ResourceContext* context, |
758 int render_process_id, | 756 int render_process_id, |
759 int render_view_id, | 757 int render_view_id, |
760 net::CookieOptions* options) { | 758 net::CookieOptions* options) { |
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
762 ProfileIOData* io_data = | 760 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
763 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
764 | |
765 CookieSettings* cookie_settings = io_data->GetCookieSettings(); | 761 CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
766 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); | 762 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
767 | 763 |
768 if (cookie_settings->IsCookieSessionOnly(url)) | 764 if (cookie_settings->IsCookieSessionOnly(url)) |
769 options->set_force_session(); | 765 options->set_force_session(); |
770 | 766 |
771 BrowserThread::PostTask( | 767 BrowserThread::PostTask( |
772 BrowserThread::UI, FROM_HERE, | 768 BrowserThread::UI, FROM_HERE, |
773 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, | 769 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
774 render_view_id, url, cookie_line, *options, !allow)); | 770 render_view_id, url, cookie_line, *options, !allow)); |
775 return allow; | 771 return allow; |
776 } | 772 } |
777 | 773 |
778 bool ChromeContentBrowserClient::AllowSaveLocalState( | 774 bool ChromeContentBrowserClient::AllowSaveLocalState( |
779 const content::ResourceContext& context) { | 775 content::ResourceContext* context) { |
780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
781 ProfileIOData* io_data = | 777 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
782 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
783 return !io_data->clear_local_state_on_exit()->GetValue(); | 778 return !io_data->clear_local_state_on_exit()->GetValue(); |
784 } | 779 } |
785 | 780 |
786 bool ChromeContentBrowserClient::AllowWorkerDatabase( | 781 bool ChromeContentBrowserClient::AllowWorkerDatabase( |
787 const GURL& url, | 782 const GURL& url, |
788 const string16& name, | 783 const string16& name, |
789 const string16& display_name, | 784 const string16& display_name, |
790 unsigned long estimated_size, | 785 unsigned long estimated_size, |
791 const content::ResourceContext& context, | 786 content::ResourceContext* context, |
792 const std::vector<std::pair<int, int> >& render_views) { | 787 const std::vector<std::pair<int, int> >& render_views) { |
793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
794 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( | 789 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
795 context.GetUserData(NULL)); | |
796 CookieSettings* cookie_settings = io_data->GetCookieSettings(); | 790 CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
797 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); | 791 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
798 | 792 |
799 // Record access to database for potential display in UI. | 793 // Record access to database for potential display in UI. |
800 std::vector<std::pair<int, int> >::const_iterator i; | 794 std::vector<std::pair<int, int> >::const_iterator i; |
801 for (i = render_views.begin(); i != render_views.end(); ++i) { | 795 for (i = render_views.begin(); i != render_views.end(); ++i) { |
802 BrowserThread::PostTask( | 796 BrowserThread::PostTask( |
803 BrowserThread::UI, FROM_HERE, | 797 BrowserThread::UI, FROM_HERE, |
804 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, | 798 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, |
805 i->first, i->second, url, name, display_name, !allow)); | 799 i->first, i->second, url, name, display_name, !allow)); |
806 } | 800 } |
807 | 801 |
808 return allow; | 802 return allow; |
809 } | 803 } |
810 | 804 |
811 bool ChromeContentBrowserClient::AllowWorkerFileSystem( | 805 bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
812 const GURL& url, | 806 const GURL& url, |
813 const content::ResourceContext& context, | 807 content::ResourceContext* context, |
814 const std::vector<std::pair<int, int> >& render_views) { | 808 const std::vector<std::pair<int, int> >& render_views) { |
815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
816 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( | 810 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
817 context.GetUserData(NULL)); | |
818 CookieSettings* cookie_settings = io_data->GetCookieSettings(); | 811 CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
819 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); | 812 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
820 | 813 |
821 // Record access to file system for potential display in UI. | 814 // Record access to file system for potential display in UI. |
822 std::vector<std::pair<int, int> >::const_iterator i; | 815 std::vector<std::pair<int, int> >::const_iterator i; |
823 for (i = render_views.begin(); i != render_views.end(); ++i) { | 816 for (i = render_views.begin(); i != render_views.end(); ++i) { |
824 BrowserThread::PostTask( | 817 BrowserThread::PostTask( |
825 BrowserThread::UI, FROM_HERE, | 818 BrowserThread::UI, FROM_HERE, |
826 base::Bind(&TabSpecificContentSettings::FileSystemAccessed, | 819 base::Bind(&TabSpecificContentSettings::FileSystemAccessed, |
827 i->first, i->second, url, !allow)); | 820 i->first, i->second, url, !allow)); |
828 } | 821 } |
829 | 822 |
830 return allow; | 823 return allow; |
831 } | 824 } |
832 | 825 |
833 net::URLRequestContext* | 826 net::URLRequestContext* |
834 ChromeContentBrowserClient::OverrideRequestContextForURL( | 827 ChromeContentBrowserClient::OverrideRequestContextForURL( |
835 const GURL& url, const content::ResourceContext& context) { | 828 const GURL& url, content::ResourceContext* context) { |
836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
837 if (url.SchemeIs(chrome::kExtensionScheme)) { | 830 if (url.SchemeIs(chrome::kExtensionScheme)) { |
838 ProfileIOData* io_data = | 831 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
839 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
840 return io_data->extensions_request_context(); | 832 return io_data->extensions_request_context(); |
841 } | 833 } |
842 | 834 |
843 return NULL; | 835 return NULL; |
844 } | 836 } |
845 | 837 |
846 QuotaPermissionContext* | 838 QuotaPermissionContext* |
847 ChromeContentBrowserClient::CreateQuotaPermissionContext() { | 839 ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
848 return new ChromeQuotaPermissionContext(); | 840 return new ChromeQuotaPermissionContext(); |
849 } | 841 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 DesktopNotificationService* service = | 960 DesktopNotificationService* service = |
969 DesktopNotificationServiceFactory::GetForProfile(profile); | 961 DesktopNotificationServiceFactory::GetForProfile(profile); |
970 service->RequestPermission( | 962 service->RequestPermission( |
971 source_origin, render_process_id, render_view_id, callback_context, | 963 source_origin, render_process_id, render_view_id, callback_context, |
972 tab_util::GetWebContentsByID(render_process_id, render_view_id)); | 964 tab_util::GetWebContentsByID(render_process_id, render_view_id)); |
973 } | 965 } |
974 | 966 |
975 WebKit::WebNotificationPresenter::Permission | 967 WebKit::WebNotificationPresenter::Permission |
976 ChromeContentBrowserClient::CheckDesktopNotificationPermission( | 968 ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
977 const GURL& source_origin, | 969 const GURL& source_origin, |
978 const content::ResourceContext& context, | 970 content::ResourceContext* context, |
979 int render_process_id) { | 971 int render_process_id) { |
980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 972 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
981 ProfileIOData* io_data = | 973 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
982 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
983 | |
984 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( | 974 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
985 source_origin, render_process_id, | 975 source_origin, render_process_id, |
986 ExtensionAPIPermission::kNotification)) | 976 ExtensionAPIPermission::kNotification)) |
987 return WebKit::WebNotificationPresenter::PermissionAllowed; | 977 return WebKit::WebNotificationPresenter::PermissionAllowed; |
988 | 978 |
989 // Fall back to the regular notification preferences, which works on an | 979 // Fall back to the regular notification preferences, which works on an |
990 // origin basis. | 980 // origin basis. |
991 return io_data->GetNotificationService() ? | 981 return io_data->GetNotificationService() ? |
992 io_data->GetNotificationService()->HasPermission(source_origin) : | 982 io_data->GetNotificationService()->HasPermission(source_origin) : |
993 WebKit::WebNotificationPresenter::PermissionNotAllowed; | 983 WebKit::WebNotificationPresenter::PermissionNotAllowed; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); | 1020 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
1031 DesktopNotificationService* service = | 1021 DesktopNotificationService* service = |
1032 DesktopNotificationServiceFactory::GetForProfile(profile); | 1022 DesktopNotificationServiceFactory::GetForProfile(profile); |
1033 service->CancelDesktopNotification( | 1023 service->CancelDesktopNotification( |
1034 render_process_id, render_view_id, notification_id); | 1024 render_process_id, render_view_id, notification_id); |
1035 } | 1025 } |
1036 | 1026 |
1037 bool ChromeContentBrowserClient::CanCreateWindow( | 1027 bool ChromeContentBrowserClient::CanCreateWindow( |
1038 const GURL& source_origin, | 1028 const GURL& source_origin, |
1039 WindowContainerType container_type, | 1029 WindowContainerType container_type, |
1040 const content::ResourceContext& context, | 1030 content::ResourceContext* context, |
1041 int render_process_id) { | 1031 int render_process_id) { |
1042 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1043 // If the opener is trying to create a background window but doesn't have | 1033 // If the opener is trying to create a background window but doesn't have |
1044 // the appropriate permission, fail the attempt. | 1034 // the appropriate permission, fail the attempt. |
1045 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { | 1035 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
1046 ProfileIOData* io_data = | 1036 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
1047 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
1048 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( | 1037 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
1049 source_origin, render_process_id, ExtensionAPIPermission::kBackground); | 1038 source_origin, render_process_id, ExtensionAPIPermission::kBackground); |
1050 } | 1039 } |
1051 return true; | 1040 return true; |
1052 } | 1041 } |
1053 | 1042 |
1054 std::string ChromeContentBrowserClient::GetWorkerProcessTitle( | 1043 std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
1055 const GURL& url, const content::ResourceContext& context) { | 1044 const GURL& url, content::ResourceContext* context) { |
1056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1057 // Check if it's an extension-created worker, in which case we want to use | 1046 // Check if it's an extension-created worker, in which case we want to use |
1058 // the name of the extension. | 1047 // the name of the extension. |
1059 ProfileIOData* io_data = | 1048 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
1060 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); | |
1061 const Extension* extension = | 1049 const Extension* extension = |
1062 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); | 1050 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
1063 return extension ? extension->name() : std::string(); | 1051 return extension ? extension->name() : std::string(); |
1064 } | 1052 } |
1065 | 1053 |
1066 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { | 1054 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
1067 return g_browser_process->ResourceDispatcherHostCreated(); | 1055 return g_browser_process->ResourceDispatcherHostCreated(); |
1068 } | 1056 } |
1069 | 1057 |
1070 ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { | 1058 ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 #if defined(USE_NSS) | 1322 #if defined(USE_NSS) |
1335 crypto::CryptoModuleBlockingPasswordDelegate* | 1323 crypto::CryptoModuleBlockingPasswordDelegate* |
1336 ChromeContentBrowserClient::GetCryptoPasswordDelegate( | 1324 ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
1337 const GURL& url) { | 1325 const GURL& url) { |
1338 return browser::NewCryptoModuleBlockingDialogDelegate( | 1326 return browser::NewCryptoModuleBlockingDialogDelegate( |
1339 browser::kCryptoModulePasswordKeygen, url.host()); | 1327 browser::kCryptoModulePasswordKeygen, url.host()); |
1340 } | 1328 } |
1341 #endif | 1329 #endif |
1342 | 1330 |
1343 } // namespace chrome | 1331 } // namespace chrome |
OLD | NEW |