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

Side by Side Diff: pdf/pdf.cc

Issue 2102823003: Tidy up pdf/pdf.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | no next file » | 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 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 13 matching lines...) Expand all
24 24
25 bool g_sdk_initialized_via_pepper = false; 25 bool g_sdk_initialized_via_pepper = false;
26 26
27 } // namespace 27 } // namespace
28 28
29 PDFModule::PDFModule() { 29 PDFModule::PDFModule() {
30 } 30 }
31 31
32 PDFModule::~PDFModule() { 32 PDFModule::~PDFModule() {
33 if (g_sdk_initialized_via_pepper) { 33 if (g_sdk_initialized_via_pepper) {
34 chrome_pdf::ShutdownSDK(); 34 ShutdownSDK();
35 g_sdk_initialized_via_pepper = false; 35 g_sdk_initialized_via_pepper = false;
36 } 36 }
37 } 37 }
38 38
39 bool PDFModule::Init() { 39 bool PDFModule::Init() {
40 return true; 40 return true;
41 } 41 }
42 42
43 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { 43 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
44 if (!g_sdk_initialized_via_pepper) { 44 if (!g_sdk_initialized_via_pepper) {
45 v8::StartupData natives; 45 v8::StartupData natives;
46 v8::StartupData snapshot; 46 v8::StartupData snapshot;
47 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance), 47 pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance),
48 &natives.data, &natives.raw_size, 48 &natives.data, &natives.raw_size,
49 &snapshot.data, &snapshot.raw_size); 49 &snapshot.data, &snapshot.raw_size);
50 if (natives.data) { 50 if (natives.data) {
51 v8::V8::SetNativesDataBlob(&natives); 51 v8::V8::SetNativesDataBlob(&natives);
52 v8::V8::SetSnapshotDataBlob(&snapshot); 52 v8::V8::SetSnapshotDataBlob(&snapshot);
53 } 53 }
54 if (!chrome_pdf::InitializeSDK()) 54 if (!InitializeSDK())
55 return NULL; 55 return nullptr;
56 g_sdk_initialized_via_pepper = true; 56 g_sdk_initialized_via_pepper = true;
57 } 57 }
58 58
59 return new OutOfProcessInstance(instance); 59 return new OutOfProcessInstance(instance);
60 } 60 }
61 61
62 62
63 // Implementation of Global PPP functions --------------------------------- 63 // Implementation of Global PPP functions ---------------------------------
64 int32_t PPP_InitializeModule(PP_Module module_id, 64 int32_t PPP_InitializeModule(PP_Module module_id,
65 PPB_GetInterface get_browser_interface) { 65 PPB_GetInterface get_browser_interface) {
66 PDFModule* module = new PDFModule(); 66 std::unique_ptr<PDFModule> module(new PDFModule);
67 if (!module->InternalInit(module_id, get_browser_interface)) { 67 if (!module->InternalInit(module_id, get_browser_interface))
68 delete module;
69 return PP_ERROR_FAILED; 68 return PP_ERROR_FAILED;
70 }
71 69
72 pp::InternalSetModuleSingleton(module); 70 pp::InternalSetModuleSingleton(module.release());
73 return PP_OK; 71 return PP_OK;
74 } 72 }
75 73
76 void PPP_ShutdownModule() { 74 void PPP_ShutdownModule() {
77 delete pp::Module::Get(); 75 delete pp::Module::Get();
78 pp::InternalSetModuleSingleton(NULL); 76 pp::InternalSetModuleSingleton(nullptr);
79 } 77 }
80 78
81 const void* PPP_GetInterface(const char* interface_name) { 79 const void* PPP_GetInterface(const char* interface_name) {
82 if (!pp::Module::Get()) 80 auto* module = pp::Module::Get();
83 return NULL; 81 return module ? module->GetPluginInterface(interface_name) : nullptr;
84 return pp::Module::Get()->GetPluginInterface(interface_name);
85 } 82 }
86 83
87 #if defined(OS_WIN) 84 #if defined(OS_WIN)
88 bool RenderPDFPageToDC(const void* pdf_buffer, 85 bool RenderPDFPageToDC(const void* pdf_buffer,
89 int buffer_size, 86 int buffer_size,
90 int page_number, 87 int page_number,
91 HDC dc, 88 HDC dc,
92 int dpi, 89 int dpi,
93 int bounds_origin_x, 90 int bounds_origin_x,
94 int bounds_origin_y, 91 int bounds_origin_y,
95 int bounds_width, 92 int bounds_width,
96 int bounds_height, 93 int bounds_height,
97 bool fit_to_bounds, 94 bool fit_to_bounds,
98 bool stretch_to_bounds, 95 bool stretch_to_bounds,
99 bool keep_aspect_ratio, 96 bool keep_aspect_ratio,
100 bool center_in_bounds, 97 bool center_in_bounds,
101 bool autorotate) { 98 bool autorotate) {
102 if (!g_sdk_initialized_via_pepper) { 99 if (!g_sdk_initialized_via_pepper) {
103 if (!chrome_pdf::InitializeSDK()) { 100 if (!InitializeSDK()) {
104 return false; 101 return false;
105 } 102 }
106 } 103 }
107 chrome_pdf::PDFEngineExports* engine_exports = 104 PDFEngineExports* engine_exports = PDFEngineExports::Get();
108 chrome_pdf::PDFEngineExports::Get(); 105 PDFEngineExports::RenderingSettings settings(
109 chrome_pdf::PDFEngineExports::RenderingSettings settings( 106 dpi, dpi,
110 dpi, dpi, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, 107 pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, bounds_height),
111 bounds_height),
112 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, 108 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
113 autorotate); 109 autorotate);
114 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, 110 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size,
115 page_number, settings, dc); 111 page_number, settings, dc);
116 if (!g_sdk_initialized_via_pepper) { 112 if (!g_sdk_initialized_via_pepper)
117 chrome_pdf::ShutdownSDK(); 113 ShutdownSDK();
118 } 114
119 return ret; 115 return ret;
120 } 116 }
121 117
122 #endif // OS_WIN 118 #endif // defined(OS_WIN)
123 119
124 bool GetPDFDocInfo(const void* pdf_buffer, 120 bool GetPDFDocInfo(const void* pdf_buffer,
125 int buffer_size, int* page_count, 121 int buffer_size, int* page_count,
126 double* max_page_width) { 122 double* max_page_width) {
127 if (!g_sdk_initialized_via_pepper) { 123 if (!g_sdk_initialized_via_pepper) {
128 if (!chrome_pdf::InitializeSDK()) 124 if (!InitializeSDK())
129 return false; 125 return false;
130 } 126 }
131 chrome_pdf::PDFEngineExports* engine_exports = 127 PDFEngineExports* engine_exports = PDFEngineExports::Get();
132 chrome_pdf::PDFEngineExports::Get();
133 bool ret = engine_exports->GetPDFDocInfo( 128 bool ret = engine_exports->GetPDFDocInfo(
134 pdf_buffer, buffer_size, page_count, max_page_width); 129 pdf_buffer, buffer_size, page_count, max_page_width);
135 if (!g_sdk_initialized_via_pepper) { 130 if (!g_sdk_initialized_via_pepper)
136 chrome_pdf::ShutdownSDK(); 131 ShutdownSDK();
137 } 132
138 return ret; 133 return ret;
139 } 134 }
140 135
141 bool GetPDFPageSizeByIndex(const void* pdf_buffer, 136 bool GetPDFPageSizeByIndex(const void* pdf_buffer,
142 int pdf_buffer_size, int page_number, 137 int pdf_buffer_size, int page_number,
143 double* width, double* height) { 138 double* width, double* height) {
144 if (!g_sdk_initialized_via_pepper) { 139 if (!g_sdk_initialized_via_pepper) {
145 if (!chrome_pdf::InitializeSDK()) 140 if (!chrome_pdf::InitializeSDK())
146 return false; 141 return false;
147 } 142 }
148 chrome_pdf::PDFEngineExports* engine_exports = 143 chrome_pdf::PDFEngineExports* engine_exports =
149 chrome_pdf::PDFEngineExports::Get(); 144 chrome_pdf::PDFEngineExports::Get();
150 bool ret = engine_exports->GetPDFPageSizeByIndex( 145 bool ret = engine_exports->GetPDFPageSizeByIndex(
151 pdf_buffer, pdf_buffer_size, page_number, width, height); 146 pdf_buffer, pdf_buffer_size, page_number, width, height);
152 if (!g_sdk_initialized_via_pepper) 147 if (!g_sdk_initialized_via_pepper)
153 chrome_pdf::ShutdownSDK(); 148 chrome_pdf::ShutdownSDK();
154 return ret; 149 return ret;
155 } 150 }
156 151
157 bool RenderPDFPageToBitmap(const void* pdf_buffer, 152 bool RenderPDFPageToBitmap(const void* pdf_buffer,
158 int pdf_buffer_size, 153 int pdf_buffer_size,
159 int page_number, 154 int page_number,
160 void* bitmap_buffer, 155 void* bitmap_buffer,
161 int bitmap_width, 156 int bitmap_width,
162 int bitmap_height, 157 int bitmap_height,
163 int dpi, 158 int dpi,
164 bool autorotate) { 159 bool autorotate) {
165 if (!g_sdk_initialized_via_pepper) { 160 if (!g_sdk_initialized_via_pepper) {
166 if (!chrome_pdf::InitializeSDK()) 161 if (!InitializeSDK())
167 return false; 162 return false;
168 } 163 }
169 chrome_pdf::PDFEngineExports* engine_exports = 164 PDFEngineExports* engine_exports = PDFEngineExports::Get();
170 chrome_pdf::PDFEngineExports::Get(); 165 PDFEngineExports::RenderingSettings settings(
171 chrome_pdf::PDFEngineExports::RenderingSettings settings(
172 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, 166 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true,
173 autorotate); 167 autorotate);
174 bool ret = engine_exports->RenderPDFPageToBitmap( 168 bool ret = engine_exports->RenderPDFPageToBitmap(
175 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); 169 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer);
176 if (!g_sdk_initialized_via_pepper) { 170 if (!g_sdk_initialized_via_pepper)
177 chrome_pdf::ShutdownSDK(); 171 ShutdownSDK();
178 } 172
179 return ret; 173 return ret;
180 } 174 }
181 175
182 } // namespace chrome_pdf 176 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698