Allow compiling PDFium without V8.
authorTom Sepez <tsepez@chromium.org>
Fri, 9 Oct 2015 19:45:15 +0000 (12:45 -0700)
committerTom Sepez <tsepez@chromium.org>
Fri, 9 Oct 2015 19:45:15 +0000 (12:45 -0700)
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 .

12 files changed:
BUILD.gn
fpdfsdk/include/javascript/IJavaScript.h
fpdfsdk/src/fpdfview.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/javascript/JS_Runtime_Stub.cpp [new file with mode: 0644]
pdfium.gni [new file with mode: 0644]
pdfium.gyp
samples/BUILD.gn
samples/pdfium_test.cc
samples/samples.gyp
testing/embedder_test.cpp
testing/embedder_test.h

index f048f9d..8ae5a08 100644 (file)
--- 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",
index a527d19..bf90210 100644 (file)
@@ -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() {}
 
index 0bf6426..b050e03 100644 (file)
@@ -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<v8::Isolate*>(cfg->m_pIsolate));
-  }
+  if (cfg && cfg->version >= 2)
+    IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
 }
 
 DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
index 83e2c9a..069edc5 100644 (file)
 #include "report.h"
 #include "util.h"
 
-/* ------------------------------ CJS_Runtime ------------------------------ */
+// 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) {
diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
new file mode 100644 (file)
index 0000000..2c5e625
--- /dev/null
@@ -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<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
new file mode 100644 (file)
index 0000000..d70131d
--- /dev/null
@@ -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
+}
index a728cea..6ea3f4a 100644 (file)
@@ -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)',],
     {
       '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',
+          ],
+        }],
       ],
     },
     {
       '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',
         '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',
         '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',
+          ],
+        }],
+      ],
     },
   ],
 }
index 6f4518c..5749de9 100644 (file)
@@ -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" ]
 }
 
index 74e797b..f15e19c 100644 (file)
 #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<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 +387,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");
@@ -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;
 }
index 4b6c16b..496a274 100644 (file)
@@ -3,6 +3,9 @@
 # found in the LICENSE file.
 
 {
+  'variables': {
+    'pdf_enable_v8%': 1,
+  },
   'target_defaults': {
     'defines' : [
       'PNG_PREFIX',
     ],
     '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',
           '-lfreetype',
         ],
       },
+      'conditions': [
+        ['pdf_enable_v8==1', {
+          'dependencies': [
+            '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform',
+          ],
+        }],
+      ],
     },
     {
       'target_name': 'pdfium_diff',
index d17df9a..9d99084 100644 (file)
 #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);
@@ -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_);
 }
index f6842d2..fb3ea42 100644 (file)
 #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_;