summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-14 14:17:26 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-14 14:17:26 -0700
commitdfbf8e7ba55695c4e6cb30eadbe9c6a2955815ba (patch)
tree58eef2a1e6763f71926524827da0f220f761f960 /fpdfsdk/src/javascript
parent758ae14e113c07285126274577d7a5cab559fa65 (diff)
downloadpdfium-dfbf8e7ba55695c4e6cb30eadbe9c6a2955815ba.tar.xz
Next round of XFA changes to match master.
This contains a missed merge of the Document:delay fixes. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1398703009 .
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/Document.cpp117
-rw-r--r--fpdfsdk/src/javascript/Document.h1
-rw-r--r--fpdfsdk/src/javascript/JS_Define.h28
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp5
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.h4
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp29
-rw-r--r--fpdfsdk/src/javascript/global.cpp1
7 files changed, 57 insertions, 128 deletions
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index bcf8af6595..4113f60735 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -861,12 +861,9 @@ FX_BOOL Document::info(IJS_Context* cc,
FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
(bool)pValueObj->GetInteger());
}
-
vp << pObj;
- return TRUE;
- } else {
- return TRUE;
}
+ return TRUE;
}
FX_BOOL Document::creationDate(IJS_Context* cc,
@@ -929,13 +926,20 @@ FX_BOOL Document::delay(IJS_Context* cc,
m_DelayData.RemoveAll();
} else {
+ CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
- Field::DoDelay(m_pDocument, pData);
- delete m_DelayData.GetAt(i);
+ DelayDataToProcess.Add(pData);
+ m_DelayData.SetAt(i, NULL);
}
}
m_DelayData.RemoveAll();
+ for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) {
+ CJS_DelayData* pData = DelayDataToProcess.GetAt(i);
+ Field::DoDelay(m_pDocument, pData);
+ DelayDataToProcess.SetAt(i, NULL);
+ delete pData;
+ }
}
}
return TRUE;
@@ -1340,40 +1344,6 @@ IconElement* IconTree::operator[](int iIndex) {
return NULL;
}
-void IconTree::DeleteIconElement(CFX_WideString swIconName) {
- IconElement* pTemp = m_pHead;
- int iLoopCount = m_iLength;
- for (int i = 0; i < iLoopCount - 1; i++) {
- if (pTemp == m_pEnd)
- break;
-
- if (m_pHead->IconName == swIconName) {
- m_pHead = m_pHead->NextIcon;
- delete pTemp;
- m_iLength--;
- pTemp = m_pHead;
- }
- if (pTemp->NextIcon->IconName == swIconName) {
- if (pTemp->NextIcon == m_pEnd) {
- m_pEnd = pTemp;
- delete pTemp->NextIcon;
- m_iLength--;
- pTemp->NextIcon = NULL;
- } else {
- IconElement* pElement = pTemp->NextIcon;
- pTemp->NextIcon = pTemp->NextIcon->NextIcon;
- delete pElement;
- m_iLength--;
- pElement = NULL;
- }
-
- continue;
- }
-
- pTemp = pTemp->NextIcon;
- }
-}
-
FX_BOOL Document::addIcon(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
@@ -1505,15 +1475,7 @@ FX_BOOL Document::removeIcon(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- CJS_Context* pContext = (CJS_Context*)cc;
- if (params.size() != 1) {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if (!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].ToCFXWideString();
+ // Unsafe, no supported.
return TRUE;
}
@@ -1639,7 +1601,10 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc,
return FALSE;
int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
+
CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
+ ASSERT(pDocument != NULL);
+
CJS_Context* pContext = static_cast<CJS_Context*>(cc);
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
@@ -1788,47 +1753,7 @@ FX_BOOL Document::deletePages(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE)))
- return FALSE;
-
- CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
- v8::Isolate* isolate = pRuntime->GetIsolate();
-
- int iSize = params.size();
- int nStart = 0;
- int nEnd = 0;
- if (iSize < 1) {
- } else if (iSize == 1) {
- if (params[0].GetType() == CJS_Value::VT_object) {
- v8::Local<v8::Object> pObj = params[0].ToV8Object();
- v8::Local<v8::Value> pValue =
- FXJS_GetObjectElement(isolate, pObj, L"nStart");
- nStart = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt();
- pValue = FXJS_GetObjectElement(isolate, pObj, L"nEnd");
- nEnd = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt();
- } else {
- nStart = params[0].ToInt();
- }
- } else {
- nStart = params[0].ToInt();
- nEnd = params[1].ToInt();
- }
-
- int nTotal = m_pDocument->GetPageCount();
- if (nStart < 0)
- nStart = 0;
- if (nStart >= nTotal)
- nStart = nTotal - 1;
-
- if (nEnd < 0)
- nEnd = 0;
- if (nEnd >= nTotal)
- nEnd = nTotal - 1;
-
- if (nEnd < nStart)
- nEnd = nStart;
-
+ // Unsafe, no supported.
return TRUE;
}
@@ -1871,13 +1796,13 @@ void Document::AddDelayData(CJS_DelayData* pData) {
void Document::DoFieldDelay(const CFX_WideString& sFieldName,
int nControlIndex) {
CFX_DWordArray DelArray;
+ CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex;
for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
if (pData->sFieldName == sFieldName &&
pData->nControlIndex == nControlIndex) {
- Field::DoDelay(m_pDocument, pData);
- delete pData;
+ DelayDataForFieldAndControlIndex.Add(pData);
m_DelayData.SetAt(i, NULL);
DelArray.Add(i);
}
@@ -1887,6 +1812,14 @@ void Document::DoFieldDelay(const CFX_WideString& sFieldName,
for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
m_DelayData.RemoveAt(DelArray[j]);
}
+
+ for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz;
+ i++) {
+ CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i);
+ Field::DoDelay(m_pDocument, pData);
+ DelayDataForFieldAndControlIndex.SetAt(i, NULL);
+ delete pData;
+ }
}
void Document::AddDelayAnnotData(CJS_AnnotObj* pData) {
diff --git a/fpdfsdk/src/javascript/Document.h b/fpdfsdk/src/javascript/Document.h
index 149102d0d1..4e6fdee218 100644
--- a/fpdfsdk/src/javascript/Document.h
+++ b/fpdfsdk/src/javascript/Document.h
@@ -52,7 +52,6 @@ class IconTree {
public:
void InsertIconElement(IconElement* pNewIcon);
- void DeleteIconElement(CFX_WideString swIconName);
void DeleteIconTree();
int GetLength();
IconElement* operator[](int iIndex);
diff --git a/fpdfsdk/src/javascript/JS_Define.h b/fpdfsdk/src/javascript/JS_Define.h
index 252c50ff1b..174e9aeaee 100644
--- a/fpdfsdk/src/javascript/JS_Define.h
+++ b/fpdfsdk/src/javascript/JS_Define.h
@@ -82,13 +82,13 @@ void JSPropGetter(const char* prop_name_string,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
CJS_PropValue value(pRuntime);
value.StartGetting();
- if (!(pObj->*M)(pRuntimeContext, value, sError)) {
+ if (!(pObj->*M)(pContext, value, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
sError));
return;
@@ -108,13 +108,13 @@ void JSPropSetter(const char* prop_name_string,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
propValue.StartSetting();
- if (!(pObj->*M)(pRuntimeContext, propValue, sError)) {
+ if (!(pObj->*M)(pContext, propValue, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
sError));
}
@@ -147,7 +147,7 @@ void JSMethod(const char* method_name_string,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
@@ -156,7 +156,7 @@ void JSMethod(const char* method_name_string,
CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
- if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) {
+ if (!(pObj->*M)(pContext, parameters, valueRes, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name_string,
method_name_string, sError));
return;
@@ -370,7 +370,7 @@ void JSSpecialPropGet(const char* class_name,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
@@ -380,7 +380,7 @@ void JSSpecialPropGet(const char* class_name,
CFX_WideString sError;
CJS_PropValue value(pRuntime);
value.StartGetting();
- if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
+ if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
return;
}
@@ -397,7 +397,7 @@ void JSSpecialPropPut(const char* class_name,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
@@ -407,7 +407,7 @@ void JSSpecialPropPut(const char* class_name,
CFX_WideString sError;
CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
PropValue.StartSetting();
- if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
+ if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) {
FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
}
}
@@ -420,7 +420,7 @@ void JSSpecialPropDel(const char* class_name,
IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
@@ -428,7 +428,7 @@ void JSSpecialPropDel(const char* class_name,
CFX_WideString propname =
CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
CFX_WideString sError;
- if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
+ if (!pObj->DelProperty(pContext, propname.c_str(), sError)) {
CFX_ByteString cbName;
cbName.Format("%s.%s", class_name, "DelProperty");
// Probably a missing call to JSFX_Error().
@@ -445,14 +445,14 @@ void JSGlobalFunc(const char* func_name_string,
static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate()));
if (!pRuntime)
return;
- IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
+ IJS_Context* pContext = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
}
CJS_Value valueRes(pRuntime);
CFX_WideString sError;
- if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) {
+ if (!(*F)(pContext, parameters, valueRes, sError)) {
FXJS_Error(pRuntime->GetIsolate(),
JSFormatErrorString(func_name_string, nullptr, sError));
return;
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index e13b50f5ef..cf5b997dd2 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -104,7 +104,7 @@ CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr;
// static
CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) {
if (!g_Instance) {
- g_Instance = new CJS_GlobalData(pApp);
+ g_Instance = new CJS_GlobalData();
}
++g_Instance->m_RefCount;
return g_Instance;
@@ -117,8 +117,7 @@ void CJS_GlobalData::Release() {
}
}
-CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp)
- : m_pApp(pApp), m_RefCount(0) {
+CJS_GlobalData::CJS_GlobalData() : m_RefCount(0) {
m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
LoadGlobalPersistentVariables();
}
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.h b/fpdfsdk/src/javascript/JS_GlobalData.h
index b174a8d76e..a358e80e55 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.h
+++ b/fpdfsdk/src/javascript/JS_GlobalData.h
@@ -79,7 +79,7 @@ class CJS_GlobalData {
private:
static CJS_GlobalData* g_Instance;
- CJS_GlobalData(CPDFDoc_Environment* pApp);
+ CJS_GlobalData();
~CJS_GlobalData();
void LoadGlobalPersistentVariables();
@@ -98,11 +98,9 @@ class CJS_GlobalData {
CJS_KeyValue* pData,
CFX_BinaryBuf& sData);
- private:
size_t m_RefCount;
CFX_ArrayTemplate<CJS_GlobalData_Element*> m_arrayGlobalData;
CFX_WideString m_sFilePath;
- CPDFDoc_Environment* m_pApp;
};
#endif // FPDFSDK_SRC_JAVASCRIPT_JS_GLOBALDATA_H_
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 0b3b38f8f1..71726a2db0 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -48,9 +48,18 @@ END_JS_STATIC_GLOBAL_FUN()
IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
-static const FX_WCHAR* months[] = {L"Jan", L"Feb", L"Mar", L"Apr",
- L"May", L"Jun", L"Jul", L"Aug",
- L"Sep", L"Oct", L"Nov", L"Dec"};
+static const FX_WCHAR* const months[] = {L"Jan",
+ L"Feb",
+ L"Mar",
+ L"Apr",
+ L"May",
+ L"Jun",
+ L"Jul",
+ L"Aug",
+ L"Sep",
+ L"Oct",
+ L"Nov",
+ L"Dec"};
static const FX_WCHAR* const fullmonths[] = {
L"January", L"February", L"March", L"April",
@@ -935,7 +944,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
strValue.Replace(",", ".");
double dValue = atof(strValue);
if (iDec > 0)
- dValue += DOUBLE_CORRECT; //
+ dValue += DOUBLE_CORRECT;
int iDec2;
int iNegative = 0;
@@ -984,11 +993,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
else
cSeperator = '.';
- int iDecPositive, iDecNegative;
- iDecPositive = iDec2;
- iDecNegative = iDec2;
-
- for (iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
+ for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
strValue.Insert(iDecPositive, cSeperator);
iMax++;
}
@@ -1274,11 +1279,7 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format(IJS_Context* cc,
else
cSeperator = '.';
- int iDecPositive, iDecNegative;
- iDecPositive = iDec2;
- iDecNegative = iDec2;
-
- for (iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
+ for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
strValue.Insert(iDecPositive, cSeperator);
iMax++;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 403cf58ebf..cd0048d95b 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -7,7 +7,6 @@
#include "global.h"
#include "../../../core/include/fxcrt/fx_ext.h"
-#include "../../include/fpdfxfa/fpdfxfa_app.h"
#include "../../include/javascript/IJavaScript.h"
#include "JS_Context.h"
#include "JS_Define.h"