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 <set> |
| 12 |
11 #include "base/i18n/icu_encoding_detection.h" | 13 #include "base/i18n/icu_encoding_detection.h" |
12 #include "base/i18n/icu_string_conversions.h" | 14 #include "base/i18n/icu_string_conversions.h" |
13 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
14 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 17 #include "base/logging.h" |
16 #include "base/macros.h" | 18 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
18 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
19 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
20 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 int page_index = FPDFDest_GetPageIndex(doc, dest); | 428 int page_index = FPDFDest_GetPageIndex(doc, dest); |
427 dict.Set(pp::Var("page"), pp::Var(page_index)); | 429 dict.Set(pp::Var("page"), pp::Var(page_index)); |
428 } | 430 } |
429 | 431 |
430 pp::VarArray children; | 432 pp::VarArray children; |
431 | 433 |
432 // Don't trust PDFium to handle circular bookmarks. | 434 // Don't trust PDFium to handle circular bookmarks. |
433 const unsigned int kMaxDepth = 128; | 435 const unsigned int kMaxDepth = 128; |
434 if (depth < kMaxDepth) { | 436 if (depth < kMaxDepth) { |
435 int child_index = 0; | 437 int child_index = 0; |
| 438 std::set<FPDF_BOOKMARK> seen_bookmarks; |
436 for (FPDF_BOOKMARK child_bookmark = | 439 for (FPDF_BOOKMARK child_bookmark = |
437 FPDFBookmark_GetFirstChild(doc, bookmark); | 440 FPDFBookmark_GetFirstChild(doc, bookmark); |
438 child_bookmark != NULL; | 441 child_bookmark; |
439 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) { | 442 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) { |
| 443 if (ContainsKey(seen_bookmarks, child_bookmark)) |
| 444 break; |
| 445 |
| 446 seen_bookmarks.insert(child_bookmark); |
440 children.Set(child_index, | 447 children.Set(child_index, |
441 TraverseBookmarks(doc, child_bookmark, depth + 1)); | 448 TraverseBookmarks(doc, child_bookmark, depth + 1)); |
442 child_index++; | 449 child_index++; |
443 } | 450 } |
444 } | 451 } |
445 dict.Set(pp::Var("children"), children); | 452 dict.Set(pp::Var("children"), children); |
446 return dict; | 453 return dict; |
447 } | 454 } |
448 | 455 |
449 std::string GetDocumentMetadata(FPDF_DOCUMENT doc, const std::string& key) { | 456 std::string GetDocumentMetadata(FPDF_DOCUMENT doc, const std::string& key) { |
(...skipping 3558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4008 double* height) { | 4015 double* height) { |
4009 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4016 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4010 if (!doc) | 4017 if (!doc) |
4011 return false; | 4018 return false; |
4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4019 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4013 FPDF_CloseDocument(doc); | 4020 FPDF_CloseDocument(doc); |
4014 return success; | 4021 return success; |
4015 } | 4022 } |
4016 | 4023 |
4017 } // namespace chrome_pdf | 4024 } // namespace chrome_pdf |
OLD | NEW |