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

Side by Side Diff: fpdfsdk/javascript/JS_GlobalData.cpp

Issue 1835693002: Remove FX_DWORD from fpdfsdk/ and testing/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « fpdfsdk/javascript/Field.cpp ('k') | fpdfsdk/javascript/JS_Object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/fx_crypt.h" 9 #include "core/fdrm/crypto/include/fx_crypt.h"
10 #include "fpdfsdk/include/javascript/IJavaScript.h" 10 #include "fpdfsdk/include/javascript/IJavaScript.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 p += sizeof(uint16_t); 321 p += sizeof(uint16_t);
322 322
323 // uint16_t wTemp = (uint16_t)(('X' << 8) | 'F'); 323 // uint16_t wTemp = (uint16_t)(('X' << 8) | 'F');
324 324
325 if (wType == (uint16_t)(('X' << 8) | 'F')) { 325 if (wType == (uint16_t)(('X' << 8) | 'F')) {
326 uint16_t wVersion = *((uint16_t*)p); 326 uint16_t wVersion = *((uint16_t*)p);
327 p += sizeof(uint16_t); 327 p += sizeof(uint16_t);
328 328
329 ASSERT(wVersion <= 2); 329 ASSERT(wVersion <= 2);
330 330
331 FX_DWORD dwCount = *((FX_DWORD*)p); 331 uint32_t dwCount = *((uint32_t*)p);
332 p += sizeof(FX_DWORD); 332 p += sizeof(uint32_t);
333 333
334 FX_DWORD dwSize = *((FX_DWORD*)p); 334 uint32_t dwSize = *((uint32_t*)p);
335 p += sizeof(FX_DWORD); 335 p += sizeof(uint32_t);
336 336
337 if (dwSize == nLength - sizeof(uint16_t) * 2 - sizeof(FX_DWORD) * 2) { 337 if (dwSize == nLength - sizeof(uint16_t) * 2 - sizeof(uint32_t) * 2) {
338 for (int32_t i = 0, sz = dwCount; i < sz; i++) { 338 for (int32_t i = 0, sz = dwCount; i < sz; i++) {
339 if (p > pBuffer + nLength) 339 if (p > pBuffer + nLength)
340 break; 340 break;
341 341
342 FX_DWORD dwNameLen = *((FX_DWORD*)p); 342 uint32_t dwNameLen = *((uint32_t*)p);
343 p += sizeof(FX_DWORD); 343 p += sizeof(uint32_t);
344 344
345 if (p + dwNameLen > pBuffer + nLength) 345 if (p + dwNameLen > pBuffer + nLength)
346 break; 346 break;
347 347
348 CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen); 348 CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
349 p += sizeof(char) * dwNameLen; 349 p += sizeof(char) * dwNameLen;
350 350
351 uint16_t wDataType = *((uint16_t*)p); 351 uint16_t wDataType = *((uint16_t*)p);
352 p += sizeof(uint16_t); 352 p += sizeof(uint16_t);
353 353
354 switch (wDataType) { 354 switch (wDataType) {
355 case JS_GLOBALDATA_TYPE_NUMBER: { 355 case JS_GLOBALDATA_TYPE_NUMBER: {
356 double dData = 0; 356 double dData = 0;
357 switch (wVersion) { 357 switch (wVersion) {
358 case 1: { 358 case 1: {
359 FX_DWORD dwData = *((FX_DWORD*)p); 359 uint32_t dwData = *((uint32_t*)p);
360 p += sizeof(FX_DWORD); 360 p += sizeof(uint32_t);
361 dData = dwData; 361 dData = dwData;
362 } break; 362 } break;
363 case 2: { 363 case 2: {
364 dData = *((double*)p); 364 dData = *((double*)p);
365 p += sizeof(double); 365 p += sizeof(double);
366 } break; 366 } break;
367 } 367 }
368 SetGlobalVariableNumber(sEntry, dData); 368 SetGlobalVariableNumber(sEntry, dData);
369 SetGlobalVariablePersistent(sEntry, TRUE); 369 SetGlobalVariablePersistent(sEntry, TRUE);
370 } break; 370 } break;
371 case JS_GLOBALDATA_TYPE_BOOLEAN: { 371 case JS_GLOBALDATA_TYPE_BOOLEAN: {
372 uint16_t wData = *((uint16_t*)p); 372 uint16_t wData = *((uint16_t*)p);
373 p += sizeof(uint16_t); 373 p += sizeof(uint16_t);
374 SetGlobalVariableBoolean(sEntry, (bool)(wData == 1)); 374 SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
375 SetGlobalVariablePersistent(sEntry, TRUE); 375 SetGlobalVariablePersistent(sEntry, TRUE);
376 } break; 376 } break;
377 case JS_GLOBALDATA_TYPE_STRING: { 377 case JS_GLOBALDATA_TYPE_STRING: {
378 FX_DWORD dwLength = *((FX_DWORD*)p); 378 uint32_t dwLength = *((uint32_t*)p);
379 p += sizeof(FX_DWORD); 379 p += sizeof(uint32_t);
380 380
381 if (p + dwLength > pBuffer + nLength) 381 if (p + dwLength > pBuffer + nLength)
382 break; 382 break;
383 383
384 SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength)); 384 SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
385 SetGlobalVariablePersistent(sEntry, TRUE); 385 SetGlobalVariablePersistent(sEntry, TRUE);
386 p += sizeof(char) * dwLength; 386 p += sizeof(char) * dwLength;
387 } break; 387 } break;
388 case JS_GLOBALDATA_TYPE_NULL: { 388 case JS_GLOBALDATA_TYPE_NULL: {
389 SetGlobalVariableNull(sEntry); 389 SetGlobalVariableNull(sEntry);
390 SetGlobalVariablePersistent(sEntry, TRUE); 390 SetGlobalVariablePersistent(sEntry, TRUE);
391 } 391 }
392 } 392 }
393 } 393 }
394 } 394 }
395 } 395 }
396 FX_Free(pBuffer); 396 FX_Free(pBuffer);
397 } 397 }
398 } 398 }
399 399
400 void CJS_GlobalData::SaveGlobalPersisitentVariables() { 400 void CJS_GlobalData::SaveGlobalPersisitentVariables() {
401 FX_DWORD nCount = 0; 401 uint32_t nCount = 0;
402 CFX_BinaryBuf sData; 402 CFX_BinaryBuf sData;
403 403
404 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) { 404 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) {
405 CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i); 405 CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
406 if (pElement->bPersistent) { 406 if (pElement->bPersistent) {
407 CFX_BinaryBuf sElement; 407 CFX_BinaryBuf sElement;
408 MakeByteString(pElement->data.sKey, &pElement->data, sElement); 408 MakeByteString(pElement->data.sKey, &pElement->data, sElement);
409 409
410 if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA) 410 if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
411 break; 411 break;
412 412
413 sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize()); 413 sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
414 nCount++; 414 nCount++;
415 } 415 }
416 } 416 }
417 417
418 CFX_BinaryBuf sFile; 418 CFX_BinaryBuf sFile;
419 419
420 uint16_t wType = (uint16_t)(('X' << 8) | 'F'); 420 uint16_t wType = (uint16_t)(('X' << 8) | 'F');
421 sFile.AppendBlock(&wType, sizeof(uint16_t)); 421 sFile.AppendBlock(&wType, sizeof(uint16_t));
422 uint16_t wVersion = 2; 422 uint16_t wVersion = 2;
423 sFile.AppendBlock(&wVersion, sizeof(uint16_t)); 423 sFile.AppendBlock(&wVersion, sizeof(uint16_t));
424 sFile.AppendBlock(&nCount, sizeof(FX_DWORD)); 424 sFile.AppendBlock(&nCount, sizeof(uint32_t));
425 FX_DWORD dwSize = sData.GetSize(); 425 uint32_t dwSize = sData.GetSize();
426 sFile.AppendBlock(&dwSize, sizeof(FX_DWORD)); 426 sFile.AppendBlock(&dwSize, sizeof(uint32_t));
427 427
428 sFile.AppendBlock(sData.GetBuffer(), sData.GetSize()); 428 sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
429 429
430 CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, 430 CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY,
431 sizeof(JS_RC4KEY)); 431 sizeof(JS_RC4KEY));
432 WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(), 432 WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(),
433 sFile.GetSize()); 433 sFile.GetSize());
434 } 434 }
435 435
436 void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath, 436 void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath,
437 uint8_t*& pBuffer, 437 uint8_t*& pBuffer,
438 int32_t& nLength) { 438 int32_t& nLength) {
439 // UnSupport. 439 // UnSupport.
440 } 440 }
441 441
442 void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath, 442 void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath,
443 const FX_CHAR* pBuffer, 443 const FX_CHAR* pBuffer,
444 int32_t nLength) { 444 int32_t nLength) {
445 // UnSupport. 445 // UnSupport.
446 } 446 }
447 447
448 void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, 448 void CJS_GlobalData::MakeByteString(const CFX_ByteString& name,
449 CJS_KeyValue* pData, 449 CJS_KeyValue* pData,
450 CFX_BinaryBuf& sData) { 450 CFX_BinaryBuf& sData) {
451 uint16_t wType = (uint16_t)pData->nType; 451 uint16_t wType = (uint16_t)pData->nType;
452 switch (wType) { 452 switch (wType) {
453 case JS_GLOBALDATA_TYPE_NUMBER: { 453 case JS_GLOBALDATA_TYPE_NUMBER: {
454 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 454 uint32_t dwNameLen = (uint32_t)name.GetLength();
455 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 455 sData.AppendBlock(&dwNameLen, sizeof(uint32_t));
456 sData.AppendString(name); 456 sData.AppendString(name);
457 sData.AppendBlock(&wType, sizeof(uint16_t)); 457 sData.AppendBlock(&wType, sizeof(uint16_t));
458 458
459 double dData = pData->dData; 459 double dData = pData->dData;
460 sData.AppendBlock(&dData, sizeof(double)); 460 sData.AppendBlock(&dData, sizeof(double));
461 } break; 461 } break;
462 case JS_GLOBALDATA_TYPE_BOOLEAN: { 462 case JS_GLOBALDATA_TYPE_BOOLEAN: {
463 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 463 uint32_t dwNameLen = (uint32_t)name.GetLength();
464 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 464 sData.AppendBlock(&dwNameLen, sizeof(uint32_t));
465 sData.AppendString(name); 465 sData.AppendString(name);
466 sData.AppendBlock(&wType, sizeof(uint16_t)); 466 sData.AppendBlock(&wType, sizeof(uint16_t));
467 467
468 uint16_t wData = (uint16_t)pData->bData; 468 uint16_t wData = (uint16_t)pData->bData;
469 sData.AppendBlock(&wData, sizeof(uint16_t)); 469 sData.AppendBlock(&wData, sizeof(uint16_t));
470 } break; 470 } break;
471 case JS_GLOBALDATA_TYPE_STRING: { 471 case JS_GLOBALDATA_TYPE_STRING: {
472 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 472 uint32_t dwNameLen = (uint32_t)name.GetLength();
473 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 473 sData.AppendBlock(&dwNameLen, sizeof(uint32_t));
474 sData.AppendString(name); 474 sData.AppendString(name);
475 sData.AppendBlock(&wType, sizeof(uint16_t)); 475 sData.AppendBlock(&wType, sizeof(uint16_t));
476 476
477 FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength(); 477 uint32_t dwDataLen = (uint32_t)pData->sData.GetLength();
478 sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD)); 478 sData.AppendBlock(&dwDataLen, sizeof(uint32_t));
479 sData.AppendString(pData->sData); 479 sData.AppendString(pData->sData);
480 } break; 480 } break;
481 case JS_GLOBALDATA_TYPE_NULL: { 481 case JS_GLOBALDATA_TYPE_NULL: {
482 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 482 uint32_t dwNameLen = (uint32_t)name.GetLength();
483 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 483 sData.AppendBlock(&dwNameLen, sizeof(uint32_t));
484 sData.AppendString(name); 484 sData.AppendString(name);
485 sData.AppendBlock(&wType, sizeof(FX_DWORD)); 485 sData.AppendBlock(&wType, sizeof(uint32_t));
486 } break; 486 } break;
487 default: 487 default:
488 break; 488 break;
489 } 489 }
490 } 490 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Field.cpp ('k') | fpdfsdk/javascript/JS_Object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698