Commit 44a0f9e1 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Make (SpecialAccess)FileURLLoaderFactory always owned by its receivers_

This CL renames the FileURLLoaderFactory in an anonymous namespace in
//chrome/browser/chrome_content_browser_client.cc to
SpecialAccessFileURLLoaderFactory (to distinguish it from the
content::FileURLLoaderFactory).

This CL introduces SpecialAccessFileURLLoaderFactory::Create static
method that allows creating a SpecialAccessFileURLLoaderFactory that is
owned by its |receivers_| and will self-delete when the last receiver
disconnects.

This CL removes the ability to directly construct and own a
std::unique_ptr<SpecialAccessFileURLLoaderFactory>, because this ability
means that the factory can be destructed while receivers bound via the
Clone method are still alive (see the associated bug).

This CL mostly just follows the pattern established earlier by
https://crrev.com/c/2337411.

Bug: 1106995
Change-Id: If5d9731ceee4d62144e12c18f67dda7df4379b0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358058Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812071}
parent 6ac9b1c6
......@@ -287,6 +287,7 @@
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/non_network_url_loader_factory_base.h"
#include "content/public/browser/overlay_window.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
......@@ -4524,13 +4525,37 @@ void ChromeContentBrowserClient::
namespace {
// The FileURLLoaderFactory provided to the extension background pages.
// Checks with the ChildProcessSecurityPolicy to validate the file access.
class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
// The SpecialAccessFileURLLoaderFactory provided to the extension background
// pages. Checks with the ChildProcessSecurityPolicy to validate the file
// access.
class SpecialAccessFileURLLoaderFactory
: public content::NonNetworkURLLoaderFactoryBase {
public:
explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {}
// Returns mojo::PendingRemote to a newly constructed
// SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will
// delete itself once there are no more receivers (including the receiver
// associated with the returned mojo::PendingRemote and the receivers bound by
// the Clone method).
static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
int child_id) {
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
// The SpecialAccessFileURLLoaderFactory will delete itself when there are
// no more receivers - see the NonNetworkURLLoaderFactoryBase::OnDisconnect
// method.
new SpecialAccessFileURLLoaderFactory(
child_id, pending_remote.InitWithNewPipeAndPassReceiver());
return pending_remote;
}
private:
explicit SpecialAccessFileURLLoaderFactory(
int child_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
: content::NonNetworkURLLoaderFactoryBase(std::move(factory_receiver)),
child_id_(child_id) {}
// network::mojom::URLLoaderFactory:
void CreateLoaderAndStart(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
......@@ -4554,14 +4579,8 @@ class FileURLLoaderFactory : public network::mojom::URLLoaderFactory {
/* allow_directory_listing */ true);
}
void Clone(
mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override {
receivers_.Add(this, std::move(loader));
}
int child_id_;
mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory);
};
#if defined(OS_CHROMEOS)
......@@ -4701,9 +4720,9 @@ void ChromeContentBrowserClient::
extensions::ProcessManager::Get(web_contents->GetBrowserContext())
->GetBackgroundHostForExtension(extension->id());
if (host) {
uniquely_owned_factories->emplace(
factories->emplace(
url::kFileScheme,
std::make_unique<FileURLLoaderFactory>(render_process_id));
SpecialAccessFileURLLoaderFactory::Create(render_process_id));
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
}
......
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