Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ppapi/shared_impl/private/ppb_x509_certificate_private_shared.cc

Issue 9693024: Add the PPAPI X509 Certificate interface and implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h"
6
7 #include "base/logging.h"
8 #include "ppapi/shared_impl/ppapi_globals.h"
9 #include "ppapi/shared_impl/var.h"
10 #include "ppapi/shared_impl/var_tracker.h"
11
12 namespace ppapi {
13
14 void PPB_X509Certificate_Fields::SetField(
15 PP_X509Certificate_Private_Field field,
16 base::Value* value) {
17 uint32_t index = static_cast<uint32_t>(field);
18 bool success = values_.Set(index, value);
19 DCHECK(success);
20 }
21
22 PP_Var PPB_X509Certificate_Fields::GetFieldAsPPVar(
23 PP_X509Certificate_Private_Field field) const {
24 uint32_t index = static_cast<uint32_t>(field);
25 base::Value* value;
26 bool success = values_.Get(index, &value);
27 if (!success) {
28 // Our list received might be smaller than the number of fields, so just
29 // return null if the index is OOB.
30 return PP_MakeNull();
31 }
32
33 switch (value->GetType()) {
34 case Value::TYPE_NULL:
35 return PP_MakeNull();
36 case Value::TYPE_BOOLEAN: {
37 bool val;
38 value->GetAsBoolean(&val);
39 return PP_MakeBool(PP_FromBool(val));
40 }
41 case Value::TYPE_INTEGER: {
42 int val;
43 value->GetAsInteger(&val);
44 return PP_MakeInt32(val);
45 }
46 case Value::TYPE_DOUBLE: {
47 double val;
48 value->GetAsDouble(&val);
49 return PP_MakeDouble(val);
50 }
51 case Value::TYPE_STRING: {
52 std::string val;
53 value->GetAsString(&val);
54 return StringVar::StringToPPVar(val);
55 }
56 case Value::TYPE_BINARY: {
57 const base::BinaryValue* binary =
58 static_cast<const base::BinaryValue*>(value);
59 uint32_t size = static_cast<uint32_t>(binary->GetSize());
60 const char* buffer = binary->GetBuffer();
61 PP_Var array_buffer =
62 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(size,
63 buffer);
64 return array_buffer;
65 }
66 case Value::TYPE_DICTIONARY:
67 case Value::TYPE_LIST:
68 // Not handled.
69 break;
70 }
71
72 // Should not reach here.
73 CHECK(false);
74 return PP_MakeUndefined();
75 }
76
77 //------------------------------------------------------------------------------
78
79 PPB_X509Certificate_Private_Shared::PPB_X509Certificate_Private_Shared(
80 ResourceObjectType type,
81 PP_Instance instance) :
82 Resource(type, instance),
83 fields_(NULL) {
84 }
85
86 PPB_X509Certificate_Private_Shared::PPB_X509Certificate_Private_Shared(
87 ResourceObjectType type,
88 PP_Instance instance,
89 PPB_X509Certificate_Fields* fields) :
yzshen1 2012/03/26 17:51:08 Either move this colon to the beginning of the nex
raymes 2012/03/26 19:31:34 Done.
90 Resource(type, instance),
91 fields_(fields)
92 {
yzshen1 2012/03/26 17:51:08 move it to the end of the previous line.
raymes 2012/03/26 19:31:34 Done.
93 }
94
95 PPB_X509Certificate_Private_Shared::~PPB_X509Certificate_Private_Shared() {
96 }
97
98 thunk::PPB_X509Certificate_Private_API*
99 PPB_X509Certificate_Private_Shared::AsPPB_X509Certificate_Private_API() {
100 return this;
101 }
102
103 PP_Bool PPB_X509Certificate_Private_Shared::Initialize(const char* bytes,
104 uint32_t length) {
105 // The certificate should be immutable once initialized.
106 if (fields_.get())
107 return PP_FALSE;
108
109 if (!bytes || length == 0)
110 return PP_FALSE;
111
112 std::vector<char> der(bytes, bytes + length);
113 scoped_ptr<PPB_X509Certificate_Fields> fields(
114 new PPB_X509Certificate_Fields());
115 bool success = ParseDER(der, fields.get());
116 if (success) {
117 fields_.swap(fields);
118 return PP_TRUE;
119 }
120 return PP_FALSE;
121 }
122
123 PP_Var PPB_X509Certificate_Private_Shared::GetField(
124 PP_X509Certificate_Private_Field field) {
125 if (!fields_.get())
126 return PP_MakeUndefined();
127
128 return fields_->GetFieldAsPPVar(field);
129 }
130
131 bool PPB_X509Certificate_Private_Shared::ParseDER(
132 const std::vector<char>& der,
133 PPB_X509Certificate_Fields* result) {
134 // A concrete PPB_X509Certificate_Private_Shared should only ever be
135 // constructed by passing in PPB_X509Certificate_Fields, in which case it is
136 // already initialized.
137 CHECK(false);
138 return false;
139 }
140
141 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698