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

Side by Side Diff: testing/embedder_test.cpp

Issue 1332653002: Merge to XFA:Fix heap use after free in CPDFSDK_Annot::GetPDFAnnot. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
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') | testing/resources/bug_507316.in » ('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) 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 225 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
226 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 226 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
227 platform->version = 2; 227 platform->version = 2;
228 platform->app_alert = AlertTrampoline; 228 platform->app_alert = AlertTrampoline;
229 229
230 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); 230 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
231 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); 231 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
232 formfillinfo->version = 1; 232 formfillinfo->version = 1;
233 formfillinfo->FFI_SetTimer = SetTimerTrampoline; 233 formfillinfo->FFI_SetTimer = SetTimerTrampoline;
234 formfillinfo->FFI_KillTimer = KillTimerTrampoline; 234 formfillinfo->FFI_KillTimer = KillTimerTrampoline;
235 formfillinfo->FFI_GetPage = GetPageTrampoline;
235 formfillinfo->m_pJsPlatform = platform; 236 formfillinfo->m_pJsPlatform = platform;
236 237
237 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); 238 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
238 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); 239 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
239 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); 240 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
240 241
241 return true; 242 return true;
242 } 243 }
243 244
244 void EmbedderTest::DoOpenActions() { 245 void EmbedderTest::DoOpenActions() {
(...skipping 18 matching lines...) Expand all
263 FPDF_PAGE EmbedderTest::LoadPage(int page_number) { 264 FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
264 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); 265 FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
265 if (!page) { 266 if (!page) {
266 return nullptr; 267 return nullptr;
267 } 268 }
268 FORM_OnAfterLoadPage(page, form_handle_); 269 FORM_OnAfterLoadPage(page, form_handle_);
269 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); 270 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
270 return page; 271 return page;
271 } 272 }
272 273
274 FPDF_PAGE EmbedderTest::LoadAndCachePage(int page_number) {
275 FPDF_PAGE page = delegate_->GetPage(form_handle_, document_, page_number);
276 if (!page) {
277 return nullptr;
278 }
279 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
280 return page;
281 }
282
273 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { 283 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) {
274 int width = static_cast<int>(FPDF_GetPageWidth(page)); 284 int width = static_cast<int>(FPDF_GetPageWidth(page));
275 int height = static_cast<int>(FPDF_GetPageHeight(page)); 285 int height = static_cast<int>(FPDF_GetPageHeight(page));
276 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); 286 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
277 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); 287 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
278 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); 288 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
279 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); 289 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
280 return bitmap; 290 return bitmap;
281 } 291 }
282 292
283 void EmbedderTest::UnloadPage(FPDF_PAGE page) { 293 void EmbedderTest::UnloadPage(FPDF_PAGE page) {
284 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); 294 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
285 FORM_OnBeforeClosePage(page, form_handle_); 295 FORM_OnBeforeClosePage(page, form_handle_);
286 FPDF_ClosePage(page); 296 FPDF_ClosePage(page);
287 } 297 }
288 298
299 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMHANDLE form_handle,
300 FPDF_DOCUMENT document,
301 int page_index) {
302 auto it = m_pageMap.find(page_index);
303 if (it != m_pageMap.end()) {
304 return it->second;
305 }
306 FPDF_PAGE page = FPDF_LoadPage(document, page_index);
307 if (!page) {
308 return nullptr;
309 }
310 m_pageMap[page_index] = page;
311 FORM_OnAfterLoadPage(page, form_handle);
312 return page;
313 }
314
289 // static 315 // static
290 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, 316 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info,
291 int type) { 317 int type) {
292 EmbedderTest* test = static_cast<EmbedderTest*>(info); 318 EmbedderTest* test = static_cast<EmbedderTest*>(info);
293 test->delegate_->UnsupportedHandler(type); 319 test->delegate_->UnsupportedHandler(type);
294 } 320 }
295 321
296 // static 322 // static
297 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform, 323 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform,
298 FPDF_WIDESTRING message, 324 FPDF_WIDESTRING message,
(...skipping 11 matching lines...) Expand all
310 EmbedderTest* test = static_cast<EmbedderTest*>(info); 336 EmbedderTest* test = static_cast<EmbedderTest*>(info);
311 return test->delegate_->SetTimer(msecs, fn); 337 return test->delegate_->SetTimer(msecs, fn);
312 } 338 }
313 339
314 // static 340 // static
315 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) { 341 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) {
316 EmbedderTest* test = static_cast<EmbedderTest*>(info); 342 EmbedderTest* test = static_cast<EmbedderTest*>(info);
317 return test->delegate_->KillTimer(id); 343 return test->delegate_->KillTimer(id);
318 } 344 }
319 345
346 // static
347 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
348 FPDF_DOCUMENT document,
349 int page_index) {
350 EmbedderTest* test = static_cast<EmbedderTest*>(info);
351 return test->delegate_->GetPage(test->m_pFormfillinfo, document, page_index);
352 }
353
320 // Can't use gtest-provided main since we need to stash the path to the 354 // Can't use gtest-provided main since we need to stash the path to the
321 // executable in order to find the external V8 binary data files. 355 // executable in order to find the external V8 binary data files.
322 int main(int argc, char** argv) { 356 int main(int argc, char** argv) {
323 g_exe_path_ = argv[0]; 357 g_exe_path_ = argv[0];
324 testing::InitGoogleTest(&argc, argv); 358 testing::InitGoogleTest(&argc, argv);
325 testing::InitGoogleMock(&argc, argv); 359 testing::InitGoogleMock(&argc, argv);
326 return RUN_ALL_TESTS(); 360 return RUN_ALL_TESTS();
327 } 361 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | testing/resources/bug_507316.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698