1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (c) 2010 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 "webkit/glue/plugins/pepper_var.h"
#include "third_party/ppapi/c/pp_var.h"
#include "third_party/ppapi/c/ppb_var.h"
#include "webkit/glue/plugins/pepper_string.h"
namespace pepper {
namespace {
void AddRef(PP_Var var) {
if (var.type == PP_VarType_String) {
reinterpret_cast<String*>(var.value.as_id)->AddRef();
} else if (var.type == PP_VarType_Object) {
// TODO(implement objects).
}
}
void Release(PP_Var var) {
if (var.type == PP_VarType_String) {
reinterpret_cast<String*>(var.value.as_id)->Release();
} else if (var.type == PP_VarType_Object) {
// TODO(implement objects).
}
}
PP_Var VarFromUtf8(const char* data, uint32_t len) {
PP_Var ret;
ret.type = PP_VarType_String;
String* str = new String(data, len);
str->AddRef(); // This is for the caller, we return w/ a refcount of 1.
return ret;
}
const char* VarToUtf8(PP_Var var, uint32_t* len) {
if (var.type != PP_VarType_String) {
*len = 0;
return NULL;
}
const std::string& str =
reinterpret_cast<const String*>(var.value.as_id)->value();
*len = static_cast<uint32_t>(str.size());
if (str.empty())
return ""; // Don't return NULL on success.
return str.data();
}
bool HasProperty(PP_Var object,
PP_Var name,
PP_Var* exception) {
// TODO(brettw) implement this.
return false;
}
PP_Var GetProperty(PP_Var object,
PP_Var name,
PP_Var* exception) {
// TODO(brettw) implement this.
PP_Var ret;
ret.type = PP_VarType_Void;
return ret;
}
void GetAllPropertyNames(PP_Var object,
uint32_t* property_count,
PP_Var** properties,
PP_Var* exception) {
// TODO(brettw) implement this.
}
void SetProperty(PP_Var object,
PP_Var name,
PP_Var value,
PP_Var* exception) {
// TODO(brettw) implement this.
}
void RemoveProperty(PP_Var object,
PP_Var name,
PP_Var* exception) {
// TODO(brettw) implement this.
}
PP_Var Call(PP_Var object,
PP_Var method_name,
int32_t argc,
PP_Var* argv,
PP_Var* exception) {
// TODO(brettw) implement this.
PP_Var ret;
ret.type = PP_VarType_Void;
return ret;
}
PP_Var Construct(PP_Var object,
int32_t argc,
PP_Var* argv,
PP_Var* exception) {
// TODO(brettw) implement this.
PP_Var ret;
ret.type = PP_VarType_Void;
return ret;
}
PP_Var CreateObject(const PPP_Class* object_class,
void* object_data) {
// TODO(brettw) implement this.
PP_Var ret;
ret.type = PP_VarType_Void;
return ret;
}
const PPB_Var var_interface = {
&AddRef,
&Release,
&VarFromUtf8,
&VarToUtf8,
&HasProperty,
&GetProperty,
&GetAllPropertyNames,
&SetProperty,
&RemoveProperty,
&Call,
&Construct,
&CreateObject
};
} // namespace
const PPB_Var* GetVarInterface() {
return &var_interface;
}
} // namespace pepper
|