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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 810623003: Add functions to collect bookmarks from Pdfium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor documentation change Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 213214f5311a35a1064722d5b26b97cb7d3cb06c..5c283357e2cd036678f5d6d05a76695e83f3fbea 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -30,6 +30,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"
@@ -527,6 +528,40 @@ 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 buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0);
+ if (buffer_size > 0) {
+ FPDFBookmark_GetTitle(bookmark,
+ WriteInto(&title, buffer_size), buffer_size);
+ }
+ 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)) {
+ pp::VarDictionary childDict = TraverseBookmarks(doc, child_bookmark);
Sam McNally 2014/12/17 02:48:45 child_dict or better yet, pass this directly to ch
Alexandre Carlton 2014/12/17 02:57:09 Done.
+ children.Set(child_index, childDict);
+ child_index++;
+ }
+ dict.Set(pp::Var("children"), children);
+ return dict;
+}
+
} // namespace
bool InitializeSDK(void* data) {
@@ -2297,6 +2332,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());
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698