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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2486683002: Improve print preview checks in the PDF plugin (Closed)
Patch Set: Improve print preview checks in the PDF plugin Created 4 years, 1 month 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // for min/max() 10 #include <algorithm> // for min/max()
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 font_substitution_reported_(false), 286 font_substitution_reported_(false),
287 #endif 287 #endif
288 print_preview_page_count_(0), 288 print_preview_page_count_(0),
289 last_progress_sent_(0), 289 last_progress_sent_(0),
290 recently_sent_find_update_(false), 290 recently_sent_find_update_(false),
291 received_viewport_message_(false), 291 received_viewport_message_(false),
292 did_call_start_loading_(false), 292 did_call_start_loading_(false),
293 stop_scrolling_(false), 293 stop_scrolling_(false),
294 background_color_(0), 294 background_color_(0),
295 top_toolbar_height_(0), 295 top_toolbar_height_(0),
296 accessibility_state_(ACCESSIBILITY_STATE_OFF) { 296 accessibility_state_(ACCESSIBILITY_STATE_OFF),
297 is_print_preview_(false) {
297 loader_factory_.Initialize(this); 298 loader_factory_.Initialize(this);
298 timer_factory_.Initialize(this); 299 timer_factory_.Initialize(this);
299 form_factory_.Initialize(this); 300 form_factory_.Initialize(this);
300 print_callback_factory_.Initialize(this); 301 print_callback_factory_.Initialize(this);
301 engine_.reset(PDFEngine::Create(this)); 302 engine_.reset(PDFEngine::Create(this));
302 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 303 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
303 AddPerInstanceObject(kPPPPdfInterface, this); 304 AddPerInstanceObject(kPPPPdfInterface, this);
304 305
305 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 306 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
306 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 307 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
(...skipping 11 matching lines...) Expand all
318 const char* argn[], 319 const char* argn[],
319 const char* argv[]) { 320 const char* argv[]) {
320 // Check if the PDF is being loaded in the PDF chrome extension. We only allow 321 // Check if the PDF is being loaded in the PDF chrome extension. We only allow
321 // the plugin to be loaded in the extension and print preview to avoid 322 // the plugin to be loaded in the extension and print preview to avoid
322 // exposing sensitive APIs directly to external websites. 323 // exposing sensitive APIs directly to external websites.
323 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this); 324 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this);
324 if (!document_url_var.is_string()) 325 if (!document_url_var.is_string())
325 return false; 326 return false;
326 std::string document_url = document_url_var.AsString(); 327 std::string document_url = document_url_var.AsString();
327 base::StringPiece document_url_piece(document_url); 328 base::StringPiece document_url_piece(document_url);
329 is_print_preview_ = document_url_piece.starts_with(kChromePrint);
328 if (!document_url_piece.starts_with(kChromeExtension) && 330 if (!document_url_piece.starts_with(kChromeExtension) &&
329 !document_url_piece.starts_with(kChromePrint)) { 331 !is_print_preview_) {
330 return false; 332 return false;
331 } 333 }
332 334
333 // Check if the plugin is full frame. This is passed in from JS. 335 // Check if the plugin is full frame. This is passed in from JS.
334 for (uint32_t i = 0; i < argc; ++i) { 336 for (uint32_t i = 0; i < argc; ++i) {
335 if (strcmp(argn[i], "full-frame") == 0) { 337 if (strcmp(argn[i], "full-frame") == 0) {
336 full_ = true; 338 full_ = true;
337 break; 339 break;
338 } 340 }
339 } 341 }
(...skipping 30 matching lines...) Expand all
370 if (!original_url) 372 if (!original_url)
371 return false; 373 return false;
372 374
373 if (!stream_url) 375 if (!stream_url)
374 stream_url = original_url; 376 stream_url = original_url;
375 377
376 // If we're in print preview mode we don't need to load the document yet. 378 // If we're in print preview mode we don't need to load the document yet.
377 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting 379 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting
378 // it know the url to load. By not loading here we avoid loading the same 380 // it know the url to load. By not loading here we avoid loading the same
379 // document twice. 381 // document twice.
380 if (IsPrintPreviewUrl(original_url)) 382 if (IsPrintPreview())
381 return true; 383 return true;
382 384
383 LoadUrl(stream_url); 385 LoadUrl(stream_url);
384 url_ = original_url; 386 url_ = original_url;
385 pp::PDF::SetCrashData(GetPluginInstance(), original_url, top_level_url); 387 pp::PDF::SetCrashData(GetPluginInstance(), original_url, top_level_url);
386 return engine_->New(original_url, headers); 388 return engine_->New(original_url, headers);
387 } 389 }
388 390
389 void OutOfProcessInstance::HandleMessage(const pp::Var& message) { 391 void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
390 pp::VarDictionary dict(message); 392 pp::VarDictionary dict(message);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 RotateClockwise(); 431 RotateClockwise();
430 } else if (type == kJSRotateCounterclockwiseType) { 432 } else if (type == kJSRotateCounterclockwiseType) {
431 RotateCounterclockwise(); 433 RotateCounterclockwise();
432 } else if (type == kJSSelectAllType) { 434 } else if (type == kJSSelectAllType) {
433 engine_->SelectAll(); 435 engine_->SelectAll();
434 } else if (type == kJSResetPrintPreviewModeType && 436 } else if (type == kJSResetPrintPreviewModeType &&
435 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() && 437 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() &&
436 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && 438 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() &&
437 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { 439 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) {
438 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); 440 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString();
441 // For security reasons we crash if the URL that is trying to be loaded here
442 // isn't a print preview one.
443 CHECK(IsPrintPreview() && IsPrintPreviewUrl(url_));
439 preview_pages_info_ = std::queue<PreviewPageInfo>(); 444 preview_pages_info_ = std::queue<PreviewPageInfo>();
440 preview_document_load_state_ = LOAD_STATE_COMPLETE; 445 preview_document_load_state_ = LOAD_STATE_COMPLETE;
441 document_load_state_ = LOAD_STATE_LOADING; 446 document_load_state_ = LOAD_STATE_LOADING;
442 LoadUrl(url_); 447 LoadUrl(url_);
443 preview_engine_.reset(); 448 preview_engine_.reset();
444 engine_.reset(PDFEngine::Create(this)); 449 engine_.reset(PDFEngine::Create(this));
445 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); 450 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
446 engine_->New(url_.c_str(), nullptr /* empty header */); 451 engine_->New(url_.c_str(), nullptr /* empty header */);
447 452
448 print_preview_page_count_ = 453 print_preview_page_count_ =
449 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); 454 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0);
450 455
451 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 456 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
452 } else if (type == kJSLoadPreviewPageType && 457 } else if (type == kJSLoadPreviewPageType &&
453 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && 458 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
454 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { 459 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) {
455 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(), 460 // For security reasons we crash if the URL that is trying to be loaded here
461 // isn't a print preview one.
462 std::string url = dict.Get(pp::Var(kJSPreviewPageUrl)).AsString();
463 CHECK(IsPrintPreview() && IsPrintPreviewUrl(url));
Lei Zhang 2016/11/08 07:38:13 Put these as 2 separate CHECKs. Then if one fails,
raymes 2016/11/08 23:18:01 Done.
464 ProcessPreviewPageInfo(url,
456 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); 465 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt());
457 } else if (type == kJSStopScrollingType) { 466 } else if (type == kJSStopScrollingType) {
458 stop_scrolling_ = true; 467 stop_scrolling_ = true;
459 } else if (type == kJSGetSelectedTextType) { 468 } else if (type == kJSGetSelectedTextType) {
460 std::string selected_text = engine_->GetSelectedText(); 469 std::string selected_text = engine_->GetSelectedText();
461 // Always return unix newlines to JS. 470 // Always return unix newlines to JS.
462 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); 471 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
463 pp::VarDictionary reply; 472 pp::VarDictionary reply;
464 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); 473 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
465 reply.Set(pp::Var(kJSSelectedText), selected_text); 474 reply.Set(pp::Var(kJSSelectedText), selected_text);
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 1487
1479 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { 1488 void OutOfProcessInstance::AppendBlankPrintPreviewPages() {
1480 if (print_preview_page_count_ == 0) 1489 if (print_preview_page_count_ == 0)
1481 return; 1490 return;
1482 engine_->AppendBlankPages(print_preview_page_count_); 1491 engine_->AppendBlankPages(print_preview_page_count_);
1483 if (!preview_pages_info_.empty()) 1492 if (!preview_pages_info_.empty())
1484 LoadAvailablePreviewPage(); 1493 LoadAvailablePreviewPage();
1485 } 1494 }
1486 1495
1487 bool OutOfProcessInstance::IsPrintPreview() { 1496 bool OutOfProcessInstance::IsPrintPreview() {
1488 return IsPrintPreviewUrl(url_); 1497 return is_print_preview_;
1489 } 1498 }
1490 1499
1491 uint32_t OutOfProcessInstance::GetBackgroundColor() { 1500 uint32_t OutOfProcessInstance::GetBackgroundColor() {
1492 return background_color_; 1501 return background_color_;
1493 } 1502 }
1494 1503
1495 void OutOfProcessInstance::CancelBrowserDownload() { 1504 void OutOfProcessInstance::CancelBrowserDownload() {
1496 pp::VarDictionary message; 1505 pp::VarDictionary message;
1497 message.Set(kType, kJSCancelStreamUrlType); 1506 message.Set(kType, kJSCancelStreamUrlType);
1498 PostMessage(message); 1507 PostMessage(message);
1499 } 1508 }
1500 1509
1501 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) { 1510 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) {
1502 pp::VarDictionary message; 1511 pp::VarDictionary message;
1503 message.Set(kType, kJSSetIsSelectingType); 1512 message.Set(kType, kJSSetIsSelectingType);
1504 message.Set(kJSIsSelecting, pp::Var(is_selecting)); 1513 message.Set(kJSIsSelecting, pp::Var(is_selecting));
1505 PostMessage(message); 1514 PostMessage(message);
1506 } 1515 }
1507 1516
1508 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, 1517 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url,
1509 int dst_page_index) { 1518 int dst_page_index) {
1510 if (!IsPrintPreview()) 1519 DCHECK(IsPrintPreview());
1511 return;
1512 1520
1513 int src_page_index = ExtractPrintPreviewPageIndex(url); 1521 int src_page_index = ExtractPrintPreviewPageIndex(url);
1514 if (src_page_index < 1) 1522 if (src_page_index < 1)
1515 return; 1523 return;
1516 1524
1517 preview_pages_info_.push(std::make_pair(url, dst_page_index)); 1525 preview_pages_info_.push(std::make_pair(url, dst_page_index));
1518 LoadAvailablePreviewPage(); 1526 LoadAvailablePreviewPage();
1519 } 1527 }
1520 1528
1521 void OutOfProcessInstance::LoadAvailablePreviewPage() { 1529 void OutOfProcessInstance::LoadAvailablePreviewPage() {
(...skipping 25 matching lines...) Expand all
1547 const pp::FloatPoint& scroll_offset) { 1555 const pp::FloatPoint& scroll_offset) {
1548 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1556 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1549 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1557 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1550 float min_y = -top_toolbar_height_; 1558 float min_y = -top_toolbar_height_;
1551 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1559 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1552 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1560 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1553 return pp::FloatPoint(x, y); 1561 return pp::FloatPoint(x, y);
1554 } 1562 }
1555 1563
1556 } // namespace chrome_pdf 1564 } // 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