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 kJSNamedDestinations[] = "namedDestinations"; | |
133 // URL reference parameters. | |
134 const char kDelimiters[] = "#&"; | |
135 const char kNamedDest[] = "nameddest"; | |
136 | |
131 const int kFindResultCooldownMs = 100; | 137 const int kFindResultCooldownMs = 100; |
132 | 138 |
133 const double kMinZoom = 0.01; | 139 const double kMinZoom = 0.01; |
134 | 140 |
135 namespace { | 141 namespace { |
136 | 142 |
137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 143 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
138 | 144 |
139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 145 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { |
140 pp::Var var; | 146 pp::Var var; |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 bool open_in_new_tab) { | 841 bool open_in_new_tab) { |
836 std::string url_copy(url); | 842 std::string url_copy(url); |
837 | 843 |
838 // Empty |url_copy| is ok, and will effectively be a reload. | 844 // 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 | 845 // Skip the code below so an empty URL does not turn into "http://", which |
840 // will cause GURL to fail a DCHECK. | 846 // will cause GURL to fail a DCHECK. |
841 if (!url_copy.empty()) { | 847 if (!url_copy.empty()) { |
842 // If |url_copy| starts with '#', then it's for the same URL with a | 848 // If |url_copy| starts with '#', then it's for the same URL with a |
843 // different URL fragment. | 849 // different URL fragment. |
844 if (url_copy[0] == '#') { | 850 if (url_copy[0] == '#') { |
845 url_copy = url_ + url_copy; | 851 // if '#' is already present in |url_| then remove old fragment and add |
852 // new |url_copy| fragment. | |
853 std::size_t index = url_.find('#'); | |
854 if (index != std::string::npos) | |
855 url_copy = url_.substr(0, index) + url_copy; | |
856 else | |
857 url_copy = url_ + url_copy; | |
846 } | 858 } |
847 // If there's no scheme, add http. | 859 // If there's no scheme, add http. |
848 if (url_copy.find("://") == std::string::npos && | 860 if (url_copy.find("://") == std::string::npos && |
849 url_copy.find("mailto:") == std::string::npos) { | 861 url_copy.find("mailto:") == std::string::npos) { |
850 url_copy = std::string("http://") + url_copy; | 862 url_copy = std::string("http://") + url_copy; |
851 } | 863 } |
852 // Make sure |url_copy| starts with a valid scheme. | 864 // Make sure |url_copy| starts with a valid scheme. |
853 if (url_copy.find("http://") != 0 && | 865 if (url_copy.find("http://") != 0 && |
854 url_copy.find("https://") != 0 && | 866 url_copy.find("https://") != 0 && |
855 url_copy.find("ftp://") != 0 && | 867 url_copy.find("ftp://") != 0 && |
856 url_copy.find("file://") != 0 && | 868 url_copy.find("file://") != 0 && |
857 url_copy.find("mailto:") != 0) { | 869 url_copy.find("mailto:") != 0) { |
858 return; | 870 return; |
859 } | 871 } |
860 // Make sure |url_copy| is not only a scheme. | 872 // Make sure |url_copy| is not only a scheme. |
861 if (url_copy == "http://" || | 873 if (url_copy == "http://" || |
862 url_copy == "https://" || | 874 url_copy == "https://" || |
863 url_copy == "ftp://" || | 875 url_copy == "ftp://" || |
864 url_copy == "file://" || | 876 url_copy == "file://" || |
865 url_copy == "mailto:") { | 877 url_copy == "mailto:") { |
866 return; | 878 return; |
867 } | 879 } |
868 } | 880 } |
raymes
2015/01/11 23:08:41
Can we move all of the above code into a function
Deepak
2015/01/12 09:21:43
Done.
| |
869 pp::VarDictionary message; | 881 pp::VarDictionary message; |
870 message.Set(kType, kJSNavigateType); | 882 message.Set(kType, kJSNavigateType); |
871 message.Set(kJSNavigateUrl, url_copy); | 883 message.Set(kJSNavigateUrl, url_copy); |
872 message.Set(kJSNavigateNewTab, open_in_new_tab); | 884 message.Set(kJSNavigateNewTab, open_in_new_tab); |
873 PostMessage(message); | 885 PostMessage(message); |
874 } | 886 } |
875 | 887 |
876 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { | 888 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { |
877 if (cursor == cursor_) | 889 if (cursor == cursor_) |
878 return; | 890 return; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 UserMetricsRecordAction("PDF.LoadSuccess"); | 1099 UserMetricsRecordAction("PDF.LoadSuccess"); |
1088 | 1100 |
1089 // Note: If we are in print preview mode the scroll location is retained | 1101 // 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. | 1102 // across document loads so we don't want to scroll again and override it. |
1091 if (IsPrintPreview()) { | 1103 if (IsPrintPreview()) { |
1092 AppendBlankPrintPreviewPages(); | 1104 AppendBlankPrintPreviewPages(); |
1093 OnGeometryChanged(0, 0); | 1105 OnGeometryChanged(0, 0); |
1094 } | 1106 } |
1095 | 1107 |
1096 pp::VarDictionary message; | 1108 pp::VarDictionary message; |
1109 pp::VarDictionary named_destinations; | |
1110 GetNamedDestinations(named_destinations); | |
1097 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1111 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); |
1098 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; | 1112 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; |
1113 message.Set(pp::Var(kJSNamedDestinations), pp::Var(named_destinations)); | |
1099 PostMessage(message); | 1114 PostMessage(message); |
1100 | 1115 |
1101 if (!full_) | 1116 if (!full_) |
1102 return; | 1117 return; |
1103 | 1118 |
1104 if (did_call_start_loading_) { | 1119 if (did_call_start_loading_) { |
1105 pp::PDF::DidStopLoading(this); | 1120 pp::PDF::DidStopLoading(this); |
1106 did_call_start_loading_ = false; | 1121 did_call_start_loading_ = false; |
1107 } | 1122 } |
1108 | 1123 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1308 | 1323 |
1309 const PPB_URLLoaderTrusted* trusted_interface = | 1324 const PPB_URLLoaderTrusted* trusted_interface = |
1310 reinterpret_cast<const PPB_URLLoaderTrusted*>( | 1325 reinterpret_cast<const PPB_URLLoaderTrusted*>( |
1311 pp::Module::Get()->GetBrowserInterface( | 1326 pp::Module::Get()->GetBrowserInterface( |
1312 PPB_URLLOADERTRUSTED_INTERFACE)); | 1327 PPB_URLLOADERTRUSTED_INTERFACE)); |
1313 if (trusted_interface) | 1328 if (trusted_interface) |
1314 trusted_interface->GrantUniversalAccess(loader.pp_resource()); | 1329 trusted_interface->GrantUniversalAccess(loader.pp_resource()); |
1315 return loader; | 1330 return loader; |
1316 } | 1331 } |
1317 | 1332 |
1333 void OutOfProcessInstance::GetNamedDestinations( | |
raymes
2015/01/11 23:08:41
Can we move all of this inside pdfium_engine and j
Deepak
2015/01/12 09:21:43
Done.
| |
1334 pp::VarDictionary& named_destinations) { | |
raymes
2015/01/11 23:08:41
for future reference: we never use references that
Deepak
2015/01/12 09:21:43
Done.
| |
1335 std::vector<std::string> name_dest(engine_->GetNameDestCount()); | |
1336 engine_->GetNameDests(&name_dest); | |
1337 | |
1338 for (size_t i = 0; i < name_dest.size(); ++i) { | |
1339 std::vector<std::string> fragments; | |
1340 Tokenize(name_dest[i], kDelimiters, &fragments); | |
1341 if ((fragments.size() == 1) && | |
1342 (fragments[0].find('=') == std::string::npos)) { | |
1343 int page_number = engine_->GetNamedDestinationPage(fragments[0]); | |
1344 if (page_number >= 0) | |
1345 named_destinations.Set(fragments[0], pp::Var(page_number)); | |
1346 continue; | |
1347 } | |
1348 | |
1349 std::vector<std::string> key_value; | |
1350 base::SplitString(name_dest[i], '=', &key_value); | |
1351 if (key_value.size() != 2) | |
1352 continue; | |
1353 const std::string& key = key_value[0]; | |
1354 const std::string& value = key_value[1]; | |
1355 if (base::strcasecmp(kNamedDest, key.c_str()) == 0) { | |
1356 int page_value = engine_->GetNamedDestinationPage(value); | |
1357 if (page_value >= 0) | |
1358 named_destinations.Set(value, page_value); | |
1359 } | |
raymes
2015/01/11 23:08:41
Is all of this really needed?? Does FPDF_GetNamedD
Deepak
2015/01/12 09:21:43
I agree with you, This code currently no needed,we
| |
1360 } | |
1361 } | |
1362 | |
1318 void OutOfProcessInstance::SetZoom(double scale) { | 1363 void OutOfProcessInstance::SetZoom(double scale) { |
1319 double old_zoom = zoom_; | 1364 double old_zoom = zoom_; |
1320 zoom_ = scale; | 1365 zoom_ = scale; |
1321 OnGeometryChanged(old_zoom, device_scale_); | 1366 OnGeometryChanged(old_zoom, device_scale_); |
1322 } | 1367 } |
1323 | 1368 |
1324 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) { | 1369 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) { |
1325 pp::Var rv(pp::PDF::GetLocalizedString(this, id)); | 1370 pp::Var rv(pp::PDF::GetLocalizedString(this, id)); |
1326 if (!rv.is_string()) | 1371 if (!rv.is_string()) |
1327 return std::string(); | 1372 return std::string(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1427 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1383 const pp::FloatPoint& scroll_offset) { | 1428 const pp::FloatPoint& scroll_offset) { |
1384 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1429 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); | 1430 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(); | 1431 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); | 1432 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1388 return pp::FloatPoint(x, y); | 1433 return pp::FloatPoint(x, y); |
1389 } | 1434 } |
1390 | 1435 |
1391 } // namespace chrome_pdf | 1436 } // namespace chrome_pdf |
OLD | NEW |