blob: 1bff94d298034d02994bbe94f9217ce9577e495f [file] [log] [blame]
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef FXJS_CJS_GLOBALDATA_H_
#define FXJS_CJS_GLOBALDATA_H_
#include <memory>
#include <vector>
#include "core/fxcrt/cfx_binarybuf.h"
#include "fxjs/cjs_keyvalue.h"
class CPDFSDK_FormFillEnvironment;
class CJS_GlobalData {
public:
class Element {
public:
Element();
~Element();
CJS_KeyValue data;
bool bPersistent;
};
static CJS_GlobalData* GetRetainedInstance(CPDFSDK_FormFillEnvironment* pApp);
void Release();
void SetGlobalVariableNumber(ByteString propname, double dData);
void SetGlobalVariableBoolean(ByteString propname, bool bData);
void SetGlobalVariableString(ByteString propname, const ByteString& sData);
void SetGlobalVariableObject(ByteString propname,
const CJS_GlobalVariableArray& array);
void SetGlobalVariableNull(ByteString propname);
bool SetGlobalVariablePersistent(ByteString propname, bool bPersistent);
bool DeleteGlobalVariable(ByteString propname);
int32_t GetSize() const;
Element* GetAt(int index) const;
private:
using iterator = std::vector<std::unique_ptr<Element>>::iterator;
using const_iterator = std::vector<std::unique_ptr<Element>>::const_iterator;
CJS_GlobalData();
~CJS_GlobalData();
void LoadGlobalPersistentVariables();
void SaveGlobalPersisitentVariables();
Element* GetGlobalVariable(const ByteString& sPropname);
iterator FindGlobalVariable(const ByteString& sPropname);
const_iterator FindGlobalVariable(const ByteString& sPropname) const;
void LoadFileBuffer(const wchar_t* sFilePath,
uint8_t*& pBuffer,
int32_t& nLength);
void WriteFileBuffer(const wchar_t* sFilePath,
const char* pBuffer,
int32_t nLength);
void MakeByteString(const ByteString& name,
CJS_KeyValue* pData,
CFX_BinaryBuf& sData);
size_t m_RefCount = 0;
std::vector<std::unique_ptr<Element>> m_arrayGlobalData;
WideString m_sFilePath;
};
#endif // FXJS_CJS_GLOBALDATA_H_