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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2828413005: Clang format pdf/ (Closed)
Patch Set: Manual tweaks Created 3 years, 8 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') | pdf/paint_aggregator.cc » ('j') | 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()
11 #define _USE_MATH_DEFINES // for M_PI 11 #define _USE_MATH_DEFINES // for M_PI
12 #include <cmath> // for log() and pow()
13 #include <math.h> 12 #include <math.h>
13 #include <cmath> // for log() and pow()
14 #include <list> 14 #include <list>
15 15
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/common/content_restriction.h" 23 #include "chrome/common/content_restriction.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 pp::Var var; 170 pp::Var var;
171 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); 171 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
172 if (object) { 172 if (object) {
173 var = static_cast<OutOfProcessInstance*>(object)->GetLinkAtPosition( 173 var = static_cast<OutOfProcessInstance*>(object)->GetLinkAtPosition(
174 pp::Point(point)); 174 pp::Point(point));
175 } 175 }
176 return var.Detach(); 176 return var.Detach();
177 } 177 }
178 178
179 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) { 179 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) {
180 void* object = 180 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
181 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
182 if (object) { 181 if (object) {
183 OutOfProcessInstance* obj_instance = 182 OutOfProcessInstance* obj_instance =
184 static_cast<OutOfProcessInstance*>(object); 183 static_cast<OutOfProcessInstance*>(object);
185 switch (type) { 184 switch (type) {
186 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: 185 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW:
187 obj_instance->RotateClockwise(); 186 obj_instance->RotateClockwise();
188 break; 187 break;
189 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: 188 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW:
190 obj_instance->RotateCounterclockwise(); 189 obj_instance->RotateCounterclockwise();
191 break; 190 break;
(...skipping 16 matching lines...) Expand all
208 void EnableAccessibility(PP_Instance instance) { 207 void EnableAccessibility(PP_Instance instance) {
209 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); 208 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
210 if (object) { 209 if (object) {
211 OutOfProcessInstance* obj_instance = 210 OutOfProcessInstance* obj_instance =
212 static_cast<OutOfProcessInstance*>(object); 211 static_cast<OutOfProcessInstance*>(object);
213 return obj_instance->EnableAccessibility(); 212 return obj_instance->EnableAccessibility();
214 } 213 }
215 } 214 }
216 215
217 const PPP_Pdf ppp_private = { 216 const PPP_Pdf ppp_private = {
218 &GetLinkAtPosition, 217 &GetLinkAtPosition, &Transform, &GetPrintPresetOptionsFromDocument,
219 &Transform, 218 &EnableAccessibility,
220 &GetPrintPresetOptionsFromDocument,
221 &EnableAccessibility,
222 }; 219 };
223 220
224 int ExtractPrintPreviewPageIndex(const std::string& src_url) { 221 int ExtractPrintPreviewPageIndex(const std::string& src_url) {
225 // Sample |src_url| format: chrome://print/id/page_index/print.pdf 222 // Sample |src_url| format: chrome://print/id/page_index/print.pdf
226 std::vector<std::string> url_substr = base::SplitString( 223 std::vector<std::string> url_substr =
227 src_url.substr(strlen(kChromePrint)), "/", 224 base::SplitString(src_url.substr(strlen(kChromePrint)), "/",
228 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 225 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
229 if (url_substr.size() != 3) 226 if (url_substr.size() != 3)
230 return -1; 227 return -1;
231 228
232 if (url_substr[2] != "print.pdf") 229 if (url_substr[2] != "print.pdf")
233 return -1; 230 return -1;
234 231
235 int page_index = 0; 232 int page_index = 0;
236 if (!base::StringToInt(url_substr[1], &page_index)) 233 if (!base::StringToInt(url_substr[1], &page_index))
237 return -1; 234 return -1;
238 return page_index; 235 return page_index;
(...skipping 21 matching lines...) Expand all
260 // replace this with a custom PPB_PDF function. 257 // replace this with a custom PPB_PDF function.
261 pp::Var ModalDialog(const pp::Instance* instance, 258 pp::Var ModalDialog(const pp::Instance* instance,
262 const std::string& type, 259 const std::string& type,
263 const std::string& message, 260 const std::string& message,
264 const std::string& default_answer) { 261 const std::string& default_answer) {
265 const PPB_Instance_Private* interface = 262 const PPB_Instance_Private* interface =
266 reinterpret_cast<const PPB_Instance_Private*>( 263 reinterpret_cast<const PPB_Instance_Private*>(
267 pp::Module::Get()->GetBrowserInterface( 264 pp::Module::Get()->GetBrowserInterface(
268 PPB_INSTANCE_PRIVATE_INTERFACE)); 265 PPB_INSTANCE_PRIVATE_INTERFACE));
269 pp::VarPrivate window(pp::PASS_REF, 266 pp::VarPrivate window(pp::PASS_REF,
270 interface->GetWindowObject(instance->pp_instance())); 267 interface->GetWindowObject(instance->pp_instance()));
271 if (default_answer.empty()) 268 if (default_answer.empty())
272 return window.Call(type, message); 269 return window.Call(type, message);
273 return window.Call(type, message, default_answer); 270 return window.Call(type, message, default_answer);
274 } 271 }
275 272
276 } // namespace 273 } // namespace
277 274
278 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) 275 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
279 : pp::Instance(instance), 276 : pp::Instance(instance),
280 pp::Find_Private(this), 277 pp::Find_Private(this),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 const char* argv[]) { 324 const char* argv[]) {
328 // Check if the PDF is being loaded in the PDF chrome extension. We only allow 325 // Check if the PDF is being loaded in the PDF chrome extension. We only allow
329 // the plugin to be loaded in the extension and print preview to avoid 326 // the plugin to be loaded in the extension and print preview to avoid
330 // exposing sensitive APIs directly to external websites. 327 // exposing sensitive APIs directly to external websites.
331 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this); 328 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this);
332 if (!document_url_var.is_string()) 329 if (!document_url_var.is_string())
333 return false; 330 return false;
334 std::string document_url = document_url_var.AsString(); 331 std::string document_url = document_url_var.AsString();
335 base::StringPiece document_url_piece(document_url); 332 base::StringPiece document_url_piece(document_url);
336 is_print_preview_ = document_url_piece.starts_with(kChromePrint); 333 is_print_preview_ = document_url_piece.starts_with(kChromePrint);
337 if (!document_url_piece.starts_with(kChromeExtension) && 334 if (!document_url_piece.starts_with(kChromeExtension) && !is_print_preview_) {
338 !is_print_preview_) {
339 return false; 335 return false;
340 } 336 }
341 337
342 // Check if the plugin is full frame. This is passed in from JS. 338 // Check if the plugin is full frame. This is passed in from JS.
343 for (uint32_t i = 0; i < argc; ++i) { 339 for (uint32_t i = 0; i < argc; ++i) {
344 if (strcmp(argn[i], "full-frame") == 0) { 340 if (strcmp(argn[i], "full-frame") == 0) {
345 full_ = true; 341 full_ = true;
346 break; 342 break;
347 } 343 }
348 } 344 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 393
398 void OutOfProcessInstance::HandleMessage(const pp::Var& message) { 394 void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
399 pp::VarDictionary dict(message); 395 pp::VarDictionary dict(message);
400 if (!dict.Get(kType).is_string()) { 396 if (!dict.Get(kType).is_string()) {
401 NOTREACHED(); 397 NOTREACHED();
402 return; 398 return;
403 } 399 }
404 400
405 std::string type = dict.Get(kType).AsString(); 401 std::string type = dict.Get(kType).AsString();
406 402
407 if (type == kJSViewportType && 403 if (type == kJSViewportType && dict.Get(pp::Var(kJSXOffset)).is_number() &&
408 dict.Get(pp::Var(kJSXOffset)).is_number() &&
409 dict.Get(pp::Var(kJSYOffset)).is_number() && 404 dict.Get(pp::Var(kJSYOffset)).is_number() &&
410 dict.Get(pp::Var(kJSZoom)).is_number() && 405 dict.Get(pp::Var(kJSZoom)).is_number() &&
411 dict.Get(pp::Var(kJSPinchPhase)).is_number()) { 406 dict.Get(pp::Var(kJSPinchPhase)).is_number()) {
412 received_viewport_message_ = true; 407 received_viewport_message_ = true;
413 stop_scrolling_ = false; 408 stop_scrolling_ = false;
414 PinchPhase pinch_phase = 409 PinchPhase pinch_phase =
415 static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt()); 410 static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt());
416 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); 411 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble();
417 double zoom_ratio = zoom / zoom_; 412 double zoom_ratio = zoom / zoom_;
418 413
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // We want to keep the paint in the middle but it must stay in the same 454 // We want to keep the paint in the middle but it must stay in the same
460 // position relative to the scroll bars. 455 // position relative to the scroll bars.
461 paint_offset = pp::Point(0, (1 - zoom_ratio) * pinch_center.y()); 456 paint_offset = pp::Point(0, (1 - zoom_ratio) * pinch_center.y());
462 scroll_delta = 457 scroll_delta =
463 pp::Point(0, (scroll_offset.y() - 458 pp::Point(0, (scroll_offset.y() -
464 scroll_offset_at_last_raster_.y() * zoom_ratio)); 459 scroll_offset_at_last_raster_.y() * zoom_ratio));
465 460
466 pinch_vector = pp::Point(); 461 pinch_vector = pp::Point();
467 last_bitmap_smaller_ = true; 462 last_bitmap_smaller_ = true;
468 } else if (last_bitmap_smaller_) { 463 } else if (last_bitmap_smaller_) {
469 pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2, 464 pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2,
470 (plugin_size_.height() / device_scale_) / 2); 465 (plugin_size_.height() / device_scale_) / 2);
471 const double zoom_when_doc_covers_plugin_width = 466 const double zoom_when_doc_covers_plugin_width =
472 zoom_ * plugin_size_.width() / GetDocumentPixelWidth(); 467 zoom_ * plugin_size_.width() / GetDocumentPixelWidth();
473 paint_offset = pp::Point( 468 paint_offset = pp::Point(
474 (1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(), 469 (1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(),
475 (1 - zoom_ratio) * pinch_center.y()); 470 (1 - zoom_ratio) * pinch_center.y());
476 pinch_vector = pp::Point(); 471 pinch_vector = pp::Point();
477 scroll_delta = 472 scroll_delta =
478 pp::Point((scroll_offset.x() - 473 pp::Point((scroll_offset.x() -
479 scroll_offset_at_last_raster_.x() * zoom_ratio), 474 scroll_offset_at_last_raster_.x() * zoom_ratio),
480 (scroll_offset.y() - 475 (scroll_offset.y() -
481 scroll_offset_at_last_raster_.y() * zoom_ratio)); 476 scroll_offset_at_last_raster_.y() * zoom_ratio));
482 } 477 }
483 478
484 paint_manager_.SetTransform(zoom_ratio, pinch_center, 479 paint_manager_.SetTransform(zoom_ratio, pinch_center,
485 pinch_vector + paint_offset + scroll_delta, 480 pinch_vector + paint_offset + scroll_delta,
486 true); 481 true);
487 needs_reraster_ = false; 482 needs_reraster_ = false;
488 return; 483 return;
489 } 484 }
490 485
491 if (pinch_phase == PINCH_UPDATE_ZOOM_OUT || pinch_phase == PINCH_END) { 486 if (pinch_phase == PINCH_UPDATE_ZOOM_OUT || pinch_phase == PINCH_END) {
492 // We reraster on pinch zoom out in order to solve the invalid regions 487 // We reraster on pinch zoom out in order to solve the invalid regions
493 // that appear after zooming out. 488 // that appear after zooming out.
494 // On pinch end the scale is again 1.f and we request a reraster 489 // On pinch end the scale is again 1.f and we request a reraster
495 // in the new position. 490 // in the new position.
496 paint_manager_.ClearTransform(); 491 paint_manager_.ClearTransform();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 547
553 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 548 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
554 } else if (type == kJSLoadPreviewPageType && 549 } else if (type == kJSLoadPreviewPageType &&
555 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && 550 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
556 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { 551 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) {
557 std::string url = dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(); 552 std::string url = dict.Get(pp::Var(kJSPreviewPageUrl)).AsString();
558 // For security reasons we crash if the URL that is trying to be loaded here 553 // For security reasons we crash if the URL that is trying to be loaded here
559 // isn't a print preview one. 554 // isn't a print preview one.
560 CHECK(IsPrintPreview()); 555 CHECK(IsPrintPreview());
561 CHECK(IsPrintPreviewUrl(url)); 556 CHECK(IsPrintPreviewUrl(url));
562 ProcessPreviewPageInfo(url, 557 ProcessPreviewPageInfo(url, dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt());
563 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt());
564 } else if (type == kJSStopScrollingType) { 558 } else if (type == kJSStopScrollingType) {
565 stop_scrolling_ = true; 559 stop_scrolling_ = true;
566 } else if (type == kJSGetSelectedTextType) { 560 } else if (type == kJSGetSelectedTextType) {
567 std::string selected_text = engine_->GetSelectedText(); 561 std::string selected_text = engine_->GetSelectedText();
568 // Always return unix newlines to JS. 562 // Always return unix newlines to JS.
569 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); 563 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
570 pp::VarDictionary reply; 564 pp::VarDictionary reply;
571 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); 565 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
572 reply.Set(pp::Var(kJSSelectedText), selected_text); 566 reply.Set(pp::Var(kJSSelectedText), selected_text);
573 PostMessage(reply); 567 PostMessage(reply);
574 } else if (type == KJSGetNamedDestinationType && 568 } else if (type == KJSGetNamedDestinationType &&
575 dict.Get(pp::Var(KJSGetNamedDestination)).is_string()) { 569 dict.Get(pp::Var(KJSGetNamedDestination)).is_string()) {
576 int page_number = engine_->GetNamedDestinationPage( 570 int page_number = engine_->GetNamedDestinationPage(
577 dict.Get(pp::Var(KJSGetNamedDestination)).AsString()); 571 dict.Get(pp::Var(KJSGetNamedDestination)).AsString());
578 pp::VarDictionary reply; 572 pp::VarDictionary reply;
579 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType)); 573 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType));
580 if (page_number >= 0) 574 if (page_number >= 0)
581 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); 575 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number);
582 PostMessage(reply); 576 PostMessage(reply);
583 } else { 577 } else {
584 NOTREACHED(); 578 NOTREACHED();
585 } 579 }
586 } 580 }
587 581
588 bool OutOfProcessInstance::HandleInputEvent( 582 bool OutOfProcessInstance::HandleInputEvent(const pp::InputEvent& event) {
589 const pp::InputEvent& event) {
590 // To simplify things, convert the event into device coordinates if it is 583 // To simplify things, convert the event into device coordinates if it is
591 // a mouse event. 584 // a mouse event.
592 pp::InputEvent event_device_res(event); 585 pp::InputEvent event_device_res(event);
593 { 586 {
594 pp::MouseInputEvent mouse_event(event); 587 pp::MouseInputEvent mouse_event(event);
595 if (!mouse_event.is_null()) { 588 if (!mouse_event.is_null()) {
596 pp::Point point = mouse_event.GetPosition(); 589 pp::Point point = mouse_event.GetPosition();
597 pp::Point movement = mouse_event.GetMovement(); 590 pp::Point movement = mouse_event.GetMovement();
598 ScalePoint(device_scale_, &point); 591 ScalePoint(device_scale_, &point);
599 ScalePoint(device_scale_, &movement); 592 ScalePoint(device_scale_, &movement);
600 mouse_event = pp::MouseInputEvent( 593 mouse_event =
601 this, 594 pp::MouseInputEvent(this, event.GetType(), event.GetTimeStamp(),
602 event.GetType(), 595 event.GetModifiers(), mouse_event.GetButton(),
603 event.GetTimeStamp(), 596 point, mouse_event.GetClickCount(), movement);
604 event.GetModifiers(),
605 mouse_event.GetButton(),
606 point,
607 mouse_event.GetClickCount(),
608 movement);
609 event_device_res = mouse_event; 597 event_device_res = mouse_event;
610 } 598 }
611 } 599 }
612 600
613 pp::InputEvent offset_event(event_device_res); 601 pp::InputEvent offset_event(event_device_res);
614 switch (offset_event.GetType()) { 602 switch (offset_event.GetType()) {
615 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 603 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
616 case PP_INPUTEVENT_TYPE_MOUSEUP: 604 case PP_INPUTEVENT_TYPE_MOUSEUP:
617 case PP_INPUTEVENT_TYPE_MOUSEMOVE: 605 case PP_INPUTEVENT_TYPE_MOUSEMOVE:
618 case PP_INPUTEVENT_TYPE_MOUSEENTER: 606 case PP_INPUTEVENT_TYPE_MOUSEENTER:
619 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { 607 case PP_INPUTEVENT_TYPE_MOUSELEAVE: {
620 pp::MouseInputEvent mouse_event(event_device_res); 608 pp::MouseInputEvent mouse_event(event_device_res);
621 pp::MouseInputEvent mouse_event_dip(event); 609 pp::MouseInputEvent mouse_event_dip(event);
622 pp::Point point = mouse_event.GetPosition(); 610 pp::Point point = mouse_event.GetPosition();
623 point.set_x(point.x() - available_area_.x()); 611 point.set_x(point.x() - available_area_.x());
624 offset_event = pp::MouseInputEvent( 612 offset_event = pp::MouseInputEvent(
625 this, 613 this, event.GetType(), event.GetTimeStamp(), event.GetModifiers(),
626 event.GetType(), 614 mouse_event.GetButton(), point, mouse_event.GetClickCount(),
627 event.GetTimeStamp(),
628 event.GetModifiers(),
629 mouse_event.GetButton(),
630 point,
631 mouse_event.GetClickCount(),
632 mouse_event.GetMovement()); 615 mouse_event.GetMovement());
633 break; 616 break;
634 } 617 }
635 default: 618 default:
636 break; 619 break;
637 } 620 }
638 if (engine_->HandleEvent(offset_event)) 621 if (engine_->HandleEvent(offset_event))
639 return true; 622 return true;
640 623
641 // Middle click is used for scrolling and is handled by the container page. 624 // Middle click is used for scrolling and is handled by the container page.
(...skipping 14 matching lines...) Expand all
656 pp::Size view_device_size(view_rect.width() * device_scale, 639 pp::Size view_device_size(view_rect.width() * device_scale,
657 view_rect.height() * device_scale); 640 view_rect.height() * device_scale);
658 641
659 if (view_device_size != plugin_size_ || device_scale != device_scale_) { 642 if (view_device_size != plugin_size_ || device_scale != device_scale_) {
660 device_scale_ = device_scale; 643 device_scale_ = device_scale;
661 plugin_dip_size_ = view_rect.size(); 644 plugin_dip_size_ = view_rect.size();
662 plugin_size_ = view_device_size; 645 plugin_size_ = view_device_size;
663 646
664 paint_manager_.SetSize(view_device_size, device_scale_); 647 paint_manager_.SetSize(view_device_size, device_scale_);
665 648
666 pp::Size new_image_data_size = PaintManager::GetNewContextSize( 649 pp::Size new_image_data_size =
667 image_data_.size(), 650 PaintManager::GetNewContextSize(image_data_.size(), plugin_size_);
668 plugin_size_);
669 if (new_image_data_size != image_data_.size()) { 651 if (new_image_data_size != image_data_.size()) {
670 image_data_ = pp::ImageData(this, 652 image_data_ = pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
671 PP_IMAGEDATAFORMAT_BGRA_PREMUL, 653 new_image_data_size, false);
672 new_image_data_size,
673 false);
674 first_paint_ = true; 654 first_paint_ = true;
675 } 655 }
676 656
677 if (image_data_.is_null()) { 657 if (image_data_.is_null()) {
678 DCHECK(plugin_size_.IsEmpty()); 658 DCHECK(plugin_size_.IsEmpty());
679 return; 659 return;
680 } 660 }
681 661
682 OnGeometryChanged(zoom_, old_device_scale); 662 OnGeometryChanged(zoom_, old_device_scale);
683 } 663 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 if (document_load_state_ == LOAD_STATE_COMPLETE) 698 if (document_load_state_ == LOAD_STATE_COMPLETE)
719 LoadAccessibility(); 699 LoadAccessibility();
720 } 700 }
721 701
722 void OutOfProcessInstance::LoadAccessibility() { 702 void OutOfProcessInstance::LoadAccessibility() {
723 accessibility_state_ = ACCESSIBILITY_STATE_LOADED; 703 accessibility_state_ = ACCESSIBILITY_STATE_LOADED;
724 PP_PrivateAccessibilityDocInfo doc_info; 704 PP_PrivateAccessibilityDocInfo doc_info;
725 doc_info.page_count = engine_->GetNumberOfPages(); 705 doc_info.page_count = engine_->GetNumberOfPages();
726 doc_info.text_accessible = PP_FromBool( 706 doc_info.text_accessible = PP_FromBool(
727 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE)); 707 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE));
728 doc_info.text_copyable = PP_FromBool( 708 doc_info.text_copyable =
729 engine_->HasPermission(PDFEngine::PERMISSION_COPY)); 709 PP_FromBool(engine_->HasPermission(PDFEngine::PERMISSION_COPY));
730 710
731 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info); 711 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info);
732 712
733 // If the document contents isn't accessible, don't send anything more. 713 // If the document contents isn't accessible, don't send anything more.
734 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || 714 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
735 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { 715 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) {
736 return; 716 return;
737 } 717 }
738 718
739 SendAccessibilityViewportInfo(); 719 SendAccessibilityViewportInfo();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 762
783 // We need to provide enough information to draw a bounding box 763 // We need to provide enough information to draw a bounding box
784 // around any arbitrary text range, but the bounding boxes of characters 764 // around any arbitrary text range, but the bounding boxes of characters
785 // we get from PDFium don't necessarily "line up". Walk through the 765 // we get from PDFium don't necessarily "line up". Walk through the
786 // characters in each text run and let the width of each character be 766 // characters in each text run and let the width of each character be
787 // the difference between the x coordinate of one character and the 767 // the difference between the x coordinate of one character and the
788 // x coordinate of the next. The rest of the bounds of each character 768 // x coordinate of the next. The rest of the bounds of each character
789 // can be computed from the bounds of the text run. 769 // can be computed from the bounds of the text run.
790 pp::FloatRect char_bounds = engine_->GetCharBounds(page_index, char_index); 770 pp::FloatRect char_bounds = engine_->GetCharBounds(page_index, char_index);
791 for (uint32_t i = 0; i < text_run_info.len - 1; i++) { 771 for (uint32_t i = 0; i < text_run_info.len - 1; i++) {
792 DCHECK_LT(char_index + i + 1, 772 DCHECK_LT(char_index + i + 1, static_cast<uint32_t>(char_count));
793 static_cast<uint32_t>(char_count)); 773 pp::FloatRect next_char_bounds =
794 pp::FloatRect next_char_bounds = engine_->GetCharBounds( 774 engine_->GetCharBounds(page_index, char_index + i + 1);
795 page_index, char_index + i + 1);
796 chars[char_index + i].char_width = next_char_bounds.x() - char_bounds.x(); 775 chars[char_index + i].char_width = next_char_bounds.x() - char_bounds.x();
797 char_bounds = next_char_bounds; 776 char_bounds = next_char_bounds;
798 } 777 }
799 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width(); 778 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width();
800 779
801 char_index += text_run_info.len; 780 char_index += text_run_info.len;
802 } 781 }
803 782
804 page_info.text_run_count = text_runs.size(); 783 page_info.text_run_count = text_runs.size();
805 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info, 784 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info,
806 text_runs.data(), chars.data()); 785 text_runs.data(), chars.data());
807 786
808 // Schedule loading the next page. 787 // Schedule loading the next page.
809 pp::CompletionCallback callback = timer_factory_.NewCallback( 788 pp::CompletionCallback callback = timer_factory_.NewCallback(
810 &OutOfProcessInstance::SendNextAccessibilityPage); 789 &OutOfProcessInstance::SendNextAccessibilityPage);
811 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, 790 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
812 callback, page_index + 1); 791 callback, page_index + 1);
813 } 792 }
814 793
815 void OutOfProcessInstance::SendAccessibilityViewportInfo() { 794 void OutOfProcessInstance::SendAccessibilityViewportInfo() {
816 PP_PrivateAccessibilityViewportInfo viewport_info; 795 PP_PrivateAccessibilityViewportInfo viewport_info;
817 viewport_info.scroll.x = 0; 796 viewport_info.scroll.x = 0;
818 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_; 797 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_;
819 viewport_info.offset = available_area_.point(); 798 viewport_info.offset = available_area_.point();
820 viewport_info.zoom = zoom_ * device_scale_; 799 viewport_info.zoom = zoom_ * device_scale_;
821 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info); 800 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info);
822 } 801 }
823 802
824 pp::Var OutOfProcessInstance::GetLinkAtPosition( 803 pp::Var OutOfProcessInstance::GetLinkAtPosition(const pp::Point& point) {
825 const pp::Point& point) {
826 pp::Point offset_point(point); 804 pp::Point offset_point(point);
827 ScalePoint(device_scale_, &offset_point); 805 ScalePoint(device_scale_, &offset_point);
828 offset_point.set_x(offset_point.x() - available_area_.x()); 806 offset_point.set_x(offset_point.x() - available_area_.x());
829 return engine_->GetLinkAtPosition(offset_point); 807 return engine_->GetLinkAtPosition(offset_point);
830 } 808 }
831 809
832 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { 810 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() {
833 return engine_->QuerySupportedPrintOutputFormats(); 811 return engine_->QuerySupportedPrintOutputFormats();
834 } 812 }
835 813
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 void OutOfProcessInstance::SelectFindResult(bool forward) { 860 void OutOfProcessInstance::SelectFindResult(bool forward) {
883 engine_->SelectFindResult(forward); 861 engine_->SelectFindResult(forward);
884 } 862 }
885 863
886 void OutOfProcessInstance::StopFind() { 864 void OutOfProcessInstance::StopFind() {
887 engine_->StopFind(); 865 engine_->StopFind();
888 tickmarks_.clear(); 866 tickmarks_.clear();
889 SetTickmarks(tickmarks_); 867 SetTickmarks(tickmarks_);
890 } 868 }
891 869
892 void OutOfProcessInstance::OnPaint( 870 void OutOfProcessInstance::OnPaint(const std::vector<pp::Rect>& paint_rects,
893 const std::vector<pp::Rect>& paint_rects, 871 std::vector<PaintManager::ReadyRect>* ready,
894 std::vector<PaintManager::ReadyRect>* ready, 872 std::vector<pp::Rect>* pending) {
895 std::vector<pp::Rect>* pending) {
896 if (image_data_.is_null()) { 873 if (image_data_.is_null()) {
897 DCHECK(plugin_size_.IsEmpty()); 874 DCHECK(plugin_size_.IsEmpty());
898 return; 875 return;
899 } 876 }
900 if (first_paint_) { 877 if (first_paint_) {
901 first_paint_ = false; 878 first_paint_ = false;
902 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); 879 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size());
903 FillRect(rect, background_color_); 880 FillRect(rect, background_color_);
904 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); 881 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
905 } 882 }
906 883
907 if (!received_viewport_message_ || !needs_reraster_) 884 if (!received_viewport_message_ || !needs_reraster_)
908 return; 885 return;
909 886
910 engine_->PrePaint(); 887 engine_->PrePaint();
911 888
912 for (const auto& paint_rect : paint_rects) { 889 for (const auto& paint_rect : paint_rects) {
913 // Intersect with plugin area since there could be pending invalidates from 890 // Intersect with plugin area since there could be pending invalidates from
914 // when the plugin area was larger. 891 // when the plugin area was larger.
915 pp::Rect rect = 892 pp::Rect rect = paint_rect.Intersect(pp::Rect(pp::Point(), plugin_size_));
916 paint_rect.Intersect(pp::Rect(pp::Point(), plugin_size_));
917 if (rect.IsEmpty()) 893 if (rect.IsEmpty())
918 continue; 894 continue;
919 895
920 pp::Rect pdf_rect = available_area_.Intersect(rect); 896 pp::Rect pdf_rect = available_area_.Intersect(rect);
921 if (!pdf_rect.IsEmpty()) { 897 if (!pdf_rect.IsEmpty()) {
922 pdf_rect.Offset(available_area_.x() * -1, 0); 898 pdf_rect.Offset(available_area_.x() * -1, 0);
923 899
924 std::vector<pp::Rect> pdf_ready; 900 std::vector<pp::Rect> pdf_ready;
925 std::vector<pp::Rect> pdf_pending; 901 std::vector<pp::Rect> pdf_pending;
926 engine_->Paint(pdf_rect, &image_data_, &pdf_ready, &pdf_pending); 902 engine_->Paint(pdf_rect, &image_data_, &pdf_ready, &pdf_pending);
927 for (auto& ready_rect : pdf_ready) { 903 for (auto& ready_rect : pdf_ready) {
928 ready_rect.Offset(available_area_.point()); 904 ready_rect.Offset(available_area_.point());
929 ready->push_back( 905 ready->push_back(
930 PaintManager::ReadyRect(ready_rect, image_data_, false)); 906 PaintManager::ReadyRect(ready_rect, image_data_, false));
931 } 907 }
932 for (auto& pending_rect : pdf_pending) { 908 for (auto& pending_rect : pdf_pending) {
933 pending_rect.Offset(available_area_.point()); 909 pending_rect.Offset(available_area_.point());
934 pending->push_back(pending_rect); 910 pending->push_back(pending_rect);
935 } 911 }
936 } 912 }
937 913
938 // Ensure the region above the first page (if any) is filled; 914 // Ensure the region above the first page (if any) is filled;
939 int32_t first_page_ypos = engine_->GetNumberOfPages() == 0 ? 915 int32_t first_page_ypos = engine_->GetNumberOfPages() == 0
940 0 : engine_->GetPageScreenRect(0).y(); 916 ? 0
917 : engine_->GetPageScreenRect(0).y();
941 if (rect.y() < first_page_ypos) { 918 if (rect.y() < first_page_ypos) {
942 pp::Rect region = rect.Intersect(pp::Rect( 919 pp::Rect region = rect.Intersect(pp::Rect(
943 pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos))); 920 pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos)));
944 ready->push_back(PaintManager::ReadyRect(region, image_data_, false)); 921 ready->push_back(PaintManager::ReadyRect(region, image_data_, false));
945 FillRect(region, background_color_); 922 FillRect(region, background_color_);
946 } 923 }
947 924
948 for (const auto& background_part : background_parts_) { 925 for (const auto& background_part : background_parts_) {
949 pp::Rect intersection = background_part.location.Intersect(rect); 926 pp::Rect intersection = background_part.location.Intersect(rect);
950 if (!intersection.IsEmpty()) { 927 if (!intersection.IsEmpty()) {
951 FillRect(intersection, background_part.color); 928 FillRect(intersection, background_part.color);
952 ready->push_back( 929 ready->push_back(
953 PaintManager::ReadyRect(intersection, image_data_, false)); 930 PaintManager::ReadyRect(intersection, image_data_, false));
954 } 931 }
955 } 932 }
956 } 933 }
957 934
958 engine_->PostPaint(); 935 engine_->PostPaint();
959 } 936 }
960 937
961 void OutOfProcessInstance::DidOpen(int32_t result) { 938 void OutOfProcessInstance::DidOpen(int32_t result) {
962 if (result == PP_OK) { 939 if (result == PP_OK) {
963 if (!engine_->HandleDocumentLoad(embed_loader_)) { 940 if (!engine_->HandleDocumentLoad(embed_loader_)) {
964 document_load_state_ = LOAD_STATE_LOADING; 941 document_load_state_ = LOAD_STATE_LOADING;
965 DocumentLoadFailed(); 942 DocumentLoadFailed();
966 } 943 }
967 } else if (result != PP_ERROR_ABORTED) { // Can happen in tests. 944 } else if (result != PP_ERROR_ABORTED) { // Can happen in tests.
968 NOTREACHED(); 945 NOTREACHED();
969 DocumentLoadFailed(); 946 DocumentLoadFailed();
970 } 947 }
971 948
972 // If it's a progressive load, cancel the stream URL request so that requests 949 // If it's a progressive load, cancel the stream URL request so that requests
973 // can be made on the original URL. 950 // can be made on the original URL.
974 // TODO(raymes): Make this clearer once the in-process plugin is deleted. 951 // TODO(raymes): Make this clearer once the in-process plugin is deleted.
975 if (engine_->IsProgressiveLoad()) { 952 if (engine_->IsProgressiveLoad()) {
976 pp::VarDictionary message; 953 pp::VarDictionary message;
977 message.Set(kType, kJSCancelStreamUrlType); 954 message.Set(kType, kJSCancelStreamUrlType);
(...skipping 17 matching lines...) Expand all
995 972
996 void OutOfProcessInstance::CalculateBackgroundParts() { 973 void OutOfProcessInstance::CalculateBackgroundParts() {
997 background_parts_.clear(); 974 background_parts_.clear();
998 int left_width = available_area_.x(); 975 int left_width = available_area_.x();
999 int right_start = available_area_.right(); 976 int right_start = available_area_.right();
1000 int right_width = abs(plugin_size_.width() - available_area_.right()); 977 int right_width = abs(plugin_size_.width() - available_area_.right());
1001 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); 978 int bottom = std::min(available_area_.bottom(), plugin_size_.height());
1002 979
1003 // Add the left, right, and bottom rectangles. Note: we assume only 980 // Add the left, right, and bottom rectangles. Note: we assume only
1004 // horizontal centering. 981 // horizontal centering.
1005 BackgroundPart part = { 982 BackgroundPart part = {pp::Rect(0, 0, left_width, bottom), background_color_};
1006 pp::Rect(0, 0, left_width, bottom),
1007 background_color_
1008 };
1009 if (!part.location.IsEmpty()) 983 if (!part.location.IsEmpty())
1010 background_parts_.push_back(part); 984 background_parts_.push_back(part);
1011 part.location = pp::Rect(right_start, 0, right_width, bottom); 985 part.location = pp::Rect(right_start, 0, right_width, bottom);
1012 if (!part.location.IsEmpty()) 986 if (!part.location.IsEmpty())
1013 background_parts_.push_back(part); 987 background_parts_.push_back(part);
1014 part.location = pp::Rect( 988 part.location =
1015 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); 989 pp::Rect(0, bottom, plugin_size_.width(), plugin_size_.height() - bottom);
1016 if (!part.location.IsEmpty()) 990 if (!part.location.IsEmpty())
1017 background_parts_.push_back(part); 991 background_parts_.push_back(part);
1018 } 992 }
1019 993
1020 int OutOfProcessInstance::GetDocumentPixelWidth() const { 994 int OutOfProcessInstance::GetDocumentPixelWidth() const {
1021 return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_)); 995 return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_));
1022 } 996 }
1023 997
1024 int OutOfProcessInstance::GetDocumentPixelHeight() const { 998 int OutOfProcessInstance::GetDocumentPixelHeight() const {
1025 return static_cast<int>( 999 return static_cast<int>(
1026 ceil(document_size_.height() * zoom_ * device_scale_)); 1000 ceil(document_size_.height() * zoom_ * device_scale_));
1027 } 1001 }
1028 1002
1029 void OutOfProcessInstance::FillRect(const pp::Rect& rect, uint32_t color) { 1003 void OutOfProcessInstance::FillRect(const pp::Rect& rect, uint32_t color) {
1030 DCHECK(!image_data_.is_null() || rect.IsEmpty()); 1004 DCHECK(!image_data_.is_null() || rect.IsEmpty());
1031 uint32_t* buffer_start = static_cast<uint32_t*>(image_data_.data()); 1005 uint32_t* buffer_start = static_cast<uint32_t*>(image_data_.data());
1032 int stride = image_data_.stride(); 1006 int stride = image_data_.stride();
1033 uint32_t* ptr = buffer_start + rect.y() * stride / 4 + rect.x(); 1007 uint32_t* ptr = buffer_start + rect.y() * stride / 4 + rect.x();
1034 int height = rect.height(); 1008 int height = rect.height();
1035 int width = rect.width(); 1009 int width = rect.width();
1036 for (int y = 0; y < height; ++y) { 1010 for (int y = 0; y < height; ++y) {
1037 for (int x = 0; x < width; ++x) 1011 for (int x = 0; x < width; ++x)
1038 *(ptr + x) = color; 1012 *(ptr + x) = color;
1039 ptr += stride /4; 1013 ptr += stride / 4;
1040 } 1014 }
1041 } 1015 }
1042 1016
1043 void OutOfProcessInstance::DocumentSizeUpdated(const pp::Size& size) { 1017 void OutOfProcessInstance::DocumentSizeUpdated(const pp::Size& size) {
1044 document_size_ = size; 1018 document_size_ = size;
1045 1019
1046 pp::VarDictionary dimensions; 1020 pp::VarDictionary dimensions;
1047 dimensions.Set(kType, kJSDocumentDimensionsType); 1021 dimensions.Set(kType, kJSDocumentDimensionsType);
1048 dimensions.Set(kJSDocumentWidth, pp::Var(document_size_.width())); 1022 dimensions.Set(kJSDocumentWidth, pp::Var(document_size_.width()));
1049 dimensions.Set(kJSDocumentHeight, pp::Var(document_size_.height())); 1023 dimensions.Set(kJSDocumentHeight, pp::Var(document_size_.height()));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 PostMessage(message); 1083 PostMessage(message);
1110 } 1084 }
1111 1085
1112 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { 1086 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
1113 if (cursor == cursor_) 1087 if (cursor == cursor_)
1114 return; 1088 return;
1115 cursor_ = cursor; 1089 cursor_ = cursor;
1116 1090
1117 const PPB_CursorControl_Dev* cursor_interface = 1091 const PPB_CursorControl_Dev* cursor_interface =
1118 reinterpret_cast<const PPB_CursorControl_Dev*>( 1092 reinterpret_cast<const PPB_CursorControl_Dev*>(
1119 pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); 1093 pp::Module::Get()->GetBrowserInterface(
1094 PPB_CURSOR_CONTROL_DEV_INTERFACE));
1120 if (!cursor_interface) { 1095 if (!cursor_interface) {
1121 NOTREACHED(); 1096 NOTREACHED();
1122 return; 1097 return;
1123 } 1098 }
1124 1099
1125 cursor_interface->SetCursor( 1100 cursor_interface->SetCursor(pp_instance(), cursor_,
1126 pp_instance(), cursor_, pp::ImageData().pp_resource(), nullptr); 1101 pp::ImageData().pp_resource(), nullptr);
1127 } 1102 }
1128 1103
1129 void OutOfProcessInstance::UpdateTickMarks( 1104 void OutOfProcessInstance::UpdateTickMarks(
1130 const std::vector<pp::Rect>& tickmarks) { 1105 const std::vector<pp::Rect>& tickmarks) {
1131 float inverse_scale = 1.0f / device_scale_; 1106 float inverse_scale = 1.0f / device_scale_;
1132 std::vector<pp::Rect> scaled_tickmarks = tickmarks; 1107 std::vector<pp::Rect> scaled_tickmarks = tickmarks;
1133 for (auto& tickmark : scaled_tickmarks) 1108 for (auto& tickmark : scaled_tickmarks)
1134 ScaleRect(inverse_scale, &tickmark); 1109 ScaleRect(inverse_scale, &tickmark);
1135 tickmarks_ = scaled_tickmarks; 1110 tickmarks_ = scaled_tickmarks;
1136 } 1111 }
1137 1112
1138 void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total, 1113 void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
1139 bool final_result) { 1114 bool final_result) {
1140 // We don't want to spam the renderer with too many updates to the number of 1115 // We don't want to spam the renderer with too many updates to the number of
1141 // find results. Don't send an update if we sent one too recently. If it's the 1116 // find results. Don't send an update if we sent one too recently. If it's the
1142 // final update, we always send it though. 1117 // final update, we always send it though.
1143 if (final_result) { 1118 if (final_result) {
1144 NumberOfFindResultsChanged(total, final_result); 1119 NumberOfFindResultsChanged(total, final_result);
1145 SetTickmarks(tickmarks_); 1120 SetTickmarks(tickmarks_);
1146 return; 1121 return;
1147 } 1122 }
1148 1123
1149 if (recently_sent_find_update_) 1124 if (recently_sent_find_update_)
1150 return; 1125 return;
1151 1126
1152 NumberOfFindResultsChanged(total, final_result); 1127 NumberOfFindResultsChanged(total, final_result);
1153 SetTickmarks(tickmarks_); 1128 SetTickmarks(tickmarks_);
1154 recently_sent_find_update_ = true; 1129 recently_sent_find_update_ = true;
1155 pp::CompletionCallback callback = 1130 pp::CompletionCallback callback = timer_factory_.NewCallback(
1156 timer_factory_.NewCallback( 1131 &OutOfProcessInstance::ResetRecentlySentFindUpdate);
1157 &OutOfProcessInstance::ResetRecentlySentFindUpdate); 1132 pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, callback,
1158 pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, 1133 0);
1159 callback, 0);
1160 } 1134 }
1161 1135
1162 void OutOfProcessInstance::NotifySelectedFindResultChanged( 1136 void OutOfProcessInstance::NotifySelectedFindResultChanged(
1163 int current_find_index) { 1137 int current_find_index) {
1164 DCHECK_GE(current_find_index, 0); 1138 DCHECK_GE(current_find_index, 0);
1165 SelectedFindResultChanged(current_find_index); 1139 SelectedFindResultChanged(current_find_index);
1166 } 1140 }
1167 1141
1168 void OutOfProcessInstance::GetDocumentPassword( 1142 void OutOfProcessInstance::GetDocumentPassword(
1169 pp::CompletionCallbackWithOutput<pp::Var> callback) { 1143 pp::CompletionCallbackWithOutput<pp::Var> callback) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 pp::URLLoader OutOfProcessInstance::CreateURLLoader() { 1240 pp::URLLoader OutOfProcessInstance::CreateURLLoader() {
1267 if (full_) { 1241 if (full_) {
1268 if (!did_call_start_loading_) { 1242 if (!did_call_start_loading_) {
1269 did_call_start_loading_ = true; 1243 did_call_start_loading_ = true;
1270 pp::PDF::DidStartLoading(this); 1244 pp::PDF::DidStartLoading(this);
1271 } 1245 }
1272 1246
1273 // Disable save and print until the document is fully loaded, since they 1247 // Disable save and print until the document is fully loaded, since they
1274 // would generate an incomplete document. Need to do this each time we 1248 // would generate an incomplete document. Need to do this each time we
1275 // call DidStartLoading since that resets the content restrictions. 1249 // call DidStartLoading since that resets the content restrictions.
1276 pp::PDF::SetContentRestriction(this, CONTENT_RESTRICTION_SAVE | 1250 pp::PDF::SetContentRestriction(
1277 CONTENT_RESTRICTION_PRINT); 1251 this, CONTENT_RESTRICTION_SAVE | CONTENT_RESTRICTION_PRINT);
1278 } 1252 }
1279 1253
1280 return CreateURLLoaderInternal(); 1254 return CreateURLLoaderInternal();
1281 } 1255 }
1282 1256
1283 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { 1257 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) {
1284 pp::CompletionCallback callback = 1258 pp::CompletionCallback callback =
1285 timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); 1259 timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired);
1286 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); 1260 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id);
1287 } 1261 }
1288 1262
1289 void OutOfProcessInstance::SearchString(const base::char16* string, 1263 void OutOfProcessInstance::SearchString(
1290 const base::char16* term, 1264 const base::char16* string,
1291 bool case_sensitive, 1265 const base::char16* term,
1292 std::vector<SearchStringResult>* results) { 1266 bool case_sensitive,
1267 std::vector<SearchStringResult>* results) {
1293 PP_PrivateFindResult* pp_results; 1268 PP_PrivateFindResult* pp_results;
1294 int count = 0; 1269 int count = 0;
1295 pp::PDF::SearchString( 1270 pp::PDF::SearchString(this, reinterpret_cast<const unsigned short*>(string),
1296 this, 1271 reinterpret_cast<const unsigned short*>(term),
1297 reinterpret_cast<const unsigned short*>(string), 1272 case_sensitive, &pp_results, &count);
1298 reinterpret_cast<const unsigned short*>(term),
1299 case_sensitive,
1300 &pp_results,
1301 &count);
1302 1273
1303 results->resize(count); 1274 results->resize(count);
1304 for (int i = 0; i < count; ++i) { 1275 for (int i = 0; i < count; ++i) {
1305 (*results)[i].start_index = pp_results[i].start_index; 1276 (*results)[i].start_index = pp_results[i].start_index;
1306 (*results)[i].length = pp_results[i].length; 1277 (*results)[i].length = pp_results[i].length;
1307 } 1278 }
1308 1279
1309 pp::Memory_Dev memory; 1280 pp::Memory_Dev memory;
1310 memory.MemFree(pp_results); 1281 memory.MemFree(pp_results);
1311 } 1282 }
1312 1283
1313 void OutOfProcessInstance::DocumentPaintOccurred() { 1284 void OutOfProcessInstance::DocumentPaintOccurred() {}
1314 }
1315 1285
1316 void OutOfProcessInstance::DocumentLoadComplete(int page_count) { 1286 void OutOfProcessInstance::DocumentLoadComplete(int page_count) {
1317 // Clear focus state for OSK. 1287 // Clear focus state for OSK.
1318 FormTextFieldFocusChange(false); 1288 FormTextFieldFocusChange(false);
1319 1289
1320 DCHECK_EQ(LOAD_STATE_LOADING, document_load_state_); 1290 DCHECK_EQ(LOAD_STATE_LOADING, document_load_state_);
1321 document_load_state_ = LOAD_STATE_COMPLETE; 1291 document_load_state_ = LOAD_STATE_COMPLETE;
1322 UserMetricsRecordAction("PDF.LoadSuccess"); 1292 UserMetricsRecordAction("PDF.LoadSuccess");
1323 uma_.HistogramEnumeration("PDF.DocumentFeature", LOADED_DOCUMENT, 1293 uma_.HistogramEnumeration("PDF.DocumentFeature", LOADED_DOCUMENT,
1324 FEATURES_COUNT); 1294 FEATURES_COUNT);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 if (preview_document_load_state_ != LOAD_STATE_LOADING || 1361 if (preview_document_load_state_ != LOAD_STATE_LOADING ||
1392 preview_pages_info_.empty()) { 1362 preview_pages_info_.empty()) {
1393 return; 1363 return;
1394 } 1364 }
1395 1365
1396 preview_document_load_state_ = LOAD_STATE_COMPLETE; 1366 preview_document_load_state_ = LOAD_STATE_COMPLETE;
1397 1367
1398 int dest_page_index = preview_pages_info_.front().second; 1368 int dest_page_index = preview_pages_info_.front().second;
1399 int src_page_index = 1369 int src_page_index =
1400 ExtractPrintPreviewPageIndex(preview_pages_info_.front().first); 1370 ExtractPrintPreviewPageIndex(preview_pages_info_.front().first);
1401 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get()) 1371 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get())
1402 engine_->AppendPage(preview_engine_.get(), dest_page_index); 1372 engine_->AppendPage(preview_engine_.get(), dest_page_index);
1403 1373
1404 preview_pages_info_.pop(); 1374 preview_pages_info_.pop();
1405 // |print_preview_page_count_| is not updated yet. Do not load any 1375 // |print_preview_page_count_| is not updated yet. Do not load any
1406 // other preview pages till we get this information. 1376 // other preview pages till we get this information.
1407 if (print_preview_page_count_ == 0) 1377 if (print_preview_page_count_ == 0)
1408 return; 1378 return;
1409 1379
1410 if (!preview_pages_info_.empty()) 1380 if (!preview_pages_info_.empty())
1411 LoadAvailablePreviewPage(); 1381 LoadAvailablePreviewPage();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1522 }
1553 1523
1554 void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) { 1524 void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) {
1555 LoadUrlInternal(url, &embed_preview_loader_, 1525 LoadUrlInternal(url, &embed_preview_loader_,
1556 &OutOfProcessInstance::DidOpenPreview); 1526 &OutOfProcessInstance::DidOpenPreview);
1557 } 1527 }
1558 1528
1559 void OutOfProcessInstance::LoadUrlInternal( 1529 void OutOfProcessInstance::LoadUrlInternal(
1560 const std::string& url, 1530 const std::string& url,
1561 pp::URLLoader* loader, 1531 pp::URLLoader* loader,
1562 void (OutOfProcessInstance::* method)(int32_t)) { 1532 void (OutOfProcessInstance::*method)(int32_t)) {
1563 pp::URLRequestInfo request(this); 1533 pp::URLRequestInfo request(this);
1564 request.SetURL(url); 1534 request.SetURL(url);
1565 request.SetMethod("GET"); 1535 request.SetMethod("GET");
1566 request.SetFollowRedirects(false); 1536 request.SetFollowRedirects(false);
1567 1537
1568 *loader = CreateURLLoaderInternal(); 1538 *loader = CreateURLLoaderInternal();
1569 pp::CompletionCallback callback = loader_factory_.NewCallback(method); 1539 pp::CompletionCallback callback = loader_factory_.NewCallback(method);
1570 int rv = loader->Open(request, callback); 1540 int rv = loader->Open(request, callback);
1571 if (rv != PP_OK_COMPLETIONPENDING) 1541 if (rv != PP_OK_COMPLETIONPENDING)
1572 callback.Run(rv); 1542 callback.Run(rv);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 1597
1628 void OutOfProcessInstance::LoadAvailablePreviewPage() { 1598 void OutOfProcessInstance::LoadAvailablePreviewPage() {
1629 if (preview_pages_info_.empty() || 1599 if (preview_pages_info_.empty() ||
1630 document_load_state_ != LOAD_STATE_COMPLETE) { 1600 document_load_state_ != LOAD_STATE_COMPLETE) {
1631 return; 1601 return;
1632 } 1602 }
1633 1603
1634 std::string url = preview_pages_info_.front().first; 1604 std::string url = preview_pages_info_.front().first;
1635 int dst_page_index = preview_pages_info_.front().second; 1605 int dst_page_index = preview_pages_info_.front().second;
1636 int src_page_index = ExtractPrintPreviewPageIndex(url); 1606 int src_page_index = ExtractPrintPreviewPageIndex(url);
1637 if (src_page_index < 1 || 1607 if (src_page_index < 1 || dst_page_index >= print_preview_page_count_ ||
1638 dst_page_index >= print_preview_page_count_ ||
1639 preview_document_load_state_ == LOAD_STATE_LOADING) { 1608 preview_document_load_state_ == LOAD_STATE_LOADING) {
1640 return; 1609 return;
1641 } 1610 }
1642 1611
1643 preview_document_load_state_ = LOAD_STATE_LOADING; 1612 preview_document_load_state_ = LOAD_STATE_LOADING;
1644 LoadPreviewUrl(url); 1613 LoadPreviewUrl(url);
1645 } 1614 }
1646 1615
1647 void OutOfProcessInstance::UserMetricsRecordAction( 1616 void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
1648 const std::string& action) {
1649 // TODO(raymes): Move this function to PPB_UMA_Private. 1617 // TODO(raymes): Move this function to PPB_UMA_Private.
1650 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); 1618 pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
1651 } 1619 }
1652 1620
1653 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1621 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1654 const pp::FloatPoint& scroll_offset) { 1622 const pp::FloatPoint& scroll_offset) {
1655 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1623 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1656 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1624 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1657 float min_y = -top_toolbar_height_; 1625 float min_y = -top_toolbar_height_;
1658 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1626 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1659 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1627 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1660 return pp::FloatPoint(x, y); 1628 return pp::FloatPoint(x, y);
1661 } 1629 }
1662 1630
1663 } // namespace chrome_pdf 1631 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/paint_aggregator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698