diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h | 8 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_annothandler.h | 4 | ||||
-rw-r--r-- | fpdfsdk/include/javascript/global.h | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_annothandler.cpp | 18 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/global.cpp | 136 |
5 files changed, 67 insertions, 103 deletions
diff --git a/fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h b/fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h index 27e7a91cd5..1ddb99064f 100644 --- a/fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h +++ b/fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h @@ -40,7 +40,6 @@ class CPDFXFA_Document : public IXFA_DocProvider { void FXRect2PDFRect(const CFX_RectF& fxRectF, CPDF_Rect& pdfRect);
- public:
virtual void SetChangeMark(IXFA_Doc* hDoc);
virtual FX_BOOL GetChangeMark(IXFA_Doc* hDoc);
// used in dynamic xfa, dwFlags refer to XFA_INVALIDATE_XXX macros.
@@ -220,16 +219,9 @@ class CPDFXFA_Document : public IXFA_DocProvider { IXFA_Doc* m_pXFADoc;
IXFA_DocView* m_pXFADocView;
CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
-
CPDFSDK_Document* m_pSDKDoc;
CPDFXFA_App* m_pApp;
-
- CFX_MapByteStringToPtr m_XfaGlobalProperty;
-
- CFX_MapByteStringToPtr m_ValueMap;
-
IFXJS_Context* m_pJSContext;
-
int m_iDocType;
};
diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h index 266c4589b0..c15681de96 100644 --- a/fpdfsdk/include/fsdk_annothandler.h +++ b/fpdfsdk/include/fsdk_annothandler.h @@ -7,6 +7,8 @@ #ifndef FPDFSDK_INCLUDE_FSDK_ANNOTHANDLER_H_ #define FPDFSDK_INCLUDE_FSDK_ANNOTHANDLER_H_ +#include <map> + #include "../../core/include/fxcrt/fx_basic.h" #define FSDK_XFAWIDGET_TYPENAME "XFAWidget" @@ -427,7 +429,7 @@ class CPDFSDK_AnnotHandlerMgr { private: CBA_AnnotHandlerArray m_Handlers; - CFX_MapByteStringToPtr m_mapType2Handler; + std::map<CFX_ByteString, IPDFSDK_AnnotHandler*> m_mapType2Handler; CPDFDoc_Environment* m_pApp; }; diff --git a/fpdfsdk/include/javascript/global.h b/fpdfsdk/include/javascript/global.h index e881625f56..7f78bb6bcb 100644 --- a/fpdfsdk/include/javascript/global.h +++ b/fpdfsdk/include/javascript/global.h @@ -7,6 +7,8 @@ #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_ #define FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_ +#include <map> + #include "JS_Define.h" class CJS_GlobalData; @@ -69,7 +71,7 @@ class JSGlobalAlternate : public CJS_EmbedObj { void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData); private: - CFX_MapByteStringToPtr m_mapGlobal; + std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal; CFX_WideString m_sFilePath; CJS_GlobalData* m_pGlobalData; CPDFDoc_Environment* m_pApp; diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp index 55d4629801..287a26baa8 100644 --- a/fpdfsdk/src/fsdk_annothandler.cpp +++ b/fpdfsdk/src/fsdk_annothandler.cpp @@ -29,25 +29,20 @@ CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { delete pHandler; } m_Handlers.RemoveAll(); - m_mapType2Handler.RemoveAll(); + m_mapType2Handler.clear(); } void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( IPDFSDK_AnnotHandler* pAnnotHandler) { - ASSERT(pAnnotHandler != NULL); - - ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); + ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); m_Handlers.Add(pAnnotHandler); - m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); + m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; } void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( IPDFSDK_AnnotHandler* pAnnotHandler) { - ASSERT(pAnnotHandler != NULL); - - m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); - + m_mapType2Handler.erase(pAnnotHandler->GetType()); for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { if (m_Handlers.GetAt(i) == pAnnotHandler) { m_Handlers.RemoveAt(i); @@ -131,9 +126,8 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( const CFX_ByteString& sType) const { - void* pRet = NULL; - m_mapType2Handler.Lookup(sType, pRet); - return (IPDFSDK_AnnotHandler*)pRet; + auto it = m_mapType2Handler.find(sType); + return it != m_mapType2Handler.end() ? it->second : nullptr; } void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp index f03c4d1f41..dea2b5852c 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -127,15 +127,12 @@ FX_BOOL JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) { FX_BOOL JSGlobalAlternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CFX_WideString& sError) { - JSGlobalData* pData = NULL; - CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); - - if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) { - pData->bDeleted = TRUE; - return TRUE; - } + auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); + if (it == m_mapGlobal.end()) + return FALSE; - return FALSE; + it->second->bDeleted = TRUE; + return TRUE; } FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc, @@ -181,19 +178,16 @@ FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc, break; } } else { - void* pVoid = nullptr; - if (!m_mapGlobal.Lookup(CFX_ByteString::FromUnicode(propname), pVoid)) { + auto it = m_mapGlobal.find(CFX_ByteString::FromUnicode(propname)); + if (it == m_mapGlobal.end()) { vp.SetNull(); return TRUE; } - if (!pVoid) { + JSGlobalData* pData = it->second; + if (pData->bDeleted) { vp.SetNull(); return TRUE; } - JSGlobalData* pData = (JSGlobalData*)pVoid; - if (pData->bDeleted) - return TRUE; - switch (pData->nType) { case JS_GLOBALDATA_TYPE_NUMBER: vp << pData->dData; @@ -230,11 +224,10 @@ FX_BOOL JSGlobalAlternate::setPersistent(IFXJS_Context* cc, return FALSE; } - CFX_ByteString sName = params[0].ToCFXByteString(); - - JSGlobalData* pData = NULL; - if (m_mapGlobal.Lookup(sName, (void*&)pData)) { - if (pData && !pData->bDeleted) { + auto it = m_mapGlobal.find(params[0].ToCFXByteString()); + if (it != m_mapGlobal.end()) { + JSGlobalData* pData = it->second; + if (!pData->bDeleted) { pData->bPersistent = params[1].ToBool(); return TRUE; } @@ -300,52 +293,42 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() { } void JSGlobalAlternate::CommitGlobalPersisitentVariables() { - ASSERT(m_pGlobalData != NULL); - - FX_POSITION pos = m_mapGlobal.GetStartPosition(); - while (pos) { - CFX_ByteString name; - JSGlobalData* pData = NULL; - m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData); - - if (pData) { - if (pData->bDeleted) { - m_pGlobalData->DeleteGlobalVariable(name); - } else { - switch (pData->nType) { - case JS_GLOBALDATA_TYPE_NUMBER: - m_pGlobalData->SetGlobalVariableNumber(name, pData->dData); + ASSERT(m_pGlobalData); + for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { + CFX_ByteString name = it->first; + JSGlobalData* pData = it->second; + if (pData->bDeleted) { + m_pGlobalData->DeleteGlobalVariable(name); + } else { + switch (pData->nType) { + case JS_GLOBALDATA_TYPE_NUMBER: + m_pGlobalData->SetGlobalVariableNumber(name, pData->dData); + m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); + break; + case JS_GLOBALDATA_TYPE_BOOLEAN: + m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); + m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); + break; + case JS_GLOBALDATA_TYPE_STRING: + m_pGlobalData->SetGlobalVariableString(name, pData->sData); + m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); + break; + case JS_GLOBALDATA_TYPE_OBJECT: + // if (pData->pData) + { + CJS_GlobalVariableArray array; + v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( + GetJSObject()->GetIsolate(), pData->pData); + ObjectToArray(obj, array); + m_pGlobalData->SetGlobalVariableObject(name, array); m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); - break; - case JS_GLOBALDATA_TYPE_BOOLEAN: - m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); - m_pGlobalData->SetGlobalVariablePersistent(name, - pData->bPersistent); - break; - case JS_GLOBALDATA_TYPE_STRING: - m_pGlobalData->SetGlobalVariableString(name, pData->sData); - m_pGlobalData->SetGlobalVariablePersistent(name, - pData->bPersistent); - break; - case JS_GLOBALDATA_TYPE_OBJECT: - // if (pData->pData) - { - CJS_GlobalVariableArray array; - v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( - GetJSObject()->GetIsolate(), pData->pData); - ObjectToArray(obj, array); - m_pGlobalData->SetGlobalVariableObject(name, array); - m_pGlobalData->SetGlobalVariablePersistent(name, - pData->bPersistent); - } - break; - case JS_GLOBALDATA_TYPE_NULL: - m_pGlobalData->SetGlobalVariableNull(name); - m_pGlobalData->SetGlobalVariablePersistent(name, - pData->bPersistent); - break; - } + } + break; + case JS_GLOBALDATA_TYPE_NULL: + m_pGlobalData->SetGlobalVariableNull(name); + m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); + break; } } } @@ -449,15 +432,10 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, } void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { - FX_POSITION pos = m_mapGlobal.GetStartPosition(); - while (pos) { - CFX_ByteString name; - JSGlobalData* pData = NULL; - m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData); - delete pData; + for (const auto& pair : m_mapGlobal) { + delete pair.second; } - - m_mapGlobal.RemoveAll(); + m_mapGlobal.clear(); } FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, @@ -467,13 +445,12 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent) { - if (propname == NULL) + if (!propname) return FALSE; - JSGlobalData* pTemp = NULL; - m_mapGlobal.Lookup(propname, (void*&)pTemp); - - if (pTemp) { + auto it = m_mapGlobal.find(propname); + if (it != m_mapGlobal.end()) { + JSGlobalData* pTemp = it->second; if (pTemp->bDeleted || pTemp->nType != nType) { pTemp->dData = 0; pTemp->bData = 0; @@ -482,7 +459,6 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, } pTemp->bDeleted = FALSE; - switch (nType) { case JS_GLOBALDATA_TYPE_NUMBER: { pTemp->dData = dData; @@ -501,7 +477,6 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, default: return FALSE; } - return TRUE; } @@ -541,8 +516,7 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, return FALSE; } - m_mapGlobal.SetAt(propname, (void*)pNewData); - + m_mapGlobal[propname] = pNewData; return TRUE; } |