1 // Copyright 2017 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fxjs/xfa/cjx_source.h"
8 
9 #include <vector>
10 
11 #include "fxjs/cfxjse_value.h"
12 #include "fxjs/js_resources.h"
13 #include "xfa/fxfa/parser/cxfa_source.h"
14 
15 const CJX_MethodSpec CJX_Source::MethodSpecs[] = {
16     {"addNew", addNew_static},
17     {"cancel", cancel_static},
18     {"cancelBatch", cancelBatch_static},
19     {"close", close_static},
20     {"delete", deleteItem_static},
21     {"first", first_static},
22     {"hasDataChanged", hasDataChanged_static},
23     {"isBOF", isBOF_static},
24     {"isEOF", isEOF_static},
25     {"last", last_static},
26     {"next", next_static},
27     {"open", open_static},
28     {"previous", previous_static},
29     {"requery", requery_static},
30     {"resync", resync_static},
31     {"update", update_static},
32     {"updateBatch", updateBatch_static}};
33 
CJX_Source(CXFA_Source * src)34 CJX_Source::CJX_Source(CXFA_Source* src) : CJX_Node(src) {
35   DefineMethods(MethodSpecs, FX_ArraySize(MethodSpecs));
36 }
37 
~CJX_Source()38 CJX_Source::~CJX_Source() {}
39 
next(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)40 CJS_Return CJX_Source::next(CJS_V8* runtime,
41                             const std::vector<v8::Local<v8::Value>>& params) {
42   if (!params.empty())
43     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
44   return CJS_Return(true);
45 }
46 
cancelBatch(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)47 CJS_Return CJX_Source::cancelBatch(
48     CJS_V8* runtime,
49     const std::vector<v8::Local<v8::Value>>& params) {
50   if (!params.empty())
51     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
52   return CJS_Return(true);
53 }
54 
first(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)55 CJS_Return CJX_Source::first(CJS_V8* runtime,
56                              const std::vector<v8::Local<v8::Value>>& params) {
57   if (!params.empty())
58     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
59   return CJS_Return(true);
60 }
61 
updateBatch(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)62 CJS_Return CJX_Source::updateBatch(
63     CJS_V8* runtime,
64     const std::vector<v8::Local<v8::Value>>& params) {
65   if (!params.empty())
66     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
67   return CJS_Return(true);
68 }
69 
previous(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)70 CJS_Return CJX_Source::previous(
71     CJS_V8* runtime,
72     const std::vector<v8::Local<v8::Value>>& params) {
73   if (!params.empty())
74     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
75   return CJS_Return(true);
76 }
77 
isBOF(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)78 CJS_Return CJX_Source::isBOF(CJS_V8* runtime,
79                              const std::vector<v8::Local<v8::Value>>& params) {
80   if (!params.empty())
81     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
82   return CJS_Return(true);
83 }
84 
isEOF(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)85 CJS_Return CJX_Source::isEOF(CJS_V8* runtime,
86                              const std::vector<v8::Local<v8::Value>>& params) {
87   if (!params.empty())
88     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
89   return CJS_Return(true);
90 }
91 
cancel(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)92 CJS_Return CJX_Source::cancel(CJS_V8* runtime,
93                               const std::vector<v8::Local<v8::Value>>& params) {
94   if (!params.empty())
95     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
96   return CJS_Return(true);
97 }
98 
update(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)99 CJS_Return CJX_Source::update(CJS_V8* runtime,
100                               const std::vector<v8::Local<v8::Value>>& params) {
101   if (!params.empty())
102     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
103   return CJS_Return(true);
104 }
105 
open(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)106 CJS_Return CJX_Source::open(CJS_V8* runtime,
107                             const std::vector<v8::Local<v8::Value>>& params) {
108   if (!params.empty())
109     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
110   return CJS_Return(true);
111 }
112 
deleteItem(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)113 CJS_Return CJX_Source::deleteItem(
114     CJS_V8* runtime,
115     const std::vector<v8::Local<v8::Value>>& params) {
116   if (!params.empty())
117     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
118   return CJS_Return(true);
119 }
120 
addNew(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)121 CJS_Return CJX_Source::addNew(CJS_V8* runtime,
122                               const std::vector<v8::Local<v8::Value>>& params) {
123   if (!params.empty())
124     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
125   return CJS_Return(true);
126 }
127 
requery(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)128 CJS_Return CJX_Source::requery(
129     CJS_V8* runtime,
130     const std::vector<v8::Local<v8::Value>>& params) {
131   if (!params.empty())
132     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
133   return CJS_Return(true);
134 }
135 
resync(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)136 CJS_Return CJX_Source::resync(CJS_V8* runtime,
137                               const std::vector<v8::Local<v8::Value>>& params) {
138   if (!params.empty())
139     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
140   return CJS_Return(true);
141 }
142 
close(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)143 CJS_Return CJX_Source::close(CJS_V8* runtime,
144                              const std::vector<v8::Local<v8::Value>>& params) {
145   if (!params.empty())
146     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
147   return CJS_Return(true);
148 }
149 
last(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)150 CJS_Return CJX_Source::last(CJS_V8* runtime,
151                             const std::vector<v8::Local<v8::Value>>& params) {
152   if (!params.empty())
153     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
154   return CJS_Return(true);
155 }
156 
hasDataChanged(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)157 CJS_Return CJX_Source::hasDataChanged(
158     CJS_V8* runtime,
159     const std::vector<v8::Local<v8::Value>>& params) {
160   if (!params.empty())
161     return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
162   return CJS_Return(true);
163 }
164 
db(CFXJSE_Value * pValue,bool bSetting,XFA_Attribute eAttribute)165 void CJX_Source::db(CFXJSE_Value* pValue,
166                     bool bSetting,
167                     XFA_Attribute eAttribute) {}
168 
use(CFXJSE_Value * pValue,bool bSetting,XFA_Attribute eAttribute)169 void CJX_Source::use(CFXJSE_Value* pValue,
170                      bool bSetting,
171                      XFA_Attribute eAttribute) {
172   Script_Attribute_String(pValue, bSetting, eAttribute);
173 }
174 
usehref(CFXJSE_Value * pValue,bool bSetting,XFA_Attribute eAttribute)175 void CJX_Source::usehref(CFXJSE_Value* pValue,
176                          bool bSetting,
177                          XFA_Attribute eAttribute) {
178   Script_Attribute_String(pValue, bSetting, eAttribute);
179 }
180