Commit e2a08881 authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Add Bundled Exchanges parser interface

This adds an interface for parsing the Bundled Exchanges format into the
data_decoder service. The actual parsing code will be added in the next
CL (https://crrev.com/c/1626065).

Bug: 969596
Change-Id: I776199c8a55cd0137dc629ef6199ffa1959b9922
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640524
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669585}
parent 1b87f49d
......@@ -6,6 +6,8 @@ import("//testing/libfuzzer/fuzzer_test.gni")
source_set("lib") {
sources = [
"bundled_exchanges_parser.cc",
"bundled_exchanges_parser.h",
"data_decoder_service.cc",
"data_decoder_service.h",
"image_decoder_impl.cc",
......
// Copyright 2019 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/bundled_exchanges_parser.h"
#include <utility>
#include "base/callback.h"
namespace data_decoder {
BundledExchangesParser::BundledExchangesParser(
std::unique_ptr<service_manager::ServiceContextRef> service_ref)
: service_ref_(std::move(service_ref)) {}
BundledExchangesParser::~BundledExchangesParser() = default;
void BundledExchangesParser::ParseMetadata(
mojo::PendingRemote<mojom::BundleDataSource> data_source,
ParseMetadataCallback callback) {
std::move(callback).Run(nullptr /* metadata */, "Not implemented");
}
void BundledExchangesParser::ParseResponse(
mojo::PendingRemote<mojom::BundleDataSource> data_source,
uint64_t response_offset,
uint64_t response_length,
ParseResponseCallback callback) {
std::move(callback).Run(nullptr /* response */, "Not implemented");
}
} // namespace data_decoder
// Copyright 2019 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_BUNDLED_EXCHANGES_PARSER_H_
#define SERVICES_DATA_DECODER_BUNDLED_EXCHANGES_PARSER_H_
#include <memory>
#include "base/macros.h"
#include "services/data_decoder/public/mojom/bundled_exchanges_parser.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
namespace data_decoder {
class BundledExchangesParser : public mojom::BundledExchangesParser {
public:
explicit BundledExchangesParser(
std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~BundledExchangesParser() override;
private:
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
// mojom::BundledExchangesParser implementation.
void ParseMetadata(mojo::PendingRemote<mojom::BundleDataSource> data_source,
ParseMetadataCallback callback) override;
void ParseResponse(mojo::PendingRemote<mojom::BundleDataSource> data_source,
uint64_t response_offset,
uint64_t response_length,
ParseResponseCallback callback) override;
DISALLOW_COPY_AND_ASSIGN(BundledExchangesParser);
};
} // namespace data_decoder
#endif // SERVICES_DATA_DECODER_BUNDLED_EXCHANGES_PARSER_H_
......@@ -11,6 +11,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/data_decoder/bundled_exchanges_parser.h"
#include "services/data_decoder/image_decoder_impl.h"
#include "services/data_decoder/json_parser_impl.h"
#include "services/data_decoder/public/mojom/image_decoder.mojom.h"
......@@ -32,6 +33,8 @@ DataDecoderService::DataDecoderService()
&DataDecoderService::BindJsonParser, base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(&DataDecoderService::BindXmlParser,
base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(
&DataDecoderService::BindBundledExchangesParser, base::Unretained(this)));
}
DataDecoderService::DataDecoderService(
......@@ -71,4 +74,11 @@ void DataDecoderService::BindXmlParser(mojom::XmlParserRequest request) {
std::move(request));
}
void DataDecoderService::BindBundledExchangesParser(
mojom::BundledExchangesParserRequest request) {
mojo::MakeStrongBinding(
std::make_unique<BundledExchangesParser>(keepalive_.CreateRef()),
std::move(request));
}
} // namespace data_decoder
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "services/data_decoder/public/mojom/bundled_exchanges_parser.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/xml_parser.mojom.h"
......@@ -35,6 +36,7 @@ class DataDecoderService : public service_manager::Service {
mojo::ScopedMessagePipeHandle interface_pipe) override;
private:
void BindBundledExchangesParser(mojom::BundledExchangesParserRequest request);
void BindImageDecoder(mojom::ImageDecoderRequest request);
void BindJsonParser(mojom::JsonParserRequest request);
void BindXmlParser(mojom::XmlParserRequest request);
......
......@@ -25,6 +25,8 @@ source_set("cpp") {
"decode_image.cc",
"decode_image.h",
"json_sanitizer.h",
"safe_bundled_exchanges_parser.cc",
"safe_bundled_exchanges_parser.h",
"safe_json_parser_impl.cc",
"safe_json_parser_impl.h",
"safe_xml_parser.cc",
......
......@@ -5,6 +5,7 @@
#include "services/data_decoder/public/cpp/manifest.h"
#include "base/no_destructor.h"
#include "services/data_decoder/public/mojom/bundled_exchanges_parser.mojom.h"
#include "services/data_decoder/public/mojom/constants.mojom.h"
#include "services/data_decoder/public/mojom/image_decoder.mojom.h"
#include "services/data_decoder/public/mojom/json_parser.mojom.h"
......@@ -35,6 +36,9 @@ const service_manager::Manifest& GetManifest() {
.ExposeCapability(
"xml_parser",
service_manager::Manifest::InterfaceList<mojom::XmlParser>())
.ExposeCapability("bundled_exchanges_parser",
service_manager::Manifest::InterfaceList<
mojom::BundledExchangesParser>())
.Build()};
return *manifest;
}
......
// Copyright 2019 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/public/cpp/safe_bundled_exchanges_parser.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
namespace data_decoder {
namespace {
// Helper callback which owns a Remote<BundledExchangesParser> until invoked.
void OnMetadataParsed(
mojo::Remote<mojom::BundledExchangesParser> parser,
mojom::BundledExchangesParser::ParseMetadataCallback callback,
mojom::BundleMetadataPtr metadata,
const base::Optional<std::string>& error_message) {
std::move(callback).Run(std::move(metadata), error_message);
}
// Helper callback which owns a Remote<BundledExchangesParser> until invoked.
void OnResponseParsed(
mojo::Remote<mojom::BundledExchangesParser> parser,
mojom::BundledExchangesParser::ParseResponseCallback callback,
mojom::BundleResponsePtr response,
const base::Optional<std::string>& error_message) {
std::move(callback).Run(std::move(response), error_message);
}
} // namespace
void ParseBundledExchangesMetadata(
service_manager::Connector* connector,
mojo::PendingRemote<mojom::BundleDataSource> data_source,
mojom::BundledExchangesParser::ParseMetadataCallback callback) {
mojo::Remote<mojom::BundledExchangesParser> parser;
connector->Connect(mojom::kServiceName, parser.BindNewPipeAndPassReceiver());
// |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
parser.set_disconnect_handler(
base::Bind(call_once, nullptr, "connection error"));
mojom::BundledExchangesParser* raw_parser = parser.get();
raw_parser->ParseMetadata(std::move(data_source),
base::BindOnce(&OnMetadataParsed, std::move(parser),
std::move(call_once)));
}
void ParseBundledExchangesResponse(
service_manager::Connector* connector,
mojo::PendingRemote<mojom::BundleDataSource> data_source,
uint64_t response_offset,
uint64_t response_length,
mojom::BundledExchangesParser::ParseResponseCallback callback) {
mojo::Remote<mojom::BundledExchangesParser> parser;
connector->Connect(mojom::kServiceName, parser.BindNewPipeAndPassReceiver());
// |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
parser.set_disconnect_handler(
base::Bind(call_once, nullptr, "connection error"));
mojom::BundledExchangesParser* raw_parser = parser.get();
raw_parser->ParseResponse(std::move(data_source), response_offset,
response_length,
base::BindOnce(&OnResponseParsed, std::move(parser),
std::move(call_once)));
}
} // namespace data_decoder
// Copyright 2019 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_PUBLIC_CPP_SAFE_BUNDLED_EXCHANGES_PARSER_H_
#define SERVICES_DATA_DECODER_PUBLIC_CPP_SAFE_BUNDLED_EXCHANGES_PARSER_H_
#include "services/data_decoder/public/mojom/bundled_exchanges_parser.mojom.h"
namespace service_manager {
class Connector;
}
namespace data_decoder {
// Parses bundle's metadata from |data_source| via the data_decoder service.
void ParseBundledExchangesMetadata(
service_manager::Connector* connector,
mojo::PendingRemote<mojom::BundleDataSource> data_source,
mojom::BundledExchangesParser::ParseMetadataCallback callback);
// Parses a response from |data_source| that starts at |response_offset| and
// has length |response_length|, via the data_decoder service.
void ParseBundledExchangesResponse(
service_manager::Connector* connector,
mojo::PendingRemote<mojom::BundleDataSource> data_source,
uint64_t response_offset,
uint64_t response_length,
mojom::BundledExchangesParser::ParseResponseCallback callback);
} // namespace data_decoder
#endif // SERVICES_DATA_DECODER_PUBLIC_CPP_SAFE_BUNDLED_EXCHANGES_PARSER_H_
......@@ -6,6 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
sources = [
"bundled_exchanges_parser.mojom",
"image_decoder.mojom",
"json_parser.mojom",
"xml_parser.mojom",
......@@ -16,6 +17,7 @@ mojom("mojom") {
"//mojo/public/mojom/base",
"//skia/public/interfaces",
"//ui/gfx/geometry/mojo",
"//url/mojom:url_mojom_gurl",
]
}
......
// Copyright 2019 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 "url/mojom/url.mojom";
interface BundledExchangesParser {
// Parses bundle's metadata from |data_source|.
ParseMetadata(pending_remote<BundleDataSource> data_source)
=> (BundleMetadata? Result, string? error);
// Parses a response from the range
// |[response_offset, response_offset + response_length)| of |data_source|.
ParseResponse(pending_remote<BundleDataSource> data_source,
uint64 response_offset,
uint64 response_length)
=> (BundleResponse? Result, string? error);
};
// Data source that provides application/webbundle data to the parser.
interface BundleDataSource {
GetSize() => (uint64 size);
Read(uint64 offset, uint64 length) => (bool success, array<uint8>? buffer);
};
struct BundleMetadata {
array<BundleIndexItem> index;
url.mojom.Url manifest_url;
};
struct BundleIndexItem {
url.mojom.Url request_url;
string request_method;
map<string, string> request_headers;
// Used as parameters to ParseResponse().
uint64 response_offset;
uint64 response_length;
};
struct BundleResponse {
int32 response_code;
map<string, string> response_headers;
// Payload offset and length within the webbundle file.
uint64 payload_offset;
uint64 payload_length;
};
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