John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ |
| 8 | #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 10 | #include "../../../core/include/fxcrt/fx_basic.h" |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 11 | #include "../jsapi/fxjs_v8.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 12 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | class CJS_Array; |
| 14 | class CJS_Date; |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 15 | class CJS_Document; |
| 16 | class CJS_Object; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 18 | class CJS_Value { |
| 19 | public: |
| 20 | CJS_Value(v8::Isolate* isolate); |
| 21 | CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, FXJSVALUETYPE t); |
| 22 | CJS_Value(v8::Isolate* isolate, const int& iValue); |
| 23 | CJS_Value(v8::Isolate* isolate, const double& dValue); |
| 24 | CJS_Value(v8::Isolate* isolate, const float& fValue); |
| 25 | CJS_Value(v8::Isolate* isolate, const bool& bValue); |
| 26 | CJS_Value(v8::Isolate* isolate, JSFXObject); |
| 27 | CJS_Value(v8::Isolate* isolate, CJS_Object*); |
| 28 | CJS_Value(v8::Isolate* isolate, CJS_Document*); |
| 29 | CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr); |
| 30 | CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr); |
| 31 | CJS_Value(v8::Isolate* isolate, CJS_Array& array); |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 33 | ~CJS_Value(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 35 | void SetNull(); |
| 36 | void Attach(v8::Local<v8::Value> pValue, FXJSVALUETYPE t); |
| 37 | void Attach(CJS_Value* pValue); |
| 38 | void Detach(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 40 | int ToInt() const; |
| 41 | bool ToBool() const; |
| 42 | double ToDouble() const; |
| 43 | float ToFloat() const; |
| 44 | CJS_Object* ToCJSObject() const; |
| 45 | CFX_WideString ToCFXWideString() const; |
| 46 | CFX_ByteString ToCFXByteString() const; |
| 47 | v8::Local<v8::Object> ToV8Object() const; |
| 48 | v8::Local<v8::Array> ToV8Array() const; |
| 49 | v8::Local<v8::Value> ToV8Value() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 51 | void operator=(int iValue); |
| 52 | void operator=(bool bValue); |
| 53 | void operator=(double); |
| 54 | void operator=(float); |
| 55 | void operator=(CJS_Object*); |
| 56 | void operator=(CJS_Document*); |
| 57 | void operator=(v8::Local<v8::Object>); |
| 58 | void operator=(CJS_Array&); |
| 59 | void operator=(CJS_Date&); |
| 60 | void operator=(const FX_WCHAR* pWstr); |
| 61 | void operator=(const FX_CHAR* pStr); |
| 62 | void operator=(CJS_Value value); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 64 | FX_BOOL IsArrayObject() const; |
| 65 | FX_BOOL IsDateObject() const; |
| 66 | FXJSVALUETYPE GetType() const; |
Tom Sepez | f79a69c | 2014-10-30 13:23:42 -0700 | [diff] [blame] | 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 68 | FX_BOOL ConvertToArray(CJS_Array&) const; |
| 69 | FX_BOOL ConvertToDate(CJS_Date&) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 71 | v8::Isolate* GetIsolate() { return m_isolate; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 73 | protected: |
| 74 | v8::Local<v8::Value> m_pValue; |
| 75 | FXJSVALUETYPE m_eType; |
| 76 | v8::Isolate* m_isolate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 79 | class CJS_Parameters : public CFX_ArrayTemplate<CJS_Value> { |
| 80 | public: |
| 81 | void push_back(const CJS_Value& newElement) { |
| 82 | CFX_ArrayTemplate<CJS_Value>::Add(newElement); |
| 83 | } |
| 84 | int size() const { return CFX_ArrayTemplate<CJS_Value>::GetSize(); } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | }; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 87 | class CJS_PropValue : public CJS_Value { |
| 88 | public: |
| 89 | CJS_PropValue(const CJS_Value&); |
| 90 | CJS_PropValue(v8::Isolate* isolate); |
| 91 | ~CJS_PropValue(); |
| 92 | |
| 93 | public: |
| 94 | FX_BOOL IsSetting(); |
| 95 | FX_BOOL IsGetting(); |
| 96 | void operator<<(int); |
| 97 | void operator>>(int&) const; |
| 98 | void operator<<(bool); |
| 99 | void operator>>(bool&) const; |
| 100 | void operator<<(double); |
| 101 | void operator>>(double&) const; |
| 102 | void operator<<(CJS_Object* pObj); |
| 103 | void operator>>(CJS_Object*& ppObj) const; |
| 104 | void operator<<(CJS_Document* pJsDoc); |
| 105 | void operator>>(CJS_Document*& ppJsDoc) const; |
| 106 | void operator<<(CFX_ByteString); |
| 107 | void operator>>(CFX_ByteString&) const; |
| 108 | void operator<<(CFX_WideString); |
| 109 | void operator>>(CFX_WideString&) const; |
| 110 | void operator<<(const FX_WCHAR* c_string); |
| 111 | void operator<<(JSFXObject); |
| 112 | void operator>>(JSFXObject&) const; |
| 113 | void operator>>(CJS_Array& array) const; |
| 114 | void operator<<(CJS_Array& array); |
| 115 | void operator<<(CJS_Date& date); |
| 116 | void operator>>(CJS_Date& date) const; |
| 117 | operator v8::Local<v8::Value>() const; |
| 118 | void StartSetting(); |
| 119 | void StartGetting(); |
| 120 | |
| 121 | private: |
| 122 | FX_BOOL m_bIsSetting; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 125 | class CJS_Array { |
| 126 | public: |
| 127 | CJS_Array(v8::Isolate* isolate); |
| 128 | virtual ~CJS_Array(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 130 | void Attach(v8::Local<v8::Array> pArray); |
| 131 | void GetElement(unsigned index, CJS_Value& value); |
| 132 | void SetElement(unsigned index, CJS_Value value); |
| 133 | int GetLength(); |
| 134 | FX_BOOL IsAttached(); |
| 135 | operator v8::Local<v8::Array>(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 137 | v8::Isolate* GetIsolate() { return m_isolate; } |
| 138 | |
| 139 | private: |
| 140 | v8::Local<v8::Array> m_pArray; |
| 141 | v8::Isolate* m_isolate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 144 | class CJS_Date { |
| 145 | friend class CJS_Value; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 146 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 147 | public: |
| 148 | CJS_Date(v8::Isolate* isolate); |
| 149 | CJS_Date(v8::Isolate* isolate, double dMsec_time); |
| 150 | CJS_Date(v8::Isolate* isolate, |
| 151 | int year, |
| 152 | int mon, |
| 153 | int day, |
| 154 | int hour, |
| 155 | int min, |
| 156 | int sec); |
| 157 | virtual ~CJS_Date(); |
| 158 | void Attach(v8::Local<v8::Value> pDate); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 159 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 160 | int GetYear(); |
| 161 | void SetYear(int iYear); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 163 | int GetMonth(); |
| 164 | void SetMonth(int iMonth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 166 | int GetDay(); |
| 167 | void SetDay(int iDay); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 168 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 169 | int GetHours(); |
| 170 | void SetHours(int iHours); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 172 | int GetMinutes(); |
| 173 | void SetMinutes(int minutes); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 174 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 175 | int GetSeconds(); |
| 176 | void SetSeconds(int seconds); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 177 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 178 | operator v8::Local<v8::Value>(); |
| 179 | operator double() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 180 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 181 | CFX_WideString ToString() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 183 | static double |
| 184 | MakeDate(int year, int mon, int mday, int hour, int min, int sec, int ms); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 185 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 186 | FX_BOOL IsValidDate(); |
| 187 | |
| 188 | protected: |
| 189 | v8::Local<v8::Value> m_pDate; |
| 190 | v8::Isolate* m_isolate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 193 | #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_ |