Remove direct calls to time

Replaces them with calles to the proxy function, FXSYS_time, so that
tests may use a stable time value instead of the wall clock value.

BUG=pdfium:1104

Change-Id: I4743c4634f56d4a6cba1f1130c4562a35cee1887
Reviewed-on: https://pdfium-review.googlesource.com/39853
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index caa82a9..bc72ad3 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -18,6 +18,7 @@
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_object.h"
 #include "core/fpdfapi/parser/cpdf_string.h"
+#include "core/fxcrt/fx_extension.h"
 
 namespace {
 
@@ -531,7 +532,7 @@
     owner_password_copy = user_password;
 
   if (m_Revision >= 5) {
-    int t = (int)time(nullptr);
+    int t = static_cast<int>(FXSYS_time(nullptr));
     CRYPT_sha2_context sha;
     CRYPT_SHA256Start(&sha);
     CRYPT_SHA256Update(&sha, (uint8_t*)&t, sizeof t);
diff --git a/fpdfsdk/cpdfsdk_datetime.cpp b/fpdfsdk/cpdfsdk_datetime.cpp
index 332ae8e..f0d5091 100644
--- a/fpdfsdk/cpdfsdk_datetime.cpp
+++ b/fpdfsdk/cpdfsdk_datetime.cpp
@@ -93,7 +93,7 @@
   tzset();
 
   time_t curTime;
-  time(&curTime);
+  FXSYS_time(&curTime);
 
   struct tm* newtime = localtime(&curTime);
   m_year = newtime->tm_year + 1900;
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index f1dbf70..438a062 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -26,6 +26,7 @@
 #include "core/fpdfapi/parser/cpdf_string.h"
 #include "core/fpdfdoc/cpdf_annot.h"
 #include "core/fpdfdoc/cpdf_annotlist.h"
+#include "core/fxcrt/fx_extension.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "public/fpdf_formfill.h"
 #include "third_party/base/logging.h"
@@ -36,12 +37,6 @@
 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
 #endif  // PDF_ENABLE_XFA
 
-#if _FX_OS_ == _FX_OS_ANDROID_
-#include <time.h>
-#else
-#include <ctime>
-#endif
-
 namespace {
 
 static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT,
@@ -166,7 +161,7 @@
   time_t currentTime;
   ByteString DateStr;
   if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
-    if (time(&currentTime) != -1) {
+    if (FXSYS_time(&currentTime) != -1) {
       tm* pTM = localtime(&currentTime);
       if (pTM) {
         DateStr = ByteString::Format(
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index d164c62..a2773b2 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -954,7 +954,7 @@
 
 void GetLocalTimeZone(int32_t* pHour, int32_t* pMin, int32_t* pSec) {
   time_t now;
-  time(&now);
+  FXSYS_time(&now);
 
   struct tm* pGmt = gmtime(&now);
   struct tm* pLocal = localtime(&now);
@@ -2539,7 +2539,7 @@
   }
 
   time_t now;
-  time(&now);
+  FXSYS_time(&now);
 
   struct tm* pGmt = gmtime(&now);
   args.GetReturnValue()->SetInteger(
diff --git a/fxjs/js_define.cpp b/fxjs/js_define.cpp
index 124fd91..0a18b6d 100644
--- a/fxjs/js_define.cpp
+++ b/fxjs/js_define.cpp
@@ -13,6 +13,7 @@
 #include <limits>
 #include <vector>
 
+#include "core/fxcrt/fx_extension.h"
 #include "fxjs/cjs_document.h"
 #include "fxjs/cjs_object.h"
 
@@ -22,7 +23,7 @@
   if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
     return 0;
   time_t t = 0;
-  time(&t);
+  FXSYS_time(&t);
   localtime(&t);
 #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
   // In gcc 'timezone' is a global variable declared in time.h. In VC++, that
@@ -174,7 +175,7 @@
 double JS_GetDateTime() {
   if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
     return 0;
-  time_t t = time(nullptr);
+  time_t t = FXSYS_time(nullptr);
   struct tm* pTm = localtime(&t);
 
   int year = pTm->tm_year + 1900;