Use DefaultConstructTraits for network::CorsErrorStatus.
This allows the default constructor for CorsErrorStatus to be restricted so it is only available to Mojo. Fixed: 1408442 Change-Id: Ia26e1689a66167d6d5ed485735509d4fd2048f70 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4129453 Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1129442}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
99e7595655
commit
5a6511254e
mojo/public/cpp/bindings/lib
pdf/loader
services/network
@ -10,6 +10,7 @@
|
|||||||
#include "mojo/public/cpp/bindings/array_traits.h"
|
#include "mojo/public/cpp/bindings/array_traits.h"
|
||||||
#include "mojo/public/cpp/bindings/enum_traits.h"
|
#include "mojo/public/cpp/bindings/enum_traits.h"
|
||||||
#include "mojo/public/cpp/bindings/lib/buffer.h"
|
#include "mojo/public/cpp/bindings/lib/buffer.h"
|
||||||
|
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
|
||||||
#include "mojo/public/cpp/bindings/lib/message_fragment.h"
|
#include "mojo/public/cpp/bindings/lib/message_fragment.h"
|
||||||
#include "mojo/public/cpp/bindings/lib/template_util.h"
|
#include "mojo/public/cpp/bindings/lib/template_util.h"
|
||||||
#include "mojo/public/cpp/bindings/map_traits.h"
|
#include "mojo/public/cpp/bindings/map_traits.h"
|
||||||
@ -63,8 +64,14 @@ bool Deserialize(DataType&& input, InputUserType* output, Args&&... args) {
|
|||||||
*output = absl::nullopt;
|
*output = absl::nullopt;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!*output)
|
if (!*output) {
|
||||||
output->emplace();
|
if constexpr (std::is_constructible_v<typename InputUserType::value_type,
|
||||||
|
::mojo::DefaultConstruct::Tag>) {
|
||||||
|
output->emplace(mojo::internal::DefaultConstructTag());
|
||||||
|
} else {
|
||||||
|
output->emplace();
|
||||||
|
}
|
||||||
|
}
|
||||||
return Deserialize<MojomType>(std::forward<DataType>(input),
|
return Deserialize<MojomType>(std::forward<DataType>(input),
|
||||||
&output->value(),
|
&output->value(),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
|
@ -579,8 +579,9 @@ TEST_F(UrlLoaderTest, DidFailWithErrorNetworkAccessDenied) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UrlLoaderTest, DidFailWithWebSecurityViolationError) {
|
TEST_F(UrlLoaderTest, DidFailWithWebSecurityViolationError) {
|
||||||
blink::WebURLError error(network::CorsErrorStatus(),
|
blink::WebURLError error(
|
||||||
blink::WebURLError::HasCopyInCache::kFalse, GURL());
|
network::CorsErrorStatus(network::mojom::CorsError::kDisallowedByMode),
|
||||||
|
blink::WebURLError::HasCopyInCache::kFalse, GURL());
|
||||||
ASSERT_TRUE(error.is_web_security_violation());
|
ASSERT_TRUE(error.is_web_security_violation());
|
||||||
|
|
||||||
int32_t result = DidFailWithError(error);
|
int32_t result = DidFailWithError(error);
|
||||||
|
@ -2004,7 +2004,7 @@ TEST_F(CorsURLLoaderTest, DevToolsObserverOnCorsErrorCallback) {
|
|||||||
EXPECT_TRUE(devtools_observer.cors_error_params());
|
EXPECT_TRUE(devtools_observer.cors_error_params());
|
||||||
const network::MockDevToolsObserver::OnCorsErrorParams& params =
|
const network::MockDevToolsObserver::OnCorsErrorParams& params =
|
||||||
*devtools_observer.cors_error_params();
|
*devtools_observer.cors_error_params();
|
||||||
EXPECT_EQ(mojom::CorsError::kDisallowedByMode, params.status.cors_error);
|
EXPECT_EQ(mojom::CorsError::kDisallowedByMode, params.status->cors_error);
|
||||||
EXPECT_EQ(initiator_origin, params.initiator_origin);
|
EXPECT_EQ(initiator_origin, params.initiator_origin);
|
||||||
EXPECT_EQ(url, params.url);
|
EXPECT_EQ(url, params.url);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
CorsErrorStatus::CorsErrorStatus() = default;
|
CorsErrorStatus::CorsErrorStatus(mojo::DefaultConstruct::Tag) {}
|
||||||
|
|
||||||
CorsErrorStatus::CorsErrorStatus(const CorsErrorStatus&) = default;
|
CorsErrorStatus::CorsErrorStatus(const CorsErrorStatus&) = default;
|
||||||
CorsErrorStatus& CorsErrorStatus::operator=(const CorsErrorStatus&) = default;
|
CorsErrorStatus& CorsErrorStatus::operator=(const CorsErrorStatus&) = default;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "base/component_export.h"
|
#include "base/component_export.h"
|
||||||
#include "base/unguessable_token.h"
|
#include "base/unguessable_token.h"
|
||||||
|
#include "mojo/public/cpp/bindings/default_construct_tag.h"
|
||||||
#include "services/network/public/mojom/cors.mojom-shared.h"
|
#include "services/network/public/mojom/cors.mojom-shared.h"
|
||||||
#include "services/network/public/mojom/ip_address_space.mojom-shared.h"
|
#include "services/network/public/mojom/ip_address_space.mojom-shared.h"
|
||||||
|
|
||||||
@ -17,12 +18,6 @@ namespace network {
|
|||||||
|
|
||||||
// Type-mapped to `network::mojom::CorsErrorStatus`.
|
// Type-mapped to `network::mojom::CorsErrorStatus`.
|
||||||
struct COMPONENT_EXPORT(NETWORK_CPP_BASE) CorsErrorStatus {
|
struct COMPONENT_EXPORT(NETWORK_CPP_BASE) CorsErrorStatus {
|
||||||
// This constructor is used by generated IPC serialization code.
|
|
||||||
// Should not use this explicitly.
|
|
||||||
// TODO(toyoshim, yhirano): Exploring a way to make this private, and allows
|
|
||||||
// only serialization code for mojo can access.
|
|
||||||
CorsErrorStatus();
|
|
||||||
|
|
||||||
// Instances of this type are copyable and efficiently movable.
|
// Instances of this type are copyable and efficiently movable.
|
||||||
CorsErrorStatus(const CorsErrorStatus&);
|
CorsErrorStatus(const CorsErrorStatus&);
|
||||||
CorsErrorStatus& operator=(const CorsErrorStatus&);
|
CorsErrorStatus& operator=(const CorsErrorStatus&);
|
||||||
@ -43,6 +38,9 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) CorsErrorStatus {
|
|||||||
bool operator==(const CorsErrorStatus& rhs) const;
|
bool operator==(const CorsErrorStatus& rhs) const;
|
||||||
bool operator!=(const CorsErrorStatus& rhs) const { return !(*this == rhs); }
|
bool operator!=(const CorsErrorStatus& rhs) const { return !(*this == rhs); }
|
||||||
|
|
||||||
|
// This constructor is used by generated IPC serialization code.
|
||||||
|
explicit CorsErrorStatus(mojo::DefaultConstruct::Tag);
|
||||||
|
|
||||||
// NOTE: This value is meaningless and should be overridden immediately either
|
// NOTE: This value is meaningless and should be overridden immediately either
|
||||||
// by a constructor or by Mojo deserialization code.
|
// by a constructor or by Mojo deserialization code.
|
||||||
mojom::CorsError cors_error = mojom::CorsError::kMaxValue;
|
mojom::CorsError cors_error = mojom::CorsError::kMaxValue;
|
||||||
|
@ -13,14 +13,13 @@ namespace network {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(CorsMojomTraitsTest, CorsErrorStatusMojoRoundTrip) {
|
TEST(CorsMojomTraitsTest, CorsErrorStatusMojoRoundTrip) {
|
||||||
CorsErrorStatus original;
|
CorsErrorStatus original(mojom::CorsError::kInsecurePrivateNetwork,
|
||||||
original.cors_error = mojom::CorsError::kInsecurePrivateNetwork;
|
mojom::IPAddressSpace::kLoopback,
|
||||||
|
mojom::IPAddressSpace::kLocal);
|
||||||
original.failed_parameter = "bleep";
|
original.failed_parameter = "bleep";
|
||||||
original.target_address_space = mojom::IPAddressSpace::kLocal;
|
|
||||||
original.resource_address_space = mojom::IPAddressSpace::kLoopback;
|
|
||||||
original.has_authorization_covered_by_wildcard_on_preflight = true;
|
original.has_authorization_covered_by_wildcard_on_preflight = true;
|
||||||
|
|
||||||
CorsErrorStatus copy;
|
CorsErrorStatus copy(mojom::CorsError::kInvalidResponse);
|
||||||
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<mojom::CorsErrorStatus>(
|
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<mojom::CorsErrorStatus>(
|
||||||
original, copy));
|
original, copy));
|
||||||
EXPECT_EQ(original, copy);
|
EXPECT_EQ(original, copy);
|
||||||
|
@ -664,6 +664,7 @@ mojom("url_loader_base") {
|
|||||||
{
|
{
|
||||||
mojom = "network.mojom.CorsErrorStatus"
|
mojom = "network.mojom.CorsErrorStatus"
|
||||||
cpp = "::network::CorsErrorStatus"
|
cpp = "::network::CorsErrorStatus"
|
||||||
|
default_constructible = false
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
traits_headers =
|
traits_headers =
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "services/network/public/mojom/http_raw_headers.mojom-forward.h"
|
#include "services/network/public/mojom/http_raw_headers.mojom-forward.h"
|
||||||
#include "services/network/public/mojom/ip_address_space.mojom-forward.h"
|
#include "services/network/public/mojom/ip_address_space.mojom-forward.h"
|
||||||
#include "testing/gmock/include/gmock/gmock.h"
|
#include "testing/gmock/include/gmock/gmock.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
@ -179,7 +180,7 @@ class MockDevToolsObserver : public mojom::DevToolsObserver {
|
|||||||
absl::optional<::url::Origin> initiator_origin;
|
absl::optional<::url::Origin> initiator_origin;
|
||||||
mojom::ClientSecurityStatePtr client_security_state;
|
mojom::ClientSecurityStatePtr client_security_state;
|
||||||
GURL url;
|
GURL url;
|
||||||
network::CorsErrorStatus status;
|
absl::optional<network::CorsErrorStatus> status;
|
||||||
bool is_warning = false;
|
bool is_warning = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user