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

Side by Side Diff: ppapi/shared_impl/private/ppb_flash_x509_certificate_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_flash_x509_certificate_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 PPB_X509Certificate_Fields::~PPB_X509Certificate_Fields() {
15 }
16
17 void PPB_X509Certificate_Fields::SetField(PP_Flash_X509Certificate_Field field,
18 base::Value* value) {
19 uint32_t index = static_cast<uint32_t>(field);
20 bool success = values_.Set(index, value);
21 DCHECK(success);
22 }
23
24 PP_Var PPB_X509Certificate_Fields::GetFieldAsPPVar(
25 PP_Flash_X509Certificate_Field field) const {
26 uint32_t index = static_cast<uint32_t>(field);
27 base::Value* value;
28 bool success = values_.Get(index, &value);
29 if (!success) {
30 // Our list received might be smaller than the number of fields, so just
31 // return null if the index is OOB.
32 return PP_MakeNull();
33 }
34
35 switch (value->GetType()) {
36 case Value::TYPE_NULL:
37 return PP_MakeNull();
38 case Value::TYPE_BOOLEAN: {
39 bool val;
40 value->GetAsBoolean(&val);
41 return PP_MakeBool(PP_FromBool(val));
42 }
43 case Value::TYPE_INTEGER: {
44 int val;
45 value->GetAsInteger(&val);
46 return PP_MakeInt32(val);
47 }
48 case Value::TYPE_DOUBLE: {
49 double val;
50 value->GetAsDouble(&val);
51 return PP_MakeDouble(val);
52 }
53 case Value::TYPE_STRING: {
54 std::string val;
55 value->GetAsString(&val);
56 return StringVar::StringToPPVar(val);
57 }
58 case Value::TYPE_BINARY: {
59 const base::BinaryValue* binary =
60 static_cast<const base::BinaryValue*>(value);
61 uint32_t size = static_cast<uint32_t>(binary->GetSize());
62 const char* buffer = binary->GetBuffer();
63 PP_Var array_buffer =
64 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(size,
65 buffer);
66 return array_buffer;
67 }
68 case Value::TYPE_DICTIONARY:
69 case Value::TYPE_LIST:
70 // Not handled.
71 break;
72 }
73
74 // Should not reach here.
75 CHECK(false);
76 return PP_MakeUndefined();
77 }
78
79 //------------------------------------------------------------------------------
80
81 PPB_Flash_X509Certificate_Shared::PPB_Flash_X509Certificate_Shared(
82 ResourceObjectType type,
83 PP_Instance instance) :
84 Resource(type, instance),
85 fields_(NULL) {
86 }
87
88 PPB_Flash_X509Certificate_Shared::PPB_Flash_X509Certificate_Shared(
89 ResourceObjectType type,
90 PP_Instance instance,
91 PPB_X509Certificate_Fields* fields) :
92 Resource(type, instance),
93 fields_(fields)
94 {
95 }
96
97 PPB_Flash_X509Certificate_Shared::~PPB_Flash_X509Certificate_Shared() {
98 }
99
100 thunk::PPB_Flash_X509Certificate_API*
101 PPB_Flash_X509Certificate_Shared::AsPPB_Flash_X509Certificate_API() {
102 return this;
103 }
104
105 PP_Bool PPB_Flash_X509Certificate_Shared::Init(const char* bytes,
106 uint32_t length) {
107 // The certificate should be immutable once initialized.
108 if (fields_.get())
109 return PP_FALSE;
110
111 if (!bytes || length == 0)
112 return PP_FALSE;
113
114 std::vector<char> der(bytes, bytes + length);
115 scoped_ptr<PPB_X509Certificate_Fields> fields(
116 new PPB_X509Certificate_Fields());
117 bool success = ParseDER(der, fields.get());
118 if (success) {
119 fields_.swap(fields);
120 return PP_TRUE;
121 }
122 return PP_FALSE;
123 }
124
125 PP_Var PPB_Flash_X509Certificate_Shared::GetField(
126 PP_Flash_X509Certificate_Field field) {
127 if (!fields_.get())
128 return PP_MakeUndefined();
129
130 return fields_->GetFieldAsPPVar(field);
131 }
132
133 bool PPB_Flash_X509Certificate_Shared::ParseDER(
yzshen1 2012/03/20 06:48:01 Why not making it a pure virtual method?
raymes 2012/03/21 20:28:08 ParseDER is only used when constructing an X509 ce
134 const std::vector<char>& der,
135 PPB_X509Certificate_Fields* result) {
136 // A concrete PPB_Flash_X509Certificate_Shared should only ever be constructed
137 // by passing in PPB_X509Certificate_Fields, in which case it is already
138 // initialized.
139 CHECK(false);
140 return false;
141 }
142
143 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698