summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-22 15:50:03 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-22 15:50:03 -0700
commit5d0e8432c63a5e7a0b42fd4621c1c454ff49985e (patch)
treee3f42bd19b8ad6ce36b2ef9e250b4def7e2e3b63 /fpdfsdk
parent7cfadd97215265afd7771d6c36b5cfda54427169 (diff)
downloadpdfium-5d0e8432c63a5e7a0b42fd4621c1c454ff49985e.tar.xz
Merge to XFA: Use std::set<> to track active event handlers.
Merge conflicts in JS_Runtime.cpp (cherry picked from commit d8d223127d706aa4961b2c9b0037ab256fce9a8f) Original Review URL: https://codereview.chromium.org/1352393003 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1365503003 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/javascript/JS_Runtime.h22
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp9
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp74
3 files changed, 17 insertions, 88 deletions
diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h
index b53e50e6ce..042bba9dcb 100644
--- a/fpdfsdk/include/javascript/JS_Runtime.h
+++ b/fpdfsdk/include/javascript/JS_Runtime.h
@@ -7,6 +7,9 @@
#ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_
#define FPDFSDK_INCLUDE_JAVASCRIPT_JS_RUNTIME_H_
+#include <set>
+#include <utility>
+
#include "../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../core/include/fxcrt/fx_basic.h"
#include "../jsapi/fxjs_v8.h"
@@ -15,15 +18,10 @@
class CJS_Context;
-class CJS_FieldEvent {
- public:
- CFX_WideString sTargetName;
- JS_EVENT_T eEventType;
- CJS_FieldEvent* pNext;
-};
-
class CJS_Runtime : public IFXJS_Runtime {
public:
+ using FieldEvent = std::pair<CFX_WideString, JS_EVENT_T>;
+
explicit CJS_Runtime(CPDFDoc_Environment* pApp);
~CJS_Runtime() override;
@@ -36,11 +34,9 @@ class CJS_Runtime : public IFXJS_Runtime {
CPDFDoc_Environment* GetReaderApp() const { return m_pApp; }
- FX_BOOL AddEventToLoop(const CFX_WideString& sTargetName,
- JS_EVENT_T eEventType);
- void RemoveEventInLoop(const CFX_WideString& sTargetName,
- JS_EVENT_T eEventType);
- void RemoveEventsInLoop(CJS_FieldEvent* pStart);
+ // Returns true if the event isn't already found in the set.
+ bool AddEventToSet(const FieldEvent& event);
+ void RemoveEventFromSet(const FieldEvent& event);
void BeginBlock() { m_bBlocking = TRUE; }
void EndBlock() { m_bBlocking = FALSE; }
@@ -61,7 +57,7 @@ class CJS_Runtime : public IFXJS_Runtime {
CPDFDoc_Environment* m_pApp;
CPDFSDK_Document* m_pDocument;
FX_BOOL m_bBlocking;
- CJS_FieldEvent* m_pFieldEventPath;
+ std::set<FieldEvent> m_FieldEventSet;
v8::Isolate* m_isolate;
bool m_isolateManaged;
nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator;
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index d4d1f2c877..f090326226 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -47,8 +47,9 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
m_bBusy = TRUE;
ASSERT(m_pEventHandler->IsValid());
- if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(),
- m_pEventHandler->EventType())) {
+ CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(),
+ m_pEventHandler->EventType());
+ if (!m_pRuntime->AddEventToSet(event)) {
info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
return FALSE;
}
@@ -69,9 +70,7 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
info = JSGetStringFromID(this, IDS_STRING_RUN);
}
- m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(),
- m_pEventHandler->EventType());
-
+ m_pRuntime->RemoveEventFromSet(event);
m_pEventHandler->Destroy();
m_bBusy = FALSE;
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 9996653215..5350e30a21 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -36,7 +36,6 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
: m_pApp(pApp),
m_pDocument(NULL),
m_bBlocking(FALSE),
- m_pFieldEventPath(NULL),
m_isolate(NULL),
m_isolateManaged(false) {
if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
@@ -84,11 +83,9 @@ CJS_Runtime::~CJS_Runtime() {
delete m_ContextArray.GetAt(i);
m_ContextArray.RemoveAll();
- RemoveEventsInLoop(m_pFieldEventPath);
m_pApp = NULL;
m_pDocument = NULL;
- m_pFieldEventPath = NULL;
m_context.Reset();
if (m_isolateManaged)
@@ -194,75 +191,12 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
}
}
-FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName,
- JS_EVENT_T eEventType) {
- if (m_pFieldEventPath == NULL) {
- m_pFieldEventPath = new CJS_FieldEvent;
- m_pFieldEventPath->sTargetName = sTargetName;
- m_pFieldEventPath->eEventType = eEventType;
- m_pFieldEventPath->pNext = NULL;
-
- return TRUE;
- }
-
- // to search
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = m_pFieldEventPath;
- while (p) {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName)
- return FALSE;
-
- pLast = p;
- p = p->pNext;
- }
-
- // to add
- CJS_FieldEvent* pNew = new CJS_FieldEvent;
- pNew->sTargetName = sTargetName;
- pNew->eEventType = eEventType;
- pNew->pNext = NULL;
-
- pLast->pNext = pNew;
-
- return TRUE;
+bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
+ return m_FieldEventSet.insert(event).second;
}
-void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName,
- JS_EVENT_T eEventType) {
- FX_BOOL bFind = FALSE;
-
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = NULL;
- while (p) {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName) {
- bFind = TRUE;
- break;
- }
-
- pLast = p;
- p = p->pNext;
- }
-
- if (bFind) {
- RemoveEventsInLoop(p);
-
- if (p == m_pFieldEventPath)
- m_pFieldEventPath = NULL;
-
- if (pLast)
- pLast->pNext = NULL;
- }
-}
-
-void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) {
- CJS_FieldEvent* p = pStart;
-
- while (p) {
- CJS_FieldEvent* pOld = p;
- p = pOld->pNext;
-
- delete pOld;
- }
+void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
+ m_FieldEventSet.erase(event);
}
v8::Local<v8::Context> CJS_Runtime::NewJSContext() {