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 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 // Returns a VarDictionary (representing a bookmark), which in turn contains | 407 // Returns a VarDictionary (representing a bookmark), which in turn contains |
408 // child VarDictionaries (representing the child bookmarks). | 408 // child VarDictionaries (representing the child bookmarks). |
409 // If NULL is passed in as the bookmark then we traverse from the "root". | 409 // If NULL is passed in as the bookmark then we traverse from the "root". |
410 // Note that the "root" bookmark contains no useful information. | 410 // Note that the "root" bookmark contains no useful information. |
411 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, | 411 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, |
412 FPDF_BOOKMARK bookmark, | 412 FPDF_BOOKMARK bookmark, |
413 unsigned int depth) { | 413 unsigned int depth) { |
414 pp::VarDictionary dict; | 414 pp::VarDictionary dict; |
415 base::string16 title; | 415 base::string16 title; |
416 unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); | 416 unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, nullptr, 0); |
417 if (buffer_size > 0) { | 417 if (buffer_size > 0) { |
418 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> api_string_adapter( | 418 PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> api_string_adapter( |
419 &title, buffer_size, true); | 419 &title, buffer_size, true); |
420 api_string_adapter.Close(FPDFBookmark_GetTitle( | 420 api_string_adapter.Close(FPDFBookmark_GetTitle( |
421 bookmark, api_string_adapter.GetData(), buffer_size)); | 421 bookmark, api_string_adapter.GetData(), buffer_size)); |
422 } | 422 } |
423 dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title))); | 423 dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title))); |
424 | 424 |
425 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark); | 425 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark); |
426 // Some bookmarks don't have a page to select. | 426 // Some bookmarks don't have a page to select. |
427 if (dest) { | 427 if (dest) { |
428 int page_index = FPDFDest_GetPageIndex(doc, dest); | 428 int page_index = FPDFDest_GetPageIndex(doc, dest); |
429 dict.Set(pp::Var("page"), pp::Var(page_index)); | 429 dict.Set(pp::Var("page"), pp::Var(page_index)); |
| 430 } else { |
| 431 // Extract URI for bookmarks linking to an external page. |
| 432 FPDF_ACTION action = FPDFBookmark_GetAction(bookmark); |
| 433 buffer_size = FPDFAction_GetURIPath(doc, action, nullptr, 0); |
| 434 if (buffer_size > 0) { |
| 435 std::string uri; |
| 436 PDFiumAPIStringBufferAdapter<std::string> |
| 437 api_string_adapter(&uri, buffer_size, true); |
| 438 api_string_adapter.Close(FPDFAction_GetURIPath( |
| 439 doc, action, api_string_adapter.GetData(), buffer_size)); |
| 440 dict.Set(pp::Var("uri"), pp::Var(uri)); |
| 441 } |
430 } | 442 } |
431 | 443 |
432 pp::VarArray children; | 444 pp::VarArray children; |
433 | 445 |
434 // Don't trust PDFium to handle circular bookmarks. | 446 // Don't trust PDFium to handle circular bookmarks. |
435 const unsigned int kMaxDepth = 128; | 447 const unsigned int kMaxDepth = 128; |
436 if (depth < kMaxDepth) { | 448 if (depth < kMaxDepth) { |
437 int child_index = 0; | 449 int child_index = 0; |
438 std::set<FPDF_BOOKMARK> seen_bookmarks; | 450 std::set<FPDF_BOOKMARK> seen_bookmarks; |
439 for (FPDF_BOOKMARK child_bookmark = | 451 for (FPDF_BOOKMARK child_bookmark = |
(...skipping 3519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3959 double* height) { | 3971 double* height) { |
3960 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3972 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3961 if (!doc) | 3973 if (!doc) |
3962 return false; | 3974 return false; |
3963 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3975 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3964 FPDF_CloseDocument(doc); | 3976 FPDF_CloseDocument(doc); |
3965 return success; | 3977 return success; |
3966 } | 3978 } |
3967 | 3979 |
3968 } // namespace chrome_pdf | 3980 } // namespace chrome_pdf |
OLD | NEW |