| Index: ppapi/shared_impl/private/ppb_x509_certificate_private_shared.cc
|
| diff --git a/ppapi/shared_impl/private/ppb_x509_certificate_private_shared.cc b/ppapi/shared_impl/private/ppb_x509_certificate_private_shared.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..665ca73dfdd6e73cc4cd6faf3af53636871180ff
|
| --- /dev/null
|
| +++ b/ppapi/shared_impl/private/ppb_x509_certificate_private_shared.cc
|
| @@ -0,0 +1,138 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +#include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "ppapi/shared_impl/ppapi_globals.h"
|
| +#include "ppapi/shared_impl/var.h"
|
| +#include "ppapi/shared_impl/var_tracker.h"
|
| +
|
| +namespace ppapi {
|
| +
|
| +void PPB_X509Certificate_Fields::SetField(
|
| + PP_X509Certificate_Private_Field field,
|
| + base::Value* value) {
|
| + uint32_t index = static_cast<uint32_t>(field);
|
| + bool success = values_.Set(index, value);
|
| + DCHECK(success);
|
| +}
|
| +
|
| +PP_Var PPB_X509Certificate_Fields::GetFieldAsPPVar(
|
| + PP_X509Certificate_Private_Field field) const {
|
| + uint32_t index = static_cast<uint32_t>(field);
|
| + base::Value* value;
|
| + bool success = values_.Get(index, &value);
|
| + if (!success) {
|
| + // Our list received might be smaller than the number of fields, so just
|
| + // return null if the index is OOB.
|
| + return PP_MakeNull();
|
| + }
|
| +
|
| + switch (value->GetType()) {
|
| + case Value::TYPE_NULL:
|
| + return PP_MakeNull();
|
| + case Value::TYPE_BOOLEAN: {
|
| + bool val;
|
| + value->GetAsBoolean(&val);
|
| + return PP_MakeBool(PP_FromBool(val));
|
| + }
|
| + case Value::TYPE_INTEGER: {
|
| + int val;
|
| + value->GetAsInteger(&val);
|
| + return PP_MakeInt32(val);
|
| + }
|
| + case Value::TYPE_DOUBLE: {
|
| + double val;
|
| + value->GetAsDouble(&val);
|
| + return PP_MakeDouble(val);
|
| + }
|
| + case Value::TYPE_STRING: {
|
| + std::string val;
|
| + value->GetAsString(&val);
|
| + return StringVar::StringToPPVar(val);
|
| + }
|
| + case Value::TYPE_BINARY: {
|
| + const base::BinaryValue* binary =
|
| + static_cast<const base::BinaryValue*>(value);
|
| + uint32_t size = static_cast<uint32_t>(binary->GetSize());
|
| + const char* buffer = binary->GetBuffer();
|
| + PP_Var array_buffer =
|
| + PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(size,
|
| + buffer);
|
| + return array_buffer;
|
| + }
|
| + case Value::TYPE_DICTIONARY:
|
| + case Value::TYPE_LIST:
|
| + // Not handled.
|
| + break;
|
| + }
|
| +
|
| + // Should not reach here.
|
| + CHECK(false);
|
| + return PP_MakeUndefined();
|
| +}
|
| +
|
| +//------------------------------------------------------------------------------
|
| +
|
| +PPB_X509Certificate_Private_Shared::PPB_X509Certificate_Private_Shared(
|
| + ResourceObjectType type,
|
| + PP_Instance instance) : Resource(type, instance), fields_(NULL) {
|
| +}
|
| +
|
| +PPB_X509Certificate_Private_Shared::PPB_X509Certificate_Private_Shared(
|
| + ResourceObjectType type,
|
| + PP_Instance instance,
|
| + PPB_X509Certificate_Fields* fields)
|
| + : Resource(type, instance),
|
| + fields_(fields) {
|
| +}
|
| +
|
| +PPB_X509Certificate_Private_Shared::~PPB_X509Certificate_Private_Shared() {
|
| +}
|
| +
|
| +thunk::PPB_X509Certificate_Private_API*
|
| +PPB_X509Certificate_Private_Shared::AsPPB_X509Certificate_Private_API() {
|
| + return this;
|
| +}
|
| +
|
| +PP_Bool PPB_X509Certificate_Private_Shared::Initialize(const char* bytes,
|
| + uint32_t length) {
|
| + // The certificate should be immutable once initialized.
|
| + if (fields_.get())
|
| + return PP_FALSE;
|
| +
|
| + if (!bytes || length == 0)
|
| + return PP_FALSE;
|
| +
|
| + std::vector<char> der(bytes, bytes + length);
|
| + scoped_ptr<PPB_X509Certificate_Fields> fields(
|
| + new PPB_X509Certificate_Fields());
|
| + bool success = ParseDER(der, fields.get());
|
| + if (success) {
|
| + fields_.swap(fields);
|
| + return PP_TRUE;
|
| + }
|
| + return PP_FALSE;
|
| +}
|
| +
|
| +PP_Var PPB_X509Certificate_Private_Shared::GetField(
|
| + PP_X509Certificate_Private_Field field) {
|
| + if (!fields_.get())
|
| + return PP_MakeUndefined();
|
| +
|
| + return fields_->GetFieldAsPPVar(field);
|
| +}
|
| +
|
| +bool PPB_X509Certificate_Private_Shared::ParseDER(
|
| + const std::vector<char>& der,
|
| + PPB_X509Certificate_Fields* result) {
|
| + // A concrete PPB_X509Certificate_Private_Shared should only ever be
|
| + // constructed by passing in PPB_X509Certificate_Fields, in which case it is
|
| + // already initialized.
|
| + CHECK(false);
|
| + return false;
|
| +}
|
| +
|
| +} // namespace ppapi
|
|
|