web-bundles: Accept GURL in WebBundleBuilder methods

Accepting GURL reduces boilerplate code. `base::StringPiece` is still
accepted as well, and can be useful when trying to create Web Bundles
with relative (or invalid) URLs.

Bug: None
Change-Id: I08659d9355a1f292873754a4e496f29c730dd296
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4020673
Reviewed-by: Hayato Ito <[email protected]>
Reviewed-by: Kelvin Jiang <[email protected]>
Reviewed-by: Devlin Cronin <[email protected]>
Reviewed-by: Robert Sesek <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Commit-Queue: Christian Flach <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1076781}
diff --git a/components/web_package/web_bundle_builder.h b/components/web_package/web_bundle_builder.h
index a3d6cd9..709ae0a 100644
--- a/components/web_package/web_bundle_builder.h
+++ b/components/web_package/web_bundle_builder.h
@@ -12,6 +12,7 @@
 
 #include "base/strings/string_piece.h"
 #include "components/cbor/writer.h"
+#include "url/gurl.h"
 
 namespace web_package {
 
@@ -35,6 +36,13 @@
 
   ~WebBundleBuilder();
 
+  // Add an exchange to the Web Bundle for a given `GURL`.
+  void AddExchange(const GURL& url,
+                   const Headers& response_headers,
+                   base::StringPiece payload);
+  // Add an exchange to the Web Bundle for a given `url` represented as a
+  // string. In contrast to providing the URL as `GURL`, this allows adding
+  // relative URLs to the Web Bundle.
   void AddExchange(base::StringPiece url,
                    const Headers& response_headers,
                    base::StringPiece payload);
@@ -42,11 +50,25 @@
   ResponseLocation AddResponse(const Headers& headers,
                                base::StringPiece payload);
 
+  // Adds an entry to the "index" section of the Web Bundle for the given
+  // `GURL`.
+  void AddIndexEntry(const GURL& url,
+                     const ResponseLocation& response_location);
+  // Adds an entry to the "index" section of the Web Bundle  for the given `url`
+  // represented as a string. In contrast to providing the URL as `GURL`, this
+  // allows adding relative URLs to the Web Bundle.
   void AddIndexEntry(base::StringPiece url,
                      const ResponseLocation& response_location);
+
   void AddSection(base::StringPiece name, cbor::Value section);
   void AddAuthority(cbor::Value::MapValue authority);
   void AddVouchedSubset(cbor::Value::MapValue vouched_subset);
+
+  // Adds a "primary" section to the Web Bundle containing a given `GURL`.
+  void AddPrimaryURL(const GURL& url);
+  // Adds a "primary" section to the Web Bundle for a given `url` represented as
+  // a string. In contrast to providing the URL as `GURL`, this allows setting
+  // relative URLs as the primary URL of a Web Bundle.
   void AddPrimaryURL(base::StringPiece url);
 
   std::vector<uint8_t> CreateBundle();