// Copyright 2014 The PDFium Authors // 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_CFX_GLOBALDATA_H_ #define FXJS_CFX_GLOBALDATA_H_ #include #include #include "core/fxcrt/binary_buffer.h" #include "core/fxcrt/unowned_ptr.h" #include "fxjs/cfx_keyvalue.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/base/containers/span.h" class CFX_GlobalData { public: class Delegate { public: virtual ~Delegate() = default; virtual bool StoreBuffer(pdfium::span pBuffer) = 0; virtual absl::optional> LoadBuffer() = 0; virtual void BufferDone() = 0; }; class Element { public: Element(); ~Element(); CFX_KeyValue data; bool bPersistent = false; }; static CFX_GlobalData* GetRetainedInstance(Delegate* pDelegate); bool Release(); void SetGlobalVariableNumber(ByteString propname, double dData); void SetGlobalVariableBoolean(ByteString propname, bool bData); void SetGlobalVariableString(ByteString propname, const ByteString& sData); void SetGlobalVariableObject( ByteString propname, std::vector> array); void SetGlobalVariableNull(ByteString propname); bool SetGlobalVariablePersistent(ByteString propname, bool bPersistent); bool DeleteGlobalVariable(ByteString propname); int32_t GetSize() const; Element* GetAt(int index); // Exposed for testing. Element* GetGlobalVariable(const ByteString& sPropname); private: using iterator = std::vector>::iterator; explicit CFX_GlobalData(Delegate* pDelegate); ~CFX_GlobalData(); bool LoadGlobalPersistentVariables(); bool LoadGlobalPersistentVariablesFromBuffer(pdfium::span buffer); bool SaveGlobalPersisitentVariables(); iterator FindGlobalVariable(const ByteString& sPropname); size_t m_RefCount = 0; UnownedPtr const m_pDelegate; std::vector> m_arrayGlobalData; }; #endif // FXJS_CFX_GLOBALDATA_H_