OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 #include <set> | 13 #include <set> |
14 | 14 |
| 15 #include "base/auto_reset.h" |
15 #include "base/i18n/encoding_detection.h" | 16 #include "base/i18n/encoding_detection.h" |
16 #include "base/i18n/icu_string_conversions.h" | 17 #include "base/i18n/icu_string_conversions.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/macros.h" | 20 #include "base/macros.h" |
20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
21 #include "base/numerics/safe_conversions.h" | 22 #include "base/numerics/safe_conversions.h" |
22 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_piece.h" | 25 #include "base/strings/string_piece.h" |
(...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2463 } | 2464 } |
2464 | 2465 |
2465 int PDFiumEngine::GetMostVisiblePage() { | 2466 int PDFiumEngine::GetMostVisiblePage() { |
2466 if (in_flight_visible_page_) | 2467 if (in_flight_visible_page_) |
2467 return *in_flight_visible_page_; | 2468 return *in_flight_visible_page_; |
2468 | 2469 |
2469 // We can call GetMostVisiblePage through a callback from PDFium. We have | 2470 // We can call GetMostVisiblePage through a callback from PDFium. We have |
2470 // to defer the page deletion otherwise we could potentially delete the page | 2471 // to defer the page deletion otherwise we could potentially delete the page |
2471 // that originated the calling JS request and destroy the objects that are | 2472 // that originated the calling JS request and destroy the objects that are |
2472 // currently being used. | 2473 // currently being used. |
2473 defer_page_unload_ = true; | 2474 base::AutoReset<bool> defer_page_unload_guard(&defer_page_unload_, true); |
2474 CalculateVisiblePages(); | 2475 CalculateVisiblePages(); |
2475 defer_page_unload_ = false; | |
2476 return most_visible_page_; | 2476 return most_visible_page_; |
2477 } | 2477 } |
2478 | 2478 |
2479 pp::Rect PDFiumEngine::GetPageRect(int index) { | 2479 pp::Rect PDFiumEngine::GetPageRect(int index) { |
2480 pp::Rect rc(pages_[index]->rect()); | 2480 pp::Rect rc(pages_[index]->rect()); |
2481 rc.Inset(-kPageShadowLeft, -kPageShadowTop, | 2481 rc.Inset(-kPageShadowLeft, -kPageShadowTop, |
2482 -kPageShadowRight, -kPageShadowBottom); | 2482 -kPageShadowRight, -kPageShadowBottom); |
2483 return rc; | 2483 return rc; |
2484 } | 2484 } |
2485 | 2485 |
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4159 FPDF_DOCUMENT doc = | 4159 FPDF_DOCUMENT doc = |
4160 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4160 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4161 if (!doc) | 4161 if (!doc) |
4162 return false; | 4162 return false; |
4163 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4163 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4164 FPDF_CloseDocument(doc); | 4164 FPDF_CloseDocument(doc); |
4165 return success; | 4165 return success; |
4166 } | 4166 } |
4167 | 4167 |
4168 } // namespace chrome_pdf | 4168 } // namespace chrome_pdf |
OLD | NEW |