[shared storage] Introduce mojom::SharedStorageBatchUpdateMethodsArgument
Introduce mojom::SharedStorageBatchUpdateMethodsArgument, which is type mapped to vector<::network::mojom::SharedStorageModifierMethodWithOptionsPtr>. Currently, the mojom traits perform a trivial conversion and no validation. When we later switch to disallow the 'withLock' option for methods within batchUpdate() (PR: [1]; Integration CL preview: [2]), the mojom traits will be updated to enforce this restriction. [1] https://github.com/WICG/shared-storage/pull/228 [2] https://crrev.com/c/6393777 Bug: 404568020 Change-Id: I31f87d3ef1c98d7a24ab9d1b9e4cb27bedf4d32c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6394820 Commit-Queue: Yao Xiao <yaoxia@chromium.org> Reviewed-by: Cammie Smith Barnes <cammie@chromium.org> Reviewed-by: Adam Rice <ricea@chromium.org> Reviewed-by: Ken Buchanan <kenrb@chromium.org> Cr-Commit-Position: refs/heads/main@{#1438964}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ebf9cae318
commit
72e320ca32
content/services/auction_worklet/public/mojom
services/network/public
cpp
mojom
third_party/blink
public
mojom
shared_storage
renderer
modules
@ -28,7 +28,7 @@ interface AuctionSharedStorageHost {
|
||||
// acquired on the resource with name `with_lock`. `with_lock` shouldn't start
|
||||
// with '-'.
|
||||
SharedStorageBatchUpdate(
|
||||
array<network.mojom.SharedStorageModifierMethodWithOptions> methods_with_options,
|
||||
network.mojom.SharedStorageBatchUpdateMethodsArgument methods_with_options,
|
||||
network.mojom.LockName? with_lock,
|
||||
AuctionWorkletFunction source_auction_worklet_function);
|
||||
};
|
||||
|
@ -43,4 +43,20 @@ bool StructTraits<network::mojom::LockNameDataView, std::string>::Read(
|
||||
return !network::IsReservedLockName(*out_value);
|
||||
}
|
||||
|
||||
// static
|
||||
bool StructTraits<
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView,
|
||||
std::vector<network::mojom::SharedStorageModifierMethodWithOptionsPtr>>::
|
||||
Read(network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView data,
|
||||
std::vector<network::mojom::SharedStorageModifierMethodWithOptionsPtr>*
|
||||
out_value) {
|
||||
if (!data.ReadData(out_value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/404568020): Add validation when we switch to disallow the
|
||||
// 'withLock' option for methods within batchUpdate().
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mojo
|
||||
|
@ -45,6 +45,23 @@ struct COMPONENT_EXPORT(NETWORK_CPP_SHARED_STORAGE)
|
||||
static const std::string& data(const std::string& input) { return input; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct COMPONENT_EXPORT(NETWORK_CPP_SHARED_STORAGE) StructTraits<
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView,
|
||||
std::vector<network::mojom::SharedStorageModifierMethodWithOptionsPtr>> {
|
||||
static bool Read(
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView data,
|
||||
std::vector<network::mojom::SharedStorageModifierMethodWithOptionsPtr>*
|
||||
out_value);
|
||||
|
||||
static const std::vector<
|
||||
network::mojom::SharedStorageModifierMethodWithOptionsPtr>&
|
||||
data(const std::vector<
|
||||
network::mojom::SharedStorageModifierMethodWithOptionsPtr>& input) {
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mojo
|
||||
|
||||
#endif // SERVICES_NETWORK_PUBLIC_CPP_SHARED_STORAGE_MOJOM_TRAITS_H_
|
||||
|
@ -77,5 +77,30 @@ TEST(SharedStorageMojomTraitsTest, SerializeAndDeserializeLockName) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SharedStorageMojomTraitsTest,
|
||||
SerializeAndDeserializeBatchUpdateMethodsArgument) {
|
||||
auto method1 = mojom::SharedStorageModifierMethodWithOptions::New(
|
||||
mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
mojom::SharedStorageSetMethod::New(/*key=*/u"a", /*key=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
/*with_lock=*/std::nullopt);
|
||||
|
||||
auto method2 = mojom::SharedStorageModifierMethodWithOptions::New(
|
||||
mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
mojom::SharedStorageAppendMethod::New(/*key=*/u"c", /*key=*/u"d")),
|
||||
/*with_lock=*/std::nullopt);
|
||||
|
||||
std::vector<mojom::SharedStorageModifierMethodWithOptionsPtr>
|
||||
original_methods;
|
||||
original_methods.push_back(std::move(method1));
|
||||
original_methods.push_back(std::move(method2));
|
||||
|
||||
std::vector<mojom::SharedStorageModifierMethodWithOptionsPtr> copied_methods;
|
||||
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
|
||||
mojom::SharedStorageBatchUpdateMethodsArgument>(original_methods,
|
||||
copied_methods));
|
||||
EXPECT_EQ(original_methods, copied_methods);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace network
|
||||
|
@ -297,6 +297,11 @@ mojom("mojom_shared_storage") {
|
||||
mojom = "network.mojom.LockName"
|
||||
cpp = "::std::string"
|
||||
},
|
||||
{
|
||||
mojom = "network.mojom.SharedStorageBatchUpdateMethodsArgument"
|
||||
cpp = "::std::vector<::network::mojom::SharedStorageModifierMethodWithOptionsPtr>"
|
||||
move_only = true
|
||||
},
|
||||
]
|
||||
traits_headers =
|
||||
[ "//services/network/public/cpp/shared_storage_mojom_traits.h" ]
|
||||
@ -318,6 +323,11 @@ mojom("mojom_shared_storage") {
|
||||
mojom = "network.mojom.LockName"
|
||||
cpp = "::WTF::String"
|
||||
},
|
||||
{
|
||||
mojom = "network.mojom.SharedStorageBatchUpdateMethodsArgument"
|
||||
cpp = "::WTF::Vector<::network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>"
|
||||
move_only = true
|
||||
},
|
||||
]
|
||||
traits_headers = [ "//third_party/blink/renderer/modules/shared_storage/shared_storage_blink_mojom_traits.h" ]
|
||||
traits_sources = [ "//third_party/blink/renderer/modules/shared_storage/shared_storage_blink_mojom_traits.cc" ]
|
||||
|
@ -65,3 +65,10 @@ struct SharedStorageModifierMethodWithOptions {
|
||||
// resource with name `with_lock`. `with_lock` shouldn't start with '-'.
|
||||
LockName? with_lock;
|
||||
};
|
||||
|
||||
// Represents the batchUpdate()'s `methods` argument in the Shared Storage
|
||||
// API. It will be validated during serialization.
|
||||
// https://wicg.github.io/shared-storage/#batch-update
|
||||
struct SharedStorageBatchUpdateMethodsArgument {
|
||||
array<SharedStorageModifierMethodWithOptions> data;
|
||||
};
|
||||
|
@ -203,7 +203,7 @@ interface URLLoaderNetworkServiceObserver {
|
||||
// triggered by response headers and Shared Storage calls from the same
|
||||
// renderer process where this request originated.
|
||||
OnSharedStorageHeaderReceived(url.mojom.Origin request_origin,
|
||||
array<SharedStorageModifierMethodWithOptions> methods_with_options,
|
||||
network.mojom.SharedStorageBatchUpdateMethodsArgument methods_with_options,
|
||||
network.mojom.LockName? with_lock) => ();
|
||||
|
||||
// Notifies the browser of the results of successful parsing of
|
||||
|
@ -151,7 +151,7 @@ interface SharedStorageDocumentService {
|
||||
// with '-'. Return an empty `error_message` on success, and return an
|
||||
// non-empty `error_message` on failure.
|
||||
SharedStorageBatchUpdate(
|
||||
array<network.mojom.SharedStorageModifierMethodWithOptions> methods_with_options,
|
||||
network.mojom.SharedStorageBatchUpdateMethodsArgument methods_with_options,
|
||||
network.mojom.LockName? with_lock)
|
||||
=> (string error_message);
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ interface SharedStorageWorkletServiceClient {
|
||||
// with '-'. Return an empty `error_message` on success, and return an
|
||||
// non-empty `error_message` on failure.
|
||||
SharedStorageBatchUpdate(
|
||||
array<network.mojom.SharedStorageModifierMethodWithOptions> methods_with_options,
|
||||
network.mojom.SharedStorageBatchUpdateMethodsArgument methods_with_options,
|
||||
network.mojom.LockName? with_lock)
|
||||
=> (string error_message);
|
||||
|
||||
|
@ -38,4 +38,21 @@ bool StructTraits<network::mojom::LockNameDataView, WTF::String>::Read(
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
// static
|
||||
bool StructTraits<
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView,
|
||||
WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>>::
|
||||
Read(network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView data,
|
||||
WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>*
|
||||
out_value) {
|
||||
// There is no need to convert
|
||||
// `SharedStorageBatchUpdateMethodsArgumentDataView` back to
|
||||
// `WTF::Vector<network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>`.
|
||||
// If we do need to implement deserialization later, we need to validate its
|
||||
// content.
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
} // namespace mojo
|
||||
|
@ -41,6 +41,26 @@ struct PLATFORM_EXPORT
|
||||
static const WTF::String& data(const WTF::String& input) { return input; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PLATFORM_EXPORT StructTraits<
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView,
|
||||
WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>> {
|
||||
static bool Read(
|
||||
network::mojom::SharedStorageBatchUpdateMethodsArgumentDataView data,
|
||||
WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>*
|
||||
out_value);
|
||||
|
||||
static const WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>&
|
||||
data(const WTF::Vector<
|
||||
network::mojom::blink::SharedStorageModifierMethodWithOptionsPtr>&
|
||||
input) {
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mojo
|
||||
|
||||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SHARED_STORAGE_SHARED_STORAGE_BLINK_MOJOM_TRAITS_H_
|
||||
|
Reference in New Issue
Block a user