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

Side by Side 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 unified diff | Download patch
OLDNEW
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 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
23 #include "ppapi/c/ppb_core.h" 23 #include "ppapi/c/ppb_core.h"
24 #include "ppapi/c/private/ppb_pdf.h" 24 #include "ppapi/c/private/ppb_pdf.h"
25 #include "ppapi/cpp/dev/memory_dev.h" 25 #include "ppapi/cpp/dev/memory_dev.h"
26 #include "ppapi/cpp/input_event.h" 26 #include "ppapi/cpp/input_event.h"
27 #include "ppapi/cpp/instance.h" 27 #include "ppapi/cpp/instance.h"
28 #include "ppapi/cpp/module.h" 28 #include "ppapi/cpp/module.h"
29 #include "ppapi/cpp/private/pdf.h" 29 #include "ppapi/cpp/private/pdf.h"
30 #include "ppapi/cpp/trusted/browser_font_trusted.h" 30 #include "ppapi/cpp/trusted/browser_font_trusted.h"
31 #include "ppapi/cpp/url_response_info.h" 31 #include "ppapi/cpp/url_response_info.h"
32 #include "ppapi/cpp/var.h" 32 #include "ppapi/cpp/var.h"
33 #include "ppapi/cpp/var_dictionary.h"
33 #include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h" 34 #include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h"
34 #include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h" 35 #include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h"
35 #include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h" 36 #include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h"
36 #include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h" 37 #include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h"
37 #include "third_party/pdfium/fpdfsdk/include/fpdf_transformpage.h" 38 #include "third_party/pdfium/fpdfsdk/include/fpdf_transformpage.h"
38 #include "third_party/pdfium/fpdfsdk/include/fpdfedit.h" 39 #include "third_party/pdfium/fpdfsdk/include/fpdfedit.h"
39 #include "third_party/pdfium/fpdfsdk/include/fpdfoom.h" 40 #include "third_party/pdfium/fpdfsdk/include/fpdfoom.h"
40 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h" 41 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h"
41 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" 42 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h"
42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" 43 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 static const base::char16 kCr[] = {L'\r', L'\0'}; 521 static const base::char16 kCr[] = {L'\r', L'\0'};
521 static const base::char16 kBlank[] = {L'\0'}; 522 static const base::char16 kBlank[] = {L'\0'};
522 base::ReplaceChars(*text, kCr, kBlank, text); 523 base::ReplaceChars(*text, kCr, kBlank, text);
523 #elif defined(OS_WIN) 524 #elif defined(OS_WIN)
524 // Do nothing 525 // Do nothing
525 #else 526 #else
526 NOTIMPLEMENTED(); 527 NOTIMPLEMENTED();
527 #endif 528 #endif
528 } 529 }
529 530
531 // Returns a VarDictionary (representing a bookmark), which in turn contains
532 // child VarDictionaries (representing the child bookmarks).
533 // If NULL is passed in as the bookmark then we traverse from the "root".
534 // Note that the "root" bookmark contains no useful information.
535 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) {
536 pp::VarDictionary dict;
537 base::string16 title;
538 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
539 if (buffer_size > 0) {
540 FPDFBookmark_GetTitle(bookmark,
541 WriteInto(&title, buffer_size), buffer_size);
542 }
raymes 2015/01/13 07:13:26 See https://codereview.chromium.org/833263003/. We
Alexandre Carlton 2015/01/15 22:53:49 Done.
543 dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title)));
544
545 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark);
546 // Some bookmarks don't have a page to select.
547 if (dest) {
548 int page_index = FPDFDest_GetPageIndex(doc, dest);
549 dict.Set(pp::Var("page"), pp::Var(page_index));
550 }
551
552 pp::VarArray children;
553 int child_index = 0;
554 for (FPDF_BOOKMARK child_bookmark = FPDFBookmark_GetFirstChild(doc, bookmark);
555 child_bookmark != NULL;
556 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) {
557 children.Set(child_index, TraverseBookmarks(doc, child_bookmark));
558 child_index++;
559 }
560 dict.Set(pp::Var("children"), children);
561 return dict;
562 }
563
530 } // namespace 564 } // namespace
531 565
532 bool InitializeSDK(void* data) { 566 bool InitializeSDK(void* data) {
533 FPDF_InitLibrary(data); 567 FPDF_InitLibrary(data);
534 568
535 #if defined(OS_LINUX) 569 #if defined(OS_LINUX)
536 // Font loading doesn't work in the renderer sandbox in Linux. 570 // Font loading doesn't work in the renderer sandbox in Linux.
537 FPDF_SetSystemFontInfo(&g_font_info); 571 FPDF_SetSystemFontInfo(&g_font_info);
538 #endif 572 #endif
539 573
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 if (pages_[i]->available()) { 2324 if (pages_[i]->available()) {
2291 selection_.push_back(PDFiumRange(pages_[i], 0, 2325 selection_.push_back(PDFiumRange(pages_[i], 0,
2292 pages_[i]->GetCharCount())); 2326 pages_[i]->GetCharCount()));
2293 } 2327 }
2294 } 2328 }
2295 2329
2296 int PDFiumEngine::GetNumberOfPages() { 2330 int PDFiumEngine::GetNumberOfPages() {
2297 return pages_.size(); 2331 return pages_.size();
2298 } 2332 }
2299 2333
2334
2335 pp::VarArray PDFiumEngine::GetBookmarks() {
2336 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
2337 // The root bookmark contains no useful information.
2338 return pp::VarArray(dict.Get(pp::Var("children")));
2339 }
2340
2300 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { 2341 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
2301 // Look for the destination. 2342 // Look for the destination.
2302 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); 2343 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
2303 if (!dest) { 2344 if (!dest) {
2304 // Look for a bookmark with the same name. 2345 // Look for a bookmark with the same name.
2305 base::string16 destination_wide = base::UTF8ToUTF16(destination); 2346 base::string16 destination_wide = base::UTF8ToUTF16(destination);
2306 FPDF_WIDESTRING destination_pdf_wide = 2347 FPDF_WIDESTRING destination_pdf_wide =
2307 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); 2348 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str());
2308 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); 2349 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide);
2309 if (!bookmark) 2350 if (!bookmark)
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 double* height) { 3937 double* height) {
3897 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3938 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3898 if (!doc) 3939 if (!doc)
3899 return false; 3940 return false;
3900 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3941 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3901 FPDF_CloseDocument(doc); 3942 FPDF_CloseDocument(doc);
3902 return success; 3943 return success;
3903 } 3944 }
3904 3945
3905 } // namespace chrome_pdf 3946 } // namespace chrome_pdf
OLDNEW
« 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