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

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

Issue 16625012: Remove ExtensionURLInfo, make security decisions in render process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // attribute because this code path is run during Extension uninstall 633 // attribute because this code path is run during Extension uninstall
634 // to do cleanup after the Extension has already been unloaded from the 634 // to do cleanup after the Extension has already been unloaded from the
635 // ExtensionService. 635 // ExtensionService.
636 bool is_isolated = !can_be_default; 636 bool is_isolated = !can_be_default;
637 if (can_be_default) { 637 if (can_be_default) {
638 const Extension* extension = NULL; 638 const Extension* extension = NULL;
639 Profile* profile = Profile::FromBrowserContext(browser_context); 639 Profile* profile = Profile::FromBrowserContext(browser_context);
640 ExtensionService* extension_service = 640 ExtensionService* extension_service =
641 extensions::ExtensionSystem::Get(profile)->extension_service(); 641 extensions::ExtensionSystem::Get(profile)->extension_service();
642 if (extension_service) { 642 if (extension_service) {
643 extension = extension_service->extensions()-> 643 extension =
644 GetExtensionOrAppByURL(ExtensionURLInfo(site)); 644 extension_service->extensions()->GetExtensionOrAppByURL(site);
645 if (extension && 645 if (extension &&
646 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { 646 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
647 is_isolated = true; 647 is_isolated = true;
648 } 648 }
649 } 649 }
650 } 650 }
651 651
652 if (is_isolated) { 652 if (is_isolated) {
653 CHECK(site.has_host()); 653 CHECK(site.has_host());
654 // For extensions with isolated storage, the the host of the |site| is 654 // For extensions with isolated storage, the the host of the |site| is
(...skipping 29 matching lines...) Expand all
684 WebContents* guest_web_contents, 684 WebContents* guest_web_contents,
685 WebContents* embedder_web_contents, 685 WebContents* embedder_web_contents,
686 int browser_plugin_instance_id) { 686 int browser_plugin_instance_id) {
687 Profile* profile = Profile::FromBrowserContext( 687 Profile* profile = Profile::FromBrowserContext(
688 embedder_web_contents->GetBrowserContext()); 688 embedder_web_contents->GetBrowserContext());
689 ExtensionService* service = 689 ExtensionService* service =
690 extensions::ExtensionSystem::Get(profile)->extension_service(); 690 extensions::ExtensionSystem::Get(profile)->extension_service();
691 if (!service) 691 if (!service)
692 return; 692 return;
693 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL(); 693 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
694 const Extension* extension = service->extensions()-> 694 const Extension* extension =
695 GetExtensionOrAppByURL(ExtensionURLInfo(url)); 695 service->extensions()->GetExtensionOrAppByURL(url);
696 if (!extension) 696 if (!extension)
697 return; 697 return;
698 std::vector<ExtensionMsg_Loaded_Params> extensions; 698 std::vector<ExtensionMsg_Loaded_Params> extensions;
699 extensions.push_back(ExtensionMsg_Loaded_Params(extension)); 699 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
700 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions)); 700 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
701 new WebViewGuest(guest_web_contents, 701 new WebViewGuest(guest_web_contents,
702 embedder_web_contents, 702 embedder_web_contents,
703 extension->id(), 703 extension->id(),
704 browser_plugin_instance_id); 704 browser_plugin_instance_id);
705 } 705 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 795
796 // If the input |url| is part of an installed app, the effective URL is an 796 // If the input |url| is part of an installed app, the effective URL is an
797 // extension URL with the ID of that extension as the host. This has the 797 // extension URL with the ID of that extension as the host. This has the
798 // effect of grouping apps together in a common SiteInstance. 798 // effect of grouping apps together in a common SiteInstance.
799 ExtensionService* extension_service = 799 ExtensionService* extension_service =
800 extensions::ExtensionSystem::Get(profile)->extension_service(); 800 extensions::ExtensionSystem::Get(profile)->extension_service();
801 if (!extension_service) 801 if (!extension_service)
802 return url; 802 return url;
803 803
804 const Extension* extension = extension_service->extensions()-> 804 const Extension* extension = extension_service->extensions()->
805 GetHostedAppByURL(ExtensionURLInfo(url)); 805 GetHostedAppByURL(url);
806 if (!extension) 806 if (!extension)
807 return url; 807 return url;
808 808
809 // Bookmark apps do not use the hosted app process model, and should be 809 // Bookmark apps do not use the hosted app process model, and should be
810 // treated as normal URLs. 810 // treated as normal URLs.
811 if (extension->from_bookmark()) 811 if (extension->from_bookmark())
812 return url; 812 return url;
813 813
814 // If the URL is part of an extension's web extent, convert it to an 814 // If the URL is part of an extension's web extent, convert it to an
815 // extension URL. 815 // extension URL.
(...skipping 20 matching lines...) Expand all
836 #endif 836 #endif
837 837
838 if (!effective_url.SchemeIs(extensions::kExtensionScheme)) 838 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
839 return false; 839 return false;
840 840
841 ExtensionService* extension_service = 841 ExtensionService* extension_service =
842 extensions::ExtensionSystem::Get(profile)->extension_service(); 842 extensions::ExtensionSystem::Get(profile)->extension_service();
843 if (!extension_service) 843 if (!extension_service)
844 return false; 844 return false;
845 845
846 const Extension* extension = extension_service->extensions()-> 846 const Extension* extension =
847 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url)); 847 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
848 if (!extension) 848 if (!extension)
849 return false; 849 return false;
850 850
851 // If the URL is part of a hosted app that does not have the background 851 // If the URL is part of a hosted app that does not have the background
852 // permission, or that does not allow JavaScript access to the background 852 // permission, or that does not allow JavaScript access to the background
853 // page, we want to give each instance its own process to improve 853 // page, we want to give each instance its own process to improve
854 // responsiveness. 854 // responsiveness.
855 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { 855 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
856 if (!extension->HasAPIPermission(APIPermission::kBackground) || 856 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
857 !extensions::BackgroundInfo::AllowJSAccess(extension)) { 857 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 // load in any process (e.g., in an iframe). However, the Chrome Web Store 902 // load in any process (e.g., in an iframe). However, the Chrome Web Store
903 // cannot be loaded in iframes and should never be requested outside its 903 // cannot be loaded in iframes and should never be requested outside its
904 // process. 904 // process.
905 Profile* profile = 905 Profile* profile =
906 Profile::FromBrowserContext(process_host->GetBrowserContext()); 906 Profile::FromBrowserContext(process_host->GetBrowserContext());
907 ExtensionService* service = 907 ExtensionService* service =
908 extensions::ExtensionSystem::Get(profile)->extension_service(); 908 extensions::ExtensionSystem::Get(profile)->extension_service();
909 if (!service) 909 if (!service)
910 return true; 910 return true;
911 const Extension* new_extension = 911 const Extension* new_extension =
912 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 912 service->extensions()->GetExtensionOrAppByURL(url);
913 if (new_extension && 913 if (new_extension &&
914 new_extension->is_hosted_app() && 914 new_extension->is_hosted_app() &&
915 new_extension->id() == extension_misc::kWebStoreAppId && 915 new_extension->id() == extension_misc::kWebStoreAppId &&
916 !service->process_map()->Contains(new_extension->id(), 916 !service->process_map()->Contains(new_extension->id(),
917 process_host->GetID())) { 917 process_host->GetID())) {
918 return false; 918 return false;
919 } 919 }
920 920
921 return true; 921 return true;
922 } 922 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return false; 986 return false;
987 987
988 Profile* profile = Profile::FromBrowserContext(browser_context); 988 Profile* profile = Profile::FromBrowserContext(browser_context);
989 ExtensionService* service = !profile ? NULL : 989 ExtensionService* service = !profile ? NULL :
990 extensions::ExtensionSystem::Get(profile)->extension_service(); 990 extensions::ExtensionSystem::Get(profile)->extension_service();
991 if (!service) 991 if (!service)
992 return false; 992 return false;
993 993
994 // We have to have a valid extension with background page to proceed. 994 // We have to have a valid extension with background page to proceed.
995 const Extension* extension = 995 const Extension* extension =
996 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 996 service->extensions()->GetExtensionOrAppByURL(url);
997 if (!extension) 997 if (!extension)
998 return false; 998 return false;
999 if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) 999 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
1000 return false; 1000 return false;
1001 1001
1002 std::set<int> process_ids; 1002 std::set<int> process_ids;
1003 size_t max_process_count = 1003 size_t max_process_count =
1004 content::RenderProcessHost::GetMaxRendererProcessCount(); 1004 content::RenderProcessHost::GetMaxRendererProcessCount();
1005 1005
1006 // Go through all profiles to ensure we have total count of extension 1006 // Go through all profiles to ensure we have total count of extension
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 extensions::ExtensionSystem::Get(profile)->info_map(), 1061 extensions::ExtensionSystem::Get(profile)->info_map(),
1062 site_instance->GetProcess()->GetID())); 1062 site_instance->GetProcess()->GetID()));
1063 } 1063 }
1064 #endif 1064 #endif
1065 1065
1066 ExtensionService* service = 1066 ExtensionService* service =
1067 extensions::ExtensionSystem::Get(profile)->extension_service(); 1067 extensions::ExtensionSystem::Get(profile)->extension_service();
1068 if (!service) 1068 if (!service)
1069 return; 1069 return;
1070 1070
1071 const Extension* extension = 1071 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1072 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo( 1072 site_instance->GetSiteURL());
1073 site_instance->GetSiteURL()));
1074 if (!extension) 1073 if (!extension)
1075 return; 1074 return;
1076 1075
1077 service->process_map()->Insert(extension->id(), 1076 service->process_map()->Insert(extension->id(),
1078 site_instance->GetProcess()->GetID(), 1077 site_instance->GetProcess()->GetID(),
1079 site_instance->GetId()); 1078 site_instance->GetId());
1080 BrowserThread::PostTask( 1079 BrowserThread::PostTask(
1081 BrowserThread::IO, FROM_HERE, 1080 BrowserThread::IO, FROM_HERE,
1082 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, 1081 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
1083 extensions::ExtensionSystem::Get(profile)->info_map(), 1082 extensions::ExtensionSystem::Get(profile)->info_map(),
1084 extension->id(), 1083 extension->id(),
1085 site_instance->GetProcess()->GetID(), 1084 site_instance->GetProcess()->GetID(),
1086 site_instance->GetId())); 1085 site_instance->GetId()));
1087 } 1086 }
1088 1087
1089 void ChromeContentBrowserClient::SiteInstanceDeleting( 1088 void ChromeContentBrowserClient::SiteInstanceDeleting(
1090 SiteInstance* site_instance) { 1089 SiteInstance* site_instance) {
1091 if (!site_instance->HasProcess()) 1090 if (!site_instance->HasProcess())
1092 return; 1091 return;
1093 1092
1094 Profile* profile = Profile::FromBrowserContext( 1093 Profile* profile = Profile::FromBrowserContext(
1095 site_instance->GetBrowserContext()); 1094 site_instance->GetBrowserContext());
1096 ExtensionService* service = 1095 ExtensionService* service =
1097 extensions::ExtensionSystem::Get(profile)->extension_service(); 1096 extensions::ExtensionSystem::Get(profile)->extension_service();
1098 if (!service) 1097 if (!service)
1099 return; 1098 return;
1100 1099
1101 const Extension* extension = 1100 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1102 service->extensions()->GetExtensionOrAppByURL( 1101 site_instance->GetSiteURL());
1103 ExtensionURLInfo(site_instance->GetSiteURL()));
1104 if (!extension) 1102 if (!extension)
1105 return; 1103 return;
1106 1104
1107 service->process_map()->Remove(extension->id(), 1105 service->process_map()->Remove(extension->id(),
1108 site_instance->GetProcess()->GetID(), 1106 site_instance->GetProcess()->GetID(),
1109 site_instance->GetId()); 1107 site_instance->GetId());
1110 BrowserThread::PostTask( 1108 BrowserThread::PostTask(
1111 BrowserThread::IO, FROM_HERE, 1109 BrowserThread::IO, FROM_HERE,
1112 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, 1110 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
1113 extensions::ExtensionSystem::Get(profile)->info_map(), 1111 extensions::ExtensionSystem::Get(profile)->info_map(),
(...skipping 29 matching lines...) Expand all
1143 Profile* profile = 1141 Profile* profile =
1144 Profile::FromBrowserContext(site_instance->GetBrowserContext()); 1142 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1145 ExtensionService* service = 1143 ExtensionService* service =
1146 extensions::ExtensionSystem::Get(profile)->extension_service(); 1144 extensions::ExtensionSystem::Get(profile)->extension_service();
1147 if (!service) 1145 if (!service)
1148 return false; 1146 return false;
1149 1147
1150 // We must swap if the URL is for an extension and we are not using an 1148 // We must swap if the URL is for an extension and we are not using an
1151 // extension process. 1149 // extension process.
1152 const Extension* new_extension = 1150 const Extension* new_extension =
1153 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url)); 1151 service->extensions()->GetExtensionOrAppByURL(new_url);
1154 // Ignore all hosted apps except the Chrome Web Store, since they do not 1152 // Ignore all hosted apps except the Chrome Web Store, since they do not
1155 // require their own BrowsingInstance (e.g., postMessage is ok). 1153 // require their own BrowsingInstance (e.g., postMessage is ok).
1156 if (new_extension && 1154 if (new_extension &&
1157 new_extension->is_hosted_app() && 1155 new_extension->is_hosted_app() &&
1158 new_extension->id() != extension_misc::kWebStoreAppId) 1156 new_extension->id() != extension_misc::kWebStoreAppId)
1159 new_extension = NULL; 1157 new_extension = NULL;
1160 if (new_extension && 1158 if (new_extension &&
1161 site_instance->HasProcess() && 1159 site_instance->HasProcess() &&
1162 !service->process_map()->Contains(new_extension->id(), 1160 !service->process_map()->Contains(new_extension->id(),
1163 site_instance->GetProcess()->GetID())) 1161 site_instance->GetProcess()->GetID()))
1164 return true; 1162 return true;
1165 1163
1166 return false; 1164 return false;
1167 } 1165 }
1168 1166
1169 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( 1167 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1170 content::ResourceContext* resource_context, const GURL& current_url, 1168 content::ResourceContext* resource_context, const GURL& current_url,
1171 const GURL& new_url) { 1169 const GURL& new_url) {
1172 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 1170 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1173 return extensions::CrossesExtensionProcessBoundary( 1171 return extensions::CrossesExtensionProcessBoundary(
1174 io_data->GetExtensionInfoMap()->extensions(), 1172 io_data->GetExtensionInfoMap()->extensions(),
1175 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false); 1173 current_url, new_url, false);
1176 } 1174 }
1177 1175
1178 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( 1176 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1179 const std::string& alias_name) { 1177 const std::string& alias_name) {
1180 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); 1178 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1181 } 1179 }
1182 1180
1183 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( 1181 void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1184 CommandLine* command_line, int child_process_id) { 1182 CommandLine* command_line, int child_process_id) {
1185 #if defined(USE_LINUX_BREAKPAD) 1183 #if defined(USE_LINUX_BREAKPAD)
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 APIPermission::kBackground)) { 1808 APIPermission::kBackground)) {
1811 return false; 1809 return false;
1812 } 1810 }
1813 1811
1814 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 1812 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1815 // return a recently installed Extension even if this CanCreateWindow call 1813 // return a recently installed Extension even if this CanCreateWindow call
1816 // was made by an old copy of the page in a normal web process. That's ok, 1814 // was made by an old copy of the page in a normal web process. That's ok,
1817 // because the permission check above would have caused an early return 1815 // because the permission check above would have caused an early return
1818 // already. We must use the full URL to find hosted apps, though, and not 1816 // already. We must use the full URL to find hosted apps, though, and not
1819 // just the origin. 1817 // just the origin.
1820 const Extension* extension = map->extensions().GetExtensionOrAppByURL( 1818 const Extension* extension =
1821 ExtensionURLInfo(opener_url)); 1819 map->extensions().GetExtensionOrAppByURL(opener_url);
1822 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 1820 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
1823 *no_javascript_access = true; 1821 *no_javascript_access = true;
1824 } 1822 }
1825 1823
1826 // No new browser window (popup or tab) in app mode. 1824 // No new browser window (popup or tab) in app mode.
1827 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && 1825 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1828 chrome::IsRunningInForcedAppMode()) { 1826 chrome::IsRunningInForcedAppMode()) {
1829 return false; 1827 return false;
1830 } 1828 }
1831 1829
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 if (CommandLine::ForCurrentProcess()->HasSwitch( 2133 if (CommandLine::ForCurrentProcess()->HasSwitch(
2136 switches::kEnableBrowserPluginForAllViewTypes)) 2134 switches::kEnableBrowserPluginForAllViewTypes))
2137 return true; 2135 return true;
2138 2136
2139 Profile* profile = Profile::FromBrowserContext(browser_context); 2137 Profile* profile = Profile::FromBrowserContext(browser_context);
2140 ExtensionService* service = 2138 ExtensionService* service =
2141 extensions::ExtensionSystem::Get(profile)->extension_service(); 2139 extensions::ExtensionSystem::Get(profile)->extension_service();
2142 if (!service) 2140 if (!service)
2143 return false; 2141 return false;
2144 2142
2145 const Extension* extension = service->extensions()-> 2143 const Extension* extension =
2146 GetExtensionOrAppByURL(ExtensionURLInfo(site_url)); 2144 service->extensions()->GetExtensionOrAppByURL(site_url);
2147 if (!extension) 2145 if (!extension)
2148 return false; 2146 return false;
2149 2147
2150 return extension->HasAPIPermission(APIPermission::kWebView) || 2148 return extension->HasAPIPermission(APIPermission::kWebView) ||
2151 extension->HasAPIPermission(APIPermission::kAdView); 2149 extension->HasAPIPermission(APIPermission::kAdView);
2152 } 2150 }
2153 2151
2154 bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2152 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2155 content::BrowserContext* browser_context, 2153 content::BrowserContext* browser_context,
2156 const GURL& url, 2154 const GURL& url,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 #if defined(USE_NSS) 2295 #if defined(USE_NSS)
2298 crypto::CryptoModuleBlockingPasswordDelegate* 2296 crypto::CryptoModuleBlockingPasswordDelegate*
2299 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 2297 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2300 const GURL& url) { 2298 const GURL& url) {
2301 return chrome::NewCryptoModuleBlockingDialogDelegate( 2299 return chrome::NewCryptoModuleBlockingDialogDelegate(
2302 chrome::kCryptoModulePasswordKeygen, url.host()); 2300 chrome::kCryptoModulePasswordKeygen, url.host());
2303 } 2301 }
2304 #endif 2302 #endif
2305 2303
2306 } // namespace chrome 2304 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698