Commit 154c311c authored by Aaron Colwell's avatar Aaron Colwell Committed by Commit Bot

Add StoragePartition::GetPartitionDomain().

Adding GetPartitionDomain() method to make it easier to determine the
partition domain and reduce the need for calls to
GetStoragePartitionConfigForSite().

There are a few cases where it is unclear whether the domain computed
from the site URL actually matches what was returned by the new method,
so these cases now call a new GetPartitionDomain() helper function on
SiteInstance. This function preserves legacy behavior and will generate
crash dumps if we encounter any situations where the config and storage
partition disagree.


Bug: 1085275
Change-Id: I4fd02a91cf702f3849010d3723bf7a223b723785
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252470
Commit-Queue: Aaron Colwell <acolwell@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791345}
parent 3bfaee89
...@@ -1316,16 +1316,12 @@ void DownloadManagerImpl::BeginResourceDownloadOnChecksComplete( ...@@ -1316,16 +1316,12 @@ void DownloadManagerImpl::BeginResourceDownloadOnChecksComplete(
BrowserContext::GetStoragePartitionForSite(browser_context_, BrowserContext::GetStoragePartitionForSite(browser_context_,
site_url)); site_url));
auto storage_partition_config =
GetContentClient()->browser()->GetStoragePartitionConfigForSite(
browser_context_, site_url);
pending_url_loader_factory = pending_url_loader_factory =
CreatePendingSharedURLLoaderFactoryFromURLLoaderFactory( CreatePendingSharedURLLoaderFactoryFromURLLoaderFactory(
CreateFileSystemURLLoaderFactory( CreateFileSystemURLLoaderFactory(
rfh->GetProcess()->GetID(), rfh->GetFrameTreeNodeId(), rfh->GetProcess()->GetID(), rfh->GetFrameTreeNodeId(),
storage_partition->GetFileSystemContext(), storage_partition->GetFileSystemContext(),
storage_partition_config.partition_domain())); storage_partition->GetPartitionDomain()));
} else if (params->url().SchemeIs(url::kDataScheme)) { } else if (params->url().SchemeIs(url::kDataScheme)) {
pending_url_loader_factory = pending_url_loader_factory =
CreatePendingSharedURLLoaderFactoryFromURLLoaderFactory( CreatePendingSharedURLLoaderFactoryFromURLLoaderFactory(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/browser/file_system/file_system_url_loader_factory.h" #include "content/browser/file_system/file_system_url_loader_factory.h"
#include "content/browser/loader/file_url_loader_factory.h" #include "content/browser/loader/file_url_loader_factory.h"
#include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -252,8 +253,8 @@ void SaveFileManager::SaveURL(SaveItemId save_item_id, ...@@ -252,8 +253,8 @@ void SaveFileManager::SaveURL(SaveItemId save_item_id,
network::mojom::URLLoaderFactory* factory = nullptr; network::mojom::URLLoaderFactory* factory = nullptr;
std::unique_ptr<network::mojom::URLLoaderFactory> url_loader_factory; std::unique_ptr<network::mojom::URLLoaderFactory> url_loader_factory;
RenderFrameHost* rfh = RenderFrameHost::FromID(render_process_host_id, auto* rfh = RenderFrameHostImpl::FromID(render_process_host_id,
render_frame_routing_id); render_frame_routing_id);
// TODO(qinmin): should this match the if statements in // TODO(qinmin): should this match the if statements in
// DownloadManagerImpl::BeginResourceDownloadOnChecksComplete so that it // DownloadManagerImpl::BeginResourceDownloadOnChecksComplete so that it
...@@ -268,16 +269,13 @@ void SaveFileManager::SaveURL(SaveItemId save_item_id, ...@@ -268,16 +269,13 @@ void SaveFileManager::SaveURL(SaveItemId save_item_id,
base::TaskPriority::USER_VISIBLE); base::TaskPriority::USER_VISIBLE);
factory = url_loader_factory.get(); factory = url_loader_factory.get();
} else if (url.SchemeIsFileSystem() && rfh) { } else if (url.SchemeIsFileSystem() && rfh) {
std::string storage_domain; auto* storage_partition_impl =
auto* site_instance = rfh->GetSiteInstance(); static_cast<StoragePartitionImpl*>(storage_partition);
auto storage_partition_config = auto partition_domain =
GetContentClient()->browser()->GetStoragePartitionConfigForSite( rfh->GetSiteInstance()->GetPartitionDomain(storage_partition_impl);
context, site_instance->GetSiteURL());
url_loader_factory = CreateFileSystemURLLoaderFactory( url_loader_factory = CreateFileSystemURLLoaderFactory(
rfh->GetProcess()->GetID(), rfh->GetFrameTreeNodeId(), rfh->GetProcess()->GetID(), rfh->GetFrameTreeNodeId(),
storage_partition->GetFileSystemContext(), storage_partition->GetFileSystemContext(), partition_domain);
storage_partition_config.partition_domain());
factory = url_loader_factory.get(); factory = url_loader_factory.get();
} else if (rfh && url.SchemeIs(content::kChromeUIScheme)) { } else if (rfh && url.SchemeIs(content::kChromeUIScheme)) {
url_loader_factory = CreateWebUIURLLoader(rfh, url.scheme(), url_loader_factory = CreateWebUIURLLoader(rfh, url.scheme(),
......
...@@ -5968,17 +5968,14 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -5968,17 +5968,14 @@ void RenderFrameHostImpl::CommitNavigation(
} }
#endif #endif
StoragePartition* partition = auto* partition =
BrowserContext::GetStoragePartition(browser_context, GetSiteInstance()); static_cast<StoragePartitionImpl*>(BrowserContext::GetStoragePartition(
auto storage_partition_config = browser_context, GetSiteInstance()));
GetContentClient()->browser()->GetStoragePartitionConfigForSite(
browser_context, site_instance_->GetSiteInfo().site_url());
non_network_url_loader_factories_.emplace( non_network_url_loader_factories_.emplace(
url::kFileSystemScheme, url::kFileSystemScheme, content::CreateFileSystemURLLoaderFactory(
content::CreateFileSystemURLLoaderFactory( process_->GetID(), GetFrameTreeNodeId(),
process_->GetID(), GetFrameTreeNodeId(), partition->GetFileSystemContext(),
partition->GetFileSystemContext(), partition->GetPartitionDomain()));
storage_partition_config.partition_domain()));
non_network_url_loader_factories_.emplace( non_network_url_loader_factories_.emplace(
url::kDataScheme, std::make_unique<DataURLLoaderFactory>()); url::kDataScheme, std::make_unique<DataURLLoaderFactory>());
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/crash_logging.h" #include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/bad_message.h" #include "content/browser/bad_message.h"
...@@ -687,6 +688,42 @@ bool SiteInstanceImpl::IsGuest() { ...@@ -687,6 +688,42 @@ bool SiteInstanceImpl::IsGuest() {
return is_guest_; return is_guest_;
} }
std::string SiteInstanceImpl::GetPartitionDomain(
StoragePartitionImpl* storage_partition) {
auto storage_partition_config =
GetContentClient()->browser()->GetStoragePartitionConfigForSite(
GetBrowserContext(), GetSiteURL());
// The DCHECK here is to allow the trybots to detect any attempt to introduce
// new code that violates this assumption.
DCHECK_EQ(storage_partition->GetPartitionDomain(),
storage_partition_config.partition_domain());
if (storage_partition->GetPartitionDomain() !=
storage_partition_config.partition_domain()) {
// Trigger crash logging if we encounter a case that violates our
// assumptions.
static auto* storage_partition_domain_key =
base::debug::AllocateCrashKeyString("storage_partition_domain",
base::debug::CrashKeySize::Size256);
static auto* storage_partition_config_domain_key =
base::debug::AllocateCrashKeyString(
"storage_partition_config_domain_key",
base::debug::CrashKeySize::Size256);
base::debug::SetCrashKeyString(storage_partition_domain_key,
storage_partition->GetPartitionDomain());
base::debug::SetCrashKeyString(storage_partition_config_domain_key,
storage_partition_config.partition_domain());
base::debug::DumpWithoutCrashing();
// Return the value from the config to preserve legacy behavior until we
// can land a fix.
return storage_partition_config.partition_domain();
}
return storage_partition->GetPartitionDomain();
}
bool SiteInstanceImpl::IsOriginalUrlSameSite( bool SiteInstanceImpl::IsOriginalUrlSameSite(
const GURL& dest_url, const GURL& dest_url,
bool should_compare_effective_urls) { bool should_compare_effective_urls) {
......
...@@ -22,6 +22,7 @@ namespace content { ...@@ -22,6 +22,7 @@ namespace content {
class BrowsingInstance; class BrowsingInstance;
class ProcessLock; class ProcessLock;
class RenderProcessHostFactory; class RenderProcessHostFactory;
class StoragePartitionImpl;
// SiteInfo represents the principal of a SiteInstance. All documents and // SiteInfo represents the principal of a SiteInstance. All documents and
// workers within a SiteInstance are considered part of this principal and will // workers within a SiteInstance are considered part of this principal and will
...@@ -268,6 +269,19 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance, ...@@ -268,6 +269,19 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
// the SiteInfo's process_lock_url() for security decisions. // the SiteInfo's process_lock_url() for security decisions.
const ProcessLock GetProcessLock() const; const ProcessLock GetProcessLock() const;
// Helper function that returns the storage partition domain for this
// object.
// This is a temporary helper function used to verify that
// the partition domain computed using this SiteInstance's site URL matches
// the partition domain returned by storage_partition->GetPartitionDomain().
// If there is a mismatch, we call DumpWithoutCrashing() and return the value
// computed from the site URL since that is the legacy behavior.
//
// TODO(acolwell) : Remove this function and update callers to directly call
// storage_partition->GetPartitionDomain() once we've verified that this is
// safe.
std::string GetPartitionDomain(StoragePartitionImpl* storage_partition);
// This function returns a SiteInfo with the appropriate site_url and // This function returns a SiteInfo with the appropriate site_url and
// process_lock_url computed. // process_lock_url computed.
// Note: eventually this function will replace GetSiteForURL(). // Note: eventually this function will replace GetSiteForURL().
......
...@@ -1391,6 +1391,10 @@ base::FilePath StoragePartitionImpl::GetPath() { ...@@ -1391,6 +1391,10 @@ base::FilePath StoragePartitionImpl::GetPath() {
return partition_path_; return partition_path_;
} }
std::string StoragePartitionImpl::GetPartitionDomain() {
return partition_domain_;
}
network::mojom::NetworkContext* StoragePartitionImpl::GetNetworkContext() { network::mojom::NetworkContext* StoragePartitionImpl::GetNetworkContext() {
DCHECK(initialized_); DCHECK(initialized_);
if (!network_context_.is_bound()) if (!network_context_.is_bound())
......
...@@ -198,6 +198,7 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -198,6 +198,7 @@ class CONTENT_EXPORT StoragePartitionImpl
QuotaContext* GetQuotaContext(); QuotaContext* GetQuotaContext();
NativeIOContext* GetNativeIOContext(); NativeIOContext* GetNativeIOContext();
ConversionManagerImpl* GetConversionManager(); ConversionManagerImpl* GetConversionManager();
std::string GetPartitionDomain();
// blink::mojom::DomStorage interface. // blink::mojom::DomStorage interface.
void OpenLocalStorage( void OpenLocalStorage(
......
...@@ -135,14 +135,6 @@ void DedicatedWorkerHost::StartScriptLoad( ...@@ -135,14 +135,6 @@ void DedicatedWorkerHost::StartScriptLoad(
return; return;
} }
// Get a storage domain.
SiteInstance* site_instance =
nearest_ancestor_render_frame_host->GetSiteInstance();
auto storage_partition_config =
GetContentClient()->browser()->GetStoragePartitionConfigForSite(
storage_partition_impl->browser_context(),
site_instance->GetSiteURL());
scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory; scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory;
if (script_url.SchemeIsBlob()) { if (script_url.SchemeIsBlob()) {
if (!blob_url_token) { if (!blob_url_token) {
...@@ -189,6 +181,11 @@ void DedicatedWorkerHost::StartScriptLoad( ...@@ -189,6 +181,11 @@ void DedicatedWorkerHost::StartScriptLoad(
service_worker_handle_ = std::make_unique<ServiceWorkerMainResourceHandle>( service_worker_handle_ = std::make_unique<ServiceWorkerMainResourceHandle>(
storage_partition_impl->GetServiceWorkerContext(), base::DoNothing()); storage_partition_impl->GetServiceWorkerContext(), base::DoNothing());
// Get a storage domain.
auto partition_domain =
nearest_ancestor_render_frame_host->GetSiteInstance()->GetPartitionDomain(
storage_partition_impl);
WorkerScriptFetchInitiator::Start( WorkerScriptFetchInitiator::Start(
worker_process_host_->GetID(), token_, SharedWorkerId(), script_url, worker_process_host_->GetID(), token_, SharedWorkerId(), script_url,
creator_render_frame_host, creator_render_frame_host,
...@@ -201,7 +198,7 @@ void DedicatedWorkerHost::StartScriptLoad( ...@@ -201,7 +198,7 @@ void DedicatedWorkerHost::StartScriptLoad(
service_worker_handle_.get(), service_worker_handle_.get(),
appcache_host ? appcache_host->GetWeakPtr() : nullptr, appcache_host ? appcache_host->GetWeakPtr() : nullptr,
std::move(blob_url_loader_factory), nullptr, storage_partition_impl, std::move(blob_url_loader_factory), nullptr, storage_partition_impl,
storage_partition_config.partition_domain(), partition_domain,
base::BindOnce(&DedicatedWorkerHost::DidStartScriptLoad, base::BindOnce(&DedicatedWorkerHost::DidStartScriptLoad,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -500,13 +497,10 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { ...@@ -500,13 +497,10 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() {
if (!ancestor_render_frame_host) if (!ancestor_render_frame_host)
return; return;
SiteInstance* site_instance = ancestor_render_frame_host->GetSiteInstance();
// Get a storage domain. // Get a storage domain.
auto storage_partition_config = auto partition_domain =
GetContentClient()->browser()->GetStoragePartitionConfigForSite( ancestor_render_frame_host->GetSiteInstance()->GetPartitionDomain(
storage_partition_impl->browser_context(), storage_partition_impl);
site_instance->GetSiteURL());
// Start observing Network Service crash again. // Start observing Network Service crash again.
ObserveNetworkServiceCrash(storage_partition_impl); ObserveNetworkServiceCrash(storage_partition_impl);
...@@ -518,7 +512,7 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { ...@@ -518,7 +512,7 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() {
WorkerScriptFetchInitiator::CreateFactoryBundle( WorkerScriptFetchInitiator::CreateFactoryBundle(
WorkerScriptFetchInitiator::LoaderType::kSubResource, WorkerScriptFetchInitiator::LoaderType::kSubResource,
worker_process_host_->GetID(), storage_partition_impl, worker_process_host_->GetID(), storage_partition_impl,
storage_partition_config.partition_domain(), file_url_support_, partition_domain, file_url_support_,
/*filesystem_url_support=*/true); /*filesystem_url_support=*/true);
bool bypass_redirect_checks = false; bool bypass_redirect_checks = false;
......
...@@ -182,15 +182,12 @@ void SharedWorkerServiceImpl::ConnectToWorker( ...@@ -182,15 +182,12 @@ void SharedWorkerServiceImpl::ConnectToWorker(
// Could not find an existing SharedWorkerHost to reuse. Create a new one. // Could not find an existing SharedWorkerHost to reuse. Create a new one.
// Get a storage domain. // Get a storage domain.
SiteInstance* site_instance = render_frame_host->GetSiteInstance(); auto* site_instance = render_frame_host->GetSiteInstance();
if (!site_instance) { if (!site_instance) {
ScriptLoadFailed(std::move(client), /*error_message=*/""); ScriptLoadFailed(std::move(client), /*error_message=*/"");
return; return;
} }
auto storage_partition_config = auto partition_domain = site_instance->GetPartitionDomain(storage_partition_);
GetContentClient()->browser()->GetStoragePartitionConfigForSite(
storage_partition_->browser_context(), site_instance->GetSiteURL());
SharedWorkerInstance instance( SharedWorkerInstance instance(
info->url, info->options->type, info->options->credentials, info->url, info->options->type, info->options->credentials,
info->options->name, constructor_origin, info->content_security_policy, info->options->name, constructor_origin, info->content_security_policy,
...@@ -198,9 +195,8 @@ void SharedWorkerServiceImpl::ConnectToWorker( ...@@ -198,9 +195,8 @@ void SharedWorkerServiceImpl::ConnectToWorker(
creation_context_type); creation_context_type);
host = CreateWorker(shared_worker_id_generator_.GenerateNextId(), instance, host = CreateWorker(shared_worker_id_generator_.GenerateNextId(), instance,
std::move(info->outside_fetch_client_settings_object), std::move(info->outside_fetch_client_settings_object),
client_render_frame_host_id, client_render_frame_host_id, partition_domain,
storage_partition_config.partition_domain(), message_port, message_port, std::move(blob_url_loader_factory));
std::move(blob_url_loader_factory));
host->AddClient(std::move(client), client_render_frame_host_id, message_port, host->AddClient(std::move(client), client_render_frame_host_id, message_port,
client_ukm_source_id); client_ukm_source_id);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment