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

Side by Side Diff: fpdfsdk/src/javascript/JS_GlobalData.cpp

Issue 1338993005: Get CJS_RuntimeFactory out of the CJS_GlobalData management business. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 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
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 "../../../core/include/fdrm/fx_crypt.h" 7 #include "../../../core/include/fdrm/fx_crypt.h"
8 #include "../../include/javascript/JavaScript.h" 8 #include "../../include/javascript/JavaScript.h"
9 #include "../../include/javascript/IJavaScript.h" 9 #include "../../include/javascript/IJavaScript.h"
10 #include "../../include/javascript/JS_GlobalData.h" 10 #include "../../include/javascript/JS_GlobalData.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 0x19, 0xa8, 0xe8, 0x01, 0xf6, 0xa8, 0xb6, 0x4d, 0x82, 0x04, 0x45, 0x6d, 92 0x19, 0xa8, 0xe8, 0x01, 0xf6, 0xa8, 0xb6, 0x4d, 0x82, 0x04, 0x45, 0x6d,
93 0xb4, 0xcf, 0xd7, 0x77, 0x67, 0xf9, 0x75, 0x9f, 0xf0, 0xe0, 0x1e, 0x51, 93 0xb4, 0xcf, 0xd7, 0x77, 0x67, 0xf9, 0x75, 0x9f, 0xf0, 0xe0, 0x1e, 0x51,
94 0xee, 0x46, 0xfd, 0x0b, 0xc9, 0x93, 0x25, 0x55, 0x4a, 0xee, 0xe0, 0x16, 94 0xee, 0x46, 0xfd, 0x0b, 0xc9, 0x93, 0x25, 0x55, 0x4a, 0xee, 0xe0, 0x16,
95 0xd0, 0xdf, 0x8c, 0xfa, 0x2a, 0xa9, 0x49, 0xfd, 0x97, 0x1c, 0x0e, 0x22, 95 0xd0, 0xdf, 0x8c, 0xfa, 0x2a, 0xa9, 0x49, 0xfd, 0x97, 0x1c, 0x0e, 0x22,
96 0x13, 0x28, 0x7c, 0xaf, 0xc4, 0xfc, 0x9c, 0x12, 0x65, 0x8c, 0x4e, 0x5b, 96 0x13, 0x28, 0x7c, 0xaf, 0xc4, 0xfc, 0x9c, 0x12, 0x65, 0x8c, 0x4e, 0x5b,
97 0x04, 0x75, 0x89, 0xc9, 0xb1, 0xed, 0x50, 0xca, 0x96, 0x6f, 0x1a, 0x7a, 97 0x04, 0x75, 0x89, 0xc9, 0xb1, 0xed, 0x50, 0xca, 0x96, 0x6f, 0x1a, 0x7a,
98 0xfe, 0x58, 0x5d, 0xec, 0x19, 0x4a, 0xf6, 0x35, 0x6a, 0x97, 0x14, 0x00, 98 0xfe, 0x58, 0x5d, 0xec, 0x19, 0x4a, 0xf6, 0x35, 0x6a, 0x97, 0x14, 0x00,
99 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0, 99 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0,
100 0xf8, 0x77, 0xd5, 0xa3}; 100 0xf8, 0x77, 0xd5, 0xa3};
101 101
102 CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) { 102 CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr;
103 // IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp); 103
104 // ASSERT(pBaseAnnot != NULL); 104 // static
105 // 105 CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) {
106 // m_sFilePath = pBaseAnnot->GetUserPath(); 106 if (!g_Instance) {
107 g_Instance = new CJS_GlobalData(pApp);
108 }
109 g_Instance->m_RefCount += 1;
Lei Zhang 2015/09/14 20:53:28 just ++, and -- in Release?
Tom Sepez 2015/09/14 21:31:24 Done.
110 return g_Instance;
111 }
112
113 void CJS_GlobalData::Release() {
114 m_RefCount -= 1;
115 if (!m_RefCount) {
116 delete g_Instance;
117 g_Instance = nullptr;
118 }
119 }
120
121 CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_RefCount(0) {
107 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; 122 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
108
109 LoadGlobalPersistentVariables(); 123 LoadGlobalPersistentVariables();
110 } 124 }
111 125
112 CJS_GlobalData::~CJS_GlobalData() { 126 CJS_GlobalData::~CJS_GlobalData() {
113 SaveGlobalPersisitentVariables(); 127 SaveGlobalPersisitentVariables();
114
115 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) 128 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++)
116 delete m_arrayGlobalData.GetAt(i); 129 delete m_arrayGlobalData.GetAt(i);
117 130
118 m_arrayGlobalData.RemoveAll(); 131 m_arrayGlobalData.RemoveAll();
119 } 132 }
120 133
121 int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) { 134 int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) {
122 ASSERT(propname != NULL);
123
124 int nRet = -1;
125
126 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) { 135 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) {
127 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i); 136 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
128 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname) { 137 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
129 nRet = i; 138 return i;
130 break;
131 }
132 } 139 }
133 140 return -1;
134 return nRet;
135 } 141 }
136 142
137 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( 143 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(
138 const FX_CHAR* propname) { 144 const FX_CHAR* propname) {
139 ASSERT(propname != NULL); 145 ASSERT(propname != NULL);
140 146
141 int nFind = FindGlobalVariable(propname); 147 int nFind = FindGlobalVariable(propname);
142 if (nFind >= 0) 148 if (nFind >= 0)
143 return m_arrayGlobalData.GetAt(nFind); 149 return m_arrayGlobalData.GetAt(nFind);
144 150
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 case JS_GLOBALDATA_TYPE_NULL: { 490 case JS_GLOBALDATA_TYPE_NULL: {
485 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 491 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
486 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 492 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
487 sData.AppendString(name); 493 sData.AppendString(name);
488 sData.AppendBlock(&wType, sizeof(FX_DWORD)); 494 sData.AppendBlock(&wType, sizeof(FX_DWORD));
489 } break; 495 } break;
490 default: 496 default:
491 break; 497 break;
492 } 498 }
493 } 499 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698