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 <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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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()); |
| 444 CHECK(IsPrintPreviewUrl(url_)); |
439 preview_pages_info_ = std::queue<PreviewPageInfo>(); | 445 preview_pages_info_ = std::queue<PreviewPageInfo>(); |
440 preview_document_load_state_ = LOAD_STATE_COMPLETE; | 446 preview_document_load_state_ = LOAD_STATE_COMPLETE; |
441 document_load_state_ = LOAD_STATE_LOADING; | 447 document_load_state_ = LOAD_STATE_LOADING; |
442 LoadUrl(url_); | 448 LoadUrl(url_); |
443 preview_engine_.reset(); | 449 preview_engine_.reset(); |
444 engine_.reset(PDFEngine::Create(this)); | 450 engine_.reset(PDFEngine::Create(this)); |
445 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); | 451 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); |
446 engine_->New(url_.c_str(), nullptr /* empty header */); | 452 engine_->New(url_.c_str(), nullptr /* empty header */); |
447 | 453 |
448 print_preview_page_count_ = | 454 print_preview_page_count_ = |
449 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); | 455 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); |
450 | 456 |
451 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); | 457 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); |
452 } else if (type == kJSLoadPreviewPageType && | 458 } else if (type == kJSLoadPreviewPageType && |
453 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && | 459 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && |
454 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { | 460 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { |
455 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(), | 461 |
| 462 std::string url = dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(); |
| 463 // For security reasons we crash if the URL that is trying to be loaded here |
| 464 // isn't a print preview one. |
| 465 CHECK(IsPrintPreview()); |
| 466 CHECK(IsPrintPreviewUrl(url)); |
| 467 ProcessPreviewPageInfo(url, |
456 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); | 468 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); |
457 } else if (type == kJSStopScrollingType) { | 469 } else if (type == kJSStopScrollingType) { |
458 stop_scrolling_ = true; | 470 stop_scrolling_ = true; |
459 } else if (type == kJSGetSelectedTextType) { | 471 } else if (type == kJSGetSelectedTextType) { |
460 std::string selected_text = engine_->GetSelectedText(); | 472 std::string selected_text = engine_->GetSelectedText(); |
461 // Always return unix newlines to JS. | 473 // Always return unix newlines to JS. |
462 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); | 474 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); |
463 pp::VarDictionary reply; | 475 pp::VarDictionary reply; |
464 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); | 476 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); |
465 reply.Set(pp::Var(kJSSelectedText), selected_text); | 477 reply.Set(pp::Var(kJSSelectedText), selected_text); |
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 | 1490 |
1479 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { | 1491 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { |
1480 if (print_preview_page_count_ == 0) | 1492 if (print_preview_page_count_ == 0) |
1481 return; | 1493 return; |
1482 engine_->AppendBlankPages(print_preview_page_count_); | 1494 engine_->AppendBlankPages(print_preview_page_count_); |
1483 if (!preview_pages_info_.empty()) | 1495 if (!preview_pages_info_.empty()) |
1484 LoadAvailablePreviewPage(); | 1496 LoadAvailablePreviewPage(); |
1485 } | 1497 } |
1486 | 1498 |
1487 bool OutOfProcessInstance::IsPrintPreview() { | 1499 bool OutOfProcessInstance::IsPrintPreview() { |
1488 return IsPrintPreviewUrl(url_); | 1500 return is_print_preview_; |
1489 } | 1501 } |
1490 | 1502 |
1491 uint32_t OutOfProcessInstance::GetBackgroundColor() { | 1503 uint32_t OutOfProcessInstance::GetBackgroundColor() { |
1492 return background_color_; | 1504 return background_color_; |
1493 } | 1505 } |
1494 | 1506 |
1495 void OutOfProcessInstance::CancelBrowserDownload() { | 1507 void OutOfProcessInstance::CancelBrowserDownload() { |
1496 pp::VarDictionary message; | 1508 pp::VarDictionary message; |
1497 message.Set(kType, kJSCancelStreamUrlType); | 1509 message.Set(kType, kJSCancelStreamUrlType); |
1498 PostMessage(message); | 1510 PostMessage(message); |
1499 } | 1511 } |
1500 | 1512 |
1501 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) { | 1513 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) { |
1502 pp::VarDictionary message; | 1514 pp::VarDictionary message; |
1503 message.Set(kType, kJSSetIsSelectingType); | 1515 message.Set(kType, kJSSetIsSelectingType); |
1504 message.Set(kJSIsSelecting, pp::Var(is_selecting)); | 1516 message.Set(kJSIsSelecting, pp::Var(is_selecting)); |
1505 PostMessage(message); | 1517 PostMessage(message); |
1506 } | 1518 } |
1507 | 1519 |
1508 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, | 1520 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, |
1509 int dst_page_index) { | 1521 int dst_page_index) { |
1510 if (!IsPrintPreview()) | 1522 DCHECK(IsPrintPreview()); |
1511 return; | |
1512 | 1523 |
1513 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1524 int src_page_index = ExtractPrintPreviewPageIndex(url); |
1514 if (src_page_index < 1) | 1525 if (src_page_index < 1) |
1515 return; | 1526 return; |
1516 | 1527 |
1517 preview_pages_info_.push(std::make_pair(url, dst_page_index)); | 1528 preview_pages_info_.push(std::make_pair(url, dst_page_index)); |
1518 LoadAvailablePreviewPage(); | 1529 LoadAvailablePreviewPage(); |
1519 } | 1530 } |
1520 | 1531 |
1521 void OutOfProcessInstance::LoadAvailablePreviewPage() { | 1532 void OutOfProcessInstance::LoadAvailablePreviewPage() { |
(...skipping 25 matching lines...) Expand all Loading... |
1547 const pp::FloatPoint& scroll_offset) { | 1558 const pp::FloatPoint& scroll_offset) { |
1548 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1559 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); | 1560 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1550 float min_y = -top_toolbar_height_; | 1561 float min_y = -top_toolbar_height_; |
1551 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1562 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); | 1563 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1553 return pp::FloatPoint(x, y); | 1564 return pp::FloatPoint(x, y); |
1554 } | 1565 } |
1555 | 1566 |
1556 } // namespace chrome_pdf | 1567 } // namespace chrome_pdf |
OLD | NEW |