Commit b0d8d902 authored by Tsuyoshi Horo's avatar Tsuyoshi Horo Committed by Commit Bot

Introduce WebContents::GenerateWebBundle() and skeleton WebBundler.

This CL introduces WebContents::GenerateWebBundle() method. This method
does the following:
 - Call GetResourceSnapshotForWebBundle() for each frame (the main frame
   and sub frames) to get an array of
   mojo::PendingRemote<ResourceSnapshotForWebBundle>.
 - Open a file to write to.
 - Call DataDecoderService::BindWebBundler() to get a
   mojo::Remote<WebBundler>. A WebBundler object is instantiated in the
   data decoder process.
 - Call WebBundler::Generate() with the opened file and the array of
   mojo::PendingRemote<ResourceSnapshotForWebBundle>.

This CL doesn’t implement the logic of WebBundler::Generate(). This
method just returns an error (kNotImplemented).

Bug: 1040752


Change-Id: Ia0a8ba0362cea181dcfd67bda9d42ebc00f9a4c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084042Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKunihiko Sakamoto <ksakamoto@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749427}
parent a21d7c80
...@@ -1858,6 +1858,8 @@ jumbo_source_set("browser") { ...@@ -1858,6 +1858,8 @@ jumbo_source_set("browser") {
"web_package/prefetched_signed_exchange_cache.h", "web_package/prefetched_signed_exchange_cache.h",
"web_package/prefetched_signed_exchange_cache_adapter.cc", "web_package/prefetched_signed_exchange_cache_adapter.cc",
"web_package/prefetched_signed_exchange_cache_adapter.h", "web_package/prefetched_signed_exchange_cache_adapter.h",
"web_package/save_as_web_bundle_job.cc",
"web_package/save_as_web_bundle_job.h",
"web_package/signed_exchange_cert_fetcher.cc", "web_package/signed_exchange_cert_fetcher.cc",
"web_package/signed_exchange_cert_fetcher.h", "web_package/signed_exchange_cert_fetcher.h",
"web_package/signed_exchange_cert_fetcher_factory.cc", "web_package/signed_exchange_cert_fetcher_factory.cc",
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#include "content/browser/site_instance_impl.h" #include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/javascript_dialog_navigation_deferrer.h" #include "content/browser/web_contents/javascript_dialog_navigation_deferrer.h"
#include "content/browser/web_contents/web_contents_view_child_frame.h" #include "content/browser/web_contents/web_contents_view_child_frame.h"
#include "content/browser/web_package/save_as_web_bundle_job.h"
#include "content/browser/webui/web_ui_controller_factory_registry.h" #include "content/browser/webui/web_ui_controller_factory_registry.h"
#include "content/browser/webui/web_ui_impl.h" #include "content/browser/webui/web_ui_impl.h"
#include "content/common/browser_plugin/browser_plugin_constants.h" #include "content/common/browser_plugin/browser_plugin_constants.h"
...@@ -4045,6 +4046,13 @@ void WebContentsImpl::GenerateMHTMLWithResult( ...@@ -4045,6 +4046,13 @@ void WebContentsImpl::GenerateMHTMLWithResult(
std::move(callback)); std::move(callback));
} }
void WebContentsImpl::GenerateWebBundle(
const base::FilePath& file_path,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)> callback) {
SaveAsWebBundleJob::Start(this, file_path, std::move(callback));
}
const std::string& WebContentsImpl::GetContentsMimeType() { const std::string& WebContentsImpl::GetContentsMimeType() {
return contents_mime_type_; return contents_mime_type_;
} }
......
...@@ -461,6 +461,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -461,6 +461,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
void GenerateMHTMLWithResult( void GenerateMHTMLWithResult(
const MHTMLGenerationParams& params, const MHTMLGenerationParams& params,
MHTMLGenerationResult::GenerateMHTMLCallback callback) override; MHTMLGenerationResult::GenerateMHTMLCallback callback) override;
void GenerateWebBundle(
const base::FilePath& file_path,
base::OnceCallback<void(uint64_t, data_decoder::mojom::WebBundlerError)>
callback) override;
const std::string& GetContentsMimeType() override; const std::string& GetContentsMimeType() override;
bool WillNotifyDisconnection() override; bool WillNotifyDisconnection() override;
blink::mojom::RendererPreferences* GetMutableRendererPrefs() override; blink::mojom::RendererPreferences* GetMutableRendererPrefs() override;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/web_package/save_as_web_bundle_job.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "components/download/public/common/download_task_runner.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "third_party/blink/public/mojom/frame/frame.mojom.h"
namespace content {
// static
void SaveAsWebBundleJob::Start(
WebContents* web_contents,
const base::FilePath& file_path,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)> callback) {
std::vector<
mojo::PendingRemote<data_decoder::mojom::ResourceSnapshotForWebBundle>>
snapshots;
web_contents->ForEachFrame(base::BindRepeating(
[](std::vector<mojo::PendingRemote<
data_decoder::mojom::ResourceSnapshotForWebBundle>>* snapshots,
RenderFrameHost* render_frame_host) {
mojo::Remote<data_decoder::mojom::ResourceSnapshotForWebBundle>
snapshot;
static_cast<RenderFrameHostImpl*>(render_frame_host)
->GetAssociatedLocalFrame()
->GetResourceSnapshotForWebBundle(
snapshot.BindNewPipeAndPassReceiver());
snapshots->push_back(snapshot.Unbind());
},
base::Unretained(&snapshots)));
new SaveAsWebBundleJob(file_path, std::move(snapshots), std::move(callback));
}
SaveAsWebBundleJob::SaveAsWebBundleJob(
const base::FilePath& file_path,
std::vector<
mojo::PendingRemote<data_decoder::mojom::ResourceSnapshotForWebBundle>>
snapshots,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)> callback)
: data_decoder_(std::make_unique<data_decoder::DataDecoder>()),
snapshots_(std::move(snapshots)),
callback_(std::move(callback)) {
base::PostTaskAndReplyWithResult(
download::GetDownloadTaskRunner().get(), FROM_HERE,
base::BindOnce(
[](const base::FilePath& file_path) {
const uint32_t file_flags =
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
return base::File(file_path, file_flags);
},
file_path),
base::BindOnce(&SaveAsWebBundleJob::OnFileAvailable,
base::Unretained(this)));
}
SaveAsWebBundleJob::~SaveAsWebBundleJob() = default;
void SaveAsWebBundleJob::OnFileAvailable(base::File file) {
if (!file.IsValid()) {
LOG(ERROR) << "Failed to create file to save page as WebBundle.";
OnFinished(0, data_decoder::mojom::WebBundlerError::kFileOpenFailed);
return;
}
data_decoder_->GetService()->BindWebBundler(
bundler_.BindNewPipeAndPassReceiver());
bundler_.set_disconnect_handler(base::BindOnce(
&SaveAsWebBundleJob::OnConnectionError, base::Unretained(this)));
bundler_->Generate(
std::move(snapshots_), std::move(file),
base::BindOnce(&SaveAsWebBundleJob::OnGenerated, base::Unretained(this)));
}
void SaveAsWebBundleJob::OnConnectionError() {
OnFinished(0,
data_decoder::mojom::WebBundlerError::kWebBundlerConnectionError);
}
void SaveAsWebBundleJob::OnGenerated(
uint64_t file_size,
data_decoder::mojom::WebBundlerError error) {
OnFinished(file_size, error);
}
void SaveAsWebBundleJob::OnFinished(
uint64_t file_size,
data_decoder::mojom::WebBundlerError error) {
DCHECK(callback_);
std::move(callback_).Run(file_size, error);
delete this; // This is the last time the SaveAsWebBundleJob is referenced.
}
} // namespace content
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_WEB_PACKAGE_SAVE_AS_WEB_BUNDLE_JOB_H_
#define CONTENT_BROWSER_WEB_PACKAGE_SAVE_AS_WEB_BUNDLE_JOB_H_
#include <memory>
#include <vector>
#include "base/callback_forward.h"
#include "base/files/file.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/mojom/resource_snapshot_for_web_bundle.mojom.h"
#include "services/data_decoder/public/mojom/web_bundler.mojom.h"
namespace base {
class FilePath;
} // namespace base
namespace data_decoder {
class DataDecoder;
} // namespace data_decoder
namespace content {
class WebContents;
// This class is used by WebContents::GenerateWebBundle() method to generate
// a Web Bundle file. The instances are created by Start() static method. Every
// instance is self-owned and responsible for deleting itself upon invoking
// OnFinished.
class SaveAsWebBundleJob {
public:
static void Start(
WebContents* web_contents,
const base::FilePath& file_path,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)> callback);
SaveAsWebBundleJob(const SaveAsWebBundleJob&) = delete;
SaveAsWebBundleJob& operator=(const SaveAsWebBundleJob&) = delete;
private:
SaveAsWebBundleJob(
const base::FilePath& file_path,
std::vector<mojo::PendingRemote<
data_decoder::mojom::ResourceSnapshotForWebBundle>> snapshots,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)> callback);
~SaveAsWebBundleJob();
void OnFileAvailable(base::File file);
void OnConnectionError();
void OnGenerated(uint64_t file_size,
data_decoder::mojom::WebBundlerError error);
void OnFinished(uint64_t file_size,
data_decoder::mojom::WebBundlerError error);
std::unique_ptr<data_decoder::DataDecoder> data_decoder_;
std::vector<
mojo::PendingRemote<data_decoder::mojom::ResourceSnapshotForWebBundle>>
snapshots_;
mojo::Remote<data_decoder::mojom::WebBundler> bundler_;
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)>
callback_;
};
} // namespace content
#endif // CONTENT_BROWSER_WEB_PACKAGE_SAVE_AS_WEB_BUNDLE_JOB_H_
...@@ -2,22 +2,34 @@ ...@@ -2,22 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <tuple>
#include "base/base_paths.h" #include "base/base_paths.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/threading/scoped_blocking_call.h"
#include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h" #include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/data_decoder/public/mojom/resource_snapshot_for_web_bundle.mojom.h" #include "services/data_decoder/public/mojom/resource_snapshot_for_web_bundle.mojom.h"
namespace content { namespace content {
namespace { namespace {
const char kOnePageSimplePath[] =
"/web_bundle/save_page_as_web_bundle/one_page_simple.html";
const char kOnePageWithImgPath[] =
"/web_bundle/save_page_as_web_bundle/one_page_with_img.html";
const char kImgPngPath[] = "/web_bundle/save_page_as_web_bundle/img.png";
uint64_t GetResourceCount( uint64_t GetResourceCount(
mojo::Remote<data_decoder::mojom::ResourceSnapshotForWebBundle>& snapshot) { mojo::Remote<data_decoder::mojom::ResourceSnapshotForWebBundle>& snapshot) {
uint64_t count_out = 0; uint64_t count_out = 0;
...@@ -63,6 +75,58 @@ base::Optional<mojo_base::BigBuffer> GetResourceBody( ...@@ -63,6 +75,58 @@ base::Optional<mojo_base::BigBuffer> GetResourceBody(
return data_out; return data_out;
} }
class MockWebBundler : public data_decoder::mojom::WebBundler {
public:
MockWebBundler() = default;
~MockWebBundler() override {
if (file_.IsValid()) {
base::ScopedAllowBlockingForTesting allow_blocking;
file_.Close();
}
}
MockWebBundler(const MockWebBundler&) = delete;
MockWebBundler& operator=(const MockWebBundler&) = delete;
void Bind(mojo::PendingReceiver<data_decoder::mojom::WebBundler> receiver) {
receiver_.Bind(std::move(receiver));
}
void WaitUntilGenerateCalled() {
if (callback_)
return;
base::RunLoop loop;
generate_called_callback_ = loop.QuitClosure();
loop.Run();
}
void ResetReceiver() { receiver_.reset(); }
private:
// mojom::WebBundleParserFactory implementation.
void Generate(
std::vector<mojo::PendingRemote<
data_decoder::mojom::ResourceSnapshotForWebBundle>> snapshots,
base::File file,
GenerateCallback callback) override {
DCHECK(!callback_);
snapshots_ = std::move(snapshots);
file_ = std::move(file);
callback_ = std::move(callback);
if (generate_called_callback_)
std::move(generate_called_callback_).Run();
}
std::vector<
mojo::PendingRemote<data_decoder::mojom::ResourceSnapshotForWebBundle>>
snapshots_;
base::File file_;
GenerateCallback callback_;
base::OnceClosure generate_called_callback_;
mojo::Receiver<data_decoder::mojom::WebBundler> receiver_{this};
};
} // namespace } // namespace
class SavePageAsWebBundleBrowserTest : public ContentBrowserTest { class SavePageAsWebBundleBrowserTest : public ContentBrowserTest {
...@@ -82,11 +146,36 @@ class SavePageAsWebBundleBrowserTest : public ContentBrowserTest { ...@@ -82,11 +146,36 @@ class SavePageAsWebBundleBrowserTest : public ContentBrowserTest {
snapshot.BindNewPipeAndPassReceiver()); snapshot.BindNewPipeAndPassReceiver());
return snapshot; return snapshot;
} }
bool CreateSaveDir() {
base::ScopedAllowBlockingForTesting allow_blocking;
return save_dir_.CreateUniqueTempDir();
}
std::tuple<uint64_t, data_decoder::mojom::WebBundlerError> GenerateWebBundle(
const base::FilePath& file_path) {
uint64_t ret_file_size = 0;
data_decoder::mojom::WebBundlerError ret_error =
data_decoder::mojom::WebBundlerError::kOK;
base::RunLoop run_loop;
shell()->web_contents()->GenerateWebBundle(
file_path, base::BindLambdaForTesting(
[&run_loop, &ret_file_size, &ret_error](
uint64_t file_size,
data_decoder::mojom::WebBundlerError error) {
ret_file_size = file_size;
ret_error = error;
run_loop.Quit();
}));
run_loop.Run();
return std::make_tuple(ret_file_size, ret_error);
}
base::ScopedTempDir save_dir_;
}; };
IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageSimple) { IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, SnapshotOnePageSimple) {
const auto page_url = embedded_test_server()->GetURL( const auto page_url = embedded_test_server()->GetURL(kOnePageSimplePath);
"/web_bundle/save_page_as_web_bundle/one_page_simple.html");
auto snapshot = NavigateAndGetSnapshot(page_url); auto snapshot = NavigateAndGetSnapshot(page_url);
ASSERT_EQ(1u, GetResourceCount(snapshot)); ASSERT_EQ(1u, GetResourceCount(snapshot));
...@@ -116,11 +205,9 @@ IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageSimple) { ...@@ -116,11 +205,9 @@ IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageSimple) {
EXPECT_FALSE(GetResourceBody(snapshot, 1).has_value()); EXPECT_FALSE(GetResourceBody(snapshot, 1).has_value());
} }
IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageWithImg) { IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, SnapshotOnePageWithImg) {
const auto page_url = embedded_test_server()->GetURL( const auto page_url = embedded_test_server()->GetURL(kOnePageWithImgPath);
"/web_bundle/save_page_as_web_bundle/one_page_with_img.html"); const auto img_url = embedded_test_server()->GetURL(kImgPngPath);
const auto img_url = embedded_test_server()->GetURL(
"/web_bundle/save_page_as_web_bundle/img.png");
auto snapshot = NavigateAndGetSnapshot(page_url); auto snapshot = NavigateAndGetSnapshot(page_url);
ASSERT_EQ(2u, GetResourceCount(snapshot)); ASSERT_EQ(2u, GetResourceCount(snapshot));
...@@ -176,4 +263,69 @@ IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageWithImg) { ...@@ -176,4 +263,69 @@ IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest, OnePageWithImg) {
// TODO(crbug.com/1040752): Implement sub frames support and add tests. // TODO(crbug.com/1040752): Implement sub frames support and add tests.
// TODO(crbug.com/1040752): Implement style sheet support and add tests. // TODO(crbug.com/1040752): Implement style sheet support and add tests.
IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest,
GenerateOnePageSimpleWebBundle) {
const auto page_url = embedded_test_server()->GetURL(kOnePageSimplePath);
NavigateToURLBlockUntilNavigationsComplete(shell(), page_url, 1);
ASSERT_TRUE(CreateSaveDir());
const auto file_path =
save_dir_.GetPath().Append(FILE_PATH_LITERAL("test.wbn"));
// Currently WebBundler in the data decoder service is not implemented yet,
// and just returns kNotImplemented.
// TODO(crbug.com/1040752): Implement WebBundler and update test.
EXPECT_EQ(
std::make_tuple(0, data_decoder::mojom::WebBundlerError::kNotImplemented),
GenerateWebBundle(file_path));
}
IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest,
GenerateWebBundleInvalidFilePath) {
const auto page_url = embedded_test_server()->GetURL(kOnePageSimplePath);
NavigateToURLBlockUntilNavigationsComplete(shell(), page_url, 1);
ASSERT_TRUE(CreateSaveDir());
const auto file_path = save_dir_.GetPath();
// Generating Web Bundle file using the existing directory path name must
// fail with kFileOpenFailed error.
EXPECT_EQ(
std::make_tuple(0, data_decoder::mojom::WebBundlerError::kFileOpenFailed),
GenerateWebBundle(file_path));
}
IN_PROC_BROWSER_TEST_F(SavePageAsWebBundleBrowserTest,
GenerateWebBundleConnectionError) {
data_decoder::test::InProcessDataDecoder in_process_data_decoder;
MockWebBundler mock_web_bundler;
in_process_data_decoder.service().SetWebBundlerBinderForTesting(
base::BindRepeating(&MockWebBundler::Bind,
base::Unretained(&mock_web_bundler)));
const auto page_url = embedded_test_server()->GetURL(kOnePageSimplePath);
NavigateToURLBlockUntilNavigationsComplete(shell(), page_url, 1);
ASSERT_TRUE(CreateSaveDir());
const auto file_path =
save_dir_.GetPath().Append(FILE_PATH_LITERAL("test.wbn"));
uint64_t result_file_size = 0ul;
data_decoder::mojom::WebBundlerError result_error =
data_decoder::mojom::WebBundlerError::kOK;
base::RunLoop run_loop;
shell()->web_contents()->GenerateWebBundle(
file_path,
base::BindLambdaForTesting(
[&run_loop, &result_file_size, &result_error](
uint64_t file_size, data_decoder::mojom::WebBundlerError error) {
result_file_size = file_size;
result_error = error;
run_loop.Quit();
}));
mock_web_bundler.WaitUntilGenerateCalled();
mock_web_bundler.ResetReceiver();
run_loop.Run();
// When the connection to the WebBundler in the data decoder service is
// disconnected, the result must be kWebBundlerConnectionError.
EXPECT_EQ(0ULL, result_file_size);
EXPECT_EQ(data_decoder::mojom::WebBundlerError::kWebBundlerConnectionError,
result_error);
}
} // namespace content } // namespace content
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "content/public/browser/visibility.h" #include "content/public/browser/visibility.h"
#include "content/public/common/stop_find_action.h" #include "content/public/common/stop_find_action.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/mojom/web_bundler.mojom.h"
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/blink/public/common/frame/sandbox_flags.h" #include "third_party/blink/public/common/frame/sandbox_flags.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom-forward.h" #include "third_party/blink/public/mojom/frame/find_in_page.mojom-forward.h"
...@@ -819,11 +820,18 @@ class WebContents : public PageNavigator, ...@@ -819,11 +820,18 @@ class WebContents : public PageNavigator,
// the file size and more. // the file size and more.
virtual void GenerateMHTML( virtual void GenerateMHTML(
const MHTMLGenerationParams& params, const MHTMLGenerationParams& params,
base::OnceCallback<void(int64_t /* size of the file */)> callback) = 0; base::OnceCallback<void(int64_t /* file_size */)> callback) = 0;
virtual void GenerateMHTMLWithResult( virtual void GenerateMHTMLWithResult(
const MHTMLGenerationParams& params, const MHTMLGenerationParams& params,
MHTMLGenerationResult::GenerateMHTMLCallback callback) = 0; MHTMLGenerationResult::GenerateMHTMLCallback callback) = 0;
// Generates a Web Bundle representation of the current page.
virtual void GenerateWebBundle(
const base::FilePath& file_path,
base::OnceCallback<void(uint64_t /* file_size */,
data_decoder::mojom::WebBundlerError)>
callback) = 0;
// Returns the contents MIME type after a navigation. // Returns the contents MIME type after a navigation.
virtual const std::string& GetContentsMimeType() = 0; virtual const std::string& GetContentsMimeType() = 0;
......
...@@ -1124,7 +1124,6 @@ test("content_browsertests") { ...@@ -1124,7 +1124,6 @@ test("content_browsertests") {
public_deps = [ public_deps = [
"//content:content_resources", "//content:content_resources",
"//content:dev_ui_content_resources", "//content:dev_ui_content_resources",
"//services/data_decoder/public/mojom:mojom_resource_snapshot_for_web_bundle",
] ]
deps = [ deps = [
......
...@@ -14,6 +14,8 @@ source_set("lib") { ...@@ -14,6 +14,8 @@ source_set("lib") {
"web_bundle_parser.h", "web_bundle_parser.h",
"web_bundle_parser_factory.cc", "web_bundle_parser_factory.cc",
"web_bundle_parser_factory.h", "web_bundle_parser_factory.h",
"web_bundler.cc",
"web_bundler.h",
"xml_parser.cc", "xml_parser.cc",
"xml_parser.h", "xml_parser.h",
] ]
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "services/data_decoder/json_parser_impl.h" #include "services/data_decoder/json_parser_impl.h"
#include "services/data_decoder/public/mojom/image_decoder.mojom.h" #include "services/data_decoder/public/mojom/image_decoder.mojom.h"
#include "services/data_decoder/web_bundle_parser_factory.h" #include "services/data_decoder/web_bundle_parser_factory.h"
#include "services/data_decoder/web_bundler.h"
#include "services/data_decoder/xml_parser.h" #include "services/data_decoder/xml_parser.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -78,6 +79,16 @@ void DataDecoderService::BindWebBundleParserFactory( ...@@ -78,6 +79,16 @@ void DataDecoderService::BindWebBundleParserFactory(
} }
} }
void DataDecoderService::BindWebBundler(
mojo::PendingReceiver<mojom::WebBundler> receiver) {
if (web_bundler_binder_) {
web_bundler_binder_.Run(std::move(receiver));
} else {
mojo::MakeSelfOwnedReceiver(std::make_unique<WebBundler>(),
std::move(receiver));
}
}
#ifdef OS_CHROMEOS #ifdef OS_CHROMEOS
void DataDecoderService::BindBleScanParser( void DataDecoderService::BindBleScanParser(
mojo::PendingReceiver<mojom::BleScanParser> receiver) { mojo::PendingReceiver<mojom::BleScanParser> receiver) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "services/data_decoder/public/mojom/image_decoder.mojom.h" #include "services/data_decoder/public/mojom/image_decoder.mojom.h"
#include "services/data_decoder/public/mojom/json_parser.mojom.h" #include "services/data_decoder/public/mojom/json_parser.mojom.h"
#include "services/data_decoder/public/mojom/web_bundle_parser.mojom.h" #include "services/data_decoder/public/mojom/web_bundle_parser.mojom.h"
#include "services/data_decoder/public/mojom/web_bundler.mojom.h"
#include "services/data_decoder/public/mojom/xml_parser.mojom.h" #include "services/data_decoder/public/mojom/xml_parser.mojom.h"
#ifdef OS_CHROMEOS #ifdef OS_CHROMEOS
...@@ -54,6 +55,14 @@ class DataDecoderService : public mojom::DataDecoderService { ...@@ -54,6 +55,14 @@ class DataDecoderService : public mojom::DataDecoderService {
web_bundle_parser_factory_binder_ = binder; web_bundle_parser_factory_binder_ = binder;
} }
// Configures the service to use |binder| to bind WebBundler in subsequent
// BindWebBundler() calls.
void SetWebBundlerBinderForTesting(
base::RepeatingCallback<void(mojo::PendingReceiver<mojom::WebBundler>)>
binder) {
web_bundler_binder_ = binder;
}
private: private:
// mojom::DataDecoderService implementation: // mojom::DataDecoderService implementation:
void BindImageDecoder( void BindImageDecoder(
...@@ -63,6 +72,8 @@ class DataDecoderService : public mojom::DataDecoderService { ...@@ -63,6 +72,8 @@ class DataDecoderService : public mojom::DataDecoderService {
void BindXmlParser(mojo::PendingReceiver<mojom::XmlParser> receiver) override; void BindXmlParser(mojo::PendingReceiver<mojom::XmlParser> receiver) override;
void BindWebBundleParserFactory( void BindWebBundleParserFactory(
mojo::PendingReceiver<mojom::WebBundleParserFactory> receiver) override; mojo::PendingReceiver<mojom::WebBundleParserFactory> receiver) override;
void BindWebBundler(
mojo::PendingReceiver<mojom::WebBundler> receiver) override;
#ifdef OS_CHROMEOS #ifdef OS_CHROMEOS
void BindBleScanParser( void BindBleScanParser(
...@@ -78,6 +89,8 @@ class DataDecoderService : public mojom::DataDecoderService { ...@@ -78,6 +89,8 @@ class DataDecoderService : public mojom::DataDecoderService {
base::RepeatingCallback<void( base::RepeatingCallback<void(
mojo::PendingReceiver<mojom::WebBundleParserFactory>)> mojo::PendingReceiver<mojom::WebBundleParserFactory>)>
web_bundle_parser_factory_binder_; web_bundle_parser_factory_binder_;
base::RepeatingCallback<void(mojo::PendingReceiver<mojom::WebBundler>)>
web_bundler_binder_;
DISALLOW_COPY_AND_ASSIGN(DataDecoderService); DISALLOW_COPY_AND_ASSIGN(DataDecoderService);
}; };
......
...@@ -10,10 +10,12 @@ mojom("mojom") { ...@@ -10,10 +10,12 @@ mojom("mojom") {
"image_decoder.mojom", "image_decoder.mojom",
"json_parser.mojom", "json_parser.mojom",
"web_bundle_parser.mojom", "web_bundle_parser.mojom",
"web_bundler.mojom",
"xml_parser.mojom", "xml_parser.mojom",
] ]
public_deps = [ public_deps = [
":mojom_resource_snapshot_for_web_bundle",
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//skia/public/mojom", "//skia/public/mojom",
"//ui/gfx/geometry/mojom", "//ui/gfx/geometry/mojom",
......
...@@ -6,6 +6,7 @@ module data_decoder.mojom; ...@@ -6,6 +6,7 @@ module data_decoder.mojom;
import "services/data_decoder/public/mojom/image_decoder.mojom"; import "services/data_decoder/public/mojom/image_decoder.mojom";
import "services/data_decoder/public/mojom/json_parser.mojom"; import "services/data_decoder/public/mojom/json_parser.mojom";
import "services/data_decoder/public/mojom/web_bundler.mojom";
import "services/data_decoder/public/mojom/web_bundle_parser.mojom"; import "services/data_decoder/public/mojom/web_bundle_parser.mojom";
import "services/data_decoder/public/mojom/xml_parser.mojom"; import "services/data_decoder/public/mojom/xml_parser.mojom";
...@@ -27,6 +28,9 @@ interface DataDecoderService { ...@@ -27,6 +28,9 @@ interface DataDecoderService {
BindWebBundleParserFactory( BindWebBundleParserFactory(
pending_receiver<WebBundleParserFactory> receiver); pending_receiver<WebBundleParserFactory> receiver);
// Binds an interface which can be used to generate a Web Bundle.
BindWebBundler(pending_receiver<WebBundler> receiver);
// Binds an interface which can be used to parse raw BLE advertising packet // Binds an interface which can be used to parse raw BLE advertising packet
// data. // data.
[EnableIf=is_chromeos] [EnableIf=is_chromeos]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module data_decoder.mojom;
import "services/data_decoder/public/mojom/resource_snapshot_for_web_bundle.mojom";
import "mojo/public/mojom/base/file.mojom";
enum WebBundlerError {
kOK,
kNotImplemented,
kFileOpenFailed,
kWebBundlerConnectionError,
};
// Bundler interface to generate a web bundle from snapshots.
interface WebBundler {
// Generates a web bundle from |snapshots| and writes to the passed |file|.
Generate(
array<pending_remote<ResourceSnapshotForWebBundle>> snapshots,
mojo_base.mojom.File file)
=> (uint64 file_size, WebBundlerError error);
};
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/data_decoder/web_bundler.h"
namespace data_decoder {
void WebBundler::Generate(
std::vector<mojo::PendingRemote<mojom::ResourceSnapshotForWebBundle>>
snapshots,
base::File file,
GenerateCallback callback) {
// The Web Bundle generation logic is not implemented yet.
// TODO(crbug.com/1040752): Implement this.
std::move(callback).Run(0, mojom::WebBundlerError::kNotImplemented);
}
} // namespace data_decoder
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_DATA_DECODER_WEB_BUNDLER_H_
#define SERVICES_DATA_DECODER_WEB_BUNDLER_H_
#include <vector>
#include "base/files/file.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/data_decoder/public/mojom/resource_snapshot_for_web_bundle.mojom.h"
#include "services/data_decoder/public/mojom/web_bundler.mojom.h"
namespace data_decoder {
class WebBundler : public mojom::WebBundler {
public:
WebBundler() = default;
~WebBundler() override = default;
WebBundler(const WebBundler&) = delete;
WebBundler& operator=(const WebBundler&) = delete;
private:
// mojom::WebBundler implementation.
void Generate(
std::vector<mojo::PendingRemote<mojom::ResourceSnapshotForWebBundle>>
snapshots,
base::File file,
GenerateCallback callback) override;
};
} // namespace data_decoder
#endif // SERVICES_DATA_DECODER_WEB_BUNDLER_H_
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