Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: pdf/pdf.cc

Issue 1346143003: Don't initialize V8 via Blink in ppapi plugins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pdf/OWNERS ('k') | pdf/pdf.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdf.h" 5 #include "pdf/pdf.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "gin/array_buffer.h"
14 #include "gin/public/isolate_holder.h"
13 #include "pdf/out_of_process_instance.h" 15 #include "pdf/out_of_process_instance.h"
14 #include "ppapi/c/ppp.h" 16 #include "ppapi/c/ppp.h"
15 #include "ppapi/cpp/private/internal_module.h" 17 #include "ppapi/cpp/private/internal_module.h"
16 #include "ppapi/cpp/private/pdf.h" 18 #include "ppapi/cpp/private/pdf.h"
17 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
18 20
21 namespace chrome_pdf {
22
23 namespace {
24
19 bool g_sdk_initialized_via_pepper = false; 25 bool g_sdk_initialized_via_pepper = false;
20 26
21 namespace chrome_pdf { 27 gin::IsolateHolder* g_isolate_holder = nullptr;
28
29 void TearDownV8() {
30 g_isolate_holder->isolate()->Exit();
31 delete g_isolate_holder;
32 g_isolate_holder = nullptr;
33 }
34
35 } // namespace
22 36
23 PDFModule::PDFModule() { 37 PDFModule::PDFModule() {
24 } 38 }
25 39
26 PDFModule::~PDFModule() { 40 PDFModule::~PDFModule() {
27 if (g_sdk_initialized_via_pepper) { 41 if (g_sdk_initialized_via_pepper) {
42 TearDownV8();
28 chrome_pdf::ShutdownSDK(); 43 chrome_pdf::ShutdownSDK();
29 g_sdk_initialized_via_pepper = false; 44 g_sdk_initialized_via_pepper = false;
30 } 45 }
31 } 46 }
32 47
33 bool PDFModule::Init() { 48 bool PDFModule::Init() {
34 return true; 49 return true;
35 } 50 }
36 51
37 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { 52 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
38 if (!g_sdk_initialized_via_pepper) { 53 if (!g_sdk_initialized_via_pepper) {
39 v8::StartupData natives; 54 v8::StartupData natives;
40 v8::StartupData snapshot; 55 v8::StartupData snapshot;
41 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), 56 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance),
42 &natives.data, &natives.raw_size, 57 &natives.data, &natives.raw_size,
43 &snapshot.data, &snapshot.raw_size); 58 &snapshot.data, &snapshot.raw_size);
44 if (natives.data) { 59 if (natives.data) {
45 v8::V8::SetNativesDataBlob(&natives); 60 v8::V8::SetNativesDataBlob(&natives);
46 v8::V8::SetSnapshotDataBlob(&snapshot); 61 v8::V8::SetSnapshotDataBlob(&snapshot);
47 } 62 }
48 if (!chrome_pdf::InitializeSDK()) 63 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
64 gin::ArrayBufferAllocator::SharedInstance());
65 g_isolate_holder =
66 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread);
67 g_isolate_holder->isolate()->Enter();
68 if (!chrome_pdf::InitializeSDK()) {
69 TearDownV8();
49 return NULL; 70 return NULL;
71 }
50 g_sdk_initialized_via_pepper = true; 72 g_sdk_initialized_via_pepper = true;
51 } 73 }
52 74
53 return new OutOfProcessInstance(instance); 75 return new OutOfProcessInstance(instance);
54 } 76 }
55 77
56 78
57 // Implementation of Global PPP functions --------------------------------- 79 // Implementation of Global PPP functions ---------------------------------
58 int32_t PPP_InitializeModule(PP_Module module_id, 80 int32_t PPP_InitializeModule(PP_Module module_id,
59 PPB_GetInterface get_browser_interface) { 81 PPB_GetInterface get_browser_interface) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 autorotate); 189 autorotate);
168 bool ret = engine_exports->RenderPDFPageToBitmap( 190 bool ret = engine_exports->RenderPDFPageToBitmap(
169 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); 191 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer);
170 if (!g_sdk_initialized_via_pepper) { 192 if (!g_sdk_initialized_via_pepper) {
171 chrome_pdf::ShutdownSDK(); 193 chrome_pdf::ShutdownSDK();
172 } 194 }
173 return ret; 195 return ret;
174 } 196 }
175 197
176 } // namespace chrome_pdf 198 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/OWNERS ('k') | pdf/pdf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698