Commit 056df686 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Rename s/factories/scheme_specific_factories/ and other refactorings.

This CL cleans-up URLLoaderFactoryBundle[Info] in preparation for adding
initiator-origin-keyed factories in the future (for supporting
URLLoaderFactories with extension-specific permissions for requests
initiated by content scripts).

Changes in the CL:

- s/factories/scheme_specific_factories/
- s/factories_info/scheme_specific_factory_infos/
    Rationale for the changes above:
    - Making it more explicit that these factories are keyed by a scheme
    - Differentiating the name from |initiator_specific_factories| that
      is planned to be introduced in a follow-up CL
      (https://crrev.com/c/1228478).

- Introducing URLLoaderFactoryBundle::SchemeMap
- Introducing URLLoaderFactoryBundleInfo::SchemeMap
- Fixes for some of issues reported by: git cl lint
- Removing URLLoaderFactoryBundle::RegisterFactory that had no callers.
- Making URLLoaderFactoryBundle::GetFactoryForURL protected
  (it used to be unnecessarily public)
- Having ChildURLLoaderFactoryBundle delegate to its base class
  (URLLoaderFactoryBundle) in its implementation of GetFactoryForURL
  and CreateLoaderAndStart methods.

There are no intended behavior changes in this CL
(well except skipping a DCHECK in GetFactoryForURL method so that
the method can be reused by subclasses with more relaxed invariants).

Bug: 846346
Change-Id: Ibbd07debaf518e2b71cf09a2fd92c8b8104b7411
Reviewed-on: https://chromium-review.googlesource.com/1227135Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593316}
parent ea971cb0
...@@ -4018,7 +4018,7 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -4018,7 +4018,7 @@ void RenderFrameHostImpl::CommitNavigation(
} else { } else {
// This is a webui scheme that doesn't have webui bindings. Give it // This is a webui scheme that doesn't have webui bindings. Give it
// access to the network loader as it might require it. // access to the network loader as it might require it.
subresource_loader_factories->factories_info().emplace( subresource_loader_factories->scheme_specific_factory_infos().emplace(
scheme, factory_for_webui.PassInterface()); scheme, factory_for_webui.PassInterface());
} }
} }
...@@ -4083,7 +4083,7 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -4083,7 +4083,7 @@ void RenderFrameHostImpl::CommitNavigation(
this, false /* is_navigation */, false /* is_download */, this, false /* is_navigation */, false /* is_download */,
&factory_request); &factory_request);
factory.second->Clone(std::move(factory_request)); factory.second->Clone(std::move(factory_request));
subresource_loader_factories->factories_info().emplace( subresource_loader_factories->scheme_specific_factory_infos().emplace(
factory.first, std::move(factory_proxy_info)); factory.first, std::move(factory_proxy_info));
} }
} }
...@@ -4212,8 +4212,7 @@ void RenderFrameHostImpl::FailedNavigation( ...@@ -4212,8 +4212,7 @@ void RenderFrameHostImpl::FailedNavigation(
common_params.url, mojo::MakeRequest(&default_factory_info)); common_params.url, mojo::MakeRequest(&default_factory_info));
subresource_loader_factories = std::make_unique<URLLoaderFactoryBundleInfo>( subresource_loader_factories = std::make_unique<URLLoaderFactoryBundleInfo>(
std::move(default_factory_info), std::move(default_factory_info),
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>(), URLLoaderFactoryBundleInfo::SchemeMap(), bypass_redirect_checks);
bypass_redirect_checks);
} }
SaveSubresourceFactories(std::move(subresource_loader_factories)); SaveSubresourceFactories(std::move(subresource_loader_factories));
...@@ -4756,8 +4755,7 @@ void RenderFrameHostImpl::UpdateSubresourceLoaderFactories() { ...@@ -4756,8 +4755,7 @@ void RenderFrameHostImpl::UpdateSubresourceLoaderFactories() {
std::unique_ptr<URLLoaderFactoryBundleInfo> subresource_loader_factories = std::unique_ptr<URLLoaderFactoryBundleInfo> subresource_loader_factories =
std::make_unique<URLLoaderFactoryBundleInfo>( std::make_unique<URLLoaderFactoryBundleInfo>(
std::move(default_factory_info), std::move(default_factory_info),
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>(), URLLoaderFactoryBundleInfo::SchemeMap(), bypass_redirect_checks);
bypass_redirect_checks);
SaveSubresourceFactories(std::move(subresource_loader_factories)); SaveSubresourceFactories(std::move(subresource_loader_factories));
GetNavigationControl()->UpdateSubresourceLoaderFactories( GetNavigationControl()->UpdateSubresourceLoaderFactories(
CloneSubresourceFactories()); CloneSubresourceFactories());
......
...@@ -90,13 +90,13 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle( ...@@ -90,13 +90,13 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
factory_bundle->default_factory_info() = std::move(default_factory_info); factory_bundle->default_factory_info() = std::move(default_factory_info);
if (use_non_network_factories) { if (use_non_network_factories) {
ContentBrowserClient::NonNetworkURLLoaderFactoryMap factories; ContentBrowserClient::NonNetworkURLLoaderFactoryMap non_network_factories;
GetContentClient() GetContentClient()
->browser() ->browser()
->RegisterNonNetworkSubresourceURLLoaderFactories( ->RegisterNonNetworkSubresourceURLLoaderFactories(
rph->GetID(), MSG_ROUTING_NONE, &factories); rph->GetID(), MSG_ROUTING_NONE, &non_network_factories);
for (auto& pair : factories) { for (auto& pair : non_network_factories) {
const std::string& scheme = pair.first; const std::string& scheme = pair.first;
std::unique_ptr<network::mojom::URLLoaderFactory> factory = std::unique_ptr<network::mojom::URLLoaderFactory> factory =
std::move(pair.second); std::move(pair.second);
...@@ -108,8 +108,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle( ...@@ -108,8 +108,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
network::mojom::URLLoaderFactoryPtr factory_ptr; network::mojom::URLLoaderFactoryPtr factory_ptr;
mojo::MakeStrongBinding(std::move(factory), mojo::MakeStrongBinding(std::move(factory),
mojo::MakeRequest(&factory_ptr)); mojo::MakeRequest(&factory_ptr));
factory_bundle->factories_info().emplace(scheme, factory_bundle->scheme_specific_factory_infos().emplace(
factory_ptr.PassInterface()); scheme, factory_ptr.PassInterface());
} }
} }
return factory_bundle; return factory_bundle;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
...@@ -66,14 +67,14 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle( ...@@ -66,14 +67,14 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
bool file_support) { bool file_support) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ContentBrowserClient::NonNetworkURLLoaderFactoryMap factories; ContentBrowserClient::NonNetworkURLLoaderFactoryMap non_network_factories;
GetContentClient() GetContentClient()
->browser() ->browser()
->RegisterNonNetworkSubresourceURLLoaderFactories( ->RegisterNonNetworkSubresourceURLLoaderFactories(
process_id, MSG_ROUTING_NONE, &factories); process_id, MSG_ROUTING_NONE, &non_network_factories);
auto factory_bundle = std::make_unique<URLLoaderFactoryBundleInfo>(); auto factory_bundle = std::make_unique<URLLoaderFactoryBundleInfo>();
for (auto& pair : factories) { for (auto& pair : non_network_factories) {
const std::string& scheme = pair.first; const std::string& scheme = pair.first;
std::unique_ptr<network::mojom::URLLoaderFactory> factory = std::unique_ptr<network::mojom::URLLoaderFactory> factory =
std::move(pair.second); std::move(pair.second);
...@@ -81,8 +82,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle( ...@@ -81,8 +82,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
network::mojom::URLLoaderFactoryPtr factory_ptr; network::mojom::URLLoaderFactoryPtr factory_ptr;
mojo::MakeStrongBinding(std::move(factory), mojo::MakeStrongBinding(std::move(factory),
mojo::MakeRequest(&factory_ptr)); mojo::MakeRequest(&factory_ptr));
factory_bundle->factories_info().emplace(scheme, factory_bundle->scheme_specific_factory_infos().emplace(
factory_ptr.PassInterface()); scheme, factory_ptr.PassInterface());
} }
if (file_support) { if (file_support) {
...@@ -94,8 +95,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle( ...@@ -94,8 +95,8 @@ std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
network::mojom::URLLoaderFactoryPtr file_factory_ptr; network::mojom::URLLoaderFactoryPtr file_factory_ptr;
mojo::MakeStrongBinding(std::move(file_factory), mojo::MakeStrongBinding(std::move(file_factory),
mojo::MakeRequest(&file_factory_ptr)); mojo::MakeRequest(&file_factory_ptr));
factory_bundle->factories_info().emplace(url::kFileScheme, factory_bundle->scheme_specific_factory_infos().emplace(
file_factory_ptr.PassInterface()); url::kFileScheme, file_factory_ptr.PassInterface());
} }
return factory_bundle; return factory_bundle;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/common/url_loader_factory_bundle.h" #include "content/common/url_loader_factory_bundle.h"
#include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -13,11 +15,10 @@ URLLoaderFactoryBundleInfo::URLLoaderFactoryBundleInfo() = default; ...@@ -13,11 +15,10 @@ URLLoaderFactoryBundleInfo::URLLoaderFactoryBundleInfo() = default;
URLLoaderFactoryBundleInfo::URLLoaderFactoryBundleInfo( URLLoaderFactoryBundleInfo::URLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
bool bypass_redirect_checks) bool bypass_redirect_checks)
: default_factory_info_(std::move(default_factory_info)), : default_factory_info_(std::move(default_factory_info)),
factories_info_(std::move(factories_info)), scheme_specific_factory_infos_(std::move(scheme_specific_factory_infos)),
bypass_redirect_checks_(bypass_redirect_checks) {} bypass_redirect_checks_(bypass_redirect_checks) {}
URLLoaderFactoryBundleInfo::~URLLoaderFactoryBundleInfo() = default; URLLoaderFactoryBundleInfo::~URLLoaderFactoryBundleInfo() = default;
...@@ -26,7 +27,8 @@ scoped_refptr<network::SharedURLLoaderFactory> ...@@ -26,7 +27,8 @@ scoped_refptr<network::SharedURLLoaderFactory>
URLLoaderFactoryBundleInfo::CreateFactory() { URLLoaderFactoryBundleInfo::CreateFactory() {
auto other = std::make_unique<URLLoaderFactoryBundleInfo>(); auto other = std::make_unique<URLLoaderFactoryBundleInfo>();
other->default_factory_info_ = std::move(default_factory_info_); other->default_factory_info_ = std::move(default_factory_info_);
other->factories_info_ = std::move(factories_info_); other->scheme_specific_factory_infos_ =
std::move(scheme_specific_factory_infos_);
other->bypass_redirect_checks_ = bypass_redirect_checks_; other->bypass_redirect_checks_ = bypass_redirect_checks_;
return base::MakeRefCounted<URLLoaderFactoryBundle>(std::move(other)); return base::MakeRefCounted<URLLoaderFactoryBundle>(std::move(other));
...@@ -48,22 +50,13 @@ void URLLoaderFactoryBundle::SetDefaultFactory( ...@@ -48,22 +50,13 @@ void URLLoaderFactoryBundle::SetDefaultFactory(
default_factory_ = std::move(factory); default_factory_ = std::move(factory);
} }
void URLLoaderFactoryBundle::RegisterFactory(
const base::StringPiece& scheme,
network::mojom::URLLoaderFactoryPtr factory) {
DCHECK(factory.is_bound());
auto result = factories_.emplace(std::string(scheme), std::move(factory));
DCHECK(result.second);
}
network::mojom::URLLoaderFactory* URLLoaderFactoryBundle::GetFactoryForURL( network::mojom::URLLoaderFactory* URLLoaderFactoryBundle::GetFactoryForURL(
const GURL& url) { const GURL& url) {
auto it = factories_.find(url.scheme()); auto it = scheme_specific_factories_.find(url.scheme());
if (it == factories_.end()) { if (it != scheme_specific_factories_.end())
DCHECK(default_factory_.is_bound()); return it->second.get();
return default_factory_.get();
} return default_factory_.get();
return it->second.get();
} }
void URLLoaderFactoryBundle::CreateLoaderAndStart( void URLLoaderFactoryBundle::CreateLoaderAndStart(
...@@ -92,15 +85,16 @@ URLLoaderFactoryBundle::Clone() { ...@@ -92,15 +85,16 @@ URLLoaderFactoryBundle::Clone() {
if (default_factory_) if (default_factory_)
default_factory_->Clone(mojo::MakeRequest(&default_factory_info)); default_factory_->Clone(mojo::MakeRequest(&default_factory_info));
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> factories_info; URLLoaderFactoryBundleInfo::SchemeMap scheme_specific_factory_infos;
for (auto& factory : factories_) { for (auto& factory : scheme_specific_factories_) {
network::mojom::URLLoaderFactoryPtrInfo factory_info; network::mojom::URLLoaderFactoryPtrInfo factory_info;
factory.second->Clone(mojo::MakeRequest(&factory_info)); factory.second->Clone(mojo::MakeRequest(&factory_info));
factories_info.emplace(factory.first, std::move(factory_info)); scheme_specific_factory_infos.emplace(factory.first,
std::move(factory_info));
} }
return std::make_unique<URLLoaderFactoryBundleInfo>( return std::make_unique<URLLoaderFactoryBundleInfo>(
std::move(default_factory_info), std::move(factories_info), std::move(default_factory_info), std::move(scheme_specific_factory_infos),
bypass_redirect_checks_); bypass_redirect_checks_);
} }
...@@ -112,8 +106,9 @@ void URLLoaderFactoryBundle::Update( ...@@ -112,8 +106,9 @@ void URLLoaderFactoryBundle::Update(
std::unique_ptr<URLLoaderFactoryBundleInfo> info) { std::unique_ptr<URLLoaderFactoryBundleInfo> info) {
if (info->default_factory_info()) if (info->default_factory_info())
default_factory_.Bind(std::move(info->default_factory_info())); default_factory_.Bind(std::move(info->default_factory_info()));
for (auto& factory_info : info->factories_info()) for (auto& factory_info : info->scheme_specific_factory_infos())
factories_[factory_info.first].Bind(std::move(factory_info.second)); scheme_specific_factories_[factory_info.first].Bind(
std::move(factory_info.second));
bypass_redirect_checks_ = info->bypass_redirect_checks(); bypass_redirect_checks_ = info->bypass_redirect_checks();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_H_ #define CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_H_
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
...@@ -22,11 +23,16 @@ namespace content { ...@@ -22,11 +23,16 @@ namespace content {
class CONTENT_EXPORT URLLoaderFactoryBundleInfo class CONTENT_EXPORT URLLoaderFactoryBundleInfo
: public network::SharedURLLoaderFactoryInfo { : public network::SharedURLLoaderFactoryInfo {
public: public:
// Map from URL scheme to URLLoaderFactoryPtrInfo for handling URL requests
// for schemes not handled by the |default_factory_info|. See also
// URLLoaderFactoryBundle::SchemeMap.
using SchemeMap =
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>;
URLLoaderFactoryBundleInfo(); URLLoaderFactoryBundleInfo();
URLLoaderFactoryBundleInfo( URLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
bool bypass_redirect_checks); bool bypass_redirect_checks);
~URLLoaderFactoryBundleInfo() override; ~URLLoaderFactoryBundleInfo() override;
...@@ -34,9 +40,8 @@ class CONTENT_EXPORT URLLoaderFactoryBundleInfo ...@@ -34,9 +40,8 @@ class CONTENT_EXPORT URLLoaderFactoryBundleInfo
return default_factory_info_; return default_factory_info_;
} }
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>& SchemeMap& scheme_specific_factory_infos() {
factories_info() { return scheme_specific_factory_infos_;
return factories_info_;
} }
bool bypass_redirect_checks() const { return bypass_redirect_checks_; } bool bypass_redirect_checks() const { return bypass_redirect_checks_; }
...@@ -49,8 +54,7 @@ class CONTENT_EXPORT URLLoaderFactoryBundleInfo ...@@ -49,8 +54,7 @@ class CONTENT_EXPORT URLLoaderFactoryBundleInfo
scoped_refptr<network::SharedURLLoaderFactory> CreateFactory() override; scoped_refptr<network::SharedURLLoaderFactory> CreateFactory() override;
network::mojom::URLLoaderFactoryPtrInfo default_factory_info_; network::mojom::URLLoaderFactoryPtrInfo default_factory_info_;
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos_;
factories_info_;
bool bypass_redirect_checks_ = false; bool bypass_redirect_checks_ = false;
DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryBundleInfo); DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryBundleInfo);
...@@ -70,15 +74,6 @@ class CONTENT_EXPORT URLLoaderFactoryBundle ...@@ -70,15 +74,6 @@ class CONTENT_EXPORT URLLoaderFactoryBundle
// |url|. // |url|.
void SetDefaultFactory(network::mojom::URLLoaderFactoryPtr factory); void SetDefaultFactory(network::mojom::URLLoaderFactoryPtr factory);
// Registers a new factory to handle requests matching scheme |scheme|.
void RegisterFactory(const base::StringPiece& scheme,
network::mojom::URLLoaderFactoryPtr factory);
// Returns a factory which can be used to acquire a loader for |url|. If no
// registered factory matches |url|'s scheme, the default factory is used. It
// is undefined behavior to call this when no default factory is set.
virtual network::mojom::URLLoaderFactory* GetFactoryForURL(const GURL& url);
// SharedURLLoaderFactory implementation. // SharedURLLoaderFactory implementation.
void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
int32_t routing_id, int32_t routing_id,
...@@ -99,8 +94,20 @@ class CONTENT_EXPORT URLLoaderFactoryBundle ...@@ -99,8 +94,20 @@ class CONTENT_EXPORT URLLoaderFactoryBundle
protected: protected:
~URLLoaderFactoryBundle() override; ~URLLoaderFactoryBundle() override;
// Returns a factory which can be used to acquire a loader for |url|. If no
// registered factory matches |url|'s scheme, the default factory is used. It
// is undefined behavior to call this when no default factory is set.
virtual network::mojom::URLLoaderFactory* GetFactoryForURL(const GURL& url);
network::mojom::URLLoaderFactoryPtr default_factory_; network::mojom::URLLoaderFactoryPtr default_factory_;
std::map<std::string, network::mojom::URLLoaderFactoryPtr> factories_;
// Map from URL scheme to URLLoaderFactoryPtr for handling URL requests for
// schemes not handled by the |default_factory_|. See also
// URLLoaderFactoryBundleInfo::SchemeMap and
// ContentBrowserClient::SchemeToURLLoaderFactoryMap.
using SchemeMap = std::map<std::string, network::mojom::URLLoaderFactoryPtr>;
SchemeMap scheme_specific_factories_;
bool bypass_redirect_checks_ = false; bool bypass_redirect_checks_ = false;
}; };
......
...@@ -9,10 +9,13 @@ import "services/network/public/mojom/url_loader_factory.mojom"; ...@@ -9,10 +9,13 @@ import "services/network/public/mojom/url_loader_factory.mojom";
// Serializes a collection of URLLoaderFactory interfaces. // Serializes a collection of URLLoaderFactory interfaces.
struct URLLoaderFactoryBundle { struct URLLoaderFactoryBundle {
// The default factory to be used when no others apply. // The default factory to be used when no others apply.
//
// TODO(jam): https://crbug.com/887109: Remove |default_factory| and put it
// inside |scheme_specific_factories| instead.
network.mojom.URLLoaderFactory default_factory; network.mojom.URLLoaderFactory default_factory;
// A mapping from URL scheme to factory interface. // A mapping from URL scheme to factory interface.
map<string, network.mojom.URLLoaderFactory> factories; map<string, network.mojom.URLLoaderFactory> scheme_specific_factories;
// Whether redirect checks should be bypassed, since they are happening in the // Whether redirect checks should be bypassed, since they are happening in the
// browser. // browser.
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "content/common/url_loader_factory_bundle_struct_traits.h" #include "content/common/url_loader_factory_bundle_struct_traits.h"
#include <memory>
#include <utility>
namespace mojo { namespace mojo {
using Traits = using Traits =
...@@ -17,9 +20,9 @@ network::mojom::URLLoaderFactoryPtrInfo Traits::default_factory( ...@@ -17,9 +20,9 @@ network::mojom::URLLoaderFactoryPtrInfo Traits::default_factory(
} }
// static // static
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> content::URLLoaderFactoryBundleInfo::SchemeMap
Traits::factories(BundleInfoType& bundle) { Traits::scheme_specific_factories(BundleInfoType& bundle) {
return std::move(bundle->factories_info()); return std::move(bundle->scheme_specific_factory_infos());
} }
// static // static
...@@ -34,7 +37,8 @@ bool Traits::Read(content::mojom::URLLoaderFactoryBundleDataView data, ...@@ -34,7 +37,8 @@ bool Traits::Read(content::mojom::URLLoaderFactoryBundleDataView data,
(*out_bundle)->default_factory_info() = (*out_bundle)->default_factory_info() =
data.TakeDefaultFactory<network::mojom::URLLoaderFactoryPtrInfo>(); data.TakeDefaultFactory<network::mojom::URLLoaderFactoryPtrInfo>();
if (!data.ReadFactories(&(*out_bundle)->factories_info())) if (!data.ReadSchemeSpecificFactories(
&(*out_bundle)->scheme_specific_factory_infos()))
return false; return false;
(*out_bundle)->set_bypass_redirect_checks(data.bypass_redirect_checks()); (*out_bundle)->set_bypass_redirect_checks(data.bypass_redirect_checks());
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_STRUCT_TRAITS_H_ #ifndef CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_STRUCT_TRAITS_H_
#define CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_STRUCT_TRAITS_H_ #define CONTENT_COMMON_URL_LOADER_FACTORY_BUNDLE_STRUCT_TRAITS_H_
#include <memory>
#include "content/common/url_loader_factory_bundle.h" #include "content/common/url_loader_factory_bundle.h"
#include "content/common/url_loader_factory_bundle.mojom-shared.h" #include "content/common/url_loader_factory_bundle.mojom-shared.h"
#include "mojo/public/cpp/bindings/struct_traits.h" #include "mojo/public/cpp/bindings/struct_traits.h"
...@@ -23,8 +25,8 @@ struct StructTraits<content::mojom::URLLoaderFactoryBundleDataView, ...@@ -23,8 +25,8 @@ struct StructTraits<content::mojom::URLLoaderFactoryBundleDataView,
static network::mojom::URLLoaderFactoryPtrInfo default_factory( static network::mojom::URLLoaderFactoryPtrInfo default_factory(
BundleInfoType& bundle); BundleInfoType& bundle);
static std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> static content::URLLoaderFactoryBundleInfo::SchemeMap
factories(BundleInfoType& bundle); scheme_specific_factories(BundleInfoType& bundle);
static bool bypass_redirect_checks(BundleInfoType& bundle); static bool bypass_redirect_checks(BundleInfoType& bundle);
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#include "content/renderer/loader/child_url_loader_factory_bundle.h" #include "content/renderer/loader/child_url_loader_factory_bundle.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -95,18 +100,18 @@ ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo() = default; ...@@ -95,18 +100,18 @@ ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo() = default;
ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo( ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo(
std::unique_ptr<URLLoaderFactoryBundleInfo> base_info) std::unique_ptr<URLLoaderFactoryBundleInfo> base_info)
: URLLoaderFactoryBundleInfo(std::move(base_info->default_factory_info()), : URLLoaderFactoryBundleInfo(
std::move(base_info->factories_info()), std::move(base_info->default_factory_info()),
base_info->bypass_redirect_checks()) {} std::move(base_info->scheme_specific_factory_infos()),
base_info->bypass_redirect_checks()) {}
ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo( ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
bool bypass_redirect_checks) bool bypass_redirect_checks)
: URLLoaderFactoryBundleInfo(std::move(default_factory_info), : URLLoaderFactoryBundleInfo(std::move(default_factory_info),
std::move(factories_info), std::move(scheme_specific_factory_infos),
bypass_redirect_checks), bypass_redirect_checks),
direct_network_factory_info_(std::move(direct_network_factory_info)) {} direct_network_factory_info_(std::move(direct_network_factory_info)) {}
...@@ -116,7 +121,8 @@ scoped_refptr<network::SharedURLLoaderFactory> ...@@ -116,7 +121,8 @@ scoped_refptr<network::SharedURLLoaderFactory>
ChildURLLoaderFactoryBundleInfo::CreateFactory() { ChildURLLoaderFactoryBundleInfo::CreateFactory() {
auto other = std::make_unique<ChildURLLoaderFactoryBundleInfo>(); auto other = std::make_unique<ChildURLLoaderFactoryBundleInfo>();
other->default_factory_info_ = std::move(default_factory_info_); other->default_factory_info_ = std::move(default_factory_info_);
other->factories_info_ = std::move(factories_info_); other->scheme_specific_factory_infos_ =
std::move(scheme_specific_factory_infos_);
other->direct_network_factory_info_ = std::move(direct_network_factory_info_); other->direct_network_factory_info_ = std::move(direct_network_factory_info_);
other->bypass_redirect_checks_ = bypass_redirect_checks_; other->bypass_redirect_checks_ = bypass_redirect_checks_;
...@@ -141,12 +147,10 @@ ChildURLLoaderFactoryBundle::~ChildURLLoaderFactoryBundle() = default; ...@@ -141,12 +147,10 @@ ChildURLLoaderFactoryBundle::~ChildURLLoaderFactoryBundle() = default;
network::mojom::URLLoaderFactory* ChildURLLoaderFactoryBundle::GetFactoryForURL( network::mojom::URLLoaderFactory* ChildURLLoaderFactoryBundle::GetFactoryForURL(
const GURL& url) { const GURL& url) {
auto it = factories_.find(url.scheme()); network::mojom::URLLoaderFactory* base_result =
if (it != factories_.end()) URLLoaderFactoryBundle::GetFactoryForURL(url);
return it->second.get(); if (base_result)
return base_result;
if (default_factory_)
return default_factory_.get();
InitDirectNetworkFactoryIfNecessary(); InitDirectNetworkFactoryIfNecessary();
DCHECK(direct_network_factory_); DCHECK(direct_network_factory_);
...@@ -179,11 +183,9 @@ void ChildURLLoaderFactoryBundle::CreateLoaderAndStart( ...@@ -179,11 +183,9 @@ void ChildURLLoaderFactoryBundle::CreateLoaderAndStart(
return; return;
} }
network::mojom::URLLoaderFactory* factory_ptr = GetFactoryForURL(request.url); URLLoaderFactoryBundle::CreateLoaderAndStart(
std::move(loader), routing_id, request_id, options, request,
factory_ptr->CreateLoaderAndStart(std::move(loader), routing_id, request_id, std::move(client), traffic_annotation);
options, request, std::move(client),
traffic_annotation);
} }
std::unique_ptr<network::SharedURLLoaderFactoryInfo> std::unique_ptr<network::SharedURLLoaderFactoryInfo>
...@@ -236,11 +238,12 @@ ChildURLLoaderFactoryBundle::CloneInternal(bool include_default) { ...@@ -236,11 +238,12 @@ ChildURLLoaderFactoryBundle::CloneInternal(bool include_default) {
if (include_default && default_factory_) if (include_default && default_factory_)
default_factory_->Clone(mojo::MakeRequest(&default_factory_info)); default_factory_->Clone(mojo::MakeRequest(&default_factory_info));
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> factories_info; URLLoaderFactoryBundleInfo::SchemeMap scheme_specific_factory_infos;
for (auto& factory : factories_) { for (auto& factory : scheme_specific_factories_) {
network::mojom::URLLoaderFactoryPtrInfo factory_info; network::mojom::URLLoaderFactoryPtrInfo factory_info;
factory.second->Clone(mojo::MakeRequest(&factory_info)); factory.second->Clone(mojo::MakeRequest(&factory_info));
factories_info.emplace(factory.first, std::move(factory_info)); scheme_specific_factory_infos.emplace(factory.first,
std::move(factory_info));
} }
network::mojom::URLLoaderFactoryPtrInfo direct_network_factory_info; network::mojom::URLLoaderFactoryPtrInfo direct_network_factory_info;
...@@ -253,7 +256,7 @@ ChildURLLoaderFactoryBundle::CloneInternal(bool include_default) { ...@@ -253,7 +256,7 @@ ChildURLLoaderFactoryBundle::CloneInternal(bool include_default) {
// therefore |subresource_overrides| are not shared with the clones. // therefore |subresource_overrides| are not shared with the clones.
return std::make_unique<ChildURLLoaderFactoryBundleInfo>( return std::make_unique<ChildURLLoaderFactoryBundleInfo>(
std::move(default_factory_info), std::move(factories_info), std::move(default_factory_info), std::move(scheme_specific_factory_infos),
std::move(direct_network_factory_info), bypass_redirect_checks_); std::move(direct_network_factory_info), bypass_redirect_checks_);
} }
...@@ -265,9 +268,10 @@ ChildURLLoaderFactoryBundle::PassInterface() { ...@@ -265,9 +268,10 @@ ChildURLLoaderFactoryBundle::PassInterface() {
if (default_factory_) if (default_factory_)
default_factory_info = default_factory_.PassInterface(); default_factory_info = default_factory_.PassInterface();
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> factories_info; URLLoaderFactoryBundleInfo::SchemeMap scheme_specific_factory_infos;
for (auto& factory : factories_) { for (auto& factory : scheme_specific_factories_) {
factories_info.emplace(factory.first, factory.second.PassInterface()); scheme_specific_factory_infos.emplace(factory.first,
factory.second.PassInterface());
} }
PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory> PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>
...@@ -277,7 +281,7 @@ ChildURLLoaderFactoryBundle::PassInterface() { ...@@ -277,7 +281,7 @@ ChildURLLoaderFactoryBundle::PassInterface() {
} }
return std::make_unique<ChildURLLoaderFactoryBundleInfo>( return std::make_unique<ChildURLLoaderFactoryBundleInfo>(
std::move(default_factory_info), std::move(factories_info), std::move(default_factory_info), std::move(scheme_specific_factory_infos),
std::move(direct_network_factory_info), bypass_redirect_checks_); std::move(direct_network_factory_info), bypass_redirect_checks_);
} }
......
...@@ -5,7 +5,12 @@ ...@@ -5,7 +5,12 @@
#ifndef CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #ifndef CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
#define CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #define CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
#include <map>
#include <memory>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/optional.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/possibly_associated_interface_ptr.h" #include "content/common/possibly_associated_interface_ptr.h"
#include "content/common/url_loader_factory_bundle.h" #include "content/common/url_loader_factory_bundle.h"
...@@ -27,8 +32,7 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundleInfo ...@@ -27,8 +32,7 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundleInfo
std::unique_ptr<URLLoaderFactoryBundleInfo> base_info); std::unique_ptr<URLLoaderFactoryBundleInfo> base_info);
ChildURLLoaderFactoryBundleInfo( ChildURLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
bool bypass_redirect_checks); bool bypass_redirect_checks);
~ChildURLLoaderFactoryBundleInfo() override; ~ChildURLLoaderFactoryBundleInfo() override;
...@@ -70,8 +74,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle ...@@ -70,8 +74,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle
PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter); PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter);
// URLLoaderFactoryBundle overrides. // URLLoaderFactoryBundle overrides.
network::mojom::URLLoaderFactory* GetFactoryForURL(const GURL& url) override;
void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
int32_t routing_id, int32_t routing_id,
int32_t request_id, int32_t request_id,
...@@ -80,7 +82,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle ...@@ -80,7 +82,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle
network::mojom::URLLoaderClientPtr client, network::mojom::URLLoaderClientPtr client,
const net::MutableNetworkTrafficAnnotationTag& const net::MutableNetworkTrafficAnnotationTag&
traffic_annotation) override; traffic_annotation) override;
std::unique_ptr<network::SharedURLLoaderFactoryInfo> Clone() override; std::unique_ptr<network::SharedURLLoaderFactoryInfo> Clone() override;
// Returns an info that omits this bundle's default factory, if any. This is // Returns an info that omits this bundle's default factory, if any. This is
...@@ -99,6 +100,9 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle ...@@ -99,6 +100,9 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle
protected: protected:
~ChildURLLoaderFactoryBundle() override; ~ChildURLLoaderFactoryBundle() override;
// URLLoaderFactoryBundle overrides.
network::mojom::URLLoaderFactory* GetFactoryForURL(const GURL& url) override;
private: private:
void InitDirectNetworkFactoryIfNecessary(); void InitDirectNetworkFactoryIfNecessary();
std::unique_ptr<network::SharedURLLoaderFactoryInfo> CloneInternal( std::unique_ptr<network::SharedURLLoaderFactoryInfo> CloneInternal(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/renderer/loader/tracked_child_url_loader_factory_bundle.h" #include "content/renderer/loader/tracked_child_url_loader_factory_bundle.h"
#include <utility>
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
namespace content { namespace content {
...@@ -13,13 +15,12 @@ TrackedChildURLLoaderFactoryBundleInfo:: ...@@ -13,13 +15,12 @@ TrackedChildURLLoaderFactoryBundleInfo::
TrackedChildURLLoaderFactoryBundleInfo::TrackedChildURLLoaderFactoryBundleInfo( TrackedChildURLLoaderFactoryBundleInfo::TrackedChildURLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle, std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle,
bool bypass_redirect_checks) bool bypass_redirect_checks)
: ChildURLLoaderFactoryBundleInfo(std::move(default_factory_info), : ChildURLLoaderFactoryBundleInfo(std::move(default_factory_info),
std::move(factories_info), std::move(scheme_specific_factory_infos),
std::move(direct_network_factory_info), std::move(direct_network_factory_info),
bypass_redirect_checks), bypass_redirect_checks),
main_thread_host_bundle_(std::move(main_thread_host_bundle)) {} main_thread_host_bundle_(std::move(main_thread_host_bundle)) {}
...@@ -31,7 +32,8 @@ scoped_refptr<network::SharedURLLoaderFactory> ...@@ -31,7 +32,8 @@ scoped_refptr<network::SharedURLLoaderFactory>
TrackedChildURLLoaderFactoryBundleInfo::CreateFactory() { TrackedChildURLLoaderFactoryBundleInfo::CreateFactory() {
auto other = std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(); auto other = std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>();
other->default_factory_info_ = std::move(default_factory_info_); other->default_factory_info_ = std::move(default_factory_info_);
other->factories_info_ = std::move(factories_info_); other->scheme_specific_factory_infos_ =
std::move(scheme_specific_factory_infos_);
other->direct_network_factory_info_ = std::move(direct_network_factory_info_); other->direct_network_factory_info_ = std::move(direct_network_factory_info_);
other->main_thread_host_bundle_ = std::move(main_thread_host_bundle_); other->main_thread_host_bundle_ = std::move(main_thread_host_bundle_);
other->bypass_redirect_checks_ = bypass_redirect_checks_; other->bypass_redirect_checks_ = bypass_redirect_checks_;
...@@ -52,7 +54,7 @@ TrackedChildURLLoaderFactoryBundle::TrackedChildURLLoaderFactoryBundle( ...@@ -52,7 +54,7 @@ TrackedChildURLLoaderFactoryBundle::TrackedChildURLLoaderFactoryBundle(
TrackedChildURLLoaderFactoryBundle::~TrackedChildURLLoaderFactoryBundle() { TrackedChildURLLoaderFactoryBundle::~TrackedChildURLLoaderFactoryBundle() {
RemoveObserverOnMainThread(); RemoveObserverOnMainThread();
}; }
std::unique_ptr<network::SharedURLLoaderFactoryInfo> std::unique_ptr<network::SharedURLLoaderFactoryInfo>
TrackedChildURLLoaderFactoryBundle::Clone() { TrackedChildURLLoaderFactoryBundle::Clone() {
...@@ -66,7 +68,7 @@ TrackedChildURLLoaderFactoryBundle::Clone() { ...@@ -66,7 +68,7 @@ TrackedChildURLLoaderFactoryBundle::Clone() {
return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(
std::move(info->default_factory_info()), std::move(info->default_factory_info()),
std::move(info->factories_info()), std::move(info->scheme_specific_factory_infos()),
std::move(info->direct_network_factory_info()), std::move(info->direct_network_factory_info()),
std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks());
} }
...@@ -129,7 +131,7 @@ HostChildURLLoaderFactoryBundle::Clone() { ...@@ -129,7 +131,7 @@ HostChildURLLoaderFactoryBundle::Clone() {
return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(
std::move(info->default_factory_info()), std::move(info->default_factory_info()),
std::move(info->factories_info()), std::move(info->scheme_specific_factory_infos()),
std::move(info->direct_network_factory_info()), std::move(info->direct_network_factory_info()),
std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks());
} }
...@@ -146,7 +148,7 @@ HostChildURLLoaderFactoryBundle::CloneWithoutDefaultFactory() { ...@@ -146,7 +148,7 @@ HostChildURLLoaderFactoryBundle::CloneWithoutDefaultFactory() {
return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(
std::move(info->default_factory_info()), std::move(info->default_factory_info()),
std::move(info->factories_info()), std::move(info->scheme_specific_factory_infos()),
std::move(info->direct_network_factory_info()), std::move(info->direct_network_factory_info()),
std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks());
} }
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#ifndef CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #ifndef CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
#define CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #define CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
#include <memory>
#include <unordered_map>
#include <utility>
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/renderer/loader/child_url_loader_factory_bundle.h" #include "content/renderer/loader/child_url_loader_factory_bundle.h"
...@@ -25,8 +29,7 @@ class CONTENT_EXPORT TrackedChildURLLoaderFactoryBundleInfo ...@@ -25,8 +29,7 @@ class CONTENT_EXPORT TrackedChildURLLoaderFactoryBundleInfo
TrackedChildURLLoaderFactoryBundleInfo(); TrackedChildURLLoaderFactoryBundleInfo();
TrackedChildURLLoaderFactoryBundleInfo( TrackedChildURLLoaderFactoryBundleInfo(
network::mojom::URLLoaderFactoryPtrInfo default_factory_info, network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> SchemeMap scheme_specific_factory_infos,
factories_info,
PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle, std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle,
bool bypass_redirect_checks); bool bypass_redirect_checks);
......
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