diff options
-rw-r--r-- | BUILD.gn | 198 | ||||
-rw-r--r-- | fpdfsdk/include/javascript/IJavaScript.h | 1 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp | 1 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime_Stub.cpp | 161 | ||||
-rw-r--r-- | pdfium.gni | 6 | ||||
-rw-r--r-- | pdfium.gyp | 157 | ||||
-rw-r--r-- | samples/BUILD.gn | 19 | ||||
-rw-r--r-- | samples/pdfium_test.cc | 11 | ||||
-rw-r--r-- | samples/samples.gyp | 25 | ||||
-rw-r--r-- | testing/embedder_test.cpp | 14 | ||||
-rw-r--r-- | testing/embedder_test.h | 13 | ||||
-rw-r--r-- | xfa.gyp | 102 |
14 files changed, 480 insertions, 241 deletions
@@ -21,6 +21,10 @@ config("pdfium_config") { defines += [ "_SKIA_SUPPORT_" ] } + if (pdf_enable_v8) { + defines += [ "PDF_ENABLE_V8" ] + } + if (pdf_enable_xfa) { defines += [ "PDF_ENABLE_XFA" ] } @@ -109,7 +113,6 @@ static_library("pdfium") { ":fxedit", ":fxge", ":javascript", - ":jsapi", ":pdfwindow", ] @@ -603,74 +606,65 @@ static_library("pdfwindow") { static_library("javascript") { sources = [ "fpdfsdk/include/javascript/IJavaScript.h", - "fpdfsdk/src/javascript/Consts.cpp", - "fpdfsdk/src/javascript/Consts.h", - "fpdfsdk/src/javascript/Document.cpp", - "fpdfsdk/src/javascript/Document.h", - "fpdfsdk/src/javascript/Field.cpp", - "fpdfsdk/src/javascript/Field.h", - "fpdfsdk/src/javascript/Icon.cpp", - "fpdfsdk/src/javascript/Icon.h", - "fpdfsdk/src/javascript/JS_Context.cpp", - "fpdfsdk/src/javascript/JS_Context.h", - "fpdfsdk/src/javascript/JS_Define.h", - "fpdfsdk/src/javascript/JS_EventHandler.cpp", - "fpdfsdk/src/javascript/JS_EventHandler.h", - "fpdfsdk/src/javascript/JS_GlobalData.cpp", - "fpdfsdk/src/javascript/JS_GlobalData.h", - "fpdfsdk/src/javascript/JS_Object.cpp", - "fpdfsdk/src/javascript/JS_Object.h", - "fpdfsdk/src/javascript/JS_Runtime.cpp", - "fpdfsdk/src/javascript/JS_Runtime.h", - "fpdfsdk/src/javascript/JS_Value.cpp", - "fpdfsdk/src/javascript/JS_Value.h", - "fpdfsdk/src/javascript/PublicMethods.cpp", - "fpdfsdk/src/javascript/PublicMethods.h", - "fpdfsdk/src/javascript/app.cpp", - "fpdfsdk/src/javascript/app.h", - "fpdfsdk/src/javascript/color.cpp", - "fpdfsdk/src/javascript/color.h", - "fpdfsdk/src/javascript/console.cpp", - "fpdfsdk/src/javascript/console.h", - "fpdfsdk/src/javascript/event.cpp", - "fpdfsdk/src/javascript/event.h", - "fpdfsdk/src/javascript/global.cpp", - "fpdfsdk/src/javascript/global.h", - "fpdfsdk/src/javascript/report.cpp", - "fpdfsdk/src/javascript/report.h", - "fpdfsdk/src/javascript/resource.cpp", - "fpdfsdk/src/javascript/resource.h", - "fpdfsdk/src/javascript/util.cpp", - "fpdfsdk/src/javascript/util.h", ] - - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ] - include_dirs = [ - "//v8", - "//v8/include", - ] - - public_deps = [ - "//v8", - ] -} - -static_library("jsapi") { - sources = [ - "fpdfsdk/include/jsapi/fxjs_v8.h", - "fpdfsdk/src/jsapi/fxjs_v8.cpp", - ] - + if (pdf_enable_v8) { + sources += [ + "fpdfsdk/src/javascript/Consts.cpp", + "fpdfsdk/src/javascript/Consts.h", + "fpdfsdk/src/javascript/Document.cpp", + "fpdfsdk/src/javascript/Document.h", + "fpdfsdk/src/javascript/Field.cpp", + "fpdfsdk/src/javascript/Field.h", + "fpdfsdk/src/javascript/Icon.cpp", + "fpdfsdk/src/javascript/Icon.h", + "fpdfsdk/src/javascript/JS_Context.cpp", + "fpdfsdk/src/javascript/JS_Context.h", + "fpdfsdk/src/javascript/JS_Define.h", + "fpdfsdk/src/javascript/JS_EventHandler.cpp", + "fpdfsdk/src/javascript/JS_EventHandler.h", + "fpdfsdk/src/javascript/JS_GlobalData.cpp", + "fpdfsdk/src/javascript/JS_GlobalData.h", + "fpdfsdk/src/javascript/JS_Object.cpp", + "fpdfsdk/src/javascript/JS_Object.h", + "fpdfsdk/src/javascript/JS_Runtime.cpp", + "fpdfsdk/src/javascript/JS_Runtime.h", + "fpdfsdk/src/javascript/JS_Value.cpp", + "fpdfsdk/src/javascript/JS_Value.h", + "fpdfsdk/src/javascript/PublicMethods.cpp", + "fpdfsdk/src/javascript/PublicMethods.h", + "fpdfsdk/src/javascript/app.cpp", + "fpdfsdk/src/javascript/app.h", + "fpdfsdk/src/javascript/color.cpp", + "fpdfsdk/src/javascript/color.h", + "fpdfsdk/src/javascript/console.cpp", + "fpdfsdk/src/javascript/console.h", + "fpdfsdk/src/javascript/event.cpp", + "fpdfsdk/src/javascript/event.h", + "fpdfsdk/src/javascript/global.cpp", + "fpdfsdk/src/javascript/global.h", + "fpdfsdk/src/javascript/report.cpp", + "fpdfsdk/src/javascript/report.h", + "fpdfsdk/src/javascript/resource.cpp", + "fpdfsdk/src/javascript/resource.h", + "fpdfsdk/src/javascript/util.cpp", + "fpdfsdk/src/javascript/util.h", + "fpdfsdk/include/jsapi/fxjs_v8.h", + "fpdfsdk/src/jsapi/fxjs_v8.cpp", + ] + include_dirs = [ + "//v8", + "//v8/include", + ] + public_deps = [ + "//v8", + ] + } else { + sources += [ "fpdfsdk/src/javascript/JS_Runtime_Stub.cpp" ] + } configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ] - include_dirs = [ - "//v8", - "//v8/include", - ] - - public_deps = [ - "//v8", + configs += [ + ":pdfium_config", + "//build/config/compiler:no_chromium_code", ] } @@ -1364,29 +1358,36 @@ static_library("xfa") { "xfa/src/fxgraphics/src/fx_path_generator.cpp", "xfa/src/fxgraphics/src/fx_path_generator.h", "xfa/src/fxgraphics/src/pre.h", - "xfa/src/fxjse/src/class.cpp", - "xfa/src/fxjse/src/class.h", - "xfa/src/fxjse/src/context.cpp", - "xfa/src/fxjse/src/context.h", - "xfa/src/fxjse/src/dynprop.cpp", - "xfa/src/fxjse/src/runtime.cpp", - "xfa/src/fxjse/src/runtime.h", - "xfa/src/fxjse/src/scope_inline.h", - "xfa/src/fxjse/src/util_inline.h", - "xfa/src/fxjse/src/value.cpp", - "xfa/src/fxjse/src/value.h" ] + if (pdf_enable_v8) { + sources += [ + "xfa/src/fxjse/src/class.cpp", + "xfa/src/fxjse/src/class.h", + "xfa/src/fxjse/src/context.cpp", + "xfa/src/fxjse/src/context.h", + "xfa/src/fxjse/src/dynprop.cpp", + "xfa/src/fxjse/src/runtime.cpp", + "xfa/src/fxjse/src/runtime.h", + "xfa/src/fxjse/src/scope_inline.h", + "xfa/src/fxjse/src/util_inline.h", + "xfa/src/fxjse/src/value.cpp", + "xfa/src/fxjse/src/value.h" + ], + include_dirs = [ + "//v8", + "//v8/include", + ] + public_deps = [ + "//v8", + ] + deps = [ + "//v8:v8_libplatform", + ] + } configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ] - include_dirs = [ - "//v8", - "//v8/include", - ] - public_deps = [ - "//v8", - ] - deps = [ - "//v8:v8_libplatform", + configs += [ + ":pdfium_config", + "//build/config/compiler:no_chromium_code", ] } @@ -1423,7 +1424,6 @@ test("pdfium_embeddertests") { "fpdfsdk/src/fpdfview_c_api_test.c", "fpdfsdk/src/fpdfview_c_api_test.h", "fpdfsdk/src/fpdfview_embeddertest.cpp", - "fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp", "testing/embedder_test.cpp", "testing/embedder_test.h", "testing/embedder_test_mock_delegate.h", @@ -1434,14 +1434,24 @@ test("pdfium_embeddertests") { deps = [ "//testing/gmock", "//testing/gtest", - "//v8:v8_libplatform", - ":pdfium" + ":pdfium", ] include_dirs = [ - ".", - "//v8", - "//v8/include", + "." ] + if (pdf_enable_v8) { + sources += [ + "fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp" + ] + deps += [ + "//v8", + "//v8:v8_libplatform", + ] + include_dirs += [ + "//v8", + "//v8/include", + ] + } configs -= [ "//build/config/compiler:chromium_code" ] configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ] } diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h index fc8bf2bd7c..f78ee52793 100644 --- a/fpdfsdk/include/javascript/IJavaScript.h +++ b/fpdfsdk/include/javascript/IJavaScript.h @@ -134,6 +134,7 @@ class IJS_Context { class IJS_Runtime { public: + static void Initialize(unsigned int slot, void* isolate); static IJS_Runtime* Create(CPDFDoc_Environment* pEnv); virtual ~IJS_Runtime() {} diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index cf05d79f5c..a5daa8f52e 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -20,7 +20,7 @@ #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_page.h" #include "../include/fpdfxfa/fpdfxfa_util.h" -#include "../include/jsapi/fxjs_v8.h" +#include "../include/javascript/IJavaScript.h" CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { m_pFS = pFS; @@ -196,10 +196,8 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { CPDF_ModuleMgr::Get()->InitPageModule(); CPDF_ModuleMgr::Get()->InitRenderModule(); CPDFXFA_App::GetInstance()->Initialize(); - if (cfg && cfg->version >= 2) { - FXJS_Initialize(cfg->m_v8EmbedderSlot, - reinterpret_cast<v8::Isolate*>(cfg->m_pIsolate)); - } + if (cfg && cfg->version >= 2) + IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); } DLLEXPORT void STDCALL FPDF_DestroyLibrary() { diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp index fed3f32318..bc19903bad 100644 --- a/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp @@ -9,7 +9,6 @@ #include "../../include/fsdk_mgr.h"
#include "../../include/fpdfxfa/fpdfxfa_doc.h"
#include "../../include/fpdfxfa/fpdfxfa_util.h"
-#include "../../include/jsapi/fxjs_v8.h"
#include "../../include/javascript/IJavaScript.h"
#include "../../include/fpdfxfa/fpdfxfa_app.h"
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 8a0d6666bb..1d2fa84323 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -33,6 +33,11 @@ v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); // static +void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { + FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate)); +} + +// static IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { return new CJS_Runtime(pEnv); } diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp new file mode 100644 index 0000000000..ea1e6c1c55 --- /dev/null +++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp @@ -0,0 +1,161 @@ +// Copyright 2015 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 + +#include "../../../third_party/base/nonstd_unique_ptr.h" +#include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. +#include "../../include/javascript/IJavaScript.h" + +class CJS_ContextStub final : public IJS_Context { + public: + CJS_ContextStub() {} + ~CJS_ContextStub() override {} + + // IJS_Context: + FX_BOOL RunScript(const CFX_WideString& script, + CFX_WideString& info) override { + return FALSE; + } + + void OnApp_Init() override {} + void OnDoc_Open(CPDFSDK_Document* pDoc, + const CFX_WideString& strTargetName) override {} + void OnDoc_WillPrint(CPDFSDK_Document* pDoc) override {} + void OnDoc_DidPrint(CPDFSDK_Document* pDoc) override {} + void OnDoc_WillSave(CPDFSDK_Document* pDoc) override {} + void OnDoc_DidSave(CPDFSDK_Document* pDoc) override {} + void OnDoc_WillClose(CPDFSDK_Document* pDoc) override {} + void OnPage_Open(CPDFSDK_Document* pTarget) override {} + void OnPage_Close(CPDFSDK_Document* pTarget) override {} + void OnPage_InView(CPDFSDK_Document* pTarget) override {} + void OnPage_OutView(CPDFSDK_Document* pTarget) override {} + void OnField_MouseDown(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget) override {} + void OnField_MouseEnter(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget) override {} + void OnField_MouseExit(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget) override {} + void OnField_MouseUp(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget) override {} + void OnField_Focus(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget, + const CFX_WideString& Value) override {} + void OnField_Blur(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget, + const CFX_WideString& Value) override {} + void OnField_Calculate(CPDF_FormField* pSource, + CPDF_FormField* pTarget, + CFX_WideString& Value, + FX_BOOL& bRc) override {} + void OnField_Format(CPDF_FormField* pTarget, + CFX_WideString& Value, + FX_BOOL bWillCommit) override {} + void 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) override {} + void 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) override {} + void OnScreen_Focus(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_Blur(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_Open(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_Close(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_MouseDown(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_MouseUp(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_MouseEnter(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_MouseExit(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_InView(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnScreen_OutView(FX_BOOL bModifier, + FX_BOOL bShift, + CPDFSDK_Annot* pScreen) override {} + void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) override {} + void OnLink_MouseUp(CPDFSDK_Document* pTarget) override {} + void OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString&) override {} + void OnBatchExec(CPDFSDK_Document* pTarget) override {} + void OnConsole_Exec() override {} + void OnExternal_Exec() override {} + void EnableMessageBox(FX_BOOL bEnable) override {} +}; + +class CJS_RuntimeStub final : public IJS_Runtime { + public: + CJS_RuntimeStub() : m_pDoc(nullptr) {} + ~CJS_RuntimeStub() override {} + + IJS_Context* NewContext() override { + if (!m_pContext) + m_pContext.reset(new CJS_ContextStub()); + return GetCurrentContext(); + } + + IJS_Context* GetCurrentContext() override { return m_pContext.get(); } + void ReleaseContext(IJS_Context* pContext) override {} + + void SetReaderDocument(CPDFSDK_Document* pReaderDoc) override { + m_pDoc = pReaderDoc; + } + CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; } + + virtual FX_BOOL GetHValueByName(const CFX_ByteStringC&, + FXJSE_HVALUE) override { + return FALSE; + } + + virtual FX_BOOL SetHValueByName(const CFX_ByteStringC&, + FXJSE_HVALUE) override { + return FALSE; + } + + protected: + CPDFSDK_Document* m_pDoc; + nonstd::unique_ptr<CJS_ContextStub> m_pContext; +}; + +// static +void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { +} + +// static +IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { + return new CJS_RuntimeStub; +} diff --git a/pdfium.gni b/pdfium.gni index 8e99e5f26a..afb1d7b217 100644 --- a/pdfium.gni +++ b/pdfium.gni @@ -9,9 +9,13 @@ declare_args() { # methods are used from it. pdfium_bundle_freetype = !is_linux + # Build PDFium either with or without v8 support. + pdf_enable_v8 = true + # Build PDFium either with or without XFA Forms support. pdf_enable_xfa = true # Build PDFium against skia (experimental) rather than agg. pdf_use_skia = false -}
\ No newline at end of file +} + diff --git a/pdfium.gyp b/pdfium.gyp index 6ef54ab80d..3785d38a1b 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -1,6 +1,7 @@ { 'variables': { 'pdf_use_skia%': 0, + 'pdf_enable_v8%': 1, 'pdf_enable_xfa%': 1, 'conditions': [ ['OS=="linux"', { @@ -27,6 +28,9 @@ ['pdf_use_skia==1', { 'defines': ['_SKIA_SUPPORT_'], }], + ['pdf_enable_v8==1', { + 'defines': ['PDF_ENABLE_V8'], + }], ['pdf_enable_xfa==1', { 'defines': ['PDF_ENABLE_XFA'], }], @@ -63,7 +67,6 @@ 'fxedit', 'fxge', 'javascript', - 'jsapi', 'pdfwindow', 'fpdfxfa', ], @@ -654,80 +657,73 @@ { 'target_name': 'javascript', 'type': 'static_library', - 'include_dirs': [ - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', - ], - 'dependencies': [ - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', - ], - 'export_dependent_settings': [ - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', - ], 'ldflags': [ '-L<(PRODUCT_DIR)',], 'sources': [ 'fpdfsdk/include/javascript/IJavaScript.h', - 'fpdfsdk/src/javascript/app.cpp', - 'fpdfsdk/src/javascript/color.cpp', - 'fpdfsdk/src/javascript/console.cpp', - 'fpdfsdk/src/javascript/Consts.cpp', - 'fpdfsdk/src/javascript/Consts.h', - 'fpdfsdk/src/javascript/Document.cpp', - 'fpdfsdk/src/javascript/Document.h', - 'fpdfsdk/src/javascript/Field.cpp', - 'fpdfsdk/src/javascript/Field.h', - 'fpdfsdk/src/javascript/Icon.cpp', - 'fpdfsdk/src/javascript/Icon.h', - 'fpdfsdk/src/javascript/JS_Context.cpp', - 'fpdfsdk/src/javascript/JS_Context.h', - 'fpdfsdk/src/javascript/JS_Define.h', - 'fpdfsdk/src/javascript/JS_EventHandler.cpp', - 'fpdfsdk/src/javascript/JS_EventHandler.h', - 'fpdfsdk/src/javascript/JS_GlobalData.cpp', - 'fpdfsdk/src/javascript/JS_GlobalData.h', - 'fpdfsdk/src/javascript/JS_Object.cpp', - 'fpdfsdk/src/javascript/JS_Object.h', - 'fpdfsdk/src/javascript/JS_Runtime.cpp', - 'fpdfsdk/src/javascript/JS_Runtime.h', - 'fpdfsdk/src/javascript/JS_Value.cpp', - 'fpdfsdk/src/javascript/JS_Value.h', - 'fpdfsdk/src/javascript/PublicMethods.cpp', - 'fpdfsdk/src/javascript/PublicMethods.h', - 'fpdfsdk/src/javascript/app.cpp', - 'fpdfsdk/src/javascript/app.h', - 'fpdfsdk/src/javascript/color.cpp', - 'fpdfsdk/src/javascript/color.h', - 'fpdfsdk/src/javascript/console.cpp', - 'fpdfsdk/src/javascript/console.h', - 'fpdfsdk/src/javascript/event.cpp', - 'fpdfsdk/src/javascript/event.h', - 'fpdfsdk/src/javascript/global.cpp', - 'fpdfsdk/src/javascript/global.h', - 'fpdfsdk/src/javascript/report.cpp', - 'fpdfsdk/src/javascript/report.h', - 'fpdfsdk/src/javascript/resource.cpp', - 'fpdfsdk/src/javascript/resource.h', - 'fpdfsdk/src/javascript/util.cpp', - 'fpdfsdk/src/javascript/util.h', - ], - }, - { - 'target_name': 'jsapi', - 'type': 'static_library', - 'dependencies': [ - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', - ], - 'export_dependent_settings': [ - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', - ], - 'include_dirs': [ - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', + 'fpdfsdk/src/javascript/JS_Runtime_Stub.cpp', ], - 'ldflags': [ '-L<(PRODUCT_DIR)',], - 'sources': [ - 'fpdfsdk/include/jsapi/fxjs_v8.h', - 'fpdfsdk/src/jsapi/fxjs_v8.cpp', + 'conditions': [ + ['pdf_enable_v8==1', { + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + 'dependencies': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + ], + 'export_dependent_settings': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + ], + 'sources!': [ + 'fpdfsdk/src/javascript/JS_Runtime_Stub.cpp', + ], + 'sources': [ + 'fpdfsdk/src/javascript/Consts.cpp', + 'fpdfsdk/src/javascript/Consts.h', + 'fpdfsdk/src/javascript/Document.cpp', + 'fpdfsdk/src/javascript/Document.h', + 'fpdfsdk/src/javascript/Field.cpp', + 'fpdfsdk/src/javascript/Field.h', + 'fpdfsdk/src/javascript/Icon.cpp', + 'fpdfsdk/src/javascript/Icon.h', + 'fpdfsdk/src/javascript/JS_Context.cpp', + 'fpdfsdk/src/javascript/JS_Context.h', + 'fpdfsdk/src/javascript/JS_Define.h', + 'fpdfsdk/src/javascript/JS_EventHandler.cpp', + 'fpdfsdk/src/javascript/JS_EventHandler.h', + 'fpdfsdk/src/javascript/JS_GlobalData.cpp', + 'fpdfsdk/src/javascript/JS_GlobalData.h', + 'fpdfsdk/src/javascript/JS_Object.cpp', + 'fpdfsdk/src/javascript/JS_Object.h', + 'fpdfsdk/src/javascript/JS_Runtime.cpp', + 'fpdfsdk/src/javascript/JS_Runtime.h', + 'fpdfsdk/src/javascript/JS_Value.cpp', + 'fpdfsdk/src/javascript/JS_Value.h', + 'fpdfsdk/src/javascript/PublicMethods.cpp', + 'fpdfsdk/src/javascript/PublicMethods.h', + 'fpdfsdk/src/javascript/app.cpp', + 'fpdfsdk/src/javascript/app.cpp', + 'fpdfsdk/src/javascript/app.h', + 'fpdfsdk/src/javascript/color.cpp', + 'fpdfsdk/src/javascript/color.cpp', + 'fpdfsdk/src/javascript/color.h', + 'fpdfsdk/src/javascript/console.cpp', + 'fpdfsdk/src/javascript/console.cpp', + 'fpdfsdk/src/javascript/console.h', + 'fpdfsdk/src/javascript/event.cpp', + 'fpdfsdk/src/javascript/event.h', + 'fpdfsdk/src/javascript/global.cpp', + 'fpdfsdk/src/javascript/global.h', + 'fpdfsdk/src/javascript/report.cpp', + 'fpdfsdk/src/javascript/report.h', + 'fpdfsdk/src/javascript/resource.cpp', + 'fpdfsdk/src/javascript/resource.h', + 'fpdfsdk/src/javascript/util.cpp', + 'fpdfsdk/src/javascript/util.h', + 'fpdfsdk/include/jsapi/fxjs_v8.h', + 'fpdfsdk/src/jsapi/fxjs_v8.cpp', + ], + }], ], }, { @@ -795,13 +791,10 @@ 'dependencies': [ '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', 'pdfium', ], 'include_dirs': [ '<(DEPTH)', - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', ], 'sources': [ 'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp', @@ -813,7 +806,6 @@ 'fpdfsdk/src/fpdfview_c_api_test.c', 'fpdfsdk/src/fpdfview_c_api_test.h', 'fpdfsdk/src/fpdfview_embeddertest.cpp', - 'fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp', 'testing/embedder_test.cpp', 'testing/embedder_test.h', 'testing/embedder_test_mock_delegate.h', @@ -821,6 +813,21 @@ 'testing/fx_string_testhelpers.cpp', 'testing/fx_string_testhelpers.h', ], + 'conditions': [ + ['pdf_enable_v8==1', { + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + 'dependencies': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', + ], + 'sources': [ + 'fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp', + ], + }], + ], }, ], } diff --git a/samples/BUILD.gn b/samples/BUILD.gn index 957b1b6b91..f3bcbda418 100644 --- a/samples/BUILD.gn +++ b/samples/BUILD.gn @@ -16,8 +16,11 @@ config("pdfium_samples_config") { "PNGPREFIX_H", "PNG_USE_READ_MACROS", ] + if (pdf_enable_v8) { + defines += [ "PDF_ENABLE_V8", ] + } if (pdf_enable_xfa) { - defines += [ "PDF_ENABLE_XFA" ] + defines += [ "PDF_ENABLE_XFA", ] } } @@ -28,12 +31,16 @@ executable("pdfium_test") { ] deps = [ "//third_party/pdfium", - "//v8:v8_libplatform", - ] - include_dirs = [ - "//v8", - "//v8/include", ] + if (pdf_enable_v8) { + deps += [ + "//v8:v8_libplatform", + ] + include_dirs = [ + "//v8", + "//v8/include", + ] + } configs += [ ":pdfium_samples_config" ] } diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index a17a85390d..0525f24067 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -20,9 +20,10 @@ #include "../public/fpdf_text.h" #include "../public/fpdfview.h" #include "image_diff_png.h" +#ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" - +#endif #ifdef _WIN32 #define snprintf _snprintf @@ -81,6 +82,7 @@ static char* GetFileContents(const char* filename, size_t* retlen) { return buffer; } +#ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA // Returns the full path for an external V8 data file based on either // the currect exectuable path or an explicit override. @@ -118,6 +120,7 @@ static bool GetExternalData(const Options& options, return true; } #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 static bool CheckDimensions(int stride, int width, int height) { if (stride < 0 || width < 0 || height < 0) @@ -373,6 +376,7 @@ bool ParseCommandLine(const std::vector<std::string>& args, options->output_format = OUTPUT_BMP; } #endif // _WIN32 +#ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { if (!options->bin_directory.empty()) { @@ -382,6 +386,7 @@ bool ParseCommandLine(const std::vector<std::string>& args, options->bin_directory = cur_arg.substr(10); } #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { if (!options->scale_factor_as_string.empty()) { fprintf(stderr, "Duplicate --scale argument\n"); @@ -605,6 +610,7 @@ int main(int argc, const char* argv[]) { return 1; } +#ifdef PDF_ENABLE_V8 v8::V8::InitializeICU(); v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); @@ -620,6 +626,7 @@ int main(int argc, const char* argv[]) { v8::V8::SetNativesDataBlob(&natives); v8::V8::SetSnapshotDataBlob(&snapshot); #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 FPDF_LIBRARY_CONFIG config; config.version = 2; @@ -654,8 +661,10 @@ int main(int argc, const char* argv[]) { } FPDF_DestroyLibrary(); +#ifdef PDF_ENABLE_V8 v8::V8::ShutdownPlatform(); delete platform; +#endif // PDF_ENABLE_V8 return 0; } diff --git a/samples/samples.gyp b/samples/samples.gyp index 97497ee2d9..e39af20882 100644 --- a/samples/samples.gyp +++ b/samples/samples.gyp @@ -3,30 +3,49 @@ # found in the LICENSE file. { + 'variables': { + 'pdf_enable_v8%': 1, + }, 'target_defaults': { 'type': 'executable', 'dependencies': [ '../pdfium.gyp:pdfium', - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', ], 'include_dirs': [ '<(DEPTH)', - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', ], 'defines' : [ 'PNG_PREFIX', 'PNGPREFIX_H', 'PNG_USE_READ_MACROS', ], + 'conditions': [ + ['pdf_enable_v8==1', { + 'defines': [ + 'PDF_ENABLE_V8', + ], + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + }], + ], }, 'targets': [ { 'target_name': 'pdfium_test', + 'type': 'executable', 'sources': [ 'pdfium_test.cc', 'image_diff_png.cc', ], + 'conditions': [ + ['pdf_enable_v8==1', { + 'dependencies': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', + ], + }], + ], }, { 'target_name': 'pdfium_diff', diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 1a3c4c6e53..0aacd48df9 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -17,8 +17,11 @@ #include "../public/fpdf_text.h" #include "../public/fpdfview.h" #include "testing/gmock/include/gmock/gmock.h" + +#ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" +#endif // PDF_ENABLE_V8 #ifdef _WIN32 #define snprintf _snprintf @@ -59,6 +62,7 @@ static char* GetFileContents(const char* filename, size_t* retlen) { return buffer; } +#ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA // Returns the full path for an external V8 data file based on either // the currect exectuable path or an explicit override. @@ -91,7 +95,7 @@ static bool GetExternalData(const std::string& exe_path, return true; } #endif // V8_USE_EXTERNAL_STARTUP_DATA - +#endif // PDF_ENABLE_V8 } // namespace class TestLoader { @@ -141,6 +145,7 @@ EmbedderTest::~EmbedderTest() { } void EmbedderTest::SetUp() { +#ifdef PDF_ENABLE_V8 v8::V8::InitializeICU(); platform_ = v8::platform::CreateDefaultPlatform(); @@ -158,12 +163,13 @@ void EmbedderTest::SetUp() { v8::V8::SetNativesDataBlob(&natives_); v8::V8::SetSnapshotDataBlob(&snapshot_); #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // FPDF_ENABLE_V8 FPDF_LIBRARY_CONFIG config; config.version = 2; config.m_pUserFontPaths = nullptr; - config.m_pIsolate = external_isolate_; config.m_v8EmbedderSlot = 0; + config.m_pIsolate = external_isolate_; FPDF_InitLibraryWithConfig(&config); UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); @@ -185,8 +191,12 @@ void EmbedderTest::TearDown() { } FPDFAvail_Destroy(avail_); FPDF_DestroyLibrary(); + +#ifdef PDF_ENABLE_V8 v8::V8::ShutdownPlatform(); delete platform_; +#endif // PDF_ENABLE_V8 + delete loader_; free(file_contents_); } diff --git a/testing/embedder_test.h b/testing/embedder_test.h index f6842d23c3..fb3ea428f1 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -14,7 +14,10 @@ #include "../public/fpdfview.h" #include "../third_party/base/nonstd_unique_ptr.h" #include "testing/gtest/include/gtest/gtest.h" + +#ifdef PDF_ENABLE_V8 #include "v8/include/v8.h" +#endif // PDF_ENABLE_v8 class TestLoader; @@ -61,8 +64,12 @@ class EmbedderTest : public ::testing::Test, void SetUp() override; void TearDown() override; +#ifdef PDF_ENABLE_V8 // Call before SetUp to pass shared isolate, otherwise PDFium creates one. - void SetExternalIsolate(v8::Isolate* isolate) { external_isolate_ = isolate; } + void SetExternalIsolate(void* isolate) { + external_isolate_ = static_cast<v8::Isolate*>(isolate); + } +#endif // PDF_ENABLE_V8 void SetDelegate(Delegate* delegate) { delegate_ = delegate ? delegate : default_delegate_.get(); @@ -105,10 +112,12 @@ class EmbedderTest : public ::testing::Test, FX_DOWNLOADHINTS hints_; FPDF_FILEACCESS file_access_; FX_FILEAVAIL file_avail_; +#ifdef PDF_ENABLE_V8 v8::Platform* platform_; v8::StartupData natives_; v8::StartupData snapshot_; - v8::Isolate* external_isolate_; +#endif // PDF_ENABLE_V8 + void* external_isolate_; TestLoader* loader_; size_t file_length_; char* file_contents_; @@ -1,4 +1,7 @@ { + "variables": { + "pdf_enable_v8%": 1, + }, "target_defaults": { "defines": [ "PDF_ENABLE_XFA", @@ -663,61 +666,58 @@ "xfa/src/fxgraphics/src/fx_path_generator.cpp", "xfa/src/fxgraphics/src/fx_path_generator.h", "xfa/src/fxgraphics/src/pre.h", - "xfa/src/fxjse/src/class.cpp", - "xfa/src/fxjse/src/class.h", - "xfa/src/fxjse/src/context.cpp", - "xfa/src/fxjse/src/context.h", - "xfa/src/fxjse/src/dynprop.cpp", - "xfa/src/fxjse/src/runtime.cpp", - "xfa/src/fxjse/src/runtime.h", - "xfa/src/fxjse/src/scope_inline.h", - "xfa/src/fxjse/src/util_inline.h", - "xfa/src/fxjse/src/value.cpp", - "xfa/src/fxjse/src/value.h" ], - "conditions":[ - [ - "OS == 'win'", - { - "configurations":{ - "Debug":{ - "msvs_configuration_attributes":{ - }, - "msvs_settings":{ - "VCCLCompilerTool":{ - }, - "VCLibrarianTool":{ - }, - "VCLinkerTool":{ - } - } - }, - "Release":{ - "msvs_configuration_attributes":{ - }, - "msvs_settings":{ - "VCCLCompilerTool":{ - }, - "VCLibrarianTool":{ - }, - "VCLinkerTool":{ - } - } + "conditions": [ + ["pdf_enable_v8==1", { + 'dependencies': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + ], + 'export_dependent_settings': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', + ], + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + 'sources': [ + "xfa/src/fxjse/src/class.cpp", + "xfa/src/fxjse/src/class.h", + "xfa/src/fxjse/src/context.cpp", + "xfa/src/fxjse/src/context.h", + "xfa/src/fxjse/src/dynprop.cpp", + "xfa/src/fxjse/src/runtime.cpp", + "xfa/src/fxjse/src/runtime.h", + "xfa/src/fxjse/src/scope_inline.h", + "xfa/src/fxjse/src/util_inline.h", + "xfa/src/fxjse/src/value.cpp", + "xfa/src/fxjse/src/value.h" + ], + }], + ["OS == 'win'", { + "configurations": { + "Debug": { + "msvs_configuration_attributes": {}, + "msvs_settings": { + "VCCLCompilerTool": {}, + "VCLibrarianTool": {}, + "VCLinkerTool": {}, } }, - "sources":[ - ] - } - ], - [ - "OS == 'mac'", - { - "configurations":{ + "Release": { + "msvs_configuration_attributes": {}, + "msvs_settings": { + "VCCLCompilerTool": {}, + "VCLibrarianTool": {}, + "VCLinkerTool": {}, + } + } }, - "sources":[ - ] - } - ] + "sources": [], + }], + ["OS == 'mac'", { + "configurations": {}, + "sources": [], + }], ] } ] |