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

Side by Side Diff: testing/embedder_test.cpp

Issue 1353063002: Merge to M45: Fix heap use after free in CPDFSDK_Annot::GetPDFAnnot. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@2454
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 | « testing/embedder_test.h ('k') | 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) 2015 PDFium Authors. All rights reserved. 1 // Copyright (c) 2015 PDFium 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 "embedder_test.h" 5 #include "embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 213 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
214 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 214 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
215 platform->version = 1; 215 platform->version = 1;
216 platform->app_alert = AlertTrampoline; 216 platform->app_alert = AlertTrampoline;
217 217
218 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); 218 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
219 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); 219 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
220 formfillinfo->version = 1; 220 formfillinfo->version = 1;
221 formfillinfo->FFI_SetTimer = SetTimerTrampoline; 221 formfillinfo->FFI_SetTimer = SetTimerTrampoline;
222 formfillinfo->FFI_KillTimer = KillTimerTrampoline; 222 formfillinfo->FFI_KillTimer = KillTimerTrampoline;
223 formfillinfo->FFI_GetPage = GetPageTrampoline;
223 formfillinfo->m_pJsPlatform = platform; 224 formfillinfo->m_pJsPlatform = platform;
224 225
225 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); 226 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
226 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); 227 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
227 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); 228 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
228 229
229 return true; 230 return true;
230 } 231 }
231 232
232 void EmbedderTest::DoOpenActions() { 233 void EmbedderTest::DoOpenActions() {
(...skipping 18 matching lines...) Expand all
251 FPDF_PAGE EmbedderTest::LoadPage(int page_number) { 252 FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
252 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); 253 FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
253 if (!page) { 254 if (!page) {
254 return nullptr; 255 return nullptr;
255 } 256 }
256 FORM_OnAfterLoadPage(page, form_handle_); 257 FORM_OnAfterLoadPage(page, form_handle_);
257 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); 258 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
258 return page; 259 return page;
259 } 260 }
260 261
262 FPDF_PAGE EmbedderTest::LoadAndCachePage(int page_number) {
263 FPDF_PAGE page = delegate_->GetPage(form_handle_, document_, page_number);
264 if (!page) {
265 return nullptr;
266 }
267 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
268 return page;
269 }
270
261 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { 271 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) {
262 int width = static_cast<int>(FPDF_GetPageWidth(page)); 272 int width = static_cast<int>(FPDF_GetPageWidth(page));
263 int height = static_cast<int>(FPDF_GetPageHeight(page)); 273 int height = static_cast<int>(FPDF_GetPageHeight(page));
264 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); 274 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
265 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); 275 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
266 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); 276 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
267 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); 277 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
268 return bitmap; 278 return bitmap;
269 } 279 }
270 280
271 void EmbedderTest::UnloadPage(FPDF_PAGE page) { 281 void EmbedderTest::UnloadPage(FPDF_PAGE page) {
272 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); 282 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
273 FORM_OnBeforeClosePage(page, form_handle_); 283 FORM_OnBeforeClosePage(page, form_handle_);
274 FPDF_ClosePage(page); 284 FPDF_ClosePage(page);
275 } 285 }
276 286
287 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMHANDLE form_handle,
288 FPDF_DOCUMENT document,
289 int page_index) {
290 auto it = m_pageMap.find(page_index);
291 if (it != m_pageMap.end()) {
292 return it->second;
293 }
294 FPDF_PAGE page = FPDF_LoadPage(document, page_index);
295 if (!page) {
296 return nullptr;
297 }
298 m_pageMap[page_index] = page;
299 FORM_OnAfterLoadPage(page, form_handle);
300 return page;
301 }
302
277 // static 303 // static
278 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, 304 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info,
279 int type) { 305 int type) {
280 EmbedderTest* test = static_cast<EmbedderTest*>(info); 306 EmbedderTest* test = static_cast<EmbedderTest*>(info);
281 test->delegate_->UnsupportedHandler(type); 307 test->delegate_->UnsupportedHandler(type);
282 } 308 }
283 309
284 // static 310 // static
285 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform, 311 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform,
286 FPDF_WIDESTRING message, 312 FPDF_WIDESTRING message,
(...skipping 10 matching lines...) Expand all
297 EmbedderTest* test = static_cast<EmbedderTest*>(info); 323 EmbedderTest* test = static_cast<EmbedderTest*>(info);
298 return test->delegate_->SetTimer(msecs, fn); 324 return test->delegate_->SetTimer(msecs, fn);
299 } 325 }
300 326
301 // static 327 // static
302 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) { 328 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) {
303 EmbedderTest* test = static_cast<EmbedderTest*>(info); 329 EmbedderTest* test = static_cast<EmbedderTest*>(info);
304 return test->delegate_->KillTimer(id); 330 return test->delegate_->KillTimer(id);
305 } 331 }
306 332
333 // static
334 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
335 FPDF_DOCUMENT document,
336 int page_index) {
337 EmbedderTest* test = static_cast<EmbedderTest*>(info);
338 return test->delegate_->GetPage(test->m_pFormfillinfo, document, page_index);
339 }
340
307 // Can't use gtest-provided main since we need to stash the path to the 341 // Can't use gtest-provided main since we need to stash the path to the
308 // executable in order to find the external V8 binary data files. 342 // executable in order to find the external V8 binary data files.
309 int main(int argc, char** argv) { 343 int main(int argc, char** argv) {
310 g_exe_path_ = argv[0]; 344 g_exe_path_ = argv[0];
311 testing::InitGoogleTest(&argc, argv); 345 testing::InitGoogleTest(&argc, argv);
312 testing::InitGoogleMock(&argc, argv); 346 testing::InitGoogleMock(&argc, argv);
313 return RUN_ALL_TESTS(); 347 return RUN_ALL_TESTS();
314 } 348 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698