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

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: Use pre-increment operator. 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
« no previous file with comments | « fpdfsdk/include/javascript/JS_GlobalData.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | 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 "../../../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;
110 return g_Instance;
111 }
112
113 void CJS_GlobalData::Release() {
114 if (!--m_RefCount) {
115 delete g_Instance;
116 g_Instance = nullptr;
117 }
118 }
119
120 CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_RefCount(0) {
107 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; 121 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
108
109 LoadGlobalPersistentVariables(); 122 LoadGlobalPersistentVariables();
110 } 123 }
111 124
112 CJS_GlobalData::~CJS_GlobalData() { 125 CJS_GlobalData::~CJS_GlobalData() {
113 SaveGlobalPersisitentVariables(); 126 SaveGlobalPersisitentVariables();
114
115 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) 127 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++)
116 delete m_arrayGlobalData.GetAt(i); 128 delete m_arrayGlobalData.GetAt(i);
117 129
118 m_arrayGlobalData.RemoveAll(); 130 m_arrayGlobalData.RemoveAll();
119 } 131 }
120 132
121 int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) { 133 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++) { 134 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) {
127 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i); 135 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
128 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname) { 136 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
129 nRet = i; 137 return i;
130 break;
131 }
132 } 138 }
133 139 return -1;
134 return nRet;
135 } 140 }
136 141
137 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( 142 CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(
138 const FX_CHAR* propname) { 143 const FX_CHAR* propname) {
139 ASSERT(propname != NULL); 144 ASSERT(propname != NULL);
140 145
141 int nFind = FindGlobalVariable(propname); 146 int nFind = FindGlobalVariable(propname);
142 if (nFind >= 0) 147 if (nFind >= 0)
143 return m_arrayGlobalData.GetAt(nFind); 148 return m_arrayGlobalData.GetAt(nFind);
144 149
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 case JS_GLOBALDATA_TYPE_NULL: { 489 case JS_GLOBALDATA_TYPE_NULL: {
485 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength(); 490 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
486 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD)); 491 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
487 sData.AppendString(name); 492 sData.AppendString(name);
488 sData.AppendBlock(&wType, sizeof(FX_DWORD)); 493 sData.AppendBlock(&wType, sizeof(FX_DWORD));
489 } break; 494 } break;
490 default: 495 default:
491 break; 496 break;
492 } 497 }
493 } 498 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/JS_GlobalData.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698