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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 870453002: Make the scripting OOP PDF API easier to use (take 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « pdf/out_of_process_instance.h ('k') | no next file » | 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 first_paint_(true), 260 first_paint_(true),
261 document_load_state_(LOAD_STATE_LOADING), 261 document_load_state_(LOAD_STATE_LOADING),
262 preview_document_load_state_(LOAD_STATE_COMPLETE), 262 preview_document_load_state_(LOAD_STATE_COMPLETE),
263 uma_(this), 263 uma_(this),
264 told_browser_about_unsupported_feature_(false), 264 told_browser_about_unsupported_feature_(false),
265 print_preview_page_count_(0), 265 print_preview_page_count_(0),
266 last_progress_sent_(0), 266 last_progress_sent_(0),
267 recently_sent_find_update_(false), 267 recently_sent_find_update_(false),
268 received_viewport_message_(false), 268 received_viewport_message_(false),
269 did_call_start_loading_(false), 269 did_call_start_loading_(false),
270 stop_scrolling_(false), 270 stop_scrolling_(false) {
271 delay_print_(false) {
272 loader_factory_.Initialize(this); 271 loader_factory_.Initialize(this);
273 timer_factory_.Initialize(this); 272 timer_factory_.Initialize(this);
274 form_factory_.Initialize(this); 273 form_factory_.Initialize(this);
275 print_callback_factory_.Initialize(this); 274 print_callback_factory_.Initialize(this);
276 engine_.reset(PDFEngine::Create(this)); 275 engine_.reset(PDFEngine::Create(this));
277 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 276 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
278 AddPerInstanceObject(kPPPPdfInterface, this); 277 AddPerInstanceObject(kPPPPdfInterface, this);
279 278
280 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 279 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
281 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 280 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 message.Set(pp::Var(kJSEmailBcc), 962 message.Set(pp::Var(kJSEmailBcc),
964 pp::Var(net::EscapeUrlEncodedData(bcc, false))); 963 pp::Var(net::EscapeUrlEncodedData(bcc, false)));
965 message.Set(pp::Var(kJSEmailSubject), 964 message.Set(pp::Var(kJSEmailSubject),
966 pp::Var(net::EscapeUrlEncodedData(subject, false))); 965 pp::Var(net::EscapeUrlEncodedData(subject, false)));
967 message.Set(pp::Var(kJSEmailBody), 966 message.Set(pp::Var(kJSEmailBody),
968 pp::Var(net::EscapeUrlEncodedData(body, false))); 967 pp::Var(net::EscapeUrlEncodedData(body, false)));
969 PostMessage(message); 968 PostMessage(message);
970 } 969 }
971 970
972 void OutOfProcessInstance::Print() { 971 void OutOfProcessInstance::Print() {
973 if (document_load_state_ == LOAD_STATE_LOADING) {
974 delay_print_ = true;
975 return;
976 }
977
978 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && 972 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
979 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { 973 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
980 return; 974 return;
981 } 975 }
982 976
983 pp::CompletionCallback callback = 977 pp::CompletionCallback callback =
984 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); 978 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint);
985 pp::Module::Get()->core()->CallOnMainThread(0, callback); 979 pp::Module::Get()->core()->CallOnMainThread(0, callback);
986 } 980 }
987 981
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 pp::VarDictionary bookmarks_message; 1089 pp::VarDictionary bookmarks_message;
1096 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); 1090 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType));
1097 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); 1091 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks());
1098 PostMessage(bookmarks_message); 1092 PostMessage(bookmarks_message);
1099 1093
1100 pp::VarDictionary progress_message; 1094 pp::VarDictionary progress_message;
1101 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); 1095 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
1102 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); 1096 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100));
1103 PostMessage(progress_message); 1097 PostMessage(progress_message);
1104 1098
1105 if (full_) { 1099 if (!full_)
1106 if (did_call_start_loading_) { 1100 return;
1107 pp::PDF::DidStopLoading(this);
1108 did_call_start_loading_ = false;
1109 }
1110 1101
1111 int content_restrictions = 1102 if (did_call_start_loading_) {
1112 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; 1103 pp::PDF::DidStopLoading(this);
1113 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 1104 did_call_start_loading_ = false;
1114 content_restrictions |= CONTENT_RESTRICTION_COPY;
1115
1116 pp::PDF::SetContentRestriction(this, content_restrictions);
1117
1118 uma_.HistogramCustomCounts("PDF.PageCount", page_count,
1119 1, 1000000, 50);
1120 } 1105 }
1121 1106
1122 if (delay_print_) 1107 int content_restrictions =
1123 Print(); 1108 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE;
1109 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY))
1110 content_restrictions |= CONTENT_RESTRICTION_COPY;
1111
1112 pp::PDF::SetContentRestriction(this, content_restrictions);
1113
1114 uma_.HistogramCustomCounts("PDF.PageCount", page_count,
1115 1, 1000000, 50);
1124 } 1116 }
1125 1117
1126 void OutOfProcessInstance::RotateClockwise() { 1118 void OutOfProcessInstance::RotateClockwise() {
1127 engine_->RotateClockwise(); 1119 engine_->RotateClockwise();
1128 } 1120 }
1129 1121
1130 void OutOfProcessInstance::RotateCounterclockwise() { 1122 void OutOfProcessInstance::RotateCounterclockwise() {
1131 engine_->RotateCounterclockwise(); 1123 engine_->RotateCounterclockwise();
1132 } 1124 }
1133 1125
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1375 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1384 const pp::FloatPoint& scroll_offset) { 1376 const pp::FloatPoint& scroll_offset) {
1385 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1377 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1386 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1378 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1387 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1379 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1388 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); 1380 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
1389 return pp::FloatPoint(x, y); 1381 return pp::FloatPoint(x, y);
1390 } 1382 }
1391 1383
1392 } // namespace chrome_pdf 1384 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698