summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbaixo <baixo@chromium.org>2014-11-14 08:34:30 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-14 16:34:55 +0000
commit5c1aafbd7729d2d1fd1bea34e865cd83080ddd8c (patch)
tree4fc145a0f67bc95f1803fc23f5f8666b406cde28
parentca3743ab392e96a9499392f4b310e28d8e665526 (diff)
downloadchromium_src-5c1aafbd7729d2d1fd1bea34e865cd83080ddd8c.zip
chromium_src-5c1aafbd7729d2d1fd1bea34e865cd83080ddd8c.tar.gz
chromium_src-5c1aafbd7729d2d1fd1bea34e865cd83080ddd8c.tar.bz2
Initialize V8 in PDFium from external files (plugin process only)
BUG=421063 Review URL: https://codereview.chromium.org/718453003 Cr-Commit-Position: refs/heads/master@{#304223}
-rw-r--r--chrome/chrome_plugin.gypi1
-rw-r--r--chrome/plugin/BUILD.gn1
-rw-r--r--chrome/plugin/DEPS1
-rw-r--r--chrome/plugin/chrome_content_plugin_client.cc8
-rw-r--r--components/pdf/renderer/ppb_pdf_impl.cc3
-rw-r--r--pdf/instance.cc2
-rw-r--r--pdf/out_of_process_instance.cc12
-rw-r--r--ppapi/BUILD.gn1
-rw-r--r--ppapi/c/private/ppb_pdf.h3
-rw-r--r--ppapi/cpp/private/pdf.cc8
-rw-r--r--ppapi/cpp/private/pdf.h3
-rw-r--r--ppapi/ppapi_internal.gyp2
-rw-r--r--ppapi/ppapi_tests.gypi1
-rw-r--r--ppapi/proxy/DEPS1
-rw-r--r--ppapi/proxy/pdf_resource.cc9
-rw-r--r--ppapi/proxy/pdf_resource.h4
-rw-r--r--ppapi/tests/DEPS1
-rw-r--r--ppapi/tests/test_pdf.cc30
-rw-r--r--ppapi/tests/test_pdf.h1
-rw-r--r--ppapi/thunk/ppb_pdf_api.h4
-rw-r--r--ppapi/thunk/ppb_pdf_thunk.cc13
21 files changed, 102 insertions, 7 deletions
diff --git a/chrome/chrome_plugin.gypi b/chrome/chrome_plugin.gypi
index 3300540..718666c 100644
--- a/chrome/chrome_plugin.gypi
+++ b/chrome/chrome_plugin.gypi
@@ -11,6 +11,7 @@
'dependencies': [
'../base/base.gyp:base',
'../content/content.gyp:content_plugin',
+ '../gin/gin.gyp:gin',
'chrome_resources.gyp:chrome_strings',
],
'include_dirs': [
diff --git a/chrome/plugin/BUILD.gn b/chrome/plugin/BUILD.gn
index 76e4109..1da688a 100644
--- a/chrome/plugin/BUILD.gn
+++ b/chrome/plugin/BUILD.gn
@@ -14,5 +14,6 @@ static_library("plugin") {
"//base",
"//chrome:strings",
"//content/public/plugin",
+ "//gin",
]
}
diff --git a/chrome/plugin/DEPS b/chrome/plugin/DEPS
index 0d9fb3e..eca72a4 100644
--- a/chrome/plugin/DEPS
+++ b/chrome/plugin/DEPS
@@ -1,4 +1,5 @@
include_rules = [
"+content/public/plugin",
+ "+gin/public/isolate_holder.h",
"+media/base",
]
diff --git a/chrome/plugin/chrome_content_plugin_client.cc b/chrome/plugin/chrome_content_plugin_client.cc
index 1abe0a3..87c20d0 100644
--- a/chrome/plugin/chrome_content_plugin_client.cc
+++ b/chrome/plugin/chrome_content_plugin_client.cc
@@ -17,9 +17,17 @@
#endif
#endif
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+#include "gin/public/isolate_holder.h"
+#endif
+
namespace chrome {
void ChromeContentPluginClient::PreSandboxInitialization() {
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ gin::IsolateHolder::LoadV8Snapshot();
+#endif
+
#if defined(ENABLE_REMOTING)
// Load crypto libraries for the Chromoting client plugin.
diff --git a/components/pdf/renderer/ppb_pdf_impl.cc b/components/pdf/renderer/ppb_pdf_impl.cc
index 85be05e..aa0a33a 100644
--- a/components/pdf/renderer/ppb_pdf_impl.cc
+++ b/components/pdf/renderer/ppb_pdf_impl.cc
@@ -330,7 +330,8 @@ void SetLinkUnderCursor(PP_Instance instance_id, const char* url) {
instance->SetLinkUnderCursor(url);
}
-void GetV8ExternalSnapshotData(const char** natives_data_out,
+void GetV8ExternalSnapshotData(PP_Instance instance_id,
+ const char** natives_data_out,
int* natives_size_out,
const char** snapshot_data_out,
int* snapshot_size_out) {
diff --git a/pdf/instance.cc b/pdf/instance.cc
index 2ffc7d4..fb8484f 100644
--- a/pdf/instance.cc
+++ b/pdf/instance.cc
@@ -322,7 +322,7 @@ Instance::~Instance() {
bool Instance::Init(uint32_t argc, const char* argn[], const char* argv[]) {
v8::StartupData natives;
v8::StartupData snapshot;
- pp::PDF::GetV8ExternalSnapshotData(&natives.data, &natives.raw_size,
+ pp::PDF::GetV8ExternalSnapshotData(this, &natives.data, &natives.raw_size,
&snapshot.data, &snapshot.raw_size);
if (natives.data) {
natives.compressed_size = natives.raw_size;
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index bfbcb93..92ef550 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -40,6 +40,7 @@
#include "ppapi/cpp/var_array.h"
#include "ppapi/cpp/var_dictionary.h"
#include "ui/events/keycodes/keyboard_codes.h"
+#include "v8/include/v8.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
@@ -266,6 +267,17 @@ OutOfProcessInstance::~OutOfProcessInstance() {
bool OutOfProcessInstance::Init(uint32_t argc,
const char* argn[],
const char* argv[]) {
+ v8::StartupData natives;
+ v8::StartupData snapshot;
+ pp::PDF::GetV8ExternalSnapshotData(this, &natives.data, &natives.raw_size,
+ &snapshot.data, &snapshot.raw_size);
+ if (natives.data) {
+ natives.compressed_size = natives.raw_size;
+ snapshot.compressed_size = snapshot.raw_size;
+ v8::V8::SetNativesDataBlob(&natives);
+ v8::V8::SetSnapshotDataBlob(&snapshot);
+ }
+
// Check if the PDF is being loaded in the PDF chrome extension. We only allow
// the plugin to be put into "full frame" mode when it is being loaded in the
// extension because this enables some features that we don't want pages
diff --git a/ppapi/BUILD.gn b/ppapi/BUILD.gn
index 82085d3..9107ee7 100644
--- a/ppapi/BUILD.gn
+++ b/ppapi/BUILD.gn
@@ -738,6 +738,7 @@ component("ppapi_proxy") {
":ppapi_ipc",
"//base",
"//base/third_party/dynamic_annotations",
+ "//gin",
"//gpu/command_buffer/client:gles2_implementation",
"//gpu/ipc",
"//media:shared_memory_support",
diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h
index 318c21d..3e708dd 100644
--- a/ppapi/c/private/ppb_pdf.h
+++ b/ppapi/c/private/ppb_pdf.h
@@ -172,7 +172,8 @@ struct PPB_PDF {
// Gets pointers to both the mmap'd V8 snapshot files and their sizes.
// This is needed when loading V8's initial snapshot from external files.
- void (*GetV8ExternalSnapshotData)(const char** natives_data_out,
+ void (*GetV8ExternalSnapshotData)(PP_Instance instance,
+ const char** natives_data_out,
int* natives_size_out,
const char** snapshot_data_out,
int* snapshot_size_out);
diff --git a/ppapi/cpp/private/pdf.cc b/ppapi/cpp/private/pdf.cc
index 52df60c..17b0b4d 100644
--- a/ppapi/cpp/private/pdf.cc
+++ b/ppapi/cpp/private/pdf.cc
@@ -198,13 +198,15 @@ void PDF::SetLinkUnderCursor(const InstanceHandle& instance, const char* url) {
}
// static
-void PDF::GetV8ExternalSnapshotData(const char** natives_data_out,
+void PDF::GetV8ExternalSnapshotData(const InstanceHandle& instance,
+ const char** natives_data_out,
int* natives_size_out,
const char** snapshot_data_out,
int* snapshot_size_out) {
if (has_interface<PPB_PDF>()) {
- get_interface<PPB_PDF>()->GetV8ExternalSnapshotData(natives_data_out,
- natives_size_out, snapshot_data_out, snapshot_size_out);
+ get_interface<PPB_PDF>()->GetV8ExternalSnapshotData(instance.pp_instance(),
+ natives_data_out, natives_size_out, snapshot_data_out,
+ snapshot_size_out);
return;
}
*natives_data_out = NULL;
diff --git a/ppapi/cpp/private/pdf.h b/ppapi/cpp/private/pdf.h
index 09db41b..160c826 100644
--- a/ppapi/cpp/private/pdf.h
+++ b/ppapi/cpp/private/pdf.h
@@ -63,7 +63,8 @@ class PDF {
const char* selected_text);
static void SetLinkUnderCursor(const InstanceHandle& instance,
const char* url);
- static void GetV8ExternalSnapshotData(const char** natives_data_out,
+ static void GetV8ExternalSnapshotData(const InstanceHandle& instance,
+ const char** natives_data_out,
int* natives_size_out,
const char** snapshot_data_out,
int* snapshot_size_out);
diff --git a/ppapi/ppapi_internal.gyp b/ppapi/ppapi_internal.gyp
index 2240ba2..d96770e 100644
--- a/ppapi/ppapi_internal.gyp
+++ b/ppapi/ppapi_internal.gyp
@@ -125,6 +125,7 @@
'dependencies': [
'../base/base.gyp:base',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
+ '../gin/gin.gyp:gin',
'../gpu/gpu.gyp:gles2_implementation',
'../gpu/gpu.gyp:gpu_ipc',
'../media/media.gyp:shared_memory_support',
@@ -175,6 +176,7 @@
'dependencies': [
'../base/base.gyp:base',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
+ '../gin/gin.gyp:gin',
'../gpu/gpu.gyp:gles2_implementation',
'../gpu/gpu.gyp:gpu_ipc',
'../media/media.gyp:shared_memory_support',
diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi
index d7bf047..9393ff3 100644
--- a/ppapi/ppapi_tests.gypi
+++ b/ppapi/ppapi_tests.gypi
@@ -18,6 +18,7 @@
'<@(test_trusted_source_files)',
],
'dependencies': [
+ '../gin/gin.gyp:gin',
'ppapi.gyp:ppapi_cpp',
'ppapi_internal.gyp:ppapi_shared',
],
diff --git a/ppapi/proxy/DEPS b/ppapi/proxy/DEPS
index 6183b60..c1fd8e2 100644
--- a/ppapi/proxy/DEPS
+++ b/ppapi/proxy/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+base",
+ "+gin",
"+gpu",
"+ipc",
"+media/audio",
diff --git a/ppapi/proxy/pdf_resource.cc b/ppapi/proxy/pdf_resource.cc
index 1398866..50370cf 100644
--- a/ppapi/proxy/pdf_resource.cc
+++ b/ppapi/proxy/pdf_resource.cc
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
+#include "gin/public/isolate_holder.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -204,5 +205,13 @@ void PDFResource::SetLinkUnderCursor(const char* url) {
Post(RENDERER, PpapiHostMsg_PDF_SetLinkUnderCursor(url));
}
+void PDFResource::GetV8ExternalSnapshotData(const char** natives_data_out,
+ int* natives_size_out,
+ const char** snapshot_data_out,
+ int* snapshot_size_out) {
+ gin::IsolateHolder::GetV8ExternalSnapshotData(natives_data_out,
+ natives_size_out, snapshot_data_out, snapshot_size_out);
+}
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/pdf_resource.h b/ppapi/proxy/pdf_resource.h
index c15d738..9ca82c6 100644
--- a/ppapi/proxy/pdf_resource.h
+++ b/ppapi/proxy/pdf_resource.h
@@ -57,6 +57,10 @@ class PPAPI_PROXY_EXPORT PDFResource
virtual PP_Bool IsOutOfProcess() override;
virtual void SetSelectedText(const char* selected_text) override;
virtual void SetLinkUnderCursor(const char* url) override;
+ virtual void GetV8ExternalSnapshotData(const char** natives_data_out,
+ int* natives_size_out,
+ const char** snapshot_data_out,
+ int* snapshot_size_out) override;
private:
std::string locale_;
diff --git a/ppapi/tests/DEPS b/ppapi/tests/DEPS
index 06b64ab..3379edc 100644
--- a/ppapi/tests/DEPS
+++ b/ppapi/tests/DEPS
@@ -7,6 +7,7 @@ include_rules = [
"-uncode",
"-testing",
"-ppapi",
+ "+gin",
"+ppapi/c",
"+ppapi/cpp",
"+ppapi/lib",
diff --git a/ppapi/tests/test_pdf.cc b/ppapi/tests/test_pdf.cc
index cd08385..11a35b1 100644
--- a/ppapi/tests/test_pdf.cc
+++ b/ppapi/tests/test_pdf.cc
@@ -11,6 +11,10 @@
#include "ppapi/cpp/var.h"
#include "ppapi/tests/testing_instance.h"
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+#include "gin/public/isolate_holder.h"
+#endif
+
REGISTER_TEST_CASE(PDF);
TestPDF::TestPDF(TestingInstance* instance)
@@ -20,6 +24,7 @@ TestPDF::TestPDF(TestingInstance* instance)
void TestPDF::RunTests(const std::string& filter) {
RUN_TEST(GetLocalizedString, filter);
RUN_TEST(GetResourceImage, filter);
+ RUN_TEST(GetV8ExternalSnapshotData, filter);
}
std::string TestPDF::TestGetLocalizedString() {
@@ -44,3 +49,28 @@ std::string TestPDF::TestGetResourceImage() {
}
PASS();
}
+
+std::string TestPDF::TestGetV8ExternalSnapshotData() {
+ const char* natives_data;
+ const char* snapshot_data;
+ int natives_size;
+ int snapshot_size;
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ bool loaded_ok = gin::IsolateHolder::LoadV8Snapshot();
+ ASSERT_TRUE(loaded_ok);
+ pp::PDF::GetV8ExternalSnapshotData(instance_, &natives_data, &natives_size,
+ &snapshot_data, &snapshot_size);
+ ASSERT_NE(natives_data, (char*) (NULL));
+ ASSERT_NE(natives_size, 0);
+ ASSERT_NE(snapshot_data, (char*) (NULL));
+ ASSERT_NE(snapshot_size, 0);
+#else
+ pp::PDF::GetV8ExternalSnapshotData(instance_, &natives_data, &natives_size,
+ &snapshot_data, &snapshot_size);
+ ASSERT_EQ(natives_data, (char*) (NULL));
+ ASSERT_EQ(natives_size, 0);
+ ASSERT_EQ(snapshot_data, (char*) (NULL));
+ ASSERT_EQ(snapshot_size, 0);
+#endif
+ PASS();
+}
diff --git a/ppapi/tests/test_pdf.h b/ppapi/tests/test_pdf.h
index 5b3e52de..fcdfbfc 100644
--- a/ppapi/tests/test_pdf.h
+++ b/ppapi/tests/test_pdf.h
@@ -20,6 +20,7 @@ class TestPDF : public TestCase {
private:
std::string TestGetLocalizedString();
std::string TestGetResourceImage();
+ std::string TestGetV8ExternalSnapshotData();
};
#endif // PAPPI_TESTS_TEST_PDF_H_
diff --git a/ppapi/thunk/ppb_pdf_api.h b/ppapi/thunk/ppb_pdf_api.h
index a37da2b..8e0f4b0 100644
--- a/ppapi/thunk/ppb_pdf_api.h
+++ b/ppapi/thunk/ppb_pdf_api.h
@@ -34,6 +34,10 @@ class PPB_PDF_API {
virtual PP_Bool IsOutOfProcess() = 0;
virtual void SetSelectedText(const char* selected_text) = 0;
virtual void SetLinkUnderCursor(const char* url) = 0;
+ virtual void GetV8ExternalSnapshotData(const char** natives_data_out,
+ int* natives_size_out,
+ const char** snapshot_data_out,
+ int* snapshot_size_out) = 0;
static const SingletonResourceID kSingletonResourceID = PDF_SINGLETON_ID;
};
diff --git a/ppapi/thunk/ppb_pdf_thunk.cc b/ppapi/thunk/ppb_pdf_thunk.cc
index a8aa080..fb06a90 100644
--- a/ppapi/thunk/ppb_pdf_thunk.cc
+++ b/ppapi/thunk/ppb_pdf_thunk.cc
@@ -161,6 +161,18 @@ void SetLinkUnderCursor(PP_Instance instance, const char* url) {
enter.functions()->SetLinkUnderCursor(url);
}
+void GetV8ExternalSnapshotData(PP_Instance instance,
+ const char** natives_data_out,
+ int* natives_size_out,
+ const char** snapshot_data_out,
+ int* snapshot_size_out) {
+ EnterInstanceAPI<PPB_PDF_API> enter(instance);
+ if (enter.failed())
+ return;
+ enter.functions()->GetV8ExternalSnapshotData(natives_data_out,
+ natives_size_out, snapshot_data_out, snapshot_size_out);
+}
+
const PPB_PDF g_ppb_pdf_thunk = {
&GetLocalizedString,
&GetResourceImage,
@@ -181,6 +193,7 @@ const PPB_PDF g_ppb_pdf_thunk = {
&IsOutOfProcess,
&SetSelectedText,
&SetLinkUnderCursor,
+ &GetV8ExternalSnapshotData,
};
} // namespace