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

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: Remove variables only used once 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
« chrome/browser/resources/pdf/pdf.js ('K') | « 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..76ed9e0fc7a73c25ea15e4a5ad8337524f2623fc 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,39 @@ 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);
raymes 2015/01/14 00:26:06 -We should use unsigned long here rather than size
Alexandre Carlton 2015/01/15 22:53:49 Done. This resolves the trailing \u0000 characters
+ if (buffer_size > 0) {
+ FPDFBookmark_GetTitle(bookmark,
+ WriteInto(&title, buffer_size), buffer_size);
+ }
raymes 2015/01/13 07:13:26 See https://codereview.chromium.org/833263003/. We
Alexandre Carlton 2015/01/15 22:53:49 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(void* data) {
@@ -2297,6 +2331,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());
« chrome/browser/resources/pdf/pdf.js ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698