Home | History | Annotate | Download | only in fxjs
      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:
     16   explicit CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv)
     17       : m_pFormFillEnv(pFormFillEnv) {}
     18   ~CJS_RuntimeStub() override {}
     19 
     20   IJS_EventContext* NewEventContext() override {
     21     if (!m_pContext)
     22       m_pContext = pdfium::MakeUnique<CJS_EventContextStub>();
     23     return m_pContext.get();
     24   }
     25 
     26   void ReleaseEventContext(IJS_EventContext* pContext) override {}
     27 
     28   CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override {
     29     return m_pFormFillEnv.Get();
     30   }
     31 
     32 #ifdef PDF_ENABLE_XFA
     33   bool GetValueByName(const ByteStringView&, CFXJSE_Value*) override {
     34     return false;
     35   }
     36 
     37   bool SetValueByName(const ByteStringView&, CFXJSE_Value*) override {
     38     return false;
     39   }
     40 #endif  // PDF_ENABLE_XFA
     41 
     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
     52 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {}
     53 
     54 // static
     55 void IJS_Runtime::Destroy() {}
     56 
     57 // static
     58 IJS_Runtime* IJS_Runtime::Create(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
     59   return new CJS_RuntimeStub(pFormFillEnv);
     60 }
     61