OLD | NEW |
---|---|
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 const char kJSRotateClockwiseType[] = "rotateClockwise"; | 126 const char kJSRotateClockwiseType[] = "rotateClockwise"; |
127 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; | 127 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; |
128 // Select all text in the document (Page -> Plugin) | 128 // Select all text in the document (Page -> Plugin) |
129 const char kJSSelectAllType[] = "selectAll"; | 129 const char kJSSelectAllType[] = "selectAll"; |
130 // Get the selected text in the document (Page -> Plugin) | 130 // Get the selected text in the document (Page -> Plugin) |
131 const char kJSGetSelectedTextType[] = "getSelectedText"; | 131 const char kJSGetSelectedTextType[] = "getSelectedText"; |
132 // Reply with selected text (Plugin -> Page) | 132 // Reply with selected text (Plugin -> Page) |
133 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; | 133 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; |
134 const char kJSSelectedText[] = "selectedText"; | 134 const char kJSSelectedText[] = "selectedText"; |
135 | 135 |
136 // List of named destinations (Plugin -> Page) | |
137 const char kJSSetNamedDestinations[] = "setNamedDestinations"; | |
raymes
2015/01/15 04:51:11
nit kJSSetNamedDestinationsType
Deepak
2015/01/15 06:30:06
Done.
| |
138 const char kJSNamedDestinations[] = "namedDestinations"; | |
139 | |
136 const int kFindResultCooldownMs = 100; | 140 const int kFindResultCooldownMs = 100; |
137 | 141 |
138 const double kMinZoom = 0.01; | 142 const double kMinZoom = 0.01; |
139 | 143 |
140 namespace { | 144 namespace { |
141 | 145 |
142 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 146 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
143 | 147 |
144 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 148 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { |
145 pp::Var var; | 149 pp::Var var; |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 return; | 843 return; |
840 | 844 |
841 pp::VarDictionary message; | 845 pp::VarDictionary message; |
842 message.Set(kType, kJSGoToPageType); | 846 message.Set(kType, kJSGoToPageType); |
843 message.Set(kJSPageNumber, pp::Var(page)); | 847 message.Set(kJSPageNumber, pp::Var(page)); |
844 PostMessage(message); | 848 PostMessage(message); |
845 } | 849 } |
846 | 850 |
847 void OutOfProcessInstance::NavigateTo(const std::string& url, | 851 void OutOfProcessInstance::NavigateTo(const std::string& url, |
848 bool open_in_new_tab) { | 852 bool open_in_new_tab) { |
849 std::string url_copy(url); | |
850 | |
851 // Empty |url_copy| is ok, and will effectively be a reload. | |
852 // Skip the code below so an empty URL does not turn into "http://", which | |
853 // will cause GURL to fail a DCHECK. | |
854 if (!url_copy.empty()) { | |
855 // If |url_copy| starts with '#', then it's for the same URL with a | |
856 // different URL fragment. | |
857 if (url_copy[0] == '#') { | |
858 url_copy = url_ + url_copy; | |
859 } | |
860 // If there's no scheme, add http. | |
861 if (url_copy.find("://") == std::string::npos && | |
862 url_copy.find("mailto:") == std::string::npos) { | |
863 url_copy = std::string("http://") + url_copy; | |
864 } | |
865 // Make sure |url_copy| starts with a valid scheme. | |
866 if (url_copy.find("http://") != 0 && | |
867 url_copy.find("https://") != 0 && | |
868 url_copy.find("ftp://") != 0 && | |
869 url_copy.find("file://") != 0 && | |
870 url_copy.find("mailto:") != 0) { | |
871 return; | |
872 } | |
873 // Make sure |url_copy| is not only a scheme. | |
874 if (url_copy == "http://" || | |
875 url_copy == "https://" || | |
876 url_copy == "ftp://" || | |
877 url_copy == "file://" || | |
878 url_copy == "mailto:") { | |
879 return; | |
880 } | |
881 } | |
882 pp::VarDictionary message; | 853 pp::VarDictionary message; |
883 message.Set(kType, kJSNavigateType); | 854 message.Set(kType, kJSNavigateType); |
884 message.Set(kJSNavigateUrl, url_copy); | 855 message.Set(kJSNavigateUrl, url); |
885 message.Set(kJSNavigateNewTab, open_in_new_tab); | 856 message.Set(kJSNavigateNewTab, open_in_new_tab); |
886 PostMessage(message); | 857 PostMessage(message); |
887 } | 858 } |
888 | 859 |
889 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { | 860 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { |
890 if (cursor == cursor_) | 861 if (cursor == cursor_) |
891 return; | 862 return; |
892 cursor_ = cursor; | 863 cursor_ = cursor; |
893 | 864 |
894 const PPB_CursorControl_Dev* cursor_interface = | 865 const PPB_CursorControl_Dev* cursor_interface = |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 document_load_state_ = LOAD_STATE_COMPLETE; | 1070 document_load_state_ = LOAD_STATE_COMPLETE; |
1100 UserMetricsRecordAction("PDF.LoadSuccess"); | 1071 UserMetricsRecordAction("PDF.LoadSuccess"); |
1101 | 1072 |
1102 // Note: If we are in print preview mode the scroll location is retained | 1073 // Note: If we are in print preview mode the scroll location is retained |
1103 // across document loads so we don't want to scroll again and override it. | 1074 // across document loads so we don't want to scroll again and override it. |
1104 if (IsPrintPreview()) { | 1075 if (IsPrintPreview()) { |
1105 AppendBlankPrintPreviewPages(); | 1076 AppendBlankPrintPreviewPages(); |
1106 OnGeometryChanged(0, 0); | 1077 OnGeometryChanged(0, 0); |
1107 } | 1078 } |
1108 | 1079 |
1109 pp::VarDictionary message; | 1080 pp::VarDictionary named_destinations_message; |
1110 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1081 pp::VarDictionary named_destinations = engine_->GetNamedDestinations(); |
1111 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; | 1082 named_destinations_message.Set(pp::Var(kType), |
1112 PostMessage(message); | 1083 pp::Var(kJSSetNamedDestinations)); |
1084 named_destinations_message.Set(pp::Var(kJSNamedDestinations), | |
1085 pp::Var(named_destinations)); | |
1086 PostMessage(named_destinations_message); | |
1087 | |
1088 pp::VarDictionary progress_message; | |
1089 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | |
1090 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); | |
1091 PostMessage(progress_message); | |
1113 | 1092 |
1114 if (!full_) | 1093 if (!full_) |
1115 return; | 1094 return; |
1116 | 1095 |
1117 if (did_call_start_loading_) { | 1096 if (did_call_start_loading_) { |
1118 pp::PDF::DidStopLoading(this); | 1097 pp::PDF::DidStopLoading(this); |
1119 did_call_start_loading_ = false; | 1098 did_call_start_loading_ = false; |
1120 } | 1099 } |
1121 | 1100 |
1122 int content_restrictions = | 1101 int content_restrictions = |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1395 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1374 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1396 const pp::FloatPoint& scroll_offset) { | 1375 const pp::FloatPoint& scroll_offset) { |
1397 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1376 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1398 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1377 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1399 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1378 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1400 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1379 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1401 return pp::FloatPoint(x, y); | 1380 return pp::FloatPoint(x, y); |
1402 } | 1381 } |
1403 | 1382 |
1404 } // namespace chrome_pdf | 1383 } // namespace chrome_pdf |
OLD | NEW |