OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/javascript/JS_GlobalData.h" | 7 #include "fpdfsdk/javascript/JS_GlobalData.h" |
8 | 8 |
9 #include "core/fdrm/crypto/fx_crypt.h" | 9 #include "core/fdrm/crypto/fx_crypt.h" |
10 #include "third_party/base/stl_util.h" | 10 #include "third_party/base/stl_util.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { | 172 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { |
173 pData->data.nType = JS_GlobalDataType::NULLOBJ; | 173 pData->data.nType = JS_GlobalDataType::NULLOBJ; |
174 return; | 174 return; |
175 } | 175 } |
176 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); | 176 std::unique_ptr<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element); |
177 pNewData->data.sKey = sPropName; | 177 pNewData->data.sKey = sPropName; |
178 pNewData->data.nType = JS_GlobalDataType::NULLOBJ; | 178 pNewData->data.nType = JS_GlobalDataType::NULLOBJ; |
179 m_arrayGlobalData.push_back(std::move(pNewData)); | 179 m_arrayGlobalData.push_back(std::move(pNewData)); |
180 } | 180 } |
181 | 181 |
182 FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent( | 182 bool CJS_GlobalData::SetGlobalVariablePersistent(const CFX_ByteString& propname, |
183 const CFX_ByteString& propname, | 183 bool bPersistent) { |
184 FX_BOOL bPersistent) { | |
185 CFX_ByteString sPropName(propname); | 184 CFX_ByteString sPropName(propname); |
186 if (!TrimPropName(&sPropName)) | 185 if (!TrimPropName(&sPropName)) |
187 return FALSE; | 186 return false; |
188 | 187 |
189 CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName); | 188 CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName); |
190 if (!pData) | 189 if (!pData) |
191 return FALSE; | 190 return false; |
192 | 191 |
193 pData->bPersistent = bPersistent; | 192 pData->bPersistent = bPersistent; |
194 return TRUE; | 193 return true; |
195 } | 194 } |
196 | 195 |
197 FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const CFX_ByteString& propname) { | 196 bool CJS_GlobalData::DeleteGlobalVariable(const CFX_ByteString& propname) { |
198 CFX_ByteString sPropName(propname); | 197 CFX_ByteString sPropName(propname); |
199 if (!TrimPropName(&sPropName)) | 198 if (!TrimPropName(&sPropName)) |
200 return FALSE; | 199 return false; |
201 | 200 |
202 auto iter = FindGlobalVariable(sPropName); | 201 auto iter = FindGlobalVariable(sPropName); |
203 if (iter == m_arrayGlobalData.end()) | 202 if (iter == m_arrayGlobalData.end()) |
204 return FALSE; | 203 return false; |
205 | 204 |
206 m_arrayGlobalData.erase(iter); | 205 m_arrayGlobalData.erase(iter); |
207 return TRUE; | 206 return true; |
208 } | 207 } |
209 | 208 |
210 int32_t CJS_GlobalData::GetSize() const { | 209 int32_t CJS_GlobalData::GetSize() const { |
211 return pdfium::CollectionSize<int32_t>(m_arrayGlobalData); | 210 return pdfium::CollectionSize<int32_t>(m_arrayGlobalData); |
212 } | 211 } |
213 | 212 |
214 CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { | 213 CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { |
215 if (index < 0 || index >= GetSize()) | 214 if (index < 0 || index >= GetSize()) |
216 return nullptr; | 215 return nullptr; |
217 return m_arrayGlobalData[index].get(); | 216 return m_arrayGlobalData[index].get(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 uint32_t dwData = *((uint32_t*)p); | 266 uint32_t dwData = *((uint32_t*)p); |
268 p += sizeof(uint32_t); | 267 p += sizeof(uint32_t); |
269 dData = dwData; | 268 dData = dwData; |
270 } break; | 269 } break; |
271 case 2: { | 270 case 2: { |
272 dData = *((double*)p); | 271 dData = *((double*)p); |
273 p += sizeof(double); | 272 p += sizeof(double); |
274 } break; | 273 } break; |
275 } | 274 } |
276 SetGlobalVariableNumber(sEntry, dData); | 275 SetGlobalVariableNumber(sEntry, dData); |
277 SetGlobalVariablePersistent(sEntry, TRUE); | 276 SetGlobalVariablePersistent(sEntry, true); |
278 } break; | 277 } break; |
279 case JS_GlobalDataType::BOOLEAN: { | 278 case JS_GlobalDataType::BOOLEAN: { |
280 uint16_t wData = *((uint16_t*)p); | 279 uint16_t wData = *((uint16_t*)p); |
281 p += sizeof(uint16_t); | 280 p += sizeof(uint16_t); |
282 SetGlobalVariableBoolean(sEntry, (bool)(wData == 1)); | 281 SetGlobalVariableBoolean(sEntry, (bool)(wData == 1)); |
283 SetGlobalVariablePersistent(sEntry, TRUE); | 282 SetGlobalVariablePersistent(sEntry, true); |
284 } break; | 283 } break; |
285 case JS_GlobalDataType::STRING: { | 284 case JS_GlobalDataType::STRING: { |
286 uint32_t dwLength = *((uint32_t*)p); | 285 uint32_t dwLength = *((uint32_t*)p); |
287 p += sizeof(uint32_t); | 286 p += sizeof(uint32_t); |
288 | 287 |
289 if (p + dwLength > pBuffer + nLength) | 288 if (p + dwLength > pBuffer + nLength) |
290 break; | 289 break; |
291 | 290 |
292 SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength)); | 291 SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength)); |
293 SetGlobalVariablePersistent(sEntry, TRUE); | 292 SetGlobalVariablePersistent(sEntry, true); |
294 p += sizeof(char) * dwLength; | 293 p += sizeof(char) * dwLength; |
295 } break; | 294 } break; |
296 case JS_GlobalDataType::NULLOBJ: { | 295 case JS_GlobalDataType::NULLOBJ: { |
297 SetGlobalVariableNull(sEntry); | 296 SetGlobalVariableNull(sEntry); |
298 SetGlobalVariablePersistent(sEntry, TRUE); | 297 SetGlobalVariablePersistent(sEntry, true); |
299 } | 298 } |
300 case JS_GlobalDataType::OBJECT: | 299 case JS_GlobalDataType::OBJECT: |
301 break; | 300 break; |
302 } | 301 } |
303 } | 302 } |
304 } | 303 } |
305 } | 304 } |
306 FX_Free(pBuffer); | 305 FX_Free(pBuffer); |
307 } | 306 } |
308 } | 307 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 case JS_GlobalDataType::NULLOBJ: { | 385 case JS_GlobalDataType::NULLOBJ: { |
387 uint32_t dwNameLen = (uint32_t)name.GetLength(); | 386 uint32_t dwNameLen = (uint32_t)name.GetLength(); |
388 sData.AppendBlock(&dwNameLen, sizeof(uint32_t)); | 387 sData.AppendBlock(&dwNameLen, sizeof(uint32_t)); |
389 sData.AppendString(name); | 388 sData.AppendString(name); |
390 sData.AppendBlock(&pData->nType, sizeof(uint32_t)); | 389 sData.AppendBlock(&pData->nType, sizeof(uint32_t)); |
391 } break; | 390 } break; |
392 default: | 391 default: |
393 break; | 392 break; |
394 } | 393 } |
395 } | 394 } |
OLD | NEW |