1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include <memory>
8 
9 #include "core/fxcrt/unowned_ptr.h"
10 #include "fxjs/cjs_event_context_stub.h"
11 #include "fxjs/ijs_runtime.h"
12 #include "third_party/base/ptr_util.h"
13 
14 class CJS_RuntimeStub final : public IJS_Runtime {
15  public:
CJS_RuntimeStub(CPDFSDK_FormFillEnvironment * pFormFillEnv)16   explicit CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv)
17       : m_pFormFillEnv(pFormFillEnv) {}
~CJS_RuntimeStub()18   ~CJS_RuntimeStub() override {}
19 
NewEventContext()20   IJS_EventContext* NewEventContext() override {
21     if (!m_pContext)
22       m_pContext = pdfium::MakeUnique<CJS_EventContextStub>();
23     return m_pContext.get();
24   }
25 
ReleaseEventContext(IJS_EventContext * pContext)26   void ReleaseEventContext(IJS_EventContext* pContext) override {}
27 
GetFormFillEnv() const28   CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override {
29     return m_pFormFillEnv.Get();
30   }
31 
32 #ifdef PDF_ENABLE_XFA
GetValueByName(const ByteStringView &,CFXJSE_Value *)33   bool GetValueByName(const ByteStringView&, CFXJSE_Value*) override {
34     return false;
35   }
36 
SetValueByName(const ByteStringView &,CFXJSE_Value *)37   bool SetValueByName(const ByteStringView&, CFXJSE_Value*) override {
38     return false;
39   }
40 #endif  // PDF_ENABLE_XFA
41 
ExecuteScript(const WideString & script,WideString * info)42   int ExecuteScript(const WideString& script, WideString* info) override {
43     return 0;
44   }
45 
46  protected:
47   UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
48   std::unique_ptr<CJS_EventContextStub> m_pContext;
49 };
50 
51 // static
Initialize(unsigned int slot,void * isolate)52 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {}
53 
54 // static
Destroy()55 void IJS_Runtime::Destroy() {}
56 
57 // static
Create(CPDFSDK_FormFillEnvironment * pFormFillEnv)58 IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
59   return new CJS_RuntimeStub(pFormFillEnv);
60 }
61