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

Side by Side Diff: testing/embedder_test.cpp

Issue 2322523002: Cleanup page when unloading in embedder tests (Closed)
Patch Set: Created 4 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 2015 PDFium Authors. All rights reserved. 1 // Copyright 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 "testing/embedder_test.h" 5 #include "testing/embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return it->second; 248 return it->second;
249 249
250 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); 250 FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
251 if (!page) { 251 if (!page) {
252 return nullptr; 252 return nullptr;
253 } 253 }
254 FORM_OnAfterLoadPage(page, form_handle_); 254 FORM_OnAfterLoadPage(page, form_handle_);
255 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); 255 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
256 // Cache the page. 256 // Cache the page.
257 page_map_[page_number] = page; 257 page_map_[page_number] = page;
258 page_reverse_map_[page] = page_number;
258 return page; 259 return page;
259 } 260 }
260 261
261 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { 262 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) {
262 int width = static_cast<int>(FPDF_GetPageWidth(page)); 263 int width = static_cast<int>(FPDF_GetPageWidth(page));
263 int height = static_cast<int>(FPDF_GetPageHeight(page)); 264 int height = static_cast<int>(FPDF_GetPageHeight(page));
264 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; 265 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0;
265 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); 266 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha);
266 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; 267 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF;
267 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); 268 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color);
268 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); 269 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
269 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); 270 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
270 return bitmap; 271 return bitmap;
271 } 272 }
272 273
273 void EmbedderTest::UnloadPage(FPDF_PAGE page) { 274 void EmbedderTest::UnloadPage(FPDF_PAGE page) {
274 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); 275 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
275 FORM_OnBeforeClosePage(page, form_handle_); 276 FORM_OnBeforeClosePage(page, form_handle_);
276 FPDF_ClosePage(page); 277 FPDF_ClosePage(page);
278
279 auto it = page_reverse_map_.find(page);
280 if (it == page_reverse_map_.end())
281 return;
282
283 page_map_.erase(it->second);
284 page_reverse_map_.erase(it);
277 } 285 }
278 286
279 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info, 287 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info,
280 FPDF_DOCUMENT document, 288 FPDF_DOCUMENT document,
281 int page_index) { 289 int page_index) {
282 EmbedderTest* test = static_cast<EmbedderTest*>(info); 290 EmbedderTest* test = static_cast<EmbedderTest*>(info);
283 auto it = test->page_map_.find(page_index); 291 auto it = test->page_map_.find(page_index);
284 return it != test->page_map_.end() ? it->second : nullptr; 292 return it != test->page_map_.end() ? it->second : nullptr;
285 } 293 }
286 294
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 343 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
336 if (g_v8_natives) 344 if (g_v8_natives)
337 free(const_cast<char*>(g_v8_natives->data)); 345 free(const_cast<char*>(g_v8_natives->data));
338 if (g_v8_snapshot) 346 if (g_v8_snapshot)
339 free(const_cast<char*>(g_v8_snapshot->data)); 347 free(const_cast<char*>(g_v8_snapshot->data));
340 #endif // V8_USE_EXTERNAL_STARTUP_DATA 348 #endif // V8_USE_EXTERNAL_STARTUP_DATA
341 #endif // PDF_ENABLE_V8 349 #endif // PDF_ENABLE_V8
342 350
343 return ret_val; 351 return ret_val;
344 } 352 }
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