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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } // namespace | 248 } // namespace |
249 | 249 |
250 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) | 250 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) |
251 : pp::Instance(instance), | 251 : pp::Instance(instance), |
252 pp::Find_Private(this), | 252 pp::Find_Private(this), |
253 pp::Printing_Dev(this), | 253 pp::Printing_Dev(this), |
254 pp::Selection_Dev(this), | 254 pp::Selection_Dev(this), |
255 cursor_(PP_CURSORTYPE_POINTER), | 255 cursor_(PP_CURSORTYPE_POINTER), |
256 zoom_(1.0), | 256 zoom_(1.0), |
257 device_scale_(1.0), | 257 device_scale_(1.0), |
258 printing_enabled_(true), | |
259 full_(false), | 258 full_(false), |
260 paint_manager_(this, this, true), | 259 paint_manager_(this, this, true), |
261 first_paint_(true), | 260 first_paint_(true), |
262 document_load_state_(LOAD_STATE_LOADING), | 261 document_load_state_(LOAD_STATE_LOADING), |
263 preview_document_load_state_(LOAD_STATE_COMPLETE), | 262 preview_document_load_state_(LOAD_STATE_COMPLETE), |
264 uma_(this), | 263 uma_(this), |
265 told_browser_about_unsupported_feature_(false), | 264 told_browser_about_unsupported_feature_(false), |
266 print_preview_page_count_(0), | 265 print_preview_page_count_(0), |
267 last_progress_sent_(0), | 266 last_progress_sent_(0), |
268 recently_sent_find_update_(false), | 267 recently_sent_find_update_(false), |
269 received_viewport_message_(false), | 268 received_viewport_message_(false), |
270 did_call_start_loading_(false), | 269 did_call_start_loading_(false), |
271 stop_scrolling_(false) { | 270 stop_scrolling_(false), |
| 271 delay_print_(false) { |
272 loader_factory_.Initialize(this); | 272 loader_factory_.Initialize(this); |
273 timer_factory_.Initialize(this); | 273 timer_factory_.Initialize(this); |
274 form_factory_.Initialize(this); | 274 form_factory_.Initialize(this); |
275 print_callback_factory_.Initialize(this); | 275 print_callback_factory_.Initialize(this); |
276 engine_.reset(PDFEngine::Create(this)); | 276 engine_.reset(PDFEngine::Create(this)); |
277 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 277 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
278 AddPerInstanceObject(kPPPPdfInterface, this); | 278 AddPerInstanceObject(kPPPPdfInterface, this); |
279 | 279 |
280 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 280 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
281 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 281 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 message.Set(pp::Var(kJSEmailBcc), | 963 message.Set(pp::Var(kJSEmailBcc), |
964 pp::Var(net::EscapeUrlEncodedData(bcc, false))); | 964 pp::Var(net::EscapeUrlEncodedData(bcc, false))); |
965 message.Set(pp::Var(kJSEmailSubject), | 965 message.Set(pp::Var(kJSEmailSubject), |
966 pp::Var(net::EscapeUrlEncodedData(subject, false))); | 966 pp::Var(net::EscapeUrlEncodedData(subject, false))); |
967 message.Set(pp::Var(kJSEmailBody), | 967 message.Set(pp::Var(kJSEmailBody), |
968 pp::Var(net::EscapeUrlEncodedData(body, false))); | 968 pp::Var(net::EscapeUrlEncodedData(body, false))); |
969 PostMessage(message); | 969 PostMessage(message); |
970 } | 970 } |
971 | 971 |
972 void OutOfProcessInstance::Print() { | 972 void OutOfProcessInstance::Print() { |
973 if (!printing_enabled_ || | 973 if (document_load_state_ == LOAD_STATE_LOADING) { |
974 (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && | 974 delay_print_ = true; |
975 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) { | |
976 return; | 975 return; |
977 } | 976 } |
978 | 977 |
| 978 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && |
| 979 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { |
| 980 return; |
| 981 } |
| 982 |
979 pp::CompletionCallback callback = | 983 pp::CompletionCallback callback = |
980 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); | 984 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); |
981 pp::Module::Get()->core()->CallOnMainThread(0, callback); | 985 pp::Module::Get()->core()->CallOnMainThread(0, callback); |
982 } | 986 } |
983 | 987 |
984 void OutOfProcessInstance::OnPrint(int32_t) { | 988 void OutOfProcessInstance::OnPrint(int32_t) { |
985 pp::PDF::Print(this); | 989 pp::PDF::Print(this); |
986 } | 990 } |
987 | 991 |
988 void OutOfProcessInstance::SubmitForm(const std::string& url, | 992 void OutOfProcessInstance::SubmitForm(const std::string& url, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 } | 1085 } |
1082 | 1086 |
1083 pp::VarDictionary named_destinations_message; | 1087 pp::VarDictionary named_destinations_message; |
1084 pp::VarDictionary named_destinations = engine_->GetNamedDestinations(); | 1088 pp::VarDictionary named_destinations = engine_->GetNamedDestinations(); |
1085 named_destinations_message.Set(pp::Var(kType), | 1089 named_destinations_message.Set(pp::Var(kType), |
1086 pp::Var(kJSSetNamedDestinationsType)); | 1090 pp::Var(kJSSetNamedDestinationsType)); |
1087 named_destinations_message.Set(pp::Var(kJSNamedDestinations), | 1091 named_destinations_message.Set(pp::Var(kJSNamedDestinations), |
1088 pp::Var(named_destinations)); | 1092 pp::Var(named_destinations)); |
1089 PostMessage(named_destinations_message); | 1093 PostMessage(named_destinations_message); |
1090 | 1094 |
| 1095 pp::VarDictionary bookmarks_message; |
| 1096 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); |
| 1097 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); |
| 1098 PostMessage(bookmarks_message); |
| 1099 |
1091 pp::VarDictionary progress_message; | 1100 pp::VarDictionary progress_message; |
1092 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1101 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); |
1093 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); | 1102 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); |
1094 PostMessage(progress_message); | 1103 PostMessage(progress_message); |
1095 | 1104 |
1096 pp::VarDictionary bookmarksMessage; | 1105 if (full_) { |
1097 bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); | 1106 if (did_call_start_loading_) { |
1098 bookmarksMessage.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); | 1107 pp::PDF::DidStopLoading(this); |
1099 PostMessage(bookmarksMessage); | 1108 did_call_start_loading_ = false; |
| 1109 } |
1100 | 1110 |
1101 if (!full_) | 1111 int content_restrictions = |
1102 return; | 1112 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; |
| 1113 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
| 1114 content_restrictions |= CONTENT_RESTRICTION_COPY; |
1103 | 1115 |
1104 if (did_call_start_loading_) { | 1116 pp::PDF::SetContentRestriction(this, content_restrictions); |
1105 pp::PDF::DidStopLoading(this); | 1117 |
1106 did_call_start_loading_ = false; | 1118 uma_.HistogramCustomCounts("PDF.PageCount", page_count, |
| 1119 1, 1000000, 50); |
1107 } | 1120 } |
1108 | 1121 |
1109 int content_restrictions = | 1122 if (delay_print_) |
1110 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; | 1123 Print(); |
1111 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | |
1112 content_restrictions |= CONTENT_RESTRICTION_COPY; | |
1113 | |
1114 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && | |
1115 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { | |
1116 printing_enabled_ = false; | |
1117 } | |
1118 | |
1119 pp::PDF::SetContentRestriction(this, content_restrictions); | |
1120 | |
1121 uma_.HistogramCustomCounts("PDF.PageCount", page_count, | |
1122 1, 1000000, 50); | |
1123 } | 1124 } |
1124 | 1125 |
1125 void OutOfProcessInstance::RotateClockwise() { | 1126 void OutOfProcessInstance::RotateClockwise() { |
1126 engine_->RotateClockwise(); | 1127 engine_->RotateClockwise(); |
1127 } | 1128 } |
1128 | 1129 |
1129 void OutOfProcessInstance::RotateCounterclockwise() { | 1130 void OutOfProcessInstance::RotateCounterclockwise() { |
1130 engine_->RotateCounterclockwise(); | 1131 engine_->RotateCounterclockwise(); |
1131 } | 1132 } |
1132 | 1133 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1383 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1383 const pp::FloatPoint& scroll_offset) { | 1384 const pp::FloatPoint& scroll_offset) { |
1384 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1385 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); | 1386 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(); | 1387 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); | 1388 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1388 return pp::FloatPoint(x, y); | 1389 return pp::FloatPoint(x, y); |
1389 } | 1390 } |
1390 | 1391 |
1391 } // namespace chrome_pdf | 1392 } // namespace chrome_pdf |
OLD | NEW |