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

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: fix nacl Created 7 years, 5 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // attribute because this code path is run during Extension uninstall 680 // attribute because this code path is run during Extension uninstall
681 // to do cleanup after the Extension has already been unloaded from the 681 // to do cleanup after the Extension has already been unloaded from the
682 // ExtensionService. 682 // ExtensionService.
683 bool is_isolated = !can_be_default; 683 bool is_isolated = !can_be_default;
684 if (can_be_default) { 684 if (can_be_default) {
685 const Extension* extension = NULL; 685 const Extension* extension = NULL;
686 Profile* profile = Profile::FromBrowserContext(browser_context); 686 Profile* profile = Profile::FromBrowserContext(browser_context);
687 ExtensionService* extension_service = 687 ExtensionService* extension_service =
688 extensions::ExtensionSystem::Get(profile)->extension_service(); 688 extensions::ExtensionSystem::Get(profile)->extension_service();
689 if (extension_service) { 689 if (extension_service) {
690 extension = extension_service->extensions()-> 690 extension =
691 GetExtensionOrAppByURL(ExtensionURLInfo(site)); 691 extension_service->extensions()->GetExtensionOrAppByURL(site);
692 if (extension && 692 if (extension &&
693 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { 693 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
694 is_isolated = true; 694 is_isolated = true;
695 } 695 }
696 } 696 }
697 } 697 }
698 698
699 if (is_isolated) { 699 if (is_isolated) {
700 CHECK(site.has_host()); 700 CHECK(site.has_host());
701 // For extensions with isolated storage, the the host of the |site| is 701 // For extensions with isolated storage, the the host of the |site| is
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 const base::DictionaryValue& extra_params) { 778 const base::DictionaryValue& extra_params) {
779 Profile* profile = Profile::FromBrowserContext( 779 Profile* profile = Profile::FromBrowserContext(
780 embedder_web_contents->GetBrowserContext()); 780 embedder_web_contents->GetBrowserContext());
781 ExtensionService* service = 781 ExtensionService* service =
782 extensions::ExtensionSystem::Get(profile)->extension_service(); 782 extensions::ExtensionSystem::Get(profile)->extension_service();
783 if (!service) { 783 if (!service) {
784 NOTREACHED(); 784 NOTREACHED();
785 return; 785 return;
786 } 786 }
787 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL(); 787 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
788 const Extension* extension = service->extensions()-> 788 const Extension* extension =
789 GetExtensionOrAppByURL(ExtensionURLInfo(url)); 789 service->extensions()->GetExtensionOrAppByURL(url);
790 if (!extension) { 790 if (!extension) {
791 NOTREACHED(); 791 NOTREACHED();
792 return; 792 return;
793 } 793 }
794 794
795 GuestView* guest = GuestView::FromWebContents(guest_web_contents); 795 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
796 if (!guest) { 796 if (!guest) {
797 NOTREACHED(); 797 NOTREACHED();
798 return; 798 return;
799 } 799 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 902
903 // If the input |url| is part of an installed app, the effective URL is an 903 // If the input |url| is part of an installed app, the effective URL is an
904 // extension URL with the ID of that extension as the host. This has the 904 // extension URL with the ID of that extension as the host. This has the
905 // effect of grouping apps together in a common SiteInstance. 905 // effect of grouping apps together in a common SiteInstance.
906 ExtensionService* extension_service = 906 ExtensionService* extension_service =
907 extensions::ExtensionSystem::Get(profile)->extension_service(); 907 extensions::ExtensionSystem::Get(profile)->extension_service();
908 if (!extension_service) 908 if (!extension_service)
909 return url; 909 return url;
910 910
911 const Extension* extension = extension_service->extensions()-> 911 const Extension* extension = extension_service->extensions()->
912 GetHostedAppByURL(ExtensionURLInfo(url)); 912 GetHostedAppByURL(url);
913 if (!extension) 913 if (!extension)
914 return url; 914 return url;
915 915
916 // Bookmark apps do not use the hosted app process model, and should be 916 // Bookmark apps do not use the hosted app process model, and should be
917 // treated as normal URLs. 917 // treated as normal URLs.
918 if (extension->from_bookmark()) 918 if (extension->from_bookmark())
919 return url; 919 return url;
920 920
921 // If the URL is part of an extension's web extent, convert it to an 921 // If the URL is part of an extension's web extent, convert it to an
922 // extension URL. 922 // extension URL.
(...skipping 20 matching lines...) Expand all
943 #endif 943 #endif
944 944
945 if (!effective_url.SchemeIs(extensions::kExtensionScheme)) 945 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
946 return false; 946 return false;
947 947
948 ExtensionService* extension_service = 948 ExtensionService* extension_service =
949 extensions::ExtensionSystem::Get(profile)->extension_service(); 949 extensions::ExtensionSystem::Get(profile)->extension_service();
950 if (!extension_service) 950 if (!extension_service)
951 return false; 951 return false;
952 952
953 const Extension* extension = extension_service->extensions()-> 953 const Extension* extension =
954 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url)); 954 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
955 if (!extension) 955 if (!extension)
956 return false; 956 return false;
957 957
958 // If the URL is part of a hosted app that does not have the background 958 // If the URL is part of a hosted app that does not have the background
959 // permission, or that does not allow JavaScript access to the background 959 // permission, or that does not allow JavaScript access to the background
960 // page, we want to give each instance its own process to improve 960 // page, we want to give each instance its own process to improve
961 // responsiveness. 961 // responsiveness.
962 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { 962 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
963 if (!extension->HasAPIPermission(APIPermission::kBackground) || 963 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
964 !extensions::BackgroundInfo::AllowJSAccess(extension)) { 964 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 // load in any process (e.g., in an iframe). However, the Chrome Web Store 1009 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1010 // cannot be loaded in iframes and should never be requested outside its 1010 // cannot be loaded in iframes and should never be requested outside its
1011 // process. 1011 // process.
1012 Profile* profile = 1012 Profile* profile =
1013 Profile::FromBrowserContext(process_host->GetBrowserContext()); 1013 Profile::FromBrowserContext(process_host->GetBrowserContext());
1014 ExtensionService* service = 1014 ExtensionService* service =
1015 extensions::ExtensionSystem::Get(profile)->extension_service(); 1015 extensions::ExtensionSystem::Get(profile)->extension_service();
1016 if (!service) 1016 if (!service)
1017 return true; 1017 return true;
1018 const Extension* new_extension = 1018 const Extension* new_extension =
1019 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 1019 service->extensions()->GetExtensionOrAppByURL(url);
1020 if (new_extension && 1020 if (new_extension &&
1021 new_extension->is_hosted_app() && 1021 new_extension->is_hosted_app() &&
1022 new_extension->id() == extension_misc::kWebStoreAppId && 1022 new_extension->id() == extension_misc::kWebStoreAppId &&
1023 !service->process_map()->Contains(new_extension->id(), 1023 !service->process_map()->Contains(new_extension->id(),
1024 process_host->GetID())) { 1024 process_host->GetID())) {
1025 return false; 1025 return false;
1026 } 1026 }
1027 1027
1028 return true; 1028 return true;
1029 } 1029 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 return false; 1093 return false;
1094 1094
1095 Profile* profile = Profile::FromBrowserContext(browser_context); 1095 Profile* profile = Profile::FromBrowserContext(browser_context);
1096 ExtensionService* service = !profile ? NULL : 1096 ExtensionService* service = !profile ? NULL :
1097 extensions::ExtensionSystem::Get(profile)->extension_service(); 1097 extensions::ExtensionSystem::Get(profile)->extension_service();
1098 if (!service) 1098 if (!service)
1099 return false; 1099 return false;
1100 1100
1101 // We have to have a valid extension with background page to proceed. 1101 // We have to have a valid extension with background page to proceed.
1102 const Extension* extension = 1102 const Extension* extension =
1103 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 1103 service->extensions()->GetExtensionOrAppByURL(url);
1104 if (!extension) 1104 if (!extension)
1105 return false; 1105 return false;
1106 if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) 1106 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
1107 return false; 1107 return false;
1108 1108
1109 std::set<int> process_ids; 1109 std::set<int> process_ids;
1110 size_t max_process_count = 1110 size_t max_process_count =
1111 content::RenderProcessHost::GetMaxRendererProcessCount(); 1111 content::RenderProcessHost::GetMaxRendererProcessCount();
1112 1112
1113 // Go through all profiles to ensure we have total count of extension 1113 // Go through all profiles to ensure we have total count of extension
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 extensions::ExtensionSystem::Get(profile)->info_map(), 1168 extensions::ExtensionSystem::Get(profile)->info_map(),
1169 site_instance->GetProcess()->GetID())); 1169 site_instance->GetProcess()->GetID()));
1170 } 1170 }
1171 #endif 1171 #endif
1172 1172
1173 ExtensionService* service = 1173 ExtensionService* service =
1174 extensions::ExtensionSystem::Get(profile)->extension_service(); 1174 extensions::ExtensionSystem::Get(profile)->extension_service();
1175 if (!service) 1175 if (!service)
1176 return; 1176 return;
1177 1177
1178 const Extension* extension = 1178 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1179 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo( 1179 site_instance->GetSiteURL());
1180 site_instance->GetSiteURL()));
1181 if (!extension) 1180 if (!extension)
1182 return; 1181 return;
1183 1182
1184 service->process_map()->Insert(extension->id(), 1183 service->process_map()->Insert(extension->id(),
1185 site_instance->GetProcess()->GetID(), 1184 site_instance->GetProcess()->GetID(),
1186 site_instance->GetId()); 1185 site_instance->GetId());
1187 BrowserThread::PostTask( 1186 BrowserThread::PostTask(
1188 BrowserThread::IO, FROM_HERE, 1187 BrowserThread::IO, FROM_HERE,
1189 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, 1188 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
1190 extensions::ExtensionSystem::Get(profile)->info_map(), 1189 extensions::ExtensionSystem::Get(profile)->info_map(),
1191 extension->id(), 1190 extension->id(),
1192 site_instance->GetProcess()->GetID(), 1191 site_instance->GetProcess()->GetID(),
1193 site_instance->GetId())); 1192 site_instance->GetId()));
1194 } 1193 }
1195 1194
1196 void ChromeContentBrowserClient::SiteInstanceDeleting( 1195 void ChromeContentBrowserClient::SiteInstanceDeleting(
1197 SiteInstance* site_instance) { 1196 SiteInstance* site_instance) {
1198 if (!site_instance->HasProcess()) 1197 if (!site_instance->HasProcess())
1199 return; 1198 return;
1200 1199
1201 Profile* profile = Profile::FromBrowserContext( 1200 Profile* profile = Profile::FromBrowserContext(
1202 site_instance->GetBrowserContext()); 1201 site_instance->GetBrowserContext());
1203 ExtensionService* service = 1202 ExtensionService* service =
1204 extensions::ExtensionSystem::Get(profile)->extension_service(); 1203 extensions::ExtensionSystem::Get(profile)->extension_service();
1205 if (!service) 1204 if (!service)
1206 return; 1205 return;
1207 1206
1208 const Extension* extension = 1207 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1209 service->extensions()->GetExtensionOrAppByURL( 1208 site_instance->GetSiteURL());
1210 ExtensionURLInfo(site_instance->GetSiteURL()));
1211 if (!extension) 1209 if (!extension)
1212 return; 1210 return;
1213 1211
1214 service->process_map()->Remove(extension->id(), 1212 service->process_map()->Remove(extension->id(),
1215 site_instance->GetProcess()->GetID(), 1213 site_instance->GetProcess()->GetID(),
1216 site_instance->GetId()); 1214 site_instance->GetId());
1217 BrowserThread::PostTask( 1215 BrowserThread::PostTask(
1218 BrowserThread::IO, FROM_HERE, 1216 BrowserThread::IO, FROM_HERE,
1219 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, 1217 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
1220 extensions::ExtensionSystem::Get(profile)->info_map(), 1218 extensions::ExtensionSystem::Get(profile)->info_map(),
(...skipping 29 matching lines...) Expand all
1250 Profile* profile = 1248 Profile* profile =
1251 Profile::FromBrowserContext(site_instance->GetBrowserContext()); 1249 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1252 ExtensionService* service = 1250 ExtensionService* service =
1253 extensions::ExtensionSystem::Get(profile)->extension_service(); 1251 extensions::ExtensionSystem::Get(profile)->extension_service();
1254 if (!service) 1252 if (!service)
1255 return false; 1253 return false;
1256 1254
1257 // We must swap if the URL is for an extension and we are not using an 1255 // We must swap if the URL is for an extension and we are not using an
1258 // extension process. 1256 // extension process.
1259 const Extension* new_extension = 1257 const Extension* new_extension =
1260 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url)); 1258 service->extensions()->GetExtensionOrAppByURL(new_url);
1261 // Ignore all hosted apps except the Chrome Web Store, since they do not 1259 // Ignore all hosted apps except the Chrome Web Store, since they do not
1262 // require their own BrowsingInstance (e.g., postMessage is ok). 1260 // require their own BrowsingInstance (e.g., postMessage is ok).
1263 if (new_extension && 1261 if (new_extension &&
1264 new_extension->is_hosted_app() && 1262 new_extension->is_hosted_app() &&
1265 new_extension->id() != extension_misc::kWebStoreAppId) 1263 new_extension->id() != extension_misc::kWebStoreAppId)
1266 new_extension = NULL; 1264 new_extension = NULL;
1267 if (new_extension && 1265 if (new_extension &&
1268 site_instance->HasProcess() && 1266 site_instance->HasProcess() &&
1269 !service->process_map()->Contains(new_extension->id(), 1267 !service->process_map()->Contains(new_extension->id(),
1270 site_instance->GetProcess()->GetID())) 1268 site_instance->GetProcess()->GetID()))
1271 return true; 1269 return true;
1272 1270
1273 return false; 1271 return false;
1274 } 1272 }
1275 1273
1276 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( 1274 bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1277 content::ResourceContext* resource_context, const GURL& current_url, 1275 content::ResourceContext* resource_context, const GURL& current_url,
1278 const GURL& new_url) { 1276 const GURL& new_url) {
1279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 1277 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1280 return extensions::CrossesExtensionProcessBoundary( 1278 return extensions::CrossesExtensionProcessBoundary(
1281 io_data->GetExtensionInfoMap()->extensions(), 1279 io_data->GetExtensionInfoMap()->extensions(),
1282 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false); 1280 current_url, new_url, false);
1283 } 1281 }
1284 1282
1285 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { 1283 bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1286 return !url.SchemeIs(chrome::kChromeNativeScheme); 1284 return !url.SchemeIs(chrome::kChromeNativeScheme);
1287 } 1285 }
1288 1286
1289 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( 1287 std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1290 const std::string& alias_name) { 1288 const std::string& alias_name) {
1291 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); 1289 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1292 } 1290 }
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 APIPermission::kBackground)) { 1929 APIPermission::kBackground)) {
1932 return false; 1930 return false;
1933 } 1931 }
1934 1932
1935 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 1933 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1936 // return a recently installed Extension even if this CanCreateWindow call 1934 // return a recently installed Extension even if this CanCreateWindow call
1937 // was made by an old copy of the page in a normal web process. That's ok, 1935 // was made by an old copy of the page in a normal web process. That's ok,
1938 // because the permission check above would have caused an early return 1936 // because the permission check above would have caused an early return
1939 // already. We must use the full URL to find hosted apps, though, and not 1937 // already. We must use the full URL to find hosted apps, though, and not
1940 // just the origin. 1938 // just the origin.
1941 const Extension* extension = map->extensions().GetExtensionOrAppByURL( 1939 const Extension* extension =
1942 ExtensionURLInfo(opener_url)); 1940 map->extensions().GetExtensionOrAppByURL(opener_url);
1943 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 1941 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
1944 *no_javascript_access = true; 1942 *no_javascript_access = true;
1945 } 1943 }
1946 1944
1947 // No new browser window (popup or tab) in app mode. 1945 // No new browser window (popup or tab) in app mode.
1948 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && 1946 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1949 chrome::IsRunningInForcedAppMode()) { 1947 chrome::IsRunningInForcedAppMode()) {
1950 return false; 1948 return false;
1951 } 1949 }
1952 1950
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 if (CommandLine::ForCurrentProcess()->HasSwitch( 2255 if (CommandLine::ForCurrentProcess()->HasSwitch(
2258 switches::kEnableBrowserPluginForAllViewTypes)) 2256 switches::kEnableBrowserPluginForAllViewTypes))
2259 return true; 2257 return true;
2260 2258
2261 Profile* profile = Profile::FromBrowserContext(browser_context); 2259 Profile* profile = Profile::FromBrowserContext(browser_context);
2262 ExtensionService* service = 2260 ExtensionService* service =
2263 extensions::ExtensionSystem::Get(profile)->extension_service(); 2261 extensions::ExtensionSystem::Get(profile)->extension_service();
2264 if (!service) 2262 if (!service)
2265 return false; 2263 return false;
2266 2264
2267 const Extension* extension = service->extensions()-> 2265 const Extension* extension =
2268 GetExtensionOrAppByURL(ExtensionURLInfo(site_url)); 2266 service->extensions()->GetExtensionOrAppByURL(site_url);
2269 if (!extension) 2267 if (!extension)
2270 return false; 2268 return false;
2271 2269
2272 return extension->HasAPIPermission(APIPermission::kWebView) || 2270 return extension->HasAPIPermission(APIPermission::kWebView) ||
2273 extension->HasAPIPermission(APIPermission::kAdView); 2271 extension->HasAPIPermission(APIPermission::kAdView);
2274 } 2272 }
2275 2273
2276 bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2274 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2277 content::BrowserContext* browser_context, 2275 content::BrowserContext* browser_context,
2278 const GURL& url, 2276 const GURL& url,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 #if defined(USE_NSS) 2460 #if defined(USE_NSS)
2463 crypto::CryptoModuleBlockingPasswordDelegate* 2461 crypto::CryptoModuleBlockingPasswordDelegate*
2464 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 2462 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2465 const GURL& url) { 2463 const GURL& url) {
2466 return chrome::NewCryptoModuleBlockingDialogDelegate( 2464 return chrome::NewCryptoModuleBlockingDialogDelegate(
2467 chrome::kCryptoModulePasswordKeygen, url.host()); 2465 chrome::kCryptoModulePasswordKeygen, url.host());
2468 } 2466 }
2469 #endif 2467 #endif
2470 2468
2471 } // namespace chrome 2469 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/offline/offline_load_page.cc » ('j') | chrome/renderer/chrome_content_renderer_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698