Skip to content

Commit

Permalink
Initialize V8 in PDFium from external files (plugin process only)
Browse files Browse the repository at this point in the history
BUG=421063

Review URL: https://codereview.chromium.org/718453003

Cr-Commit-Position: refs/heads/master@{#304223}
  • Loading branch information
baixo authored and Commit bot committed Nov 14, 2014
1 parent ca3743a commit 5c1aafb
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 7 deletions.
1 change: 1 addition & 0 deletions chrome/chrome_plugin.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
1 change: 1 addition & 0 deletions chrome/plugin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ static_library("plugin") {
"//base",
"//chrome:strings",
"//content/public/plugin",
"//gin",
]
}
1 change: 1 addition & 0 deletions chrome/plugin/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+content/public/plugin",
"+gin/public/isolate_holder.h",
"+media/base",
]
8 changes: 8 additions & 0 deletions chrome/plugin/chrome_content_plugin_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion components/pdf/renderer/ppb_pdf_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pdf/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ppapi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion ppapi/c/private/ppb_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions ppapi/cpp/private/pdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ppapi/cpp/private/pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ppapi/ppapi_internal.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions ppapi/ppapi_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'<@(test_trusted_source_files)',
],
'dependencies': [
'../gin/gin.gyp:gin',
'ppapi.gyp:ppapi_cpp',
'ppapi_internal.gyp:ppapi_shared',
],
Expand Down
1 change: 1 addition & 0 deletions ppapi/proxy/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+base",
"+gin",
"+gpu",
"+ipc",
"+media/audio",
Expand Down
9 changes: 9 additions & 0 deletions ppapi/proxy/pdf_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions ppapi/proxy/pdf_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
1 change: 1 addition & 0 deletions ppapi/tests/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include_rules = [
"-uncode",
"-testing",
"-ppapi",
"+gin",
"+ppapi/c",
"+ppapi/cpp",
"+ppapi/lib",
Expand Down
30 changes: 30 additions & 0 deletions ppapi/tests/test_pdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions ppapi/tests/test_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestPDF : public TestCase {
private:
std::string TestGetLocalizedString();
std::string TestGetResourceImage();
std::string TestGetV8ExternalSnapshotData();
};

#endif // PAPPI_TESTS_TEST_PDF_H_
4 changes: 4 additions & 0 deletions ppapi/thunk/ppb_pdf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
13 changes: 13 additions & 0 deletions ppapi/thunk/ppb_pdf_thunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -181,6 +193,7 @@ const PPB_PDF g_ppb_pdf_thunk = {
&IsOutOfProcess,
&SetSelectedText,
&SetLinkUnderCursor,
&GetV8ExternalSnapshotData,
};

} // namespace
Expand Down

0 comments on commit 5c1aafb

Please sign in to comment.