From f1c713663192368d26031a4caed1f9705f4510af Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 9 Oct 2015 12:45:15 -0700 Subject: Allow compiling PDFium without V8. Original patch from issue 1391843004 at patchset 1 (http://crrev.com/1391843004#ps1) Introduce a pdf_enable_v8 GYP variable, which controls a corresponding PDF_ENABLE_V8 #define, and bring in the real JS library when set. Otherwise, link against a stub JS runtime. BUG=pdfium:211 R=dml@google.com, jochen@chromium.org, thestig@chromium.org Review URL: https://codereview.chromium.org/1395733006 . --- BUILD.gn | 155 +++++++++++++--------------- fpdfsdk/include/javascript/IJavaScript.h | 1 + fpdfsdk/src/fpdfview.cpp | 8 +- fpdfsdk/src/javascript/JS_Runtime.cpp | 5 +- fpdfsdk/src/javascript/JS_Runtime_Stub.cpp | 151 +++++++++++++++++++++++++++ pdfium.gni | 17 ++++ pdfium.gyp | 158 +++++++++++++++-------------- samples/BUILD.gn | 21 +++- samples/pdfium_test.cc | 10 ++ samples/samples.gyp | 24 ++++- testing/embedder_test.cpp | 14 ++- testing/embedder_test.h | 13 ++- 12 files changed, 400 insertions(+), 177 deletions(-) create mode 100644 fpdfsdk/src/javascript/JS_Runtime_Stub.cpp create mode 100644 pdfium.gni diff --git a/BUILD.gn b/BUILD.gn index f048f9db3c..8ae5a085f0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3,14 +3,7 @@ # found in the LICENSE file. import("//testing/test.gni") - -pdf_use_skia = false - -declare_args() { - # On Android there's no system FreeType. On Windows and Mac, only a few - # methods are used from it. - pdfium_bundle_freetype = !is_linux -} +import("pdfium.gni") config("pdfium_config") { cflags = [] @@ -25,6 +18,10 @@ config("pdfium_config") { defines += [ "_SKIA_SUPPORT_" ] } + if (pdf_enable_v8) { + defines += [ "PDF_ENABLE_V8" ] + } + if (is_linux) { if (current_cpu == "x64") { defines += [ "_FX_CPU_=_FX_X64_" ] @@ -111,7 +108,6 @@ static_library("pdfium") { ":fxedit", ":fxge", ":javascript", - ":jsapi", ":pdfwindow", ] @@ -632,81 +628,66 @@ 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", - ] } static_library("formfiller") { @@ -778,7 +759,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", @@ -789,15 +769,24 @@ test("pdfium_embeddertests") { deps = [ "//testing/gmock", "//testing/gtest", - "//v8", - "//v8:v8_libplatform", ":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", diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h index a527d19544..bf90210794 100644 --- a/fpdfsdk/include/javascript/IJavaScript.h +++ b/fpdfsdk/include/javascript/IJavaScript.h @@ -133,6 +133,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 0bf6426b66..b050e033cd 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -14,7 +14,7 @@ #include "../include/fsdk_define.h" #include "../include/fsdk_mgr.h" #include "../include/fsdk_rendercontext.h" -#include "../include/jsapi/fxjs_v8.h" +#include "../include/javascript/IJavaScript.h" CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { if (pFileAccess) @@ -110,10 +110,8 @@ DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig( pModuleMgr->LoadEmbeddedCNS1CMaps(); pModuleMgr->LoadEmbeddedKorea1CMaps(); } - if (cfg && cfg->version >= 2) { - FXJS_Initialize(cfg->m_v8EmbedderSlot, - reinterpret_cast(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/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index 83e2c9af2a..069edc5cd6 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -27,7 +27,10 @@ #include "report.h" #include "util.h" -/* ------------------------------ CJS_Runtime ------------------------------ */ +// static +void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { + FXJS_Initialize(slot, reinterpret_cast(isolate)); +} // static IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* 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..2c5e625fdc --- /dev/null +++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp @@ -0,0 +1,151 @@ +// 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; } + + protected: + CPDFSDK_Document* m_pDoc; + nonstd::unique_ptr 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 new file mode 100644 index 0000000000..d70131dd60 --- /dev/null +++ b/pdfium.gni @@ -0,0 +1,17 @@ +# 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. + +# This file contains PDFium-related build flags. + +declare_args() { + # On Android there's no system FreeType. On Windows and Mac, only a few + # methods are used from it. + pdfium_bundle_freetype = !is_linux + + # Build PDFium either with or without v8 support. + pdf_enable_v8 = true + + # Build PDFium against skia (experimental) rather than agg. + pdf_use_skia = false +} diff --git a/pdfium.gyp b/pdfium.gyp index a728cea89e..6ea3f4ab07 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -1,6 +1,7 @@ { 'variables': { 'pdf_use_skia%': 0, + 'pdf_enable_v8%': 1, 'conditions': [ ['OS=="linux"', { 'bundle_freetype%': 0, @@ -23,6 +24,9 @@ ['pdf_use_skia==1', { 'defines': ['_SKIA_SUPPORT_'], }], + ['pdf_enable_v8==1', { + 'defines': ['PDF_ENABLE_V8'], + }], ['OS=="linux"', { 'conditions': [ ['target_arch=="x64"', { @@ -56,7 +60,6 @@ 'fxedit', 'fxge', 'javascript', - 'jsapi', 'pdfwindow', ], 'ldflags': [ '-L<(PRODUCT_DIR)',], @@ -612,80 +615,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', + ], + }], ], }, { @@ -747,14 +743,10 @@ 'dependencies': [ '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8', - '<(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', @@ -766,7 +758,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', @@ -774,6 +765,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 6f4518c17e..5749de90f1 100644 --- a/samples/BUILD.gn +++ b/samples/BUILD.gn @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("../pdfium.gni") + group("samples") { deps = [ ":pdfium_test", @@ -15,6 +17,11 @@ config("pdfium_samples_config") { "PNGPREFIX_H", "PNG_USE_READ_MACROS", ] + if (pdf_enable_v8) { + defines += [ + "PDF_ENABLE_V8", + ] + } } executable("pdfium_test") { @@ -28,13 +35,17 @@ executable("pdfium_test") { # always link this binary against the bundled one for consistency # of results across platforms. "//third_party/pdfium/third_party:fx_freetype", - "//v8:v8_libplatform", ":fx_lpng", ] - 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 74e797b944..f15e19c75b 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -19,8 +19,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 @@ -79,6 +81,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. @@ -116,6 +119,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 +377,7 @@ bool ParseCommandLine(const std::vector& 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 +387,7 @@ bool ParseCommandLine(const std::vector& 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"); @@ -595,6 +601,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); @@ -615,6 +622,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; @@ -649,8 +657,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 4b6c16bf2e..496a274da7 100644 --- a/samples/samples.gyp +++ b/samples/samples.gyp @@ -3,6 +3,9 @@ # found in the LICENSE file. { + 'variables': { + 'pdf_enable_v8%': 1, + }, 'target_defaults': { 'defines' : [ 'PNG_PREFIX', @@ -11,8 +14,17 @@ ], 'include_dirs': [ '<(DEPTH)', - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', + ], + 'conditions': [ + ['pdf_enable_v8==1', { + 'defines': [ + 'PDF_ENABLE_V8', + ], + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + }], ], }, 'targets': [ @@ -26,7 +38,6 @@ # always link this binary against the bundled one for consistency # of results across platforms. '../third_party/third_party.gyp:fx_freetype', - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', ], 'sources': [ 'pdfium_test.cc', @@ -37,6 +48,13 @@ '-lfreetype', ], }, + '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 d17df9a458..9d99084050 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(this); @@ -181,8 +187,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(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_; -- cgit v1.2.3