480 lines
15 KiB
C++
Executable File
480 lines
15 KiB
C++
Executable File
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4065)
|
|
#endif
|
|
|
|
#include "components/pdf/common/pdf.mojom-shared.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/logging.h"
|
|
#include "mojo/public/cpp/bindings/lib/validate_params.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_context.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_util.h"
|
|
namespace pdf {
|
|
namespace mojom {
|
|
|
|
namespace internal {
|
|
|
|
|
|
// static
|
|
bool PdfListener_SetCaretPosition_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfListener_SetCaretPosition_Params_Data* object = static_cast<const PdfListener_SetCaretPosition_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->position, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->position, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfListener_SetCaretPosition_Params_Data::PdfListener_SetCaretPosition_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfListener_MoveRangeSelectionExtent_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfListener_MoveRangeSelectionExtent_Params_Data* object = static_cast<const PdfListener_MoveRangeSelectionExtent_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->extent, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->extent, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfListener_MoveRangeSelectionExtent_Params_Data::PdfListener_MoveRangeSelectionExtent_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfListener_SetSelectionBounds_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfListener_SetSelectionBounds_Params_Data* object = static_cast<const PdfListener_SetSelectionBounds_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->base, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->base, validation_context))
|
|
return false;
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->extent, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->extent, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfListener_SetSelectionBounds_Params_Data::PdfListener_SetSelectionBounds_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfService_SetListener_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfService_SetListener_Params_Data* object = static_cast<const PdfService_SetListener_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidateHandleOrInterfaceNonNullable(
|
|
object->client, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateHandleOrInterface(object->client,
|
|
validation_context)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfService_SetListener_Params_Data::PdfService_SetListener_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfService_UpdateContentRestrictions_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfService_UpdateContentRestrictions_Params_Data* object = static_cast<const PdfService_UpdateContentRestrictions_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfService_UpdateContentRestrictions_Params_Data::PdfService_UpdateContentRestrictions_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfService_HasUnsupportedFeature_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfService_HasUnsupportedFeature_Params_Data* object = static_cast<const PdfService_HasUnsupportedFeature_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 8 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfService_HasUnsupportedFeature_Params_Data::PdfService_HasUnsupportedFeature_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfService_SaveUrlAs_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfService_SaveUrlAs_Params_Data* object = static_cast<const PdfService_SaveUrlAs_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->url, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->url, validation_context))
|
|
return false;
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->referrer, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->referrer, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfService_SaveUrlAs_Params_Data::PdfService_SaveUrlAs_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool PdfService_SelectionChanged_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const PdfService_SelectionChanged_Params_Data* object = static_cast<const PdfService_SelectionChanged_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 32 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->left, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->left, validation_context))
|
|
return false;
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->right, 3, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->right, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
PdfService_SelectionChanged_Params_Data::PdfService_SelectionChanged_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
} // namespace internal
|
|
} // namespace mojom
|
|
} // namespace pdf
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(pop)
|
|
#endif
|