Allow non-content code use FileURLLoaderFactory
This CL exposes a method that allows the creation of FileURLLoaderFactory
instances. through the content/browser public API.
This is a preparation for CL https://crrev.com/c/1066370.
BUG=773295,844928
Change-Id: I89c9cd2e82ee54f4dae1c121d5e0f7b5c0597fb1
Reviewed-on: https://chromium-review.googlesource.com/1156885
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579818}
diff --git a/content/browser/file_url_loader_factory.cc b/content/browser/file_url_loader_factory.cc
index 822e0a0..25c2df3 100644
--- a/content/browser/file_url_loader_factory.cc
+++ b/content/browser/file_url_loader_factory.cc
@@ -684,4 +684,12 @@
std::move(extra_response_headers)));
}
+std::unique_ptr<network::mojom::URLLoaderFactory> CreateFileURLLoaderFactory(
+ const base::FilePath& profile_path) {
+ return std::make_unique<content::FileURLLoaderFactory>(
+ profile_path, base::CreateSequencedTaskRunnerWithTraits(
+ {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
+ base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
+}
+
} // namespace content
diff --git a/content/public/browser/file_url_loader.h b/content/public/browser/file_url_loader.h
index b6f0f24..1f06a8f 100644
--- a/content/public/browser/file_url_loader.h
+++ b/content/public/browser/file_url_loader.h
@@ -13,6 +13,12 @@
#include "net/http/http_response_headers.h"
#include "services/network/public/mojom/url_loader.mojom.h"
+namespace network {
+namespace mojom {
+class URLLoaderFactory;
+}
+} // namespace network
+
namespace content {
class CONTENT_EXPORT FileURLLoaderObserver
@@ -47,6 +53,15 @@
std::unique_ptr<FileURLLoaderObserver> observer,
scoped_refptr<net::HttpResponseHeaders> extra_response_headers = nullptr);
+// Helper to create a FileURLLoaderFactory instance. This exposes the ability
+// to load file:// URLs through SimpleURLLoader to non-content classes.
+//
+// When non-empty, |profile_path| is used to whitelist specific directories on
+// ChromeOS and Android. It is checked by
+// ContentBrowserClient::IsFileAccessAllowed.
+CONTENT_EXPORT std::unique_ptr<network::mojom::URLLoaderFactory>
+CreateFileURLLoaderFactory(const base::FilePath& profile_path);
+
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_FILE_URL_LOADER_H_