diff options
author | baixo <baixo@chromium.org> | 2014-11-13 04:41:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-13 12:42:01 +0000 |
commit | f28960dabfe03eff699df0e00f7edf7023ae46e8 (patch) | |
tree | f042640696b0749dc25acd0300daef6f2175eca7 /gin/isolate_holder.cc | |
parent | f881f652f007ea0480eb0a0fa72a8e5efa00c9ae (diff) | |
download | chromium_src-f28960dabfe03eff699df0e00f7edf7023ae46e8.zip chromium_src-f28960dabfe03eff699df0e00f7edf7023ae46e8.tar.gz chromium_src-f28960dabfe03eff699df0e00f7edf7023ae46e8.tar.bz2 |
Initialize V8 in PDFium from external files when plugin is running in the renderer process.
BUG=421063
Review URL: https://codereview.chromium.org/705623002
Cr-Commit-Position: refs/heads/master@{#304020}
Diffstat (limited to 'gin/isolate_holder.cc')
-rw-r--r-- | gin/isolate_holder.cc | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc index 334c0e0..2cdacc0 100644 --- a/gin/isolate_holder.cc +++ b/gin/isolate_holder.cc @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> +#include "base/files/memory_mapped_file.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" #include "base/rand_util.h" @@ -19,7 +20,6 @@ #include "gin/run_microtasks_observer.h" #ifdef V8_USE_EXTERNAL_STARTUP_DATA -#include "base/files/memory_mapped_file.h" #include "base/path_service.h" #endif // V8_USE_EXTERNAL_STARTUP_DATA @@ -34,10 +34,10 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) { return true; } -#ifdef V8_USE_EXTERNAL_STARTUP_DATA base::MemoryMappedFile* g_mapped_natives = NULL; base::MemoryMappedFile* g_mapped_snapshot = NULL; +#ifdef V8_USE_EXTERNAL_STARTUP_DATA bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path, int natives_fd = -1, int snapshot_fd = -1) { int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; @@ -80,7 +80,13 @@ bool IsolateHolder::LoadV8Snapshot() { return true; base::FilePath data_path; - PathService::Get(base::DIR_ANDROID_APP_DATA, &data_path); + PathService::Get( +#if defined(OS_ANDROID) + base::DIR_ANDROID_APP_DATA, +#elif defined(OS_POSIX) + base::DIR_EXE, +#endif + &data_path); DCHECK(!data_path.empty()); base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin"); @@ -98,6 +104,22 @@ bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { } #endif // V8_USE_EXTERNAL_STARTUP_DATA +//static +void IsolateHolder::GetV8ExternalSnapshotData(const char** natives_data_out, + int* natives_size_out, + const char** snapshot_data_out, + int* snapshot_size_out) { + if (!g_mapped_natives || !g_mapped_snapshot) { + *natives_data_out = *snapshot_data_out = NULL; + *natives_size_out = *snapshot_size_out = 0; + return; + } + *natives_data_out = reinterpret_cast<const char*>(g_mapped_natives->data()); + *snapshot_data_out = reinterpret_cast<const char*>(g_mapped_snapshot->data()); + *natives_size_out = static_cast<int>(g_mapped_natives->length()); + *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); +} + IsolateHolder::IsolateHolder() { CHECK(g_array_buffer_allocator) << "You need to invoke gin::IsolateHolder::Initialize first"; @@ -158,14 +180,14 @@ void IsolateHolder::Initialize(ScriptMode mode, #ifdef V8_USE_EXTERNAL_STARTUP_DATA v8::StartupData natives; natives.data = reinterpret_cast<const char*>(g_mapped_natives->data()); - natives.raw_size = g_mapped_natives->length(); - natives.compressed_size = g_mapped_natives->length(); + natives.raw_size = static_cast<int>(g_mapped_natives->length()); + natives.compressed_size = static_cast<int>(g_mapped_natives->length()); v8::V8::SetNativesDataBlob(&natives); v8::StartupData snapshot; snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data()); - snapshot.raw_size = g_mapped_snapshot->length(); - snapshot.compressed_size = g_mapped_snapshot->length(); + snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length()); + snapshot.compressed_size = static_cast<int>(g_mapped_snapshot->length()); v8::V8::SetSnapshotDataBlob(&snapshot); #endif // V8_USE_EXTERNAL_STARTUP_DATA v8::V8::Initialize(); |