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

BundledExchangesParser: Update the bundle format [1/2]

This updates BundledExchangesParser to parse the new bundle format [1].

Changes:
- Updated the magic header bytes [2]
- Version field is added (we use implementation-specific version string
  "b1\0\0", which matches gen-bundle's output [3])
- Fallback URL (== Primary URL) field is added
- ParseMetadata() returns error type ("format error" or "version error")
  and fallback URL if available
- Updated spec ref comments

The structure change of the index section is not reflected yet. It will
be updated in the next CL.

The test bundle file (hello.wbn) is generated with gen-bundle of
github.com/WICG/webpackage revision a3cef2c, which supports the new
bundle format except for the new index section structure.

[1] https://github.com/WICG/webpackage/pull/450
[2] https://github.com/WICG/webpackage/pull/454
[3] https://github.com/WICG/webpackage/pull/458

Bug: 969596
Change-Id: I95744ed00fdd09d369bb8648d1cdf62ca181d0dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715487Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684200}
parent 68048b0c
...@@ -163,7 +163,9 @@ class BundledExchangesReaderTest : public testing::Test { ...@@ -163,7 +163,9 @@ class BundledExchangesReaderTest : public testing::Test {
items.push_back(std::move(item)); items.push_back(std::move(item));
data_decoder::mojom::BundleMetadataPtr metadata = data_decoder::mojom::BundleMetadataPtr metadata =
data_decoder::mojom::BundleMetadata::New(std::move(items), GURL()); data_decoder::mojom::BundleMetadata::New(GURL() /* primary_url */,
std::move(items),
GURL() /* manifest_url */);
factory_->RunMetadataCallback(std::move(metadata)); factory_->RunMetadataCallback(std::move(metadata));
run_loop.Run(); run_loop.Run();
} }
......
...@@ -60,7 +60,9 @@ void SafeBundledExchangesParser::ParseMetadata( ...@@ -60,7 +60,9 @@ void SafeBundledExchangesParser::ParseMetadata(
// simultaneous request is fine enough. // simultaneous request is fine enough.
if (disconnected_ || !metadata_callback_.is_null()) { if (disconnected_ || !metadata_callback_.is_null()) {
std::move(callback).Run( std::move(callback).Run(
nullptr, mojom::BundleMetadataParseError::New(kConnectionError)); nullptr, mojom::BundleMetadataParseError::New(
mojom::BundleParseErrorType::kParserInternalError,
GURL() /* fallback_url */, kConnectionError));
return; return;
} }
metadata_callback_ = std::move(callback); metadata_callback_ = std::move(callback);
...@@ -78,7 +80,9 @@ void SafeBundledExchangesParser::ParseResponse( ...@@ -78,7 +80,9 @@ void SafeBundledExchangesParser::ParseResponse(
if (disconnected_ || if (disconnected_ ||
response_callbacks_.contains(response_callback_next_id_)) { response_callbacks_.contains(response_callback_next_id_)) {
std::move(callback).Run( std::move(callback).Run(
nullptr, mojom::BundleResponseParseError::New(kConnectionError)); nullptr, mojom::BundleResponseParseError::New(
mojom::BundleParseErrorType::kParserInternalError,
kConnectionError));
return; return;
} }
size_t callback_id = response_callback_next_id_++; size_t callback_id = response_callback_next_id_++;
...@@ -93,10 +97,14 @@ void SafeBundledExchangesParser::OnDisconnect() { ...@@ -93,10 +97,14 @@ void SafeBundledExchangesParser::OnDisconnect() {
disconnected_ = true; disconnected_ = true;
if (!metadata_callback_.is_null()) if (!metadata_callback_.is_null())
std::move(metadata_callback_) std::move(metadata_callback_)
.Run(nullptr, mojom::BundleMetadataParseError::New(kConnectionError)); .Run(nullptr, mojom::BundleMetadataParseError::New(
mojom::BundleParseErrorType::kParserInternalError,
GURL() /* fallback_url */, kConnectionError));
for (auto& callback : response_callbacks_) for (auto& callback : response_callbacks_)
std::move(callback.second) std::move(callback.second)
.Run(nullptr, mojom::BundleResponseParseError::New(kConnectionError)); .Run(nullptr, mojom::BundleResponseParseError::New(
mojom::BundleParseErrorType::kParserInternalError,
kConnectionError));
response_callbacks_.clear(); response_callbacks_.clear();
} }
......
...@@ -38,16 +38,26 @@ interface BundleDataSource { ...@@ -38,16 +38,26 @@ interface BundleDataSource {
Read(uint64 offset, uint64 length) => (array<uint8>? buffer); Read(uint64 offset, uint64 length) => (array<uint8>? buffer);
}; };
enum BundleParseErrorType {
kParserInternalError,
kFormatError,
kVersionError,
};
struct BundleMetadataParseError { struct BundleMetadataParseError {
BundleParseErrorType type;
url.mojom.Url fallback_url;
string message; string message;
// TODO(crbug.com/969596): Add fields for error type and fallback URL.
}; };
struct BundleResponseParseError { struct BundleResponseParseError {
BundleParseErrorType type;
string message; string message;
}; };
// https://wicg.github.io/webpackage/draft-yasskin-wpack-bundled-exchanges.html#semantics-load-metadata
struct BundleMetadata { struct BundleMetadata {
url.mojom.Url primary_url;
array<BundleIndexItem> index; array<BundleIndexItem> index;
url.mojom.Url manifest_url; url.mojom.Url manifest_url;
}; };
......
...@@ -12,7 +12,8 @@ if ! command -v gen-bundle > /dev/null 2>&1; then ...@@ -12,7 +12,8 @@ if ! command -v gen-bundle > /dev/null 2>&1; then
exit 1 exit 1
fi fi
gen-bundle -baseURL https://test.example.org/ \ gen-bundle -version b1 \
-baseURL https://test.example.org/ \
-dir hello/ \ -dir hello/ \
-manifestURL manifest.webmanifest \ -manifestURL manifest.webmanifest \
-o hello.wbn -o hello.wbn
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