#include "components/web_package/web_bundle_parser.h"
#include <memory>
#include <optional>
#include <string_view>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "components/cbor/reader.h"
#include "components/web_package/input_reader.h"
#include "components/web_package/mojom/web_bundle_parser.mojom.h"
#include "components/web_package/signed_web_bundles/integrity_block_parser.h"
#include "components/web_package/web_bundle_utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/http/http_util.h"
namespace web_package {
namespace {
constexpr uint64_t kTrailingLengthNumBytes = …;
constexpr uint64_t kMaxSectionLengthsCBORSize = …;
constexpr uint64_t kMaxMetadataSectionSize = …;
constexpr uint64_t kMaxResponseHeaderLength = …;
constexpr uint64_t kInitialBufferSizeForResponse = …;
constexpr uint8_t kBundleHeadByte = …;
constexpr uint8_t kBundleB1HeadByte = …;
const uint8_t kBundleMagicBytes[] = …;
const uint8_t kVersionB2MagicBytes[] = …;
const uint8_t kVersionB1MagicBytes[] = …;
constexpr char kCriticalSection[] = …;
constexpr char kIndexSection[] = …;
constexpr char kPrimarySection[] = …;
constexpr char kResponsesSection[] = …;
SectionLengths;
SectionOffsets;
bool IsMetadataSection(const std::string& name) { … }
std::optional<SectionLengths> ParseSectionLengths(
base::span<const uint8_t> data) { … }
struct ParsedHeaders { … };
std::optional<ParsedHeaders> ConvertCBORValueToHeaders(
const cbor::Value& headers_value) { … }
GURL ParseExchangeURL(std::string_view str, const GURL& base_url) { … }
}
class WebBundleParser::MetadataParser
: public WebBundleParser::WebBundleSectionParser { … };
class WebBundleParser::ResponseParser
: public WebBundleParser::WebBundleSectionParser { … };
WebBundleParser::WebBundleParser(
mojo::PendingRemote<mojom::BundleDataSource> data_source,
GURL base_url)
: … { … }
WebBundleParser::~WebBundleParser() { … }
void WebBundleParser::ParseIntegrityBlock(
ParseIntegrityBlockCallback callback) { … }
void WebBundleParser::ParseMetadata(std::optional<uint64_t> offset,
ParseMetadataCallback callback) { … }
void WebBundleParser::ParseResponse(uint64_t response_offset,
uint64_t response_length,
ParseResponseCallback callback) { … }
void WebBundleParser::ActivateParser(
std::unique_ptr<WebBundleSectionParser> parser) { … }
void WebBundleParser::OnParsingComplete(WebBundleSectionParser* parser,
base::OnceClosure result_callback) { … }
void WebBundleParser::OnDisconnect() { … }
void WebBundleParser::Close(CloseCallback parser_closed_callback) { … }
void WebBundleParser::OnDataSourceClosed(CloseCallback parser_closed_callback) { … }
bool WebBundleParser::CheckIfClosed() { … }
}