diff options
-rw-r--r-- | components/pdf.gypi | 1 | ||||
-rw-r--r-- | components/pdf/renderer/BUILD.gn | 1 | ||||
-rw-r--r-- | components/pdf/renderer/DEPS | 1 | ||||
-rw-r--r-- | components/pdf/renderer/ppb_pdf_impl.cc | 10 | ||||
-rw-r--r-- | gin/isolate_holder.cc | 36 | ||||
-rw-r--r-- | gin/public/isolate_holder.h | 6 | ||||
-rw-r--r-- | pdf/DEPS | 1 | ||||
-rw-r--r-- | pdf/instance.cc | 12 | ||||
-rw-r--r-- | ppapi/c/private/ppb_pdf.h | 7 | ||||
-rw-r--r-- | ppapi/cpp/private/pdf.cc | 16 | ||||
-rw-r--r-- | ppapi/cpp/private/pdf.h | 4 |
11 files changed, 86 insertions, 9 deletions
diff --git a/components/pdf.gypi b/components/pdf.gypi index bd4eea4..0c3b7ef 100644 --- a/components/pdf.gypi +++ b/components/pdf.gypi @@ -38,6 +38,7 @@ 'type': 'static_library', 'dependencies': [ '<(DEPTH)/content/content.gyp:content_renderer', + '<(DEPTH)/gin/gin.gyp:gin', '<(DEPTH)/ppapi/ppapi_internal.gyp:ppapi_shared', '<(DEPTH)/third_party/icu/icu.gyp:icuuc', '<(DEPTH)/third_party/icu/icu.gyp:icui18n', diff --git a/components/pdf/renderer/BUILD.gn b/components/pdf/renderer/BUILD.gn index c83ea41..5792d8d 100644 --- a/components/pdf/renderer/BUILD.gn +++ b/components/pdf/renderer/BUILD.gn @@ -20,6 +20,7 @@ static_library("renderer") { "//components/resources:components_resources", "//components/strings", "//content/public/renderer", + "//gin", "//ppapi:ppapi_shared", "//third_party/icu", "//v8", diff --git a/components/pdf/renderer/DEPS b/components/pdf/renderer/DEPS index 42effda..85a0dde 100644 --- a/components/pdf/renderer/DEPS +++ b/components/pdf/renderer/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+components/strings/grit/components_strings.h", + "+gin", "+grit/components_scaled_resources.h", "+skia/ext", "+ui/gfx", diff --git a/components/pdf/renderer/ppb_pdf_impl.cc b/components/pdf/renderer/ppb_pdf_impl.cc index 7dda10a..85be05e 100644 --- a/components/pdf/renderer/ppb_pdf_impl.cc +++ b/components/pdf/renderer/ppb_pdf_impl.cc @@ -16,6 +16,7 @@ #include "content/public/renderer/pepper_plugin_instance.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_view.h" +#include "gin/public/isolate_holder.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/trusted/ppb_browser_font_trusted.h" @@ -329,6 +330,14 @@ void SetLinkUnderCursor(PP_Instance instance_id, const char* url) { instance->SetLinkUnderCursor(url); } +void 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); +} + const PPB_PDF ppb_pdf = { // &GetLocalizedString, // &GetResourceImage, // @@ -349,6 +358,7 @@ const PPB_PDF ppb_pdf = { // &IsOutOfProcess, // &SetSelectedText, // &SetLinkUnderCursor, // + &GetV8ExternalSnapshotData, // }; } // namespace 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(); diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h index 4e14ade..b12734c 100644 --- a/gin/public/isolate_holder.h +++ b/gin/public/isolate_holder.h @@ -52,11 +52,13 @@ class GIN_EXPORT IsolateHolder { void RemoveRunMicrotasksObserver(); #ifdef V8_USE_EXTERNAL_STARTUP_DATA -#ifdef OS_ANDROID static bool LoadV8SnapshotFD(int natives_fd, int snapshot_fd); -#endif static bool LoadV8Snapshot(); #endif // V8_USE_EXTERNAL_STARTUP_DATA + static void GetV8ExternalSnapshotData(const char** natives_data_out, + int* natives_size_out, + const char** snapshot_data_out, + int* snapshot_size_out); private: v8::Isolate* isolate_; @@ -6,4 +6,5 @@ include_rules = [ "+ppapi", "+third_party/pdfium/fpdfsdk/include", "+ui/events/keycodes/keyboard_codes.h", + "+v8/include/v8.h" ] diff --git a/pdf/instance.cc b/pdf/instance.cc index 37192ba..2ffc7d4 100644 --- a/pdf/instance.cc +++ b/pdf/instance.cc @@ -41,6 +41,7 @@ #include "ppapi/cpp/resource.h" #include "ppapi/cpp/url_request_info.h" #include "ui/events/keycodes/keyboard_codes.h" +#include "v8/include/v8.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -319,6 +320,17 @@ 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, + &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); + } + // For now, we hide HiDPI support behind a flag. if (pp::PDF::IsFeatureEnabled(this, PP_PDFFEATURE_HIDPI)) hidpi_enabled_ = true; diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h index fdd62fe..318c21d 100644 --- a/ppapi/c/private/ppb_pdf.h +++ b/ppapi/c/private/ppb_pdf.h @@ -169,6 +169,13 @@ struct PPB_PDF { // Sets the link currently under the cursor. void (*SetLinkUnderCursor)(PP_Instance instance, const char* url); + + // 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, + int* natives_size_out, + const char** snapshot_data_out, + int* snapshot_size_out); }; #endif // PPAPI_C_PRIVATE_PPB_PDF_H_ diff --git a/ppapi/cpp/private/pdf.cc b/ppapi/cpp/private/pdf.cc index ac5b941..52df60c 100644 --- a/ppapi/cpp/private/pdf.cc +++ b/ppapi/cpp/private/pdf.cc @@ -197,4 +197,20 @@ void PDF::SetLinkUnderCursor(const InstanceHandle& instance, const char* url) { get_interface<PPB_PDF>()->SetLinkUnderCursor(instance.pp_instance(), url); } +// static +void PDF::GetV8ExternalSnapshotData(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); + return; + } + *natives_data_out = NULL; + *snapshot_data_out = NULL; + *natives_size_out = 0; + *snapshot_size_out = 0; +} + } // namespace pp diff --git a/ppapi/cpp/private/pdf.h b/ppapi/cpp/private/pdf.h index 586952c..09db41b 100644 --- a/ppapi/cpp/private/pdf.h +++ b/ppapi/cpp/private/pdf.h @@ -63,6 +63,10 @@ class PDF { const char* selected_text); static void SetLinkUnderCursor(const InstanceHandle& instance, const char* url); + static void GetV8ExternalSnapshotData(const char** natives_data_out, + int* natives_size_out, + const char** snapshot_data_out, + int* snapshot_size_out); }; } // namespace pp |