Move fpdfsdk/jsapi into fxjs/

This CL moves the fpdfsdk/sjapi code info fxjs/. The "fxjs" library is moved
from being XFA specific to being compiled if V8 is enabled.

The fxjs_v8 files are required when building for XFA (they have XFA defines
in them) and are used in CFXJS_RuntimeData. The cfxjse_* files are only added
if XFA is also enabled.

Review-Url: https://codereview.chromium.org/2144603003
diff --git a/BUILD.gn b/BUILD.gn
index 96df81c..706ea90 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -828,15 +828,9 @@
       "fpdfsdk/javascript/resource.h",
       "fpdfsdk/javascript/util.cpp",
       "fpdfsdk/javascript/util.h",
-      "fpdfsdk/jsapi/fxjs_v8.cpp",
-      "fpdfsdk/jsapi/include/fxjs_v8.h",
     ]
-    include_dirs = [
-      "//v8",
-      "//v8/include",
-    ]
-    public_deps = [
-      "//v8",
+    deps = [
+      ":fxjs",
     ]
     configs += [ "//v8:external_startup_data" ]
   } else {
@@ -869,25 +863,32 @@
   configs += [ ":pdfium_core_config" ]
 }
 
-if (pdf_enable_xfa) {
+if (pdf_enable_v8) {
   static_library("fxjs") {
     sources = [
-      "fxjs/cfxjse_arguments.cpp",
-      "fxjs/cfxjse_class.cpp",
-      "fxjs/cfxjse_context.cpp",
-      "fxjs/cfxjse_isolatetracker.cpp",
-      "fxjs/cfxjse_isolatetracker.h",
-      "fxjs/cfxjse_runtimedata.cpp",
-      "fxjs/cfxjse_runtimedata.h",
-      "fxjs/cfxjse_value.cpp",
-      "fxjs/include/cfxjse_arguments.h",
-      "fxjs/include/cfxjse_class.h",
-      "fxjs/include/cfxjse_context.h",
-      "fxjs/include/cfxjse_value.h",
-      "fxjs/include/fxjse.h",
+      "fxjs/fxjs_v8.cpp",
+      "fxjs/include/fxjs_v8.h",
     ]
+    if (pdf_enable_xfa) {
+      sources += [
+        "fxjs/cfxjse_arguments.cpp",
+        "fxjs/cfxjse_class.cpp",
+        "fxjs/cfxjse_context.cpp",
+        "fxjs/cfxjse_isolatetracker.cpp",
+        "fxjs/cfxjse_isolatetracker.h",
+        "fxjs/cfxjse_runtimedata.cpp",
+        "fxjs/cfxjse_runtimedata.h",
+        "fxjs/cfxjse_value.cpp",
+        "fxjs/include/cfxjse_arguments.h",
+        "fxjs/include/cfxjse_class.h",
+        "fxjs/include/cfxjse_context.h",
+        "fxjs/include/cfxjse_value.h",
+        "fxjs/include/fxjse.h",
+      ]
+    }
     deps = [
-        "//v8:v8_libplatform",
+      "//v8",
+      "//v8:v8_libplatform",
     ]
     configs += [ ":pdfium_core_config" ]
     include_dirs = [
@@ -898,7 +899,9 @@
       "//v8",
     ]
   }
+}
 
+if (pdf_enable_xfa) {
   static_library("fpdfxfa") {
     sources = [
       "fpdfsdk/fpdfxfa/fpdfxfa_app.cpp",
@@ -1456,9 +1459,7 @@
       "xfa/fxgraphics/cfx_shading.h",
       "xfa/fxgraphics/include/cfx_graphics.h",
     ]
-    include_dirs = [
-      ".",
-    ]
+    include_dirs = [ "." ]
     deps = [
       ":fxjs",
     ]
@@ -1565,18 +1566,11 @@
   if (pdf_enable_v8) {
     sources += [
       "fpdfsdk/javascript/public_methods_embeddertest.cpp",
-      "fpdfsdk/jsapi/fxjs_v8_embeddertest.cpp",
+      "fxjs/fxjs_v8_embeddertest.cpp",
       "testing/js_embedder_test.cpp",
       "testing/js_embedder_test.h",
     ]
-    deps += [
-      "//v8",
-      "//v8:v8_libplatform",
-    ]
-    include_dirs += [
-      "//v8",
-      "//v8/include",
-    ]
+    deps += [ ":fxjs" ]
     configs += [ "//v8:external_startup_data" ]
   }
   configs += [ ":pdfium_core_config" ]
diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h
index 2c00818..ffef626 100644
--- a/fpdfsdk/javascript/JS_Define.h
+++ b/fpdfsdk/javascript/JS_Define.h
@@ -12,7 +12,7 @@
 #include "fpdfsdk/javascript/JS_Object.h"
 #include "fpdfsdk/javascript/JS_Value.h"
 #include "fpdfsdk/javascript/resource.h"
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 
 struct JSConstSpec {
   const wchar_t* pName;
diff --git a/fpdfsdk/javascript/JS_Object.h b/fpdfsdk/javascript/JS_Object.h
index 908645c..7105ec6 100644
--- a/fpdfsdk/javascript/JS_Object.h
+++ b/fpdfsdk/javascript/JS_Object.h
@@ -12,7 +12,7 @@
 
 #include "fpdfsdk/include/fsdk_define.h"
 #include "fpdfsdk/javascript/cjs_runtime.h"
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 
 class CJS_Context;
 class CJS_Object;
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 958c5e0..e854450 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -10,7 +10,7 @@
 #include <vector>
 
 #include "core/fxcrt/include/fx_basic.h"
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 
 class CJS_Array;
 class CJS_Date;
diff --git a/fpdfsdk/javascript/cjs_runtime.h b/fpdfsdk/javascript/cjs_runtime.h
index 2668367..c43a34b 100644
--- a/fpdfsdk/javascript/cjs_runtime.h
+++ b/fpdfsdk/javascript/cjs_runtime.h
@@ -16,7 +16,7 @@
 #include "core/fxcrt/include/fx_basic.h"
 #include "fpdfsdk/javascript/JS_EventHandler.h"
 #include "fpdfsdk/javascript/ijs_runtime.h"
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 
 class CJS_Context;
 
diff --git a/fxjs/DEPS b/fxjs/DEPS
index 18698e4..ccea0b5 100644
--- a/fxjs/DEPS
+++ b/fxjs/DEPS
@@ -1,6 +1,4 @@
 include_rules = [
   '+core/fxcrt/include',
-  # TODO(dsinclair): Layering violation. FXJSE can't include FPDFSDK.
-  '+fpdfsdk/jsapi/include',
   '+v8/include',
 ]
diff --git a/fxjs/cfxjse_runtimedata.cpp b/fxjs/cfxjse_runtimedata.cpp
index f58f5f8..b203cb7 100644
--- a/fxjs/cfxjse_runtimedata.cpp
+++ b/fxjs/cfxjse_runtimedata.cpp
@@ -6,8 +6,8 @@
 
 #include "fxjs/cfxjse_runtimedata.h"
 
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
 #include "fxjs/cfxjse_isolatetracker.h"
+#include "fxjs/include/fxjs_v8.h"
 
 namespace {
 
diff --git a/fpdfsdk/jsapi/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
similarity index 98%
rename from fpdfsdk/jsapi/fxjs_v8.cpp
rename to fxjs/fxjs_v8.cpp
index ddeb28f..c98de07 100644
--- a/fpdfsdk/jsapi/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 
 #include <vector>
 
@@ -514,8 +514,8 @@
     pObjDef->m_pConstructor(pIRuntime, obj);
 
   if (!bStatic && FXJS_PerIsolateData::Get(pIsolate)->m_pDynamicObjsMap) {
-    FXJS_PerIsolateData::Get(pIsolate)
-        ->m_pDynamicObjsMap->set(pPerObjData, obj);
+    FXJS_PerIsolateData::Get(pIsolate)->m_pDynamicObjsMap->set(pPerObjData,
+                                                               obj);
   }
   return obj;
 }
diff --git a/fpdfsdk/jsapi/fxjs_v8_embeddertest.cpp b/fxjs/fxjs_v8_embeddertest.cpp
similarity index 100%
rename from fpdfsdk/jsapi/fxjs_v8_embeddertest.cpp
rename to fxjs/fxjs_v8_embeddertest.cpp
diff --git a/fpdfsdk/jsapi/include/fxjs_v8.h b/fxjs/include/fxjs_v8.h
similarity index 98%
rename from fpdfsdk/jsapi/include/fxjs_v8.h
rename to fxjs/include/fxjs_v8.h
index 3ae1d5e..465feef 100644
--- a/fpdfsdk/jsapi/include/fxjs_v8.h
+++ b/fxjs/include/fxjs_v8.h
@@ -11,8 +11,8 @@
 // PDFium code should include this file rather than including V8 headers
 // directly.
 
-#ifndef FPDFSDK_JSAPI_INCLUDE_FXJS_V8_H_
-#define FPDFSDK_JSAPI_INCLUDE_FXJS_V8_H_
+#ifndef FXJS_INCLUDE_FXJS_V8_H_
+#define FXJS_INCLUDE_FXJS_V8_H_
 
 #include <v8-util.h>
 #include <v8.h>
@@ -287,4 +287,4 @@
                                   v8::Local<v8::Value> pValue);
 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
 
-#endif  // FPDFSDK_JSAPI_INCLUDE_FXJS_V8_H_
+#endif  // FXJS_INCLUDE_FXJS_V8_H_
diff --git a/pdfium.gyp b/pdfium.gyp
index 76a22a9..79ff088 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -779,15 +779,8 @@
       ],
       'conditions': [
         ['pdf_enable_v8==1', {
-          'include_dirs': [
-            '<(DEPTH)/v8',
-            '<(DEPTH)/v8/include',
-          ],
           'dependencies': [
-            '<(DEPTH)/v8/src/v8.gyp:v8',
-          ],
-          'export_dependent_settings': [
-            '<(DEPTH)/v8/src/v8.gyp:v8',
+            ':fxjs'
           ],
           'sources!': [
             'fpdfsdk/javascript/JS_Runtime_Stub.cpp',
@@ -835,8 +828,6 @@
             'fpdfsdk/javascript/resource.h',
             'fpdfsdk/javascript/util.cpp',
             'fpdfsdk/javascript/util.h',
-            'fpdfsdk/jsapi/include/fxjs_v8.h',
-            'fpdfsdk/jsapi/fxjs_v8.cpp',
           ],
         }],
       ],
@@ -977,7 +968,7 @@
           ],
           'sources': [
             'fpdfsdk/javascript/public_methods_embeddertest.cpp',
-            'fpdfsdk/jsapi/fxjs_v8_embeddertest.cpp',
+            'fxjs/fxjs_v8_embeddertest.cpp',
             'testing/js_embedder_test.cpp',
             'testing/js_embedder_test.h',
           ],
@@ -1013,12 +1004,57 @@
     },
   ],
   'conditions': [
+    ['pdf_enable_v8==1', {
+      'targets': [
+        {
+          "target_name": "fxjs",
+          "type": "static_library",
+          'include_dirs': [
+            # This is implicit in GN.
+            '<(DEPTH)',
+            '.',
+            '<(DEPTH)/v8',
+            '<(DEPTH)/v8/include',
+          ],
+          'dependencies': [
+            '<(DEPTH)/v8/src/v8.gyp:v8',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/v8/src/v8.gyp:v8',
+          ],
+          "sources": [
+            "fxjs/fxjs_v8.cpp",
+            "fxjs/include/fxjs_v8.h",
+          ],
+          "conditions": [
+            ['pdf_enable_xfa==1', {
+              'sources': [
+                "fxjs/cfxjse_arguments.cpp",
+                "fxjs/cfxjse_class.cpp",
+                "fxjs/cfxjse_context.cpp",
+                "fxjs/cfxjse_isolatetracker.cpp",
+                "fxjs/cfxjse_isolatetracker.h",
+                "fxjs/cfxjse_runtimedata.cpp",
+                "fxjs/cfxjse_runtimedata.h",
+                "fxjs/cfxjse_value.cpp",
+                "fxjs/include/cfxjse_arguments.h",
+                "fxjs/include/cfxjse_class.h",
+                "fxjs/include/cfxjse_context.h",
+                "fxjs/include/cfxjse_value.h",
+                "fxjs/include/fxjse.h",
+              ]
+            }],
+          ],
+        },
+      ]
+    }],
     ['pdf_enable_xfa==1', {
       'targets': [
         {
           'target_name': 'fpdfxfa',
           'type': 'static_library',
           'dependencies': [
+            'fxjs',
             'javascript',
             'xfa.gyp:xfa',
           ],
diff --git a/testing/DEPS b/testing/DEPS
index 44e0646..babefb8 100644
--- a/testing/DEPS
+++ b/testing/DEPS
@@ -3,7 +3,7 @@
   '+core/fxcodec',
   '+core/fxcrt/include',
   '+core/fxge/include',
-  '+fpdfsdk/jsapi/include',
+  '+fxjs/include',
   '+public',
   '+v8',
   '+xfa/fde',
diff --git a/testing/js_embedder_test.h b/testing/js_embedder_test.h
index 5583e7e..b2bd5a8 100644
--- a/testing/js_embedder_test.h
+++ b/testing/js_embedder_test.h
@@ -8,7 +8,7 @@
 #include <memory>
 #include <vector>
 
-#include "fpdfsdk/jsapi/include/fxjs_v8.h"
+#include "fxjs/include/fxjs_v8.h"
 #include "testing/embedder_test.h"
 
 class JSEmbedderTest : public EmbedderTest {
diff --git a/xfa.gyp b/xfa.gyp
index d8c165e..e21f905 100644
--- a/xfa.gyp
+++ b/xfa.gyp
@@ -16,38 +16,6 @@
   },
   "targets":[
     {
-      "target_name": "fxjs",
-      "type": "static_library",
-      'include_dirs': [
-        # This is implicit in GN.
-        '<(DEPTH)',
-        '.',
-        '<(DEPTH)/v8',
-        '<(DEPTH)/v8/include',
-      ],
-      'dependencies': [
-        '<(DEPTH)/v8/src/v8.gyp:v8',
-      ],
-      'export_dependent_settings': [
-        '<(DEPTH)/v8/src/v8.gyp:v8',
-      ],
-      "sources": [
-        "fxjs/cfxjse_arguments.cpp",
-        "fxjs/cfxjse_class.cpp",
-        "fxjs/cfxjse_context.cpp",
-        "fxjs/cfxjse_isolatetracker.cpp",
-        "fxjs/cfxjse_isolatetracker.h",
-        "fxjs/cfxjse_runtimedata.cpp",
-        "fxjs/cfxjse_runtimedata.h",
-        "fxjs/cfxjse_value.cpp",
-        "fxjs/include/cfxjse_arguments.h",
-        "fxjs/include/cfxjse_class.h",
-        "fxjs/include/cfxjse_context.h",
-        "fxjs/include/cfxjse_value.h",
-        "fxjs/include/fxjse.h",
-      ]
-    },
-    {
       "target_name":"xfa",
       "type":"static_library",
       'include_dirs': [
@@ -60,9 +28,6 @@
       'defines' : [
         'FT2_BUILD_LIBRARY',
       ],
-      'dependencies': [
-        ':fxjs',
-      ],
       "sources":[
         "xfa/fde/cfde_path.cpp",
         "xfa/fde/cfde_path.h",