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

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: Implement Sam's suggestions 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
« pdf/pdf_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) {
raymes 2014/12/16 23:35:53 Add a comment about what this returns (include det
Alexandre Carlton 2014/12/17 00:51:13 Done.
532
raymes 2014/12/16 23:35:53 nit: remove this blank line
Alexandre Carlton 2014/12/17 00:51:13 Done.
533 pp::VarDictionary dict;
534 base::string16 title;
535 size_t buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0);
536 if (buffer_size > 1) {
raymes 2014/12/16 23:35:54 buffer_size > 0
Alexandre Carlton 2014/12/17 00:51:13 Done.
537 FPDFBookmark_GetTitle(bookmark,
538 WriteInto(&title, buffer_size + 1), buffer_size);
raymes 2014/12/16 23:35:53 -buffer_size should already include the null chara
Alexandre Carlton 2014/12/17 00:51:13 Done.
539 }
540 dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title)));
541
542
raymes 2014/12/16 23:35:54 nit: remove a blink line here
Alexandre Carlton 2014/12/17 00:51:13 Done.
543 FPDF_DEST dest = FPDFBookmark_GetDest(doc, bookmark);
544 if (dest) {
545 int pageIndex = FPDFDest_GetPageIndex(doc, dest);
raymes 2014/12/16 23:35:53 we don't use camel case in chrome C++ so this shou
Alexandre Carlton 2014/12/17 00:51:13 Done.
546 dict.Set(pp::Var("page"), pp::Var(pageIndex));
547 }
raymes 2014/12/16 23:35:53 if the dest is invalid, should we still set "page"
Alexandre Carlton 2014/12/17 00:51:13 As discussed, some bookmarks don't have pages at a
548
549 pp::VarArray children;
550
551 FPDF_BOOKMARK childBookmark = FPDFBookmark_GetFirstChild(doc, bookmark);
raymes 2014/12/16 23:35:53 child_bookmark
Alexandre Carlton 2014/12/17 00:51:13 Done.
552 for (int i = 0; childBookmark != NULL; i++) {
raymes 2014/12/16 23:35:53 This is a little unconventional. Maybe just have a
Alexandre Carlton 2014/12/17 00:51:13 Done.
553 pp::VarDictionary childDict = TraverseBookmarks(doc, childBookmark);
554 children.Set(i, childDict);
555 childBookmark = FPDFBookmark_GetNextSibling(doc, childBookmark);
556 }
557 dict.Set(pp::Var("children"), children);
558 return dict;
559 }
560
530 } // namespace 561 } // namespace
531 562
532 bool InitializeSDK(void* data) { 563 bool InitializeSDK(void* data) {
533 FPDF_InitLibrary(data); 564 FPDF_InitLibrary(data);
534 565
535 #if defined(OS_LINUX) 566 #if defined(OS_LINUX)
536 // Font loading doesn't work in the renderer sandbox in Linux. 567 // Font loading doesn't work in the renderer sandbox in Linux.
537 FPDF_SetSystemFontInfo(&g_font_info); 568 FPDF_SetSystemFontInfo(&g_font_info);
538 #endif 569 #endif
539 570
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 if (pages_[i]->available()) { 2321 if (pages_[i]->available()) {
2291 selection_.push_back(PDFiumRange(pages_[i], 0, 2322 selection_.push_back(PDFiumRange(pages_[i], 0,
2292 pages_[i]->GetCharCount())); 2323 pages_[i]->GetCharCount()));
2293 } 2324 }
2294 } 2325 }
2295 2326
2296 int PDFiumEngine::GetNumberOfPages() { 2327 int PDFiumEngine::GetNumberOfPages() {
2297 return pages_.size(); 2328 return pages_.size();
2298 } 2329 }
2299 2330
2331
2332 pp::VarDictionary PDFiumEngine::GetBookmarks() {
2333 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
raymes 2014/12/16 23:35:53 as mentioned, let's pull out the array from the ro
Alexandre Carlton 2014/12/17 00:51:13 Done.
2334 return dict;
raymes 2014/12/16 23:35:53 or just: return TraverseBookmarks(doc_, NULL);
2335 }
2336
2300 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { 2337 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
2301 // Look for the destination. 2338 // Look for the destination.
2302 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); 2339 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
2303 if (!dest) { 2340 if (!dest) {
2304 // Look for a bookmark with the same name. 2341 // Look for a bookmark with the same name.
2305 base::string16 destination_wide = base::UTF8ToUTF16(destination); 2342 base::string16 destination_wide = base::UTF8ToUTF16(destination);
2306 FPDF_WIDESTRING destination_pdf_wide = 2343 FPDF_WIDESTRING destination_pdf_wide =
2307 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); 2344 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str());
2308 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); 2345 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide);
2309 if (!bookmark) 2346 if (!bookmark)
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 double* height) { 3933 double* height) {
3897 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3934 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3898 if (!doc) 3935 if (!doc)
3899 return false; 3936 return false;
3900 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3937 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3901 FPDF_CloseDocument(doc); 3938 FPDF_CloseDocument(doc);
3902 return success; 3939 return success;
3903 } 3940 }
3904 3941
3905 } // namespace chrome_pdf 3942 } // namespace chrome_pdf
OLDNEW
« pdf/pdf_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698