diff options
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r-- | fpdfsdk/src/fsdk_baseform.cpp | 84 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Document.cpp | 698 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Object.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 323 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/report.cpp | 17 |
5 files changed, 166 insertions, 963 deletions
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 7cdb32f4bd..f2873b51fd 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -3141,20 +3141,6 @@ FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBuf return TRUE; } -FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName, - const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude) -{ - if (sFDFFileName.IsEmpty()) return FALSE; - ASSERT(m_pDocument != NULL); - ASSERT(m_pInterForm != NULL); - - CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude); - if (!pFDF) return FALSE; - FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;// - delete pFDF; - - return bRet; -} FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf) { ASSERT(m_pDocument != NULL); @@ -3234,22 +3220,6 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOO return TRUE; } -FX_BOOL CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName) -{ - if (sFDFFileName.IsEmpty()) return FALSE; - - ASSERT(m_pInterForm != NULL); - ASSERT(m_pDocument != NULL); - - CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath()); - if (!pFDF) return FALSE; - - FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); - delete pFDF; - - return bRet; -} - FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { @@ -3265,43 +3235,6 @@ FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) return bRet; } -FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName) -{ - ASSERT(m_pInterForm != NULL); - - CFX_WideString sFieldNames; - CFX_WideString sFieldValues; - - int nSize = m_pInterForm->CountFields(); - - if (nSize > 0) - { - for (int i=0; i<nSize; i++) - { - CPDF_FormField* pField = m_pInterForm->GetField(i); - ASSERT(pField != NULL); - - if (i != 0) - { - sFieldNames += L"\t"; - sFieldValues += L"\t"; - } - sFieldNames += pField->GetFullName(); - sFieldValues += pField->GetValue(); - } - - return TRUE; - } - - return FALSE; -} - -FX_BOOL CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName) -{ - ASSERT(m_pInterForm != NULL); - - return TRUE; -} FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { @@ -3332,23 +3265,6 @@ FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { - ASSERT(action != NULL); - - CFX_WideString sFilePath = action.GetFilePath(); - if (sFilePath.IsEmpty()) - return FALSE; - - if (!ImportFormFromFDFFile(sFilePath, TRUE)) - { - return FALSE; - } - - return TRUE; -} - -FX_BOOL CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName, - FX_BOOL bNotify) -{ return FALSE; } diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index e35c538c22..8a5ab6b454 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -1,7 +1,7 @@ // Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - + // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/javascript/JavaScript.h" @@ -78,7 +78,7 @@ BEGIN_JS_STATIC_PROP(CJS_Document) JS_STATIC_PROP_ENTRY(external) JS_STATIC_PROP_ENTRY(filesize) JS_STATIC_PROP_ENTRY(icons) - JS_STATIC_PROP_ENTRY(info) + JS_STATIC_PROP_ENTRY(info) JS_STATIC_PROP_ENTRY(keywords) JS_STATIC_PROP_ENTRY(layout) JS_STATIC_PROP_ENTRY(media) @@ -87,7 +87,7 @@ BEGIN_JS_STATIC_PROP(CJS_Document) JS_STATIC_PROP_ENTRY(mouseY) JS_STATIC_PROP_ENTRY(numFields) JS_STATIC_PROP_ENTRY(numPages) - JS_STATIC_PROP_ENTRY(pageNum) + JS_STATIC_PROP_ENTRY(pageNum) JS_STATIC_PROP_ENTRY(pageWindowRect) JS_STATIC_PROP_ENTRY(path) JS_STATIC_PROP_ENTRY(producer) @@ -137,7 +137,7 @@ BEGIN_JS_STATIC_METHOD(CJS_Document) JS_STATIC_METHOD_ENTRY(removeIcon, 0) JS_STATIC_METHOD_ENTRY(saveAs, 5) JS_STATIC_METHOD_ENTRY(submitForm, 23) - JS_STATIC_METHOD_ENTRY(mailDoc, 0) + JS_STATIC_METHOD_ENTRY(mailDoc, 0) END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_Document, Document) @@ -149,7 +149,7 @@ FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc) Document* pDoc = (Document*)GetEmbedObject(); ASSERT(pDoc != NULL); - + pDoc->AttachDoc(pContext->GetReaderDocument()); pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); return TRUE; @@ -181,7 +181,7 @@ Document::~Document() delete pData; pData = NULL; m_DelayData.SetAt(i, NULL); - + } } @@ -253,14 +253,14 @@ FX_BOOL Document::pageNum(OBJ_PROP_PARAMS) ASSERT(m_pDocument != NULL); if (vp.IsGetting()) - { + { if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { vp << pPageView->GetPageIndex(); } } else - { + { int iPageCount = m_pDocument->GetPageCount(); int iPageNum = 0; @@ -289,131 +289,37 @@ FX_BOOL Document::pageNum(OBJ_PROP_PARAMS) FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj) { + // Not supported. return TRUE; } FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS) { + // Not supported. return TRUE; } FX_BOOL Document::addField(OBJ_METHOD_PARAMS) { - //Doesn't support. + // Not supported. return TRUE; } -//exports form fields as a tab-delimited text file to a local hard disk. -//comment: need reader support -//note : watch the third parameter:cPath, for what case it can be safely saved? -//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath); -//return value, int the index of the parameters illegal, the index is based on 1. - FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; + // Unsafe, not supported. return TRUE; } -//exports form fields as a fdf file to the local hard drive -//comment: need reader supports -//note:the last parameter hasn't been confirmed.because the previous one blocks the way. -//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations); - FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS) { - v8::Isolate* isolate = GetIsolate(cc); - if (IsSafeMode(cc)) return TRUE; - - ASSERT(m_pDocument != NULL); - - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; - - FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE; - FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE; - FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE; - CJS_Array arrayFileds(isolate); - if (!bWhole) - arrayFileds.Attach(params[2]); - //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE; - CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : L""; - - if (swFilePath.IsEmpty()) - { - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - swFilePath = pEnv->JS_fieldBrowse(); - if(swFilePath.IsEmpty()) - return TRUE; - } - else - { - swFilePath = app::PDFPathToSysPath(swFilePath); - } - - m_pDocument->SetFocusAnnot(NULL); - - CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - ASSERT(pPDFForm != NULL); - - CFX_PtrArray aFields; - - if (bWhole) - { - for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++) - { - aFields.Add(pPDFForm->GetField(j)); - } - } - else - { - for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++) - { - CJS_Value valName(isolate); - arrayFileds.GetElement(i,valName); - CFX_WideString swName = valName.operator CFX_WideString(); - - for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++) - { - aFields.Add(pPDFForm->GetField(j, swName)); - } - } - } - - CFX_PtrArray fields; - - for (int i=0,sz=aFields.GetSize(); i<sz; i++) - { - CPDF_FormField* pField = (CPDF_FormField*)aFields[i]; - - if (!bAllFields) - if (pField->GetValue() == L"") - continue; - - if (bNoPassWord) - if (pField->GetFieldFlags() & 0x2000) - continue; - - fields.Add((void*)pField); - } - - return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE); + // Unsafe, not supported. + return TRUE; } -//exports form fields an XFDF file to the local hard drive -//comment: need reder supports -//note:the last parameter can't be test -//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations); - FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; - + // Unsafe, not supported. return TRUE; } @@ -436,7 +342,7 @@ FX_BOOL Document::getField(OBJ_METHOD_PARAMS) CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); ASSERT(pPDFForm != NULL); - if (pPDFForm->CountFields(wideName) <= 0) + if (pPDFForm->CountFields(wideName) <= 0) { vRet.SetNull(); return TRUE; @@ -452,7 +358,7 @@ FX_BOOL Document::getField(OBJ_METHOD_PARAMS) CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj); ASSERT(pJSField != NULL); - Field * pField = (Field *)pJSField->GetEmbedObject(); + Field * pField = (Field *)pJSField->GetEmbedObject(); ASSERT(pField != NULL); pField->AttachField(this, wideName); @@ -461,10 +367,7 @@ FX_BOOL Document::getField(OBJ_METHOD_PARAMS) return TRUE; } -//Gets the name of the nth field in the document -//comment: -//note: the parameter nIndex, if it is not available - +//Gets the name of the nth field in the document FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS) { ASSERT(m_pDocument != NULL); @@ -483,90 +386,24 @@ FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS) return FALSE; vRet = pField->GetFullName(); - return TRUE; + return TRUE; } -//imports the specified fdf file. -//comments: need reader suppport -//note:once the cpath is illigl then a file dialog box pops up in order to ask user to chooose the file -//int CPDFSDK_Document::importAnFDF(String cPath); - FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; - - - CFX_WideString swPath; - - if (params.size() > 0) - swPath = params[0]; - - if (swPath.IsEmpty()) - { - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - swPath = pEnv->JS_fieldBrowse(); - if(swPath.IsEmpty()) - return TRUE; - } - else - { - swPath = app::PDFPathToSysPath(swPath); - } - - m_pDocument->SetFocusAnnot(NULL); - - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - - if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE)) - return FALSE; - - m_pDocument->SetChangeMark(); -// CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); -// ASSERT(pEnv != NULL); -// IUndo* pUndo = IUndo::GetUndo(pEnv); -// ASSERT(pUndo != NULL); -// pUndo->Reset(m_pDocument); - + // Unsafe, not supported. return TRUE; } -//imports and specified XFDF file containing XML form data -//comment: need reader supports -//note: same as up -//int CPDFSDK_Document::importAnFDF(String cPath) - FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; - + // Unsafe, not supported. return TRUE; } -//imports and specified text file -//commnet: need reader supports -//note: same as up,when nRow is not rational,adobe is dumb for it. -//int CPDFSDK_Document::importTextData(String cPath,int nRow); - FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; - + // Unsafe, not supported. return TRUE; } @@ -650,7 +487,7 @@ FX_BOOL Document::print(OBJ_METHOD_PARAMS) } } } - } + } } } else @@ -674,7 +511,7 @@ FX_BOOL Document::print(OBJ_METHOD_PARAMS) } ASSERT(m_pDocument != NULL); - + if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); @@ -691,7 +528,7 @@ FX_BOOL Document::removeField(OBJ_METHOD_PARAMS) { ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE; if (params.size() < 1) @@ -725,7 +562,7 @@ FX_BOOL Document::removeField(OBJ_METHOD_PARAMS) CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage(); ASSERT(pPage != NULL); - + CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); pPageView->DeleteAnnot(pWidget); @@ -745,7 +582,7 @@ FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS) { ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; @@ -776,12 +613,12 @@ FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS) { CJS_Value valElement(isolate); aName.GetElement(i,valElement); - CFX_WideString swVal = valElement.operator CFX_WideString(); - + CFX_WideString swVal = valElement.operator CFX_WideString(); + for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++) { aFields.Add((void*)pPDFForm->GetField(j,swVal)); - } + } } if (aFields.GetSize() > 0) @@ -804,14 +641,8 @@ FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS) FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS) { - - if (IsSafeMode(cc)) return TRUE; - - ASSERT(m_pDocument != NULL); - -// m_pDocument->DoSaveAs(); - - return TRUE; + // Unsafe, not supported. + return TRUE; } @@ -853,7 +684,7 @@ FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS) bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)); pValue = JS_GetObjectElement(isolate,pObj,L"aFields"); aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue))); - } + } CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); @@ -869,7 +700,7 @@ FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS) CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - + if (pPDFInterForm->CheckRequiredFields()) { pRuntime->BeginBlock(); @@ -880,7 +711,7 @@ FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS) return TRUE; } else - { + { CFX_PtrArray fieldObjects; for (int i=0,sz=aFields.GetLength(); i<sz; i++) @@ -907,7 +738,7 @@ FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS) CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - + if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) { pRuntime->BeginBlock(); @@ -943,7 +774,7 @@ FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFo } FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS) -{ +{ return TRUE; } @@ -957,7 +788,7 @@ FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS) CFX_WideString cBcc = L""; CFX_WideString cSubject = L""; CFX_WideString cMsg = L""; - + bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE; cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L""; @@ -965,7 +796,7 @@ FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS) cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L""; cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L""; cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L""; - + v8::Isolate* isolate = GetIsolate(cc); if(params.size()>=1 && params[0].GetType() == VT_object) @@ -989,7 +820,7 @@ FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS) pValue = JS_GetObjectElement(isolate,pObj, L"cMsg"); cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); - + } CJS_Context* pContext = (CJS_Context*)cc; @@ -1064,7 +895,7 @@ FX_BOOL Document::info(OBJ_PROP_PARAMS) JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate); JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped); -// 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) { @@ -1155,7 +986,7 @@ FX_BOOL Document::delay(OBJ_PROP_PARAMS) m_bDelay = b; - if (m_bDelay) + if (m_bDelay) { for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++) delete m_DelayData.GetAt(i); @@ -1356,7 +1187,7 @@ FX_BOOL Document::filesize(OBJ_PROP_PARAMS) FX_BOOL Document::mouseX(OBJ_PROP_PARAMS) { - return TRUE; + return TRUE; } FX_BOOL Document::mouseY(OBJ_PROP_PARAMS) @@ -1487,7 +1318,7 @@ FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS) } FX_BOOL Document::layout(OBJ_PROP_PARAMS) -{ +{ return TRUE; } @@ -1501,8 +1332,8 @@ FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS) ASSERT(m_pDocument != NULL); - - + + return TRUE; } @@ -1537,7 +1368,7 @@ FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS) } FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS) -{ +{ return TRUE; } @@ -1577,7 +1408,7 @@ void IconTree::InsertIconElement(IconElement* pNewIcon) void IconTree::DeleteIconTree() { if (!m_pHead || !m_pEnd)return; - + IconElement* pTemp = NULL; while(m_pEnd != m_pHead) { @@ -1614,12 +1445,12 @@ IconElement* IconTree::operator [](int iIndex) void IconTree::DeleteIconElement(CFX_WideString swIconName) { IconElement* pTemp = m_pHead; - int iLoopCount = m_iLength; + 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; @@ -1662,7 +1493,7 @@ FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS) ASSERT(pRuntime != NULL); CFX_WideString swIconName = params[0].operator CFX_WideString(); - + JSFXObject pJSIcon = (JSFXObject)params[1]; if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE; @@ -1702,10 +1533,10 @@ FX_BOOL Document::icons(OBJ_PROP_PARAMS) for (int i = 0; i < iIconTreeLength; i++) { pIconElement = (*m_pIconTree)[i]; - + JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); if (pObj.IsEmpty()) return FALSE; - + CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); if (!pJS_Icon) return FALSE; @@ -1737,10 +1568,10 @@ FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS) if ((*m_pIconTree)[i]->IconName == swIconName) { Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; - + JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); if (pObj.IsEmpty()) return FALSE; - + CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); if (!pJS_Icon) return FALSE; @@ -1768,71 +1599,8 @@ FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS) FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - - CFX_WideString swName = L""; - CFX_ByteString sbName = ""; - CFX_WideString swValue = L""; - CFX_WideString swMIMEType = L""; - CFX_WideString swCryptFilter = L""; - CFX_ByteString sbFileValue = ""; - - int iParamSize = params.size(); - for (int i = 0; i < iParamSize; i++) - { - if (i == 0) - swName = params[0]; - if (i == 1) - swValue = params[1]; - if (i == 2) - swMIMEType = params[2]; - if (i == 3) - swCryptFilter = params[4]; - } - - FILE* pFile = NULL; - - //CFileStatus fileStatus; - const int BUFSIZE = 17; - FX_BYTE buf[BUFSIZE]; - FX_BYTE *pBuffer = NULL; - char* pBuf = NULL; - int nFileSize = 0; - sbFileValue = CFX_ByteString::FromUnicode(swValue); - sbName = CFX_ByteString::FromUnicode(swName); - int iBufLength = sbFileValue.GetLength(); - pBuf = (char*)malloc(sizeof(char) * iBufLength); - pBuf = sbFileValue.GetBuffer(iBufLength); - - if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) ) - { - return FALSE; - } - - fwrite( pBuf, sizeof(char), iBufLength, pFile ); - fclose( pFile ); - pFile = NULL; - - pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" ); - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - - pBuffer = new FX_BYTE[nFileSize]; - fseek( pFile, 0, SEEK_SET ); - size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile ); - if(s == 0) - { - delete[] pBuffer; - return FALSE; - } - - CRYPT_MD5Generate(pBuffer, nFileSize, buf); - buf[BUFSIZE - 1] = 0; - CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16); - delete[] pBuffer; - - return TRUE; + // Unsafe, not implemented. + return TRUE; } FX_BOOL Document::media(OBJ_PROP_PARAMS) @@ -1844,7 +1612,7 @@ FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS) { ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; @@ -1861,8 +1629,6 @@ FX_BOOL Document::Collab(OBJ_PROP_PARAMS) FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS) { - //if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; @@ -1925,8 +1691,6 @@ FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS) FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS) { - //if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; @@ -2020,7 +1784,7 @@ int Document::CountWords(CPDF_TextObject* pTextObj) if (ISLATINWORD(unicode) && bIsLatin) continue; - + bIsLatin = ISLATINWORD(unicode); if (unicode != 0x20) nWords++; @@ -2057,10 +1821,10 @@ CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex { } else - { + { bIsLatin = ISLATINWORD(unicode); if (unicode != 0x20) - nWords++; + nWords++; } if (nWords-1 == nWordIndex) @@ -2093,28 +1857,17 @@ FX_BOOL Document::zoomType(OBJ_PROP_PARAMS) FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS) { - - - - - - v8::Isolate* isolate = GetIsolate(cc); -// if (pEnv->GetAppName().Compare(PHANTOM) != 0) -// return TRUE; - - //if (IsSafeMode(cc)) return TRUE; - ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE; int iSize = params.size(); - + int nStart = 0; int nEnd = 0; - + if (iSize < 1) { } @@ -2150,336 +1903,33 @@ FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS) if (nEnd < nStart) nEnd = nStart; - + return TRUE; } FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS) { - - - - - - - v8::Isolate* isolate = GetIsolate(cc); - - if (IsSafeMode(cc)) return TRUE; - - ASSERT(m_pDocument != NULL); - - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE; - - int iSize = params.size(); - - int nTotal = m_pDocument->GetPageCount(); - int nStart = 0; - int nEnd = nTotal - 1; - - CFX_WideString swFilePath; - - if (iSize < 1) - { - } - else if (iSize == 1) - { - if (params[0].GetType() == VT_object) - { - JSObject pObj = (JSObject )params[0]; - v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart"); - nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"nEnd"); - nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"cPath"); - swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); - } - else - { - nStart = (int)params[0]; - } - } - else if (iSize == 2) - { - nStart = (int)params[0]; - nEnd = (int)params[1]; - } - else - { - nStart = (int)params[0]; - nEnd = (int)params[1]; - swFilePath = params[2].operator CFX_WideString(); - } - - if (nEnd < nStart) - nEnd = nStart; - - CPDF_Document *pNewDoc = new CPDF_Document; - pNewDoc->CreateNewDoc(); - - CFX_WordArray array; - for (int i=nStart; i<=nEnd; i++) - array.Add(i); - -// m_pDocument->ExtractPages(array, pNewDoc); - - if (swFilePath.IsEmpty()) - { - - } - else - { - swFilePath = app::PDFPathToSysPath(swFilePath); - CPDF_Creator PDFCreater(pNewDoc); - PDFCreater.Create(swFilePath); - delete pNewDoc; -// pEnv->OpenDocument(swFilePath); - vRet.SetNull(); - } - - return TRUE; + // Unsafe, not supported. + return TRUE; } FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS) { - - - - - - - v8::Isolate* isolate = GetIsolate(cc); - - if (IsSafeMode(cc)) return TRUE; - - ASSERT(m_pDocument != NULL); - - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE; - - int iSize = params.size(); - - int nStart = 0; - int nEnd = 0; - int nPage = 0; - - CFX_WideString swFilePath; - - if (iSize < 1) - { - } - else if (iSize == 1) - { - if (params[0].GetType() == VT_object) - { - JSObject pObj = (JSObject )params[0]; - - v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage"); - nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"cPath"); - swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); - - pValue = JS_GetObjectElement(isolate,pObj, L"nStart"); - nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"nEnd"); - nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - } - else - { - nPage = (int)params[0]; - } - } - else - { - nPage = (int)params[0]; - - if (iSize >= 2) - swFilePath = params[1].operator CFX_WideString(); - - if (iSize >= 3) - nStart = (int)params[2]; - - if (iSize >= 4) - nEnd = (int)params[3]; - } - - nPage++; - - if (nPage < 0) - nPage = 0; - - if (nPage > m_pDocument->GetPageCount()) - nPage = m_pDocument->GetPageCount(); - - if (swFilePath.IsEmpty()) return FALSE; - - swFilePath = app::PDFPathToSysPath(swFilePath); - - CPDF_Parser pdfParser; - pdfParser.StartParse(swFilePath, FALSE); - CPDF_Document* pSrcDoc = pdfParser.GetDocument(); - - if (!pSrcDoc) - { - pdfParser.CloseParser(); - return FALSE; - } - - int nTotal = pSrcDoc->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; - - CFX_WordArray array; - for (int i=nStart; i<=nEnd; i++) - array.Add(i); - -// m_pDocument->InsertPages(nPage, pSrcDoc, array); - - pdfParser.CloseParser(); - - return TRUE; + // Unsafe, not supported. + return TRUE; } FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS) { - - - - - - - v8::Isolate* isolate = GetIsolate(cc); - - if (IsSafeMode(cc)) return TRUE; - - ASSERT(m_pDocument != NULL); - - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE; - - int iSize = params.size(); - - int nStart = -1; - int nEnd = -1; - int nPage = 0; - - CFX_WideString swFilePath; - - if (iSize < 1) - { - } - else if (iSize == 1) - { - if (params[0].GetType() == VT_object) - { - JSObject pObj = (JSObject )params[0]; - - v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage"); - nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"cPath"); - swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); - - pValue = JS_GetObjectElement(isolate,pObj, L"nStart"); - nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate,pObj, L"nEnd"); - nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)); - } - else - { - nPage = (int)params[0]; - } - } - else - { - nPage = (int)params[0]; - - if (iSize >= 2) - swFilePath = params[1].operator CFX_WideString(); - - if (iSize >= 3) - nStart = (int)params[2]; - - if (iSize >= 4) - nEnd = (int)params[3]; - } - - if (nPage < 0) - nPage = 0; - - if (nPage >= m_pDocument->GetPageCount()) - nPage = m_pDocument->GetPageCount() - 1; - - if (swFilePath.IsEmpty()) return FALSE; - - swFilePath = app::PDFPathToSysPath(swFilePath); - - CPDF_Parser pdfParser; - pdfParser.StartParse(swFilePath, FALSE); - CPDF_Document* pSrcDoc = pdfParser.GetDocument(); - - if (!pSrcDoc) - { - pdfParser.CloseParser(); - return FALSE; - } - - int nTotal = pSrcDoc->GetPageCount(); - - if (nStart < 0) - { - if (nEnd < 0) - { - nStart = 0; - nEnd = nTotal - 1; - } - else - { - nStart = 0; - } - } - else - { - if (nEnd < 0) - { - nEnd = nStart; - } - else - { - if (nStart >= nTotal) nStart = nTotal - 1; - if (nEnd >= nTotal) nEnd = nTotal - 1; - - if (nEnd < nStart) nEnd = nStart; - } - } - - CFX_WordArray array; - for (int i=nStart; i<=nEnd; i++) - array.Add(i); - -// m_pDocument->ReplacePages(nPage, pSrcDoc, array); - - pdfParser.CloseParser(); - - return TRUE; + // Unsafe, not supported. + return TRUE; } FX_BOOL Document::getURL(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - - return TRUE; + // Unsafe, not supported. + return TRUE; } void Document::AddDelayData(CJS_DelayData* pData) @@ -2519,7 +1969,7 @@ void Document::AddDelayAnnotData(CJS_AnnotObj *pData) void Document::DoAnnotDelay() { CFX_DWordArray DelArray; - + for (int j=DelArray.GetSize()-1; j>=0; j--) { m_DelayData.RemoveAt(DelArray[j]); diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp index 34ad8e1f0a..44978fa421 100644 --- a/fpdfsdk/src/javascript/JS_Object.cpp +++ b/fpdfsdk/src/javascript/JS_Object.cpp @@ -87,13 +87,6 @@ void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) delete pTimer; } -FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc) -{ - ASSERT(cc != NULL); - - return TRUE; -} - /* --------------------------------- CJS_Object --------------------------------- */ void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data) { diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index 7cf2663d25..e3604b09cb 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -1,7 +1,7 @@ // Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - + // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/javascript/JavaScript.h" @@ -45,7 +45,7 @@ TimerObj::TimerObj(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), m_pTimer(NULL) { - + } TimerObj::~TimerObj() @@ -90,7 +90,7 @@ BEGIN_JS_STATIC_PROP(CJS_App) JS_STATIC_PROP_ENTRY(runtimeHighlight) JS_STATIC_PROP_ENTRY(viewerType) JS_STATIC_PROP_ENTRY(viewerVariation) - JS_STATIC_PROP_ENTRY(viewerVersion) + JS_STATIC_PROP_ENTRY(viewerVersion) END_JS_STATIC_PROP() BEGIN_JS_STATIC_METHOD(CJS_App) @@ -105,7 +105,7 @@ BEGIN_JS_STATIC_METHOD(CJS_App) JS_STATIC_METHOD_ENTRY(goBack, 0) JS_STATIC_METHOD_ENTRY(goForward, 0) JS_STATIC_METHOD_ENTRY(launchURL, 0) - JS_STATIC_METHOD_ENTRY(mailMsg, 0) + JS_STATIC_METHOD_ENTRY(mailMsg, 0) JS_STATIC_METHOD_ENTRY(newFDF, 0) JS_STATIC_METHOD_ENTRY(newDoc, 0) JS_STATIC_METHOD_ENTRY(openDoc, 0) @@ -141,29 +141,29 @@ FX_BOOL app::activeDocs(OBJ_PROP_PARAMS) CJS_Context* pContext = (CJS_Context *)cc; ASSERT(pContext != NULL); - + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); ASSERT(pApp != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); - + CJS_Array aDocs(pRuntime->GetIsolate()); // int iNumDocs = pApp->CountDocuments(); - + // for(int iIndex = 0; iIndex<iNumDocs; iIndex++) // { CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); if (pDoc) { CJS_Document * pJSDocument = NULL; - + if (pDoc == pCurDoc) { JSFXObject pObj = JS_GetThisObj(*pRuntime); - + if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) { pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); @@ -174,15 +174,15 @@ FX_BOOL app::activeDocs(OBJ_PROP_PARAMS) JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); ASSERT(pJSDocument != NULL); - - + + // pDocument->AttachDoc(pDoc); } - + aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); } // } - + if (aDocs.GetLength() > 0) vp << aDocs; else @@ -202,16 +202,16 @@ FX_BOOL app::calculate(OBJ_PROP_PARAMS) CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); - + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); ASSERT(pApp != NULL); - + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); CJS_Array aDocs(pRuntime->GetIsolate()); // int iNumDocs = pApp->CountDocuments(); -// +// // for (int iIndex = 0;iIndex < iNumDocs; iIndex++) // { if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc()) @@ -219,14 +219,14 @@ FX_BOOL app::calculate(OBJ_PROP_PARAMS) CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm(); ASSERT(pInterForm != NULL); pInterForm->EnableCalculate((FX_BOOL)m_bCalculate); - } + } // } } else { vp << (bool)m_bCalculate; } - + return TRUE; } @@ -237,30 +237,18 @@ FX_BOOL app::formsVersion(OBJ_PROP_PARAMS) vp << JS_NUM_FORMSVERSION; return TRUE; } - + return FALSE; } FX_BOOL app::viewerType(OBJ_PROP_PARAMS) { - - - - - - if (vp.IsGetting()) { -// if (pApp->GetAppName() == PHANTOM) -// vp << JS_STR_VIEWERTYPE_STANDARD; -// else -// vp << JS_STR_VIEWERTYPE_READER; vp << L"unknown"; - - //vp << pApp->GetAppTitle(); return TRUE; } - + return FALSE; } @@ -271,7 +259,7 @@ FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS) vp << JS_STR_VIEWERVARIATION; return TRUE; } - + return FALSE; } @@ -281,10 +269,10 @@ FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS) { CJS_Context* pContext = (CJS_Context *)cc; ASSERT(pContext != NULL); - + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); ASSERT(pApp != NULL); - + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); CPDFXFA_Document* pDoc = pCurDoc->GetDocument(); @@ -294,7 +282,7 @@ FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS) vp << JS_STR_VIEWERVERSION; return TRUE; } - + return FALSE; } @@ -305,7 +293,7 @@ FX_BOOL app::platform(OBJ_PROP_PARAMS) vp << JS_STR_PLATFORM; return TRUE; } - + return FALSE; } @@ -316,7 +304,7 @@ FX_BOOL app::language(OBJ_PROP_PARAMS) vp << JS_STR_LANGUANGE; return TRUE; } - + return FALSE; } @@ -438,7 +426,7 @@ FX_BOOL app::alert(OBJ_METHOD_PARAMS) swMsg = params[0]; } swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); - + for(int i = 1;i<iSize;i++) { if (i == 1) @@ -446,7 +434,7 @@ FX_BOOL app::alert(OBJ_METHOD_PARAMS) if (i == 2) iType = int(params[i]); if (i == 3) - swTitle = params[i]; + swTitle = params[i]; } } @@ -458,7 +446,7 @@ FX_BOOL app::alert(OBJ_METHOD_PARAMS) pRuntime->BeginBlock(); vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon); pRuntime->EndBlock(); - + return TRUE; } @@ -487,7 +475,7 @@ FX_BOOL app::findComponent(OBJ_METHOD_PARAMS) } FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS) -{ +{ return FALSE; } @@ -498,26 +486,26 @@ FX_BOOL app::fs(OBJ_PROP_PARAMS) FX_BOOL app::setInterval(OBJ_METHOD_PARAMS) { - if (params.size() > 2 || params.size() == 0) + if (params.size() > 2 || params.size() == 0) { - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); return FALSE; } - + CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : L""; - if (script.IsEmpty()) + if (script.IsEmpty()) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); return TRUE; } FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000; - + CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); ASSERT(pApp); CJS_Timer* pTimer = new CJS_Timer(this, pApp); @@ -529,19 +517,19 @@ FX_BOOL app::setInterval(OBJ_METHOD_PARAMS) pTimer->SetTimeOut(0); // pTimer->SetStartTime(GetTickCount()); pTimer->SetJSTimer(dwInterval); - + JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); - + CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj); ASSERT(pJS_TimerObj != NULL); - + TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); ASSERT(pTimerObj != NULL); - - pTimerObj->SetTimer(pTimer); - + + pTimerObj->SetTimer(pTimer); + vRet = pRetObj; - + return TRUE; } @@ -549,29 +537,29 @@ FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS) { if (params.size() > 2 || params.size() == 0) { - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); return FALSE; } - + CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - + CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : L""; - if (script.IsEmpty()) + if (script.IsEmpty()) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); return TRUE; } - + FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000; - + CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); ASSERT(pApp); CJS_Timer* pTimer = new CJS_Timer(this, pApp); m_aTimer.Add(pTimer); - + pTimer->SetType(1); pTimer->SetRuntime(pRuntime); pTimer->SetJScript(script); @@ -579,20 +567,20 @@ FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS) // pTimer->SetStartTime(GetTickCount()); // pTimer->SetJSTimer(1000); pTimer->SetJSTimer(dwTimeOut); - + JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj")); // ASSERT(pRetObj != NULL); - + CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj); ASSERT(pJS_TimerObj != NULL); - + TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); ASSERT(pTimerObj != NULL); - - pTimerObj->SetTimer(pTimer); - + + pTimerObj->SetTimer(pTimer); + vRet = pRetObj; - + return TRUE; } @@ -602,13 +590,13 @@ FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS) ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); - + if (params.size() != 1) { - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); return FALSE; } - + if (params[0].GetType() == VT_fxobject) { JSFXObject pObj = (JSFXObject)params[0]; @@ -622,7 +610,7 @@ FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS) if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { pTimer->KillJSTimer(); - + for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++) { if (m_aTimer[i] == pTimer) @@ -631,7 +619,7 @@ FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS) break; } } - + delete pTimer; pTimerObj->SetTimer(NULL); } @@ -640,7 +628,7 @@ FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS) } } } - + return TRUE; } @@ -653,10 +641,10 @@ FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS) if (params.size() != 1) { - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); return FALSE; } - + if (params[0].GetType() == VT_fxobject) { JSFXObject pObj = (JSFXObject)params[0]; @@ -670,7 +658,7 @@ FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS) if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { pTimer->KillJSTimer(); - + for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++) { if (m_aTimer[i] == pTimer) @@ -679,7 +667,7 @@ FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS) break; } } - + delete pTimer; pTimerObj->SetTimer(NULL); } @@ -688,12 +676,12 @@ FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS) } } } - + return TRUE; } FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS) -{ +{ return FALSE; } @@ -714,7 +702,7 @@ void app::TimerProc(CJS_Timer* pTimer) } break; } - + } void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript) @@ -734,24 +722,14 @@ void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript) FX_BOOL app::goBack(OBJ_METHOD_PARAMS) { - - - - - - - return TRUE; + // Not supported. + return TRUE; } FX_BOOL app::goForward(OBJ_METHOD_PARAMS) -{ - - - - - - - return TRUE; +{ + // Not supported. + return TRUE; } FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS) @@ -775,7 +753,7 @@ FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS) cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L""; cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L""; cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L""; - cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L""; + cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L""; if (params[0].GetType() == VT_object) @@ -800,8 +778,8 @@ FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS) pValue = JS_GetObjectElement(isolate,pObj, L"cMsg"); cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString(); } - - + + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); @@ -820,25 +798,8 @@ FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS) FX_BOOL app::launchURL(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - - - - - CFX_WideString swURL = params[0].operator CFX_WideString(); - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - pRuntime->BeginBlock(); -// FX_BOOL bRet = pApp->OpenURL(swURL); - pRuntime->EndBlock(); - -// return bRet; - return FALSE; + // Unsafe, not supported. + return TRUE; } FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS) @@ -868,90 +829,14 @@ FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS) FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS) { - //This method may trigger a "file save" dialog,while enable user to save contents of the document. - //Such action is considered to be unsafe. - if (IsSafeMode(cc)) return TRUE; - - v8::Isolate* isolate = GetIsolate(cc); - - bool bSave = false; - CFX_ByteString cFilenameInit = CFX_ByteString(); - CFX_ByteString cFSInit = CFX_ByteString(); - - if(params.size()>0 && (params[0].GetType() == VT_object)) - { - JSObject pObj = (JSObject )params[0]; - - v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave"); - bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)); - - pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit"); - { - CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)); - cFilenameInit = t.operator CFX_ByteString(); - } - - pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit"); - { - CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)); - cFSInit = t.operator CFX_ByteString(); - } - } - else - { - if(params.size() >= 1) - { - bSave = (bool)params[0]; - } - if(params.size() >= 2) - { - CJS_Value t = params[1]; - cFilenameInit = t.operator CFX_ByteString(); - } - if(params.size() >= 3) - { - CJS_Value t = params[2]; - cFSInit = t.operator CFX_ByteString(); - } - } - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit); - CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit); - CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit); - if(wsFilePath.IsEmpty()) - return FALSE; - - JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); - - JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath)); - JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath)); - - if (!cFSInit.IsEmpty()) - { - JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength()))); - } - else - { - JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS")); - } - - vRet = pRetObj; - - return TRUE; + // Unsafe, not supported. + return TRUE; } CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { CFX_WideString sRet = L"/"; - + for (int i=0,sz=sOldPath.GetLength(); i<sz; i++) { wchar_t c = sOldPath.GetAt(i); @@ -970,47 +855,8 @@ CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) } } } - - return sRet; -} - -CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath) -{ - //strLPath = "D:\temporay.fdf"; - CFX_WideString strOPath = sOldPath; - strOPath.TrimLeft(); - strOPath.TrimRight(); - - if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/') - { - wchar_t c_Drive = strOPath.GetAt(1); - if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z')) - { - strOPath.Replace(L"/",L"\\"); - //strOPath.SetAt(0,''); - strOPath.Insert(2,':'); - strOPath.Delete(0); - } - } - - return strOPath; -} -CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath) -{ -// if (!PathIsRelative(sOldPath)) return sOldPath; - - int nSplit = 0; - for (int i=sFilePath.GetLength()-1; i>=0; i--) - { - if (sFilePath[i] == '\\' || sFilePath[i] == '/') - { - nSplit = i; - break; - } - } - - return sFilePath.Left(nSplit+1) + sOldPath; + return sRet; } FX_BOOL app::newDoc(OBJ_METHOD_PARAMS) @@ -1112,4 +958,3 @@ FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) { return TRUE; } - diff --git a/fpdfsdk/src/javascript/report.cpp b/fpdfsdk/src/javascript/report.cpp index 9cb9da5051..189ab87d32 100644 --- a/fpdfsdk/src/javascript/report.cpp +++ b/fpdfsdk/src/javascript/report.cpp @@ -1,7 +1,7 @@ // Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - + // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/javascript/JavaScript.h" @@ -19,13 +19,13 @@ END_JS_STATIC_CONST() BEGIN_JS_STATIC_PROP(CJS_Report) END_JS_STATIC_PROP() -BEGIN_JS_STATIC_METHOD(CJS_Report) +BEGIN_JS_STATIC_METHOD(CJS_Report) JS_STATIC_METHOD_ENTRY(save, 1) JS_STATIC_METHOD_ENTRY(writeText,1) END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_Report, Report) - + Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) { @@ -33,18 +33,17 @@ Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) Report::~Report() { - + } FX_BOOL Report::writeText(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - return TRUE; + // Unsafe, not supported. + return TRUE; } FX_BOOL Report::save(OBJ_METHOD_PARAMS) { - if (IsSafeMode(cc)) return TRUE; - return TRUE; + // Unsafe, not supported. + return TRUE; } - |