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

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: 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
19 bool g_sdk_initialized_via_pepper = false; 21 bool g_sdk_initialized_via_pepper = false;
20 22
23 gin::IsolateHolder* g_isolate_holder = nullptr;
24
21 namespace chrome_pdf { 25 namespace chrome_pdf {
22 26
23 PDFModule::PDFModule() { 27 PDFModule::PDFModule() {
24 } 28 }
25 29
26 PDFModule::~PDFModule() { 30 PDFModule::~PDFModule() {
27 if (g_sdk_initialized_via_pepper) { 31 if (g_sdk_initialized_via_pepper) {
28 chrome_pdf::ShutdownSDK(); 32 chrome_pdf::ShutdownSDK();
33 if (g_sdk_initialized_via_pepper) {
Lei Zhang 2015/09/16 21:22:24 Didn't we just check |g_sdk_initialized_via_pepper
jochen (gone - plz use gerrit) 2015/09/17 06:55:07 done
34 g_isolate_holder->isolate()->Exit();
35 delete g_isolate_holder;
36 g_isolate_holder = nullptr;
37 }
29 g_sdk_initialized_via_pepper = false; 38 g_sdk_initialized_via_pepper = false;
30 } 39 }
31 } 40 }
32 41
33 bool PDFModule::Init() { 42 bool PDFModule::Init() {
34 return true; 43 return true;
35 } 44 }
36 45
37 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { 46 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
38 if (!g_sdk_initialized_via_pepper) { 47 if (!g_sdk_initialized_via_pepper) {
39 v8::StartupData natives; 48 v8::StartupData natives;
40 v8::StartupData snapshot; 49 v8::StartupData snapshot;
41 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), 50 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance),
42 &natives.data, &natives.raw_size, 51 &natives.data, &natives.raw_size,
43 &snapshot.data, &snapshot.raw_size); 52 &snapshot.data, &snapshot.raw_size);
44 if (natives.data) { 53 if (natives.data) {
45 v8::V8::SetNativesDataBlob(&natives); 54 v8::V8::SetNativesDataBlob(&natives);
46 v8::V8::SetSnapshotDataBlob(&snapshot); 55 v8::V8::SetSnapshotDataBlob(&snapshot);
47 } 56 }
48 if (!chrome_pdf::InitializeSDK()) 57 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
58 gin::ArrayBufferAllocator::SharedInstance());
59 g_isolate_holder =
Lei Zhang 2015/09/16 21:22:24 CreateInstance() only gets called once per process
raymes 2015/09/17 02:30:41 I believe CreateInstance will get called multiple
jochen (gone - plz use gerrit) 2015/09/17 06:55:07 this block is protected by !g_sdk_initialized_via_
60 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread);
61 g_isolate_holder->isolate()->Enter();
raymes 2015/09/17 02:30:41 nit: indentation looks funny here.
jochen (gone - plz use gerrit) 2015/09/17 06:55:07 done
62 if (!chrome_pdf::InitializeSDK()) {
63 g_isolate_holder->isolate()->Exit();
Lei Zhang 2015/09/16 21:22:24 Write a function for these 3 lines? Then reused on
jochen (gone - plz use gerrit) 2015/09/17 06:55:07 done
64 delete g_isolate_holder;
65 g_isolate_holder = nullptr;
49 return NULL; 66 return NULL;
67 }
50 g_sdk_initialized_via_pepper = true; 68 g_sdk_initialized_via_pepper = true;
51 } 69 }
52 70
53 return new OutOfProcessInstance(instance); 71 return new OutOfProcessInstance(instance);
54 } 72 }
55 73
56 74
57 // Implementation of Global PPP functions --------------------------------- 75 // Implementation of Global PPP functions ---------------------------------
58 int32_t PPP_InitializeModule(PP_Module module_id, 76 int32_t PPP_InitializeModule(PP_Module module_id,
59 PPB_GetInterface get_browser_interface) { 77 PPB_GetInterface get_browser_interface) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 autorotate); 185 autorotate);
168 bool ret = engine_exports->RenderPDFPageToBitmap( 186 bool ret = engine_exports->RenderPDFPageToBitmap(
169 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); 187 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer);
170 if (!g_sdk_initialized_via_pepper) { 188 if (!g_sdk_initialized_via_pepper) {
171 chrome_pdf::ShutdownSDK(); 189 chrome_pdf::ShutdownSDK();
172 } 190 }
173 return ret; 191 return ret;
174 } 192 }
175 193
176 } // namespace chrome_pdf 194 } // 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