Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 bool g_sdk_initialized_via_pepper = false; | 25 bool g_sdk_initialized_via_pepper = false; |
| 26 | 26 |
| 27 gin::IsolateHolder* g_isolate_holder = nullptr; | 27 gin::IsolateHolder* g_isolate_holder = nullptr; |
| 28 | 28 |
| 29 void TearDownV8() { | 29 void TearDownV8() { |
| 30 g_isolate_holder->isolate()->Exit(); | 30 g_isolate_holder->isolate()->Exit(); |
| 31 delete g_isolate_holder; | 31 delete g_isolate_holder; |
| 32 g_isolate_holder = nullptr; | 32 g_isolate_holder = nullptr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SetUpV8() { | |
| 36 g_isolate_holder = | |
| 37 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread); | |
| 38 g_isolate_holder->isolate()->Enter(); | |
| 39 } | |
| 40 | |
| 35 } // namespace | 41 } // namespace |
| 36 | 42 |
| 37 PDFModule::PDFModule() { | 43 PDFModule::PDFModule() { |
| 38 } | 44 } |
| 39 | 45 |
| 40 PDFModule::~PDFModule() { | 46 PDFModule::~PDFModule() { |
| 41 if (g_sdk_initialized_via_pepper) { | 47 if (g_sdk_initialized_via_pepper) { |
| 42 TearDownV8(); | 48 TearDownV8(); |
| 43 chrome_pdf::ShutdownSDK(); | 49 chrome_pdf::ShutdownSDK(); |
| 44 g_sdk_initialized_via_pepper = false; | 50 g_sdk_initialized_via_pepper = false; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 v8::StartupData snapshot; | 61 v8::StartupData snapshot; |
| 56 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), | 62 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), |
| 57 &natives.data, &natives.raw_size, | 63 &natives.data, &natives.raw_size, |
| 58 &snapshot.data, &snapshot.raw_size); | 64 &snapshot.data, &snapshot.raw_size); |
| 59 if (natives.data) { | 65 if (natives.data) { |
| 60 v8::V8::SetNativesDataBlob(&natives); | 66 v8::V8::SetNativesDataBlob(&natives); |
| 61 v8::V8::SetSnapshotDataBlob(&snapshot); | 67 v8::V8::SetSnapshotDataBlob(&snapshot); |
| 62 } | 68 } |
| 63 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 69 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
| 64 gin::ArrayBufferAllocator::SharedInstance()); | 70 gin::ArrayBufferAllocator::SharedInstance()); |
| 65 g_isolate_holder = | 71 SetUpV8(); |
| 66 new gin::IsolateHolder(gin::IsolateHolder::kSingleThread); | |
| 67 g_isolate_holder->isolate()->Enter(); | |
| 68 if (!chrome_pdf::InitializeSDK()) { | 72 if (!chrome_pdf::InitializeSDK()) { |
|
Lei Zhang
2015/11/05 21:44:01
Should we write wrappers for chrome_pdf::Initializ
| |
| 69 TearDownV8(); | 73 TearDownV8(); |
| 70 return NULL; | 74 return NULL; |
| 71 } | 75 } |
| 72 g_sdk_initialized_via_pepper = true; | 76 g_sdk_initialized_via_pepper = true; |
| 73 } | 77 } |
| 74 | 78 |
| 75 return new OutOfProcessInstance(instance); | 79 return new OutOfProcessInstance(instance); |
| 76 } | 80 } |
| 77 | 81 |
| 78 | 82 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 109 int bounds_origin_x, | 113 int bounds_origin_x, |
| 110 int bounds_origin_y, | 114 int bounds_origin_y, |
| 111 int bounds_width, | 115 int bounds_width, |
| 112 int bounds_height, | 116 int bounds_height, |
| 113 bool fit_to_bounds, | 117 bool fit_to_bounds, |
| 114 bool stretch_to_bounds, | 118 bool stretch_to_bounds, |
| 115 bool keep_aspect_ratio, | 119 bool keep_aspect_ratio, |
| 116 bool center_in_bounds, | 120 bool center_in_bounds, |
| 117 bool autorotate) { | 121 bool autorotate) { |
| 118 if (!g_sdk_initialized_via_pepper) { | 122 if (!g_sdk_initialized_via_pepper) { |
| 123 SetUpV8(); | |
| 119 if (!chrome_pdf::InitializeSDK()) { | 124 if (!chrome_pdf::InitializeSDK()) { |
| 125 TearDownV8(); | |
| 120 return false; | 126 return false; |
| 121 } | 127 } |
| 122 } | 128 } |
| 123 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 129 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
| 124 chrome_pdf::PDFEngineExports::Create()); | 130 chrome_pdf::PDFEngineExports::Create()); |
| 125 chrome_pdf::PDFEngineExports::RenderingSettings settings( | 131 chrome_pdf::PDFEngineExports::RenderingSettings settings( |
| 126 dpi, dpi, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, | 132 dpi, dpi, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, |
| 127 bounds_height), | 133 bounds_height), |
| 128 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, | 134 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, |
| 129 autorotate); | 135 autorotate); |
| 130 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, | 136 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, |
| 131 page_number, settings, dc); | 137 page_number, settings, dc); |
| 132 if (!g_sdk_initialized_via_pepper) { | 138 if (!g_sdk_initialized_via_pepper) { |
| 139 TearDownV8(); | |
| 133 chrome_pdf::ShutdownSDK(); | 140 chrome_pdf::ShutdownSDK(); |
| 134 } | 141 } |
| 135 return ret; | 142 return ret; |
| 136 } | 143 } |
| 137 | 144 |
| 138 #endif // OS_WIN | 145 #endif // OS_WIN |
| 139 | 146 |
| 140 bool GetPDFDocInfo(const void* pdf_buffer, | 147 bool GetPDFDocInfo(const void* pdf_buffer, |
| 141 int buffer_size, int* page_count, | 148 int buffer_size, int* page_count, |
| 142 double* max_page_width) { | 149 double* max_page_width) { |
| 143 if (!g_sdk_initialized_via_pepper) { | 150 if (!g_sdk_initialized_via_pepper) { |
| 144 if (!chrome_pdf::InitializeSDK()) | 151 SetUpV8(); |
| 152 if (!chrome_pdf::InitializeSDK()) { | |
| 153 TearDownV8(); | |
| 145 return false; | 154 return false; |
| 155 } | |
| 146 } | 156 } |
| 147 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 157 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
| 148 chrome_pdf::PDFEngineExports::Create()); | 158 chrome_pdf::PDFEngineExports::Create()); |
| 149 bool ret = engine_exports->GetPDFDocInfo( | 159 bool ret = engine_exports->GetPDFDocInfo( |
| 150 pdf_buffer, buffer_size, page_count, max_page_width); | 160 pdf_buffer, buffer_size, page_count, max_page_width); |
| 151 if (!g_sdk_initialized_via_pepper) { | 161 if (!g_sdk_initialized_via_pepper) { |
| 162 TearDownV8(); | |
| 152 chrome_pdf::ShutdownSDK(); | 163 chrome_pdf::ShutdownSDK(); |
| 153 } | 164 } |
| 154 return ret; | 165 return ret; |
| 155 } | 166 } |
| 156 | 167 |
| 157 bool GetPDFPageSizeByIndex(const void* pdf_buffer, | 168 bool GetPDFPageSizeByIndex(const void* pdf_buffer, |
| 158 int pdf_buffer_size, int page_number, | 169 int pdf_buffer_size, int page_number, |
| 159 double* width, double* height) { | 170 double* width, double* height) { |
| 160 if (!g_sdk_initialized_via_pepper) { | 171 if (!g_sdk_initialized_via_pepper) { |
| 161 if (!chrome_pdf::InitializeSDK()) | 172 SetUpV8(); |
| 173 if (!chrome_pdf::InitializeSDK()) { | |
| 174 TearDownV8(); | |
| 162 return false; | 175 return false; |
| 176 } | |
| 163 } | 177 } |
| 164 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 178 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
| 165 chrome_pdf::PDFEngineExports::Create()); | 179 chrome_pdf::PDFEngineExports::Create()); |
| 166 bool ret = engine_exports->GetPDFPageSizeByIndex( | 180 bool ret = engine_exports->GetPDFPageSizeByIndex( |
| 167 pdf_buffer, pdf_buffer_size, page_number, width, height); | 181 pdf_buffer, pdf_buffer_size, page_number, width, height); |
| 168 if (!g_sdk_initialized_via_pepper) | 182 if (!g_sdk_initialized_via_pepper) { |
| 183 TearDownV8(); | |
| 169 chrome_pdf::ShutdownSDK(); | 184 chrome_pdf::ShutdownSDK(); |
| 185 } | |
| 170 return ret; | 186 return ret; |
| 171 } | 187 } |
| 172 | 188 |
| 173 bool RenderPDFPageToBitmap(const void* pdf_buffer, | 189 bool RenderPDFPageToBitmap(const void* pdf_buffer, |
| 174 int pdf_buffer_size, | 190 int pdf_buffer_size, |
| 175 int page_number, | 191 int page_number, |
| 176 void* bitmap_buffer, | 192 void* bitmap_buffer, |
| 177 int bitmap_width, | 193 int bitmap_width, |
| 178 int bitmap_height, | 194 int bitmap_height, |
| 179 int dpi, | 195 int dpi, |
| 180 bool autorotate) { | 196 bool autorotate) { |
| 181 if (!g_sdk_initialized_via_pepper) { | 197 if (!g_sdk_initialized_via_pepper) { |
| 182 if (!chrome_pdf::InitializeSDK()) | 198 SetUpV8(); |
| 199 if (!chrome_pdf::InitializeSDK()) { | |
| 200 TearDownV8(); | |
| 183 return false; | 201 return false; |
| 202 } | |
| 184 } | 203 } |
| 185 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 204 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
| 186 chrome_pdf::PDFEngineExports::Create()); | 205 chrome_pdf::PDFEngineExports::Create()); |
| 187 chrome_pdf::PDFEngineExports::RenderingSettings settings( | 206 chrome_pdf::PDFEngineExports::RenderingSettings settings( |
| 188 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, | 207 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, |
| 189 autorotate); | 208 autorotate); |
| 190 bool ret = engine_exports->RenderPDFPageToBitmap( | 209 bool ret = engine_exports->RenderPDFPageToBitmap( |
| 191 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); | 210 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); |
| 192 if (!g_sdk_initialized_via_pepper) { | 211 if (!g_sdk_initialized_via_pepper) { |
| 212 TearDownV8(); | |
| 193 chrome_pdf::ShutdownSDK(); | 213 chrome_pdf::ShutdownSDK(); |
| 194 } | 214 } |
| 195 return ret; | 215 return ret; |
| 196 } | 216 } |
| 197 | 217 |
| 198 } // namespace chrome_pdf | 218 } // namespace chrome_pdf |
| OLD | NEW |