• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "fpdfsdk/include/fsdk_mgr.h"  // For CPDFDoc_Environment.
10 #include "fpdfsdk/include/javascript/IJavaScript.h"
11 
12 class CJS_ContextStub final : public IJS_Context {
13  public:
CJS_ContextStub()14   CJS_ContextStub() {}
~CJS_ContextStub()15   ~CJS_ContextStub() override {}
16 
17   // IJS_Context:
RunScript(const CFX_WideString & script,CFX_WideString * info)18   FX_BOOL RunScript(const CFX_WideString& script,
19                     CFX_WideString* info) override {
20     return FALSE;
21   }
22 
OnApp_Init()23   void OnApp_Init() override {}
OnDoc_Open(CPDFSDK_Document * pDoc,const CFX_WideString & strTargetName)24   void OnDoc_Open(CPDFSDK_Document* pDoc,
25                   const CFX_WideString& strTargetName) override {}
OnDoc_WillPrint(CPDFSDK_Document * pDoc)26   void OnDoc_WillPrint(CPDFSDK_Document* pDoc) override {}
OnDoc_DidPrint(CPDFSDK_Document * pDoc)27   void OnDoc_DidPrint(CPDFSDK_Document* pDoc) override {}
OnDoc_WillSave(CPDFSDK_Document * pDoc)28   void OnDoc_WillSave(CPDFSDK_Document* pDoc) override {}
OnDoc_DidSave(CPDFSDK_Document * pDoc)29   void OnDoc_DidSave(CPDFSDK_Document* pDoc) override {}
OnDoc_WillClose(CPDFSDK_Document * pDoc)30   void OnDoc_WillClose(CPDFSDK_Document* pDoc) override {}
OnPage_Open(CPDFSDK_Document * pTarget)31   void OnPage_Open(CPDFSDK_Document* pTarget) override {}
OnPage_Close(CPDFSDK_Document * pTarget)32   void OnPage_Close(CPDFSDK_Document* pTarget) override {}
OnPage_InView(CPDFSDK_Document * pTarget)33   void OnPage_InView(CPDFSDK_Document* pTarget) override {}
OnPage_OutView(CPDFSDK_Document * pTarget)34   void OnPage_OutView(CPDFSDK_Document* pTarget) override {}
OnField_MouseDown(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget)35   void OnField_MouseDown(FX_BOOL bModifier,
36                          FX_BOOL bShift,
37                          CPDF_FormField* pTarget) override {}
OnField_MouseEnter(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget)38   void OnField_MouseEnter(FX_BOOL bModifier,
39                           FX_BOOL bShift,
40                           CPDF_FormField* pTarget) override {}
OnField_MouseExit(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget)41   void OnField_MouseExit(FX_BOOL bModifier,
42                          FX_BOOL bShift,
43                          CPDF_FormField* pTarget) override {}
OnField_MouseUp(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget)44   void OnField_MouseUp(FX_BOOL bModifier,
45                        FX_BOOL bShift,
46                        CPDF_FormField* pTarget) override {}
OnField_Focus(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget,const CFX_WideString & Value)47   void OnField_Focus(FX_BOOL bModifier,
48                      FX_BOOL bShift,
49                      CPDF_FormField* pTarget,
50                      const CFX_WideString& Value) override {}
OnField_Blur(FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget,const CFX_WideString & Value)51   void OnField_Blur(FX_BOOL bModifier,
52                     FX_BOOL bShift,
53                     CPDF_FormField* pTarget,
54                     const CFX_WideString& Value) override {}
OnField_Calculate(CPDF_FormField * pSource,CPDF_FormField * pTarget,CFX_WideString & Value,FX_BOOL & bRc)55   void OnField_Calculate(CPDF_FormField* pSource,
56                          CPDF_FormField* pTarget,
57                          CFX_WideString& Value,
58                          FX_BOOL& bRc) override {}
OnField_Format(CPDF_FormField * pTarget,CFX_WideString & Value,FX_BOOL bWillCommit)59   void OnField_Format(CPDF_FormField* pTarget,
60                       CFX_WideString& Value,
61                       FX_BOOL bWillCommit) override {}
OnField_Keystroke(CFX_WideString & strChange,const CFX_WideString & strChangeEx,FX_BOOL KeyDown,FX_BOOL bModifier,int & nSelEnd,int & nSelStart,FX_BOOL bShift,CPDF_FormField * pTarget,CFX_WideString & Value,FX_BOOL bWillCommit,FX_BOOL bFieldFull,FX_BOOL & bRc)62   void OnField_Keystroke(CFX_WideString& strChange,
63                          const CFX_WideString& strChangeEx,
64                          FX_BOOL KeyDown,
65                          FX_BOOL bModifier,
66                          int& nSelEnd,
67                          int& nSelStart,
68                          FX_BOOL bShift,
69                          CPDF_FormField* pTarget,
70                          CFX_WideString& Value,
71                          FX_BOOL bWillCommit,
72                          FX_BOOL bFieldFull,
73                          FX_BOOL& bRc) override {}
OnField_Validate(CFX_WideString & strChange,const CFX_WideString & strChangeEx,FX_BOOL bKeyDown,FX_BOOL bModifier,FX_BOOL bShift,CPDF_FormField * pTarget,CFX_WideString & Value,FX_BOOL & bRc)74   void OnField_Validate(CFX_WideString& strChange,
75                         const CFX_WideString& strChangeEx,
76                         FX_BOOL bKeyDown,
77                         FX_BOOL bModifier,
78                         FX_BOOL bShift,
79                         CPDF_FormField* pTarget,
80                         CFX_WideString& Value,
81                         FX_BOOL& bRc) override {}
OnScreen_Focus(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)82   void OnScreen_Focus(FX_BOOL bModifier,
83                       FX_BOOL bShift,
84                       CPDFSDK_Annot* pScreen) override {}
OnScreen_Blur(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)85   void OnScreen_Blur(FX_BOOL bModifier,
86                      FX_BOOL bShift,
87                      CPDFSDK_Annot* pScreen) override {}
OnScreen_Open(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)88   void OnScreen_Open(FX_BOOL bModifier,
89                      FX_BOOL bShift,
90                      CPDFSDK_Annot* pScreen) override {}
OnScreen_Close(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)91   void OnScreen_Close(FX_BOOL bModifier,
92                       FX_BOOL bShift,
93                       CPDFSDK_Annot* pScreen) override {}
OnScreen_MouseDown(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)94   void OnScreen_MouseDown(FX_BOOL bModifier,
95                           FX_BOOL bShift,
96                           CPDFSDK_Annot* pScreen) override {}
OnScreen_MouseUp(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)97   void OnScreen_MouseUp(FX_BOOL bModifier,
98                         FX_BOOL bShift,
99                         CPDFSDK_Annot* pScreen) override {}
OnScreen_MouseEnter(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)100   void OnScreen_MouseEnter(FX_BOOL bModifier,
101                            FX_BOOL bShift,
102                            CPDFSDK_Annot* pScreen) override {}
OnScreen_MouseExit(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)103   void OnScreen_MouseExit(FX_BOOL bModifier,
104                           FX_BOOL bShift,
105                           CPDFSDK_Annot* pScreen) override {}
OnScreen_InView(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)106   void OnScreen_InView(FX_BOOL bModifier,
107                        FX_BOOL bShift,
108                        CPDFSDK_Annot* pScreen) override {}
OnScreen_OutView(FX_BOOL bModifier,FX_BOOL bShift,CPDFSDK_Annot * pScreen)109   void OnScreen_OutView(FX_BOOL bModifier,
110                         FX_BOOL bShift,
111                         CPDFSDK_Annot* pScreen) override {}
OnBookmark_MouseUp(CPDF_Bookmark * pBookMark)112   void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) override {}
OnLink_MouseUp(CPDFSDK_Document * pTarget)113   void OnLink_MouseUp(CPDFSDK_Document* pTarget) override {}
OnMenu_Exec(CPDFSDK_Document * pTarget,const CFX_WideString &)114   void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString&) override {}
OnBatchExec(CPDFSDK_Document * pTarget)115   void OnBatchExec(CPDFSDK_Document* pTarget) override {}
OnConsole_Exec()116   void OnConsole_Exec() override {}
OnExternal_Exec()117   void OnExternal_Exec() override {}
EnableMessageBox(FX_BOOL bEnable)118   void EnableMessageBox(FX_BOOL bEnable) override {}
119 };
120 
121 class CJS_RuntimeStub final : public IJS_Runtime {
122  public:
CJS_RuntimeStub()123   CJS_RuntimeStub() : m_pDoc(nullptr) {}
~CJS_RuntimeStub()124   ~CJS_RuntimeStub() override {}
125 
NewContext()126   IJS_Context* NewContext() override {
127     if (!m_pContext)
128       m_pContext.reset(new CJS_ContextStub());
129     return GetCurrentContext();
130   }
131 
GetCurrentContext()132   IJS_Context* GetCurrentContext() override { return m_pContext.get(); }
ReleaseContext(IJS_Context * pContext)133   void ReleaseContext(IJS_Context* pContext) override {}
134 
SetReaderDocument(CPDFSDK_Document * pReaderDoc)135   void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override {
136     m_pDoc = pReaderDoc;
137   }
GetReaderDocument()138   CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; }
139 
140 #ifdef PDF_ENABLE_XFA
GetHValueByName(const CFX_ByteStringC &,FXJSE_HVALUE)141   virtual FX_BOOL GetHValueByName(const CFX_ByteStringC&,
142                                   FXJSE_HVALUE) override {
143     return FALSE;
144   }
145 
SetHValueByName(const CFX_ByteStringC &,FXJSE_HVALUE)146   virtual FX_BOOL SetHValueByName(const CFX_ByteStringC&,
147                                   FXJSE_HVALUE) override {
148     return FALSE;
149   }
150 #endif  // PDF_ENABLE_XFA
151 
Execute(IJS_Context * cc,const wchar_t * script,CFX_WideString * info)152   int Execute(IJS_Context* cc,
153               const wchar_t* script,
154               CFX_WideString* info) override {
155     return 0;
156   }
157 
158  protected:
159   CPDFSDK_Document* m_pDoc;
160   std::unique_ptr<CJS_ContextStub> m_pContext;
161 };
162 
163 // static
Initialize(unsigned int slot,void * isolate)164 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
165 }
166 
167 // static
Create(CPDFDoc_Environment * pEnv)168 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) {
169   return new CJS_RuntimeStub;
170 }
171