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

Side by Side Diff: pdf/out_of_process_instance.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: Fixing Build error. 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
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | pdf/pdf_engine.h » ('j') | 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/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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const char kJSRotateClockwiseType[] = "rotateClockwise"; 129 const char kJSRotateClockwiseType[] = "rotateClockwise";
130 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; 130 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
131 // Select all text in the document (Page -> Plugin) 131 // Select all text in the document (Page -> Plugin)
132 const char kJSSelectAllType[] = "selectAll"; 132 const char kJSSelectAllType[] = "selectAll";
133 // Get the selected text in the document (Page -> Plugin) 133 // Get the selected text in the document (Page -> Plugin)
134 const char kJSGetSelectedTextType[] = "getSelectedText"; 134 const char kJSGetSelectedTextType[] = "getSelectedText";
135 // Reply with selected text (Plugin -> Page) 135 // Reply with selected text (Plugin -> Page)
136 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; 136 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
137 const char kJSSelectedText[] = "selectedText"; 137 const char kJSSelectedText[] = "selectedText";
138 138
139 // List of named destinations (Plugin -> Page)
140 const char kJSSetNamedDestinationsType[] = "setNamedDestinations";
141 const char kJSNamedDestinations[] = "namedDestinations";
142
139 const int kFindResultCooldownMs = 100; 143 const int kFindResultCooldownMs = 100;
140 144
141 const double kMinZoom = 0.01; 145 const double kMinZoom = 0.01;
142 146
143 namespace { 147 namespace {
144 148
145 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; 149 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
146 150
147 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { 151 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
148 pp::Var var; 152 pp::Var var;
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return; 846 return;
843 847
844 pp::VarDictionary message; 848 pp::VarDictionary message;
845 message.Set(kType, kJSGoToPageType); 849 message.Set(kType, kJSGoToPageType);
846 message.Set(kJSPageNumber, pp::Var(page)); 850 message.Set(kJSPageNumber, pp::Var(page));
847 PostMessage(message); 851 PostMessage(message);
848 } 852 }
849 853
850 void OutOfProcessInstance::NavigateTo(const std::string& url, 854 void OutOfProcessInstance::NavigateTo(const std::string& url,
851 bool open_in_new_tab) { 855 bool open_in_new_tab) {
852 std::string url_copy(url);
853
854 // Empty |url_copy| is ok, and will effectively be a reload.
855 // Skip the code below so an empty URL does not turn into "http://", which
856 // will cause GURL to fail a DCHECK.
857 if (!url_copy.empty()) {
858 // If |url_copy| starts with '#', then it's for the same URL with a
859 // different URL fragment.
860 if (url_copy[0] == '#') {
861 url_copy = url_ + url_copy;
862 }
863 // If there's no scheme, add http.
864 if (url_copy.find("://") == std::string::npos &&
865 url_copy.find("mailto:") == std::string::npos) {
866 url_copy = std::string("http://") + url_copy;
867 }
868 // Make sure |url_copy| starts with a valid scheme.
869 if (url_copy.find("http://") != 0 &&
870 url_copy.find("https://") != 0 &&
871 url_copy.find("ftp://") != 0 &&
872 url_copy.find("file://") != 0 &&
873 url_copy.find("mailto:") != 0) {
874 return;
875 }
876 // Make sure |url_copy| is not only a scheme.
877 if (url_copy == "http://" ||
878 url_copy == "https://" ||
879 url_copy == "ftp://" ||
880 url_copy == "file://" ||
881 url_copy == "mailto:") {
882 return;
883 }
884 }
885 pp::VarDictionary message; 856 pp::VarDictionary message;
886 message.Set(kType, kJSNavigateType); 857 message.Set(kType, kJSNavigateType);
887 message.Set(kJSNavigateUrl, url_copy); 858 message.Set(kJSNavigateUrl, url);
888 message.Set(kJSNavigateNewTab, open_in_new_tab); 859 message.Set(kJSNavigateNewTab, open_in_new_tab);
889 PostMessage(message); 860 PostMessage(message);
890 } 861 }
891 862
892 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { 863 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
893 if (cursor == cursor_) 864 if (cursor == cursor_)
894 return; 865 return;
895 cursor_ = cursor; 866 cursor_ = cursor;
896 867
897 const PPB_CursorControl_Dev* cursor_interface = 868 const PPB_CursorControl_Dev* cursor_interface =
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 document_load_state_ = LOAD_STATE_COMPLETE; 1073 document_load_state_ = LOAD_STATE_COMPLETE;
1103 UserMetricsRecordAction("PDF.LoadSuccess"); 1074 UserMetricsRecordAction("PDF.LoadSuccess");
1104 1075
1105 // Note: If we are in print preview mode the scroll location is retained 1076 // Note: If we are in print preview mode the scroll location is retained
1106 // across document loads so we don't want to scroll again and override it. 1077 // across document loads so we don't want to scroll again and override it.
1107 if (IsPrintPreview()) { 1078 if (IsPrintPreview()) {
1108 AppendBlankPrintPreviewPages(); 1079 AppendBlankPrintPreviewPages();
1109 OnGeometryChanged(0, 0); 1080 OnGeometryChanged(0, 0);
1110 } 1081 }
1111 1082
1112 pp::VarDictionary message; 1083 pp::VarDictionary named_destinations_message;
1113 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); 1084 pp::VarDictionary named_destinations = engine_->GetNamedDestinations();
1114 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; 1085 named_destinations_message.Set(pp::Var(kType),
1115 PostMessage(message); 1086 pp::Var(kJSSetNamedDestinationsType));
1087 named_destinations_message.Set(pp::Var(kJSNamedDestinations),
1088 pp::Var(named_destinations));
1089 PostMessage(named_destinations_message);
1090
1091 pp::VarDictionary progress_message;
1092 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
1093 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100));
1094 PostMessage(progress_message);
1116 1095
1117 pp::VarDictionary bookmarksMessage; 1096 pp::VarDictionary bookmarksMessage;
1118 bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); 1097 bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType));
1119 bookmarksMessage.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); 1098 bookmarksMessage.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks());
1120 PostMessage(bookmarksMessage); 1099 PostMessage(bookmarksMessage);
1121 1100
1122 if (!full_) 1101 if (!full_)
1123 return; 1102 return;
1124 1103
1125 if (did_call_start_loading_) { 1104 if (did_call_start_loading_) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1382 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1404 const pp::FloatPoint& scroll_offset) { 1383 const pp::FloatPoint& scroll_offset) {
1405 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1384 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1406 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1385 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1407 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1386 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1408 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); 1387 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
1409 return pp::FloatPoint(x, y); 1388 return pp::FloatPoint(x, y);
1410 } 1389 }
1411 1390
1412 } // namespace chrome_pdf 1391 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698