Index: fpdfsdk/src/javascript/Document.cpp |
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp |
index c35045c76b53068f2c4cac17bac7bfc7bb58d515..33de577e37a53f4b5ba0256336bf4971defde0fc 100644 |
--- a/fpdfsdk/src/javascript/Document.cpp |
+++ b/fpdfsdk/src/javascript/Document.cpp |
@@ -637,6 +637,7 @@ FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ |
{ |
ASSERT(m_pDocument != NULL); |
CJS_Context* pContext = (CJS_Context*)cc; |
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Lei Zhang
2015/07/21 21:44:47
Why move this up here when we don't use it until m
Tom Sepez
2015/07/22 20:38:24
Ah, right. I was de-duplicating them but the can
|
int nSize = params.size(); |
if (nSize < 1) { |
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
@@ -675,68 +676,44 @@ FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ |
} |
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
- ASSERT(pInterForm != NULL); |
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
- ASSERT(pPDFInterForm != NULL); |
- |
FX_BOOL bAll = (aFields.GetLength() == 0); |
- |
if (bAll && bEmpty) |
{ |
- CJS_Context* pContext = (CJS_Context*)cc; |
- ASSERT(pContext != NULL); |
- CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
- ASSERT(pRuntime != NULL); |
- |
- |
if (pPDFInterForm->CheckRequiredFields()) |
{ |
pRuntime->BeginBlock(); |
pInterForm->SubmitForm(strURL, FALSE); |
pRuntime->EndBlock(); |
} |
- |
return TRUE; |
} |
- else |
- { |
- CFX_PtrArray fieldObjects; |
- for (int i=0,sz=aFields.GetLength(); i<sz; i++) |
- { |
- CJS_Value valName(isolate); |
- aFields.GetElement(i, valName); |
- CFX_WideString sName = valName.ToCFXWideString(); |
+ CFX_PtrArray fieldObjects; |
+ for (int i=0,sz=aFields.GetLength(); i<sz; i++) |
+ { |
+ CJS_Value valName(isolate); |
+ aFields.GetElement(i, valName); |
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
- ASSERT(pPDFForm != NULL); |
+ CFX_WideString sName = valName.ToCFXWideString(); |
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
+ for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) |
+ { |
+ CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
+ if (!bEmpty && pField->GetValue().IsEmpty()) |
+ continue; |
- for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++) |
- { |
- CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
- if (!bEmpty && pField->GetValue().IsEmpty()) |
- continue; |
- |
- fieldObjects.Add(pField); |
- } |
- } |
- |
- CJS_Context* pContext = (CJS_Context*)cc; |
- ASSERT(pContext != NULL); |
- CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
- ASSERT(pRuntime != NULL); |
- |
- |
- if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) |
- { |
- pRuntime->BeginBlock(); |
- pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); |
- pRuntime->EndBlock(); |
- } |
- |
- return TRUE; |
- } |
+ fieldObjects.Add(pField); |
+ } |
+ } |
+ if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) |
+ { |
+ pRuntime->BeginBlock(); |
+ pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); |
+ pRuntime->EndBlock(); |
+ } |
+ return TRUE; |
} |
////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -858,7 +835,8 @@ FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr |
ASSERT(m_pDocument != NULL); |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author"); |
CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title"); |
@@ -875,9 +853,7 @@ FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr |
{ |
CJS_Context* pContext = (CJS_Context *)cc; |
CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
- |
JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); |
- |
JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); |
JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); |
JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); |
@@ -888,7 +864,7 @@ FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr |
JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); |
JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); |
-// It's to be compatible to non-standard info dictionary. |
+ // It's to be compatible to non-standard info dictionary. |
FX_POSITION pos = pDictionary->GetStartPos(); |
while(pos) |
{ |
@@ -902,63 +878,55 @@ FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr |
if(pValueObj->GetType()==PDFOBJ_BOOLEAN) |
JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); |
} |
- |
vp << pObj; |
- return TRUE; |
- } |
- else |
- { |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("CreationDate"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString csCreationDate; |
vp >> csCreationDate; |
pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); |
m_pDocument->SetChangeMark(); |
- |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::creator(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("Creator"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString csCreator; |
vp >> csCreator; |
pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
@@ -966,19 +934,15 @@ FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE |
if (vp.IsGetting()) |
{ |
vp << m_bDelay; |
- return TRUE; |
} |
else |
{ |
- ASSERT(m_pDocument != NULL); |
- |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
bool b; |
vp >> b; |
- |
m_bDelay = b; |
- |
if (m_bDelay) |
{ |
for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++) |
@@ -989,7 +953,6 @@ FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE |
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)) |
@@ -999,7 +962,6 @@ FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE |
} |
} |
m_DelayData.RemoveAll(); |
- |
for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i++) |
{ |
CJS_DelayData* pData = DelayDataToProcess.GetAt(i); |
@@ -1008,132 +970,126 @@ FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE |
delete pData; |
} |
} |
- |
- return TRUE; |
- } |
+ } |
+ return TRUE; |
} |
FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("Keywords"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString csKeywords; |
vp >> csKeywords; |
pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::modDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("ModDate"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString csmodDate; |
vp >> csmodDate; |
pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::producer(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("Producer"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString csproducer; |
vp >> csproducer; |
pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::subject(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("Subject"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString cssubject; |
vp >> cssubject; |
pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
{ |
- ASSERT(m_pDocument != NULL); |
- |
if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) |
return FALSE; |
CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); |
- if (!pDictionary)return FALSE; |
+ if (!pDictionary) |
+ return FALSE; |
if (vp.IsGetting()) |
{ |
vp << pDictionary->GetUnicodeText("Title"); |
- return TRUE; |
} |
else |
{ |
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; |
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
+ return FALSE; |
CFX_WideString cstitle; |
vp >> cstitle; |
pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); |
m_pDocument->SetChangeMark(); |
- return TRUE; |
} |
+ return TRUE; |
} |
FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) |
@@ -1357,13 +1313,10 @@ FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ |
bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) |
{ |
- if (rect.left <= LinkRect.left |
- && rect.top <= LinkRect.top |
- && rect.right >= LinkRect.right |
- && rect.bottom >= LinkRect.bottom) |
- return true; |
- else |
- return false; |
+ return (rect.left <= LinkRect.left && |
+ rect.top <= LinkRect.top && |
+ rect.right >= LinkRect.right && |
+ rect.bottom >= LinkRect.bottom); |
} |
void IconTree::InsertIconElement(IconElement* pNewIcon) |
@@ -1416,8 +1369,7 @@ IconElement* IconTree::operator [](int iIndex) |
} |
return pTemp; |
} |
- else |
- return NULL; |
+ return NULL; |
} |
FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) |