Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: fpdfsdk/javascript/cjs_runtime.cpp

Issue 2322743002: Replace CJS_Runtime::Observer with CFX_Runtime<CJS_Runtime>::Observer (Closed)
Patch Set: Order matters Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/javascript/cjs_runtime.h" 7 #include "fpdfsdk/javascript/cjs_runtime.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #ifdef PDF_ENABLE_XFA 117 #ifdef PDF_ENABLE_XFA
118 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); 118 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
119 #endif 119 #endif
120 120
121 CJS_Context* pContext = (CJS_Context*)NewContext(); 121 CJS_Context* pContext = (CJS_Context*)NewContext();
122 InitializeEngine(); 122 InitializeEngine();
123 ReleaseContext(pContext); 123 ReleaseContext(pContext);
124 } 124 }
125 125
126 CJS_Runtime::~CJS_Runtime() { 126 CJS_Runtime::~CJS_Runtime() {
127 for (auto* obs : m_observers) 127 NotifyObservers();
128 obs->OnDestroyed();
129
130 ReleaseEngine(); 128 ReleaseEngine();
131 if (m_isolateManaged) { 129 if (m_isolateManaged) {
132 GetIsolate()->Dispose(); 130 GetIsolate()->Dispose();
133 SetIsolate(nullptr); 131 SetIsolate(nullptr);
134 } 132 }
135 } 133 }
136 134
137 void CJS_Runtime::DefineJSObjects() { 135 void CJS_Runtime::DefineJSObjects() {
138 v8::Isolate::Scope isolate_scope(GetIsolate()); 136 v8::Isolate::Scope isolate_scope(GetIsolate());
139 v8::HandleScope handle_scope(GetIsolate()); 137 v8::HandleScope handle_scope(GetIsolate());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 246 }
249 247
250 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { 248 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
251 return m_FieldEventSet.insert(event).second; 249 return m_FieldEventSet.insert(event).second;
252 } 250 }
253 251
254 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { 252 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
255 m_FieldEventSet.erase(event); 253 m_FieldEventSet.erase(event);
256 } 254 }
257 255
258 void CJS_Runtime::AddObserver(Observer* observer) {
259 ASSERT(!pdfium::ContainsKey(m_observers, observer));
260 m_observers.insert(observer);
261 }
262
263 void CJS_Runtime::RemoveObserver(Observer* observer) {
264 ASSERT(pdfium::ContainsKey(m_observers, observer));
265 m_observers.erase(observer);
266 }
267
268 #ifdef PDF_ENABLE_XFA 256 #ifdef PDF_ENABLE_XFA
269 CFX_WideString ChangeObjName(const CFX_WideString& str) { 257 CFX_WideString ChangeObjName(const CFX_WideString& str) {
270 CFX_WideString sRet = str; 258 CFX_WideString sRet = str;
271 sRet.Replace(L"_", L"."); 259 sRet.Replace(L"_", L".");
272 return sRet; 260 return sRet;
273 } 261 }
274 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, 262 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
275 CFXJSE_Value* pValue) { 263 CFXJSE_Value* pValue) {
276 const FX_CHAR* name = utf8Name.c_str(); 264 const FX_CHAR* name = utf8Name.c_str();
277 265
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 304 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
317 v8::Local<v8::Value> propvalue = 305 v8::Local<v8::Value> propvalue =
318 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); 306 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue());
319 context->Global()->Set( 307 context->Global()->Set(
320 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 308 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
321 utf8Name.GetLength()), 309 utf8Name.GetLength()),
322 propvalue); 310 propvalue);
323 return TRUE; 311 return TRUE;
324 } 312 }
325 #endif 313 #endif
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698