Chromium Code Reviews| Index: pdf/pdfium/pdfium_engine.cc |
| diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
| index 87f8d65dc90e3a09695495146564febe52b6ce6c..94f018e3f10c165c17d96a5f15d5fecde0c118f8 100644 |
| --- a/pdf/pdfium/pdfium_engine.cc |
| +++ b/pdf/pdfium/pdfium_engine.cc |
| @@ -31,6 +31,7 @@ |
| #include "ppapi/cpp/trusted/browser_font_trusted.h" |
| #include "ppapi/cpp/url_response_info.h" |
| #include "ppapi/cpp/var.h" |
| +#include "ppapi/cpp/var_dictionary.h" |
| #include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h" |
| #include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h" |
| #include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h" |
| @@ -514,6 +515,48 @@ void FormatStringForOS(base::string16* text) { |
| #endif |
| } |
| +// Returns a VarDictionary (representing a bookmark), which in turn contains |
| +// child VarDictionaries (representing the child bookmarks). |
| +// If NULL is passed in as the bookmark then we traverse from the "root". |
| +// Note that the "root" bookmark contains no useful information. |
| +pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) { |
| + pp::VarDictionary dict; |
| + base::string16 title; |
| + size_t character_size = sizeof(base::string16::value_type); |
| + unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); |
| + size_t title_length = buffer_size / character_size; |
| + |
| + if (title_length > 0) { |
| + PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( |
| + &title, title_length, true); |
| + void* data = api_string_adapter.GetData(); |
| + unsigned long bytes_written = FPDFBookmark_GetTitle( |
| + bookmark, data, buffer_size); |
| + api_string_adapter.Close(bytes_written / character_size); |
|
raymes
2015/01/16 02:44:23
this should just be
api_string_adapter.Close(titl
Alexandre Carlton
2015/01/16 03:01:40
Done.
|
| + } |
| + |
| + |
|
raymes
2015/01/16 02:44:23
nit: remove the above 2 blank lines
Alexandre Carlton
2015/01/16 03:01:40
Done.
|
| + dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title))); |
| + |
| + FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark); |
| + // Some bookmarks don't have a page to select. |
| + if (dest) { |
| + int page_index = FPDFDest_GetPageIndex(doc, dest); |
| + dict.Set(pp::Var("page"), pp::Var(page_index)); |
| + } |
| + |
| + pp::VarArray children; |
| + int child_index = 0; |
| + for (FPDF_BOOKMARK child_bookmark = FPDFBookmark_GetFirstChild(doc, bookmark); |
| + child_bookmark != NULL; |
| + child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) { |
| + children.Set(child_index, TraverseBookmarks(doc, child_bookmark)); |
| + child_index++; |
| + } |
| + dict.Set(pp::Var("children"), children); |
| + return dict; |
| +} |
| + |
| } // namespace |
| bool InitializeSDK() { |
| @@ -2317,6 +2360,13 @@ int PDFiumEngine::GetNumberOfPages() { |
| return pages_.size(); |
| } |
| + |
| +pp::VarArray PDFiumEngine::GetBookmarks() { |
| + pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); |
| + // The root bookmark contains no useful information. |
| + return pp::VarArray(dict.Get(pp::Var("children"))); |
| +} |
| + |
| int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { |
| // Look for the destination. |
| FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); |