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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 830433002: Navigation to relative fragments does not work correctly for OOP pdf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 11 months 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/fpdfppo.h" 40 #include "third_party/pdfium/fpdfsdk/include/fpdfppo.h"
40 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h" 41 #include "third_party/pdfium/fpdfsdk/include/fpdfsave.h"
41 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h" 42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h"
42 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PWL_FontMap.h" 43 #include "third_party/pdfium/fpdfsdk/include/pdfwindow/PWL_FontMap.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // do its thing and still fit within the timelimit for 60Hz. For the 86 // do its thing and still fit within the timelimit for 60Hz. For the
86 // non-composited case, this doesn't make things worse since we're still 87 // non-composited case, this doesn't make things worse since we're still
87 // painting the scrollbars > 60 Hz. 88 // painting the scrollbars > 60 Hz.
88 #define kMaxInitialProgressivePaintTimeMs 10 89 #define kMaxInitialProgressivePaintTimeMs 10
89 90
90 // Copied from printing/units.cc because we don't want to depend on printing 91 // Copied from printing/units.cc because we don't want to depend on printing
91 // since it brings in libpng which causes duplicate symbols with PDFium. 92 // since it brings in libpng which causes duplicate symbols with PDFium.
92 const int kPointsPerInch = 72; 93 const int kPointsPerInch = 72;
93 const int kPixelsPerInch = 96; 94 const int kPixelsPerInch = 96;
94 95
96 // URL reference parameters.
97 const char kDelimiters[] = "#&";
raymes 2015/01/13 01:59:32 We can remove this (see below)
Deepak 2015/01/13 08:29:08 Done.
98
95 struct ClipBox { 99 struct ClipBox {
96 float left; 100 float left;
97 float right; 101 float right;
98 float top; 102 float top;
99 float bottom; 103 float bottom;
100 }; 104 };
101 105
102 int ConvertUnit(int value, int old_unit, int new_unit) { 106 int ConvertUnit(int value, int old_unit, int new_unit) {
103 // With integer arithmetic, to divide a value with correct rounding, you need 107 // With integer arithmetic, to divide a value with correct rounding, you need
104 // to add half of the divisor value to the dividend value. You need to do the 108 // to add half of the divisor value to the dividend value. You need to do the
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 need_update = true; 1185 need_update = true;
1182 if (IsPageVisible(i)) 1186 if (IsPageVisible(i))
1183 client_->Invalidate(GetPageScreenRect(i)); 1187 client_->Invalidate(GetPageScreenRect(i));
1184 } 1188 }
1185 if (need_update) 1189 if (need_update)
1186 LoadPageInfo(true); 1190 LoadPageInfo(true);
1187 1191
1188 FinishLoadingDocument(); 1192 FinishLoadingDocument();
1189 } 1193 }
1190 1194
1195 unsigned long PDFiumEngine::GetNameDestCount() {
1196 return FPDF_CountNamedDests(doc_);
raymes 2015/01/13 01:59:32 This is quite simple, so let's inline it :)
Deepak 2015/01/13 08:29:07 Done.
Deepak 2015/01/13 08:29:08 Done.
1197 }
1198
1199 void PDFiumEngine::GetNameDests(std::vector<std::string>* name_dest) {
raymes 2015/01/13 01:59:32 Given the simplifications I mentioned below, I thi
Deepak 2015/01/13 08:29:08 Done.
1200 unsigned long count = GetNameDestCount();
1201 for (unsigned long i = 0; i < count; i++) {
1202 wchar_t* name = NULL;
raymes 2015/01/13 01:59:31 I think we should use a std::string16 and the Writ
Deepak 2015/01/13 08:29:08 done
1203 unsigned long len = 0;
1204 FPDF_DEST dest = NULL;
1205 dest = FPDF_GetNamedDest(doc_, i, name, len);
1206 if (dest) {
raymes 2015/01/13 01:59:32 -This is strange - the API documentation says it s
Deepak 2015/01/13 08:29:07 agreed
1207 name = new wchar_t[len];
1208 FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, name, len);
1209 if (dest) {
1210 name_dest->push_back(
1211 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(name)));
1212 }
1213 delete[] name;
1214 }
1215 }
1216 }
1217
1218 void PDFiumEngine::GetAllNameDests(pp::VarDictionary* named_destinations) {
1219 std::vector<std::string> name_dest(GetNameDestCount());
1220 GetNameDests(&name_dest);
1221 for (size_t i = 0; i < name_dest.size(); ++i) {
1222 std::vector<std::string> fragments;
1223 Tokenize(name_dest[i], kDelimiters, &fragments);
1224 if ((fragments.size() == 1) &&
1225 (fragments[0].find('=') == std::string::npos)) {
raymes 2015/01/13 01:59:32 I don't think we need the above 3 lines. I suspect
Deepak 2015/01/13 08:29:08 Done.
1226 int page_number = GetNamedDestinationPage(fragments[0]);
raymes 2015/01/13 01:59:32 We can just have GetNamedDestinationPage(name_dest
Deepak 2015/01/13 08:29:07 Done.
1227 if (page_number >= 0)
1228 named_destinations->Set(fragments[0], pp::Var(page_number));
1229 }
1230 }
1231 }
1232
1191 void PDFiumEngine::FinishLoadingDocument() { 1233 void PDFiumEngine::FinishLoadingDocument() {
1192 DCHECK(doc_loader_.IsDocumentComplete() && doc_); 1234 DCHECK(doc_loader_.IsDocumentComplete() && doc_);
1193 if (called_do_document_action_) 1235 if (called_do_document_action_)
1194 return; 1236 return;
1195 called_do_document_action_ = true; 1237 called_do_document_action_ = true;
1196 1238
1197 // These can only be called now, as the JS might end up needing a page. 1239 // These can only be called now, as the JS might end up needing a page.
1198 FORM_DoDocumentJSAction(form_); 1240 FORM_DoDocumentJSAction(form_);
1199 FORM_DoDocumentOpenAction(form_); 1241 FORM_DoDocumentOpenAction(form_);
1200 if (most_visible_page_ != -1) { 1242 if (most_visible_page_ != -1) {
(...skipping 2713 matching lines...) Expand 10 before | Expand all | Expand 10 after
3914 double* height) { 3956 double* height) {
3915 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3957 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3916 if (!doc) 3958 if (!doc)
3917 return false; 3959 return false;
3918 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3960 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3919 FPDF_CloseDocument(doc); 3961 FPDF_CloseDocument(doc);
3920 return success; 3962 return success;
3921 } 3963 }
3922 3964
3923 } // namespace chrome_pdf 3965 } // 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