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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 918953002: Fix for PDFs with lots of named destinations take a long time to load. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <algorithm> // for min/max() 7 #include <algorithm> // for min/max()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 const char kJSRotateClockwiseType[] = "rotateClockwise"; 133 const char kJSRotateClockwiseType[] = "rotateClockwise";
134 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; 134 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
135 // Select all text in the document (Page -> Plugin) 135 // Select all text in the document (Page -> Plugin)
136 const char kJSSelectAllType[] = "selectAll"; 136 const char kJSSelectAllType[] = "selectAll";
137 // Get the selected text in the document (Page -> Plugin) 137 // Get the selected text in the document (Page -> Plugin)
138 const char kJSGetSelectedTextType[] = "getSelectedText"; 138 const char kJSGetSelectedTextType[] = "getSelectedText";
139 // Reply with selected text (Plugin -> Page) 139 // Reply with selected text (Plugin -> Page)
140 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; 140 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
141 const char kJSSelectedText[] = "selectedText"; 141 const char kJSSelectedText[] = "selectedText";
142 142
143 // List of named destinations (Plugin -> Page) 143 // Get the named destinations (Page -> Plugin)
144 const char kJSSetNamedDestinationsType[] = "setNamedDestinations"; 144 const char KJSGetNamedDestinationType[] = "getNamedDestination";
145 const char kJSNamedDestinations[] = "namedDestinations"; 145 const char KJSGetNamedDestination[] = "namedDestination";
146 const char KJSGetNavigationUrl[] = "navigationUrl";
147 // Reply with page number of named destination (Plugin -> Page)
148 const char kJSGetNamedDestinationReplyType[] = "getNamedDestinationReply";
149 const char kJSNamedDestinationPageNumber[] = "namedDestinationPageNumber";
146 150
147 const int kFindResultCooldownMs = 100; 151 const int kFindResultCooldownMs = 100;
148 152
149 const double kMinZoom = 0.01; 153 const double kMinZoom = 0.01;
150 154
151 namespace { 155 namespace {
152 156
153 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; 157 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
154 158
155 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { 159 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } else if (type == kJSStopScrollingType) { 473 } else if (type == kJSStopScrollingType) {
470 stop_scrolling_ = true; 474 stop_scrolling_ = true;
471 } else if (type == kJSGetSelectedTextType) { 475 } else if (type == kJSGetSelectedTextType) {
472 std::string selected_text = engine_->GetSelectedText(); 476 std::string selected_text = engine_->GetSelectedText();
473 // Always return unix newlines to JS. 477 // Always return unix newlines to JS.
474 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); 478 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
475 pp::VarDictionary reply; 479 pp::VarDictionary reply;
476 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); 480 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
477 reply.Set(pp::Var(kJSSelectedText), selected_text); 481 reply.Set(pp::Var(kJSSelectedText), selected_text);
478 PostMessage(reply); 482 PostMessage(reply);
483 } else if (type == KJSGetNamedDestinationType &&
484 dict.Get(pp::Var(KJSGetNamedDestination)).is_string()) {
485 int page_number = engine_->GetNamedDestinationPage(
486 dict.Get(pp::Var(KJSGetNamedDestination)).AsString());
487 pp::VarDictionary reply;
488 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType));
489 if (dict.Get(pp::Var(KJSGetNavigationUrl)).is_string())
490 reply.Set(pp::Var(KJSGetNavigationUrl),
491 dict.Get(pp::Var(KJSGetNavigationUrl)));
492 if (page_number >= 0)
493 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number);
494 PostMessage(reply);
479 } else { 495 } else {
480 NOTREACHED(); 496 NOTREACHED();
481 } 497 }
482 } 498 }
483 499
484 bool OutOfProcessInstance::HandleInputEvent( 500 bool OutOfProcessInstance::HandleInputEvent(
485 const pp::InputEvent& event) { 501 const pp::InputEvent& event) {
486 // To simplify things, convert the event into device coordinates if it is 502 // To simplify things, convert the event into device coordinates if it is
487 // a mouse event. 503 // a mouse event.
488 pp::InputEvent event_device_res(event); 504 pp::InputEvent event_device_res(event);
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 document_load_state_ = LOAD_STATE_COMPLETE; 1100 document_load_state_ = LOAD_STATE_COMPLETE;
1085 UserMetricsRecordAction("PDF.LoadSuccess"); 1101 UserMetricsRecordAction("PDF.LoadSuccess");
1086 1102
1087 // Note: If we are in print preview mode the scroll location is retained 1103 // Note: If we are in print preview mode the scroll location is retained
1088 // across document loads so we don't want to scroll again and override it. 1104 // across document loads so we don't want to scroll again and override it.
1089 if (IsPrintPreview()) { 1105 if (IsPrintPreview()) {
1090 AppendBlankPrintPreviewPages(); 1106 AppendBlankPrintPreviewPages();
1091 OnGeometryChanged(0, 0); 1107 OnGeometryChanged(0, 0);
1092 } 1108 }
1093 1109
1094 pp::VarDictionary named_destinations_message;
1095 pp::VarDictionary named_destinations = engine_->GetNamedDestinations();
1096 named_destinations_message.Set(pp::Var(kType),
1097 pp::Var(kJSSetNamedDestinationsType));
1098 named_destinations_message.Set(pp::Var(kJSNamedDestinations),
1099 pp::Var(named_destinations));
1100 PostMessage(named_destinations_message);
1101
1102 pp::VarDictionary bookmarks_message; 1110 pp::VarDictionary bookmarks_message;
1103 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); 1111 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType));
1104 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); 1112 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks());
1105 PostMessage(bookmarks_message); 1113 PostMessage(bookmarks_message);
1106 1114
1107 pp::VarDictionary progress_message; 1115 pp::VarDictionary progress_message;
1108 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); 1116 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
1109 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); 1117 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100));
1110 PostMessage(progress_message); 1118 PostMessage(progress_message);
1111 1119
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1400 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1393 const pp::FloatPoint& scroll_offset) { 1401 const pp::FloatPoint& scroll_offset) {
1394 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1402 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1395 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1403 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1396 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1404 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1397 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); 1405 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
1398 return pp::FloatPoint(x, y); 1406 return pp::FloatPoint(x, y);
1399 } 1407 }
1400 1408
1401 } // namespace chrome_pdf 1409 } // namespace chrome_pdf
OLDNEW
« chrome/browser/resources/pdf/pdf.js ('K') | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698