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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 const char kJSEmailCc[] = "cc"; | 121 const char kJSEmailCc[] = "cc"; |
122 const char kJSEmailBcc[] = "bcc"; | 122 const char kJSEmailBcc[] = "bcc"; |
123 const char kJSEmailSubject[] = "subject"; | 123 const char kJSEmailSubject[] = "subject"; |
124 const char kJSEmailBody[] = "body"; | 124 const char kJSEmailBody[] = "body"; |
125 // Rotation (Page -> Plugin) | 125 // Rotation (Page -> Plugin) |
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 | 130 |
131 // List of named destinations (Plugin -> Page) | |
132 const char kJSSetNamedDestinations[] = "setNamedDestinations"; | |
133 const char kJSNamedDestinations[] = "namedDestinations"; | |
134 | |
131 const int kFindResultCooldownMs = 100; | 135 const int kFindResultCooldownMs = 100; |
132 | 136 |
133 const double kMinZoom = 0.01; | 137 const double kMinZoom = 0.01; |
134 | 138 |
135 namespace { | 139 namespace { |
136 | 140 |
137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 141 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
138 | 142 |
139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 143 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { |
140 pp::Var var; | 144 pp::Var var; |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 bool open_in_new_tab) { | 839 bool open_in_new_tab) { |
836 std::string url_copy(url); | 840 std::string url_copy(url); |
837 | 841 |
838 // Empty |url_copy| is ok, and will effectively be a reload. | 842 // Empty |url_copy| is ok, and will effectively be a reload. |
839 // Skip the code below so an empty URL does not turn into "http://", which | 843 // Skip the code below so an empty URL does not turn into "http://", which |
840 // will cause GURL to fail a DCHECK. | 844 // will cause GURL to fail a DCHECK. |
841 if (!url_copy.empty()) { | 845 if (!url_copy.empty()) { |
842 // If |url_copy| starts with '#', then it's for the same URL with a | 846 // If |url_copy| starts with '#', then it's for the same URL with a |
843 // different URL fragment. | 847 // different URL fragment. |
844 if (url_copy[0] == '#') { | 848 if (url_copy[0] == '#') { |
845 url_copy = url_ + url_copy; | 849 // if '#' is already present in |url_| then remove old fragment and add |
846 } | 850 // new |url_copy| fragment. |
847 // If there's no scheme, add http. | 851 std::size_t index = url_.find('#'); |
848 if (url_copy.find("://") == std::string::npos && | 852 if (index != std::string::npos) |
849 url_copy.find("mailto:") == std::string::npos) { | 853 url_copy = url_.substr(0, index) + url_copy; |
850 url_copy = std::string("http://") + url_copy; | 854 else |
851 } | 855 url_copy = url_ + url_copy; |
852 // Make sure |url_copy| starts with a valid scheme. | |
853 if (url_copy.find("http://") != 0 && | |
854 url_copy.find("https://") != 0 && | |
855 url_copy.find("ftp://") != 0 && | |
856 url_copy.find("file://") != 0 && | |
857 url_copy.find("mailto:") != 0) { | |
858 return; | |
859 } | |
860 // Make sure |url_copy| is not only a scheme. | |
861 if (url_copy == "http://" || | |
862 url_copy == "https://" || | |
863 url_copy == "ftp://" || | |
864 url_copy == "file://" || | |
865 url_copy == "mailto:") { | |
866 return; | |
867 } | 856 } |
raymes
2015/01/13 01:59:31
Can we move this code into JS as well? We should h
Deepak
2015/01/13 08:29:07
Done.
| |
868 } | 857 } |
869 pp::VarDictionary message; | 858 pp::VarDictionary message; |
870 message.Set(kType, kJSNavigateType); | 859 message.Set(kType, kJSNavigateType); |
871 message.Set(kJSNavigateUrl, url_copy); | 860 message.Set(kJSNavigateUrl, url_copy); |
872 message.Set(kJSNavigateNewTab, open_in_new_tab); | 861 message.Set(kJSNavigateNewTab, open_in_new_tab); |
873 PostMessage(message); | 862 PostMessage(message); |
874 } | 863 } |
875 | 864 |
876 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { | 865 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { |
877 if (cursor == cursor_) | 866 if (cursor == cursor_) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 } | 1061 } |
1073 | 1062 |
1074 pp::Memory_Dev memory; | 1063 pp::Memory_Dev memory; |
1075 memory.MemFree(pp_results); | 1064 memory.MemFree(pp_results); |
1076 } | 1065 } |
1077 | 1066 |
1078 void OutOfProcessInstance::DocumentPaintOccurred() { | 1067 void OutOfProcessInstance::DocumentPaintOccurred() { |
1079 } | 1068 } |
1080 | 1069 |
1081 void OutOfProcessInstance::DocumentLoadComplete(int page_count) { | 1070 void OutOfProcessInstance::DocumentLoadComplete(int page_count) { |
1071 pp::VarDictionary named_message; | |
raymes
2015/01/13 01:59:31
nit: move this down to right above where it is use
Deepak
2015/01/13 08:29:07
Done.
| |
1072 pp::VarDictionary named_destinations; | |
1073 engine_->GetAllNameDests(&named_destinations); | |
raymes
2015/01/13 01:59:31
Can't this function just return a pp::VarDictionar
Deepak
2015/01/13 08:29:07
Done.
| |
1074 named_message.Set(pp::Var(kType), pp::Var(kJSSetNamedDestinations)); | |
1075 named_message.Set(pp::Var(kJSNamedDestinations), pp::Var(named_destinations)); | |
1076 PostMessage(named_message); | |
raymes
2015/01/13 01:59:31
nit: let's move the above code down to right above
Deepak
2015/01/13 08:29:07
Done.
| |
1077 | |
1082 // Clear focus state for OSK. | 1078 // Clear focus state for OSK. |
1083 FormTextFieldFocusChange(false); | 1079 FormTextFieldFocusChange(false); |
1084 | 1080 |
1085 DCHECK(document_load_state_ == LOAD_STATE_LOADING); | 1081 DCHECK(document_load_state_ == LOAD_STATE_LOADING); |
1086 document_load_state_ = LOAD_STATE_COMPLETE; | 1082 document_load_state_ = LOAD_STATE_COMPLETE; |
1087 UserMetricsRecordAction("PDF.LoadSuccess"); | 1083 UserMetricsRecordAction("PDF.LoadSuccess"); |
1088 | 1084 |
1089 // Note: If we are in print preview mode the scroll location is retained | 1085 // Note: If we are in print preview mode the scroll location is retained |
1090 // across document loads so we don't want to scroll again and override it. | 1086 // across document loads so we don't want to scroll again and override it. |
1091 if (IsPrintPreview()) { | 1087 if (IsPrintPreview()) { |
1092 AppendBlankPrintPreviewPages(); | 1088 AppendBlankPrintPreviewPages(); |
1093 OnGeometryChanged(0, 0); | 1089 OnGeometryChanged(0, 0); |
1094 } | 1090 } |
1095 | 1091 |
1096 pp::VarDictionary message; | 1092 pp::VarDictionary message; |
raymes
2015/01/13 01:59:31
Maybe call this progress_message now since there a
Deepak
2015/01/13 08:29:07
Done.
| |
1097 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1093 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); |
1098 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; | 1094 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; |
1099 PostMessage(message); | 1095 PostMessage(message); |
1100 | 1096 |
1101 if (!full_) | 1097 if (!full_) |
1102 return; | 1098 return; |
1103 | 1099 |
1104 if (did_call_start_loading_) { | 1100 if (did_call_start_loading_) { |
1105 pp::PDF::DidStopLoading(this); | 1101 pp::PDF::DidStopLoading(this); |
1106 did_call_start_loading_ = false; | 1102 did_call_start_loading_ = false; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1378 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1383 const pp::FloatPoint& scroll_offset) { | 1379 const pp::FloatPoint& scroll_offset) { |
1384 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1380 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1385 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1381 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1386 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1382 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1387 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1383 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1388 return pp::FloatPoint(x, y); | 1384 return pp::FloatPoint(x, y); |
1389 } | 1385 } |
1390 | 1386 |
1391 } // namespace chrome_pdf | 1387 } // namespace chrome_pdf |
OLD | NEW |