summaryrefslogtreecommitdiffstats
path: root/pdf
diff options
context:
space:
mode:
authoralexandrec <alexandrec@chromium.org>2015-01-18 19:43:44 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-19 03:44:44 +0000
commit6a36d4d1cc5e7d31d578c077bbf92a84d02a7578 (patch)
tree22550825d5d6fdd01a37f2d361065a59ccc2c5f6 /pdf
parentbdf88951860ff4ed1df66f632416b19a39aa2469 (diff)
downloadchromium_src-6a36d4d1cc5e7d31d578c077bbf92a84d02a7578.zip
chromium_src-6a36d4d1cc5e7d31d578c077bbf92a84d02a7578.tar.gz
chromium_src-6a36d4d1cc5e7d31d578c077bbf92a84d02a7578.tar.bz2
Add functions to collect bookmarks from Pdfium
TraverseBookmarks() collects the bookmarks into a VarDictionary, with the following key/values: - title - page (if one is available) - children, a VarArray of bookmarks (each a VarDictionary with the same structure) BUG=110020 Review URL: https://codereview.chromium.org/810623003 Cr-Commit-Position: refs/heads/master@{#312059}
Diffstat (limited to 'pdf')
-rw-r--r--pdf/out_of_process_instance.cc8
-rw-r--r--pdf/pdf_engine.h9
-rw-r--r--pdf/pdfium/pdfium_engine.cc46
-rw-r--r--pdf/pdfium/pdfium_engine.h2
4 files changed, 65 insertions, 0 deletions
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index 4e76e32..f9a7031 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -73,6 +73,9 @@ const char kJSPageHeight[] = "height";
// Document load progress arguments (Plugin -> Page)
const char kJSLoadProgressType[] = "loadProgress";
const char kJSProgressPercentage[] = "progress";
+// Bookmarks
+const char kJSBookmarksType[] = "bookmarks";
+const char kJSBookmarks[] = "bookmarks";
// Get password arguments (Plugin -> Page)
const char kJSGetPasswordType[] = "getPassword";
// Get password complete arguments (Page -> Plugin)
@@ -1111,6 +1114,11 @@ void OutOfProcessInstance::DocumentLoadComplete(int page_count) {
message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ;
PostMessage(message);
+ pp::VarDictionary bookmarksMessage;
+ bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType));
+ bookmarksMessage.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks());
+ PostMessage(bookmarksMessage);
+
if (!full_)
return;
diff --git a/pdf/pdf_engine.h b/pdf/pdf_engine.h
index b81494f..a9f828e5 100644
--- a/pdf/pdf_engine.h
+++ b/pdf/pdf_engine.h
@@ -24,6 +24,7 @@
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/url_loader.h"
+#include "ppapi/cpp/var_array.h"
namespace pp {
class InputEvent;
@@ -246,6 +247,14 @@ class PDFEngine {
// Returns number of copies to be printed.
virtual int GetCopiesToPrint() = 0;
+ // Returns a VarArray of Bookmarks, each a VarDictionary containing the
+ // following key/values:
+ // - "title" - a string Var.
+ // - "page" - an int Var.
+ // - "children" - a VarArray(), with each entry containing a VarDictionary of
+ // the same structure.
+ virtual pp::VarArray GetBookmarks() = 0;
+
// Append blank pages to make a 1-page document to a |num_pages| document.
// Always retain the first page data.
virtual void AppendBlankPages(int num_pages) = 0;
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 29ef475..6066f34 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,44 @@ 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;
+ unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0);
+ size_t title_length = buffer_size / sizeof(base::string16::value_type);
+
+ if (title_length > 0) {
+ PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(
+ &title, title_length, true);
+ void* data = api_string_adapter.GetData();
+ FPDFBookmark_GetTitle(bookmark, data, buffer_size);
+ api_string_adapter.Close(title_length);
+ }
+ 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() {
@@ -2320,6 +2359,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());
diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h
index 960c5f2..cf1fe052 100644
--- a/pdf/pdfium/pdfium_engine.h
+++ b/pdf/pdfium/pdfium_engine.h
@@ -20,6 +20,7 @@
#include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/var_array.h"
#include "third_party/pdfium/fpdfsdk/include/fpdf_dataavail.h"
#include "third_party/pdfium/fpdfsdk/include/fpdf_progressive.h"
#include "third_party/pdfium/fpdfsdk/include/fpdfformfill.h"
@@ -78,6 +79,7 @@ class PDFiumEngine : public PDFEngine,
virtual bool HasPermission(DocumentPermission permission) const;
virtual void SelectAll();
virtual int GetNumberOfPages();
+ virtual pp::VarArray GetBookmarks();
virtual int GetNamedDestinationPage(const std::string& destination);
virtual int GetFirstVisiblePage();
virtual int GetMostVisiblePage();