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

Side by Side Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 226093007: Convert Chrome usages of WebFrame to WebLocalFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "chrome/renderer/printing/print_web_view_helper.h" 5 #include "chrome/renderer/printing/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 switches::kRendererPrintPreview); 405 switches::kRendererPrintPreview);
406 } 406 }
407 407
408 bool IsPrintThrottlingDisabled() { 408 bool IsPrintThrottlingDisabled() {
409 return CommandLine::ForCurrentProcess()->HasSwitch( 409 return CommandLine::ForCurrentProcess()->HasSwitch(
410 switches::kDisableScriptedPrintThrottling); 410 switches::kDisableScriptedPrintThrottling);
411 } 411 }
412 412
413 } // namespace 413 } // namespace
414 414
415 FrameReference::FrameReference(blink::WebFrame* frame) { 415 FrameReference::FrameReference(blink::WebLocalFrame* frame) { Reset(frame); }
416 Reset(frame);
417 }
418 416
419 FrameReference::FrameReference() { 417 FrameReference::FrameReference() {
420 Reset(NULL); 418 Reset(NULL);
421 } 419 }
422 420
423 FrameReference::~FrameReference() { 421 FrameReference::~FrameReference() {
424 } 422 }
425 423
426 void FrameReference::Reset(blink::WebFrame* frame) { 424 void FrameReference::Reset(blink::WebLocalFrame* frame) {
427 if (frame) { 425 if (frame) {
428 view_ = frame->view(); 426 view_ = frame->view();
429 frame_ = frame; 427 frame_ = frame;
430 } else { 428 } else {
431 view_ = NULL; 429 view_ = NULL;
432 frame_ = NULL; 430 frame_ = NULL;
433 } 431 }
434 } 432 }
435 433
436 blink::WebFrame* FrameReference::GetFrame() { 434 blink::WebLocalFrame* FrameReference::GetFrame() {
437 if (view_ == NULL || frame_ == NULL) 435 if (view_ == NULL || frame_ == NULL)
438 return NULL; 436 return NULL;
439 for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL; 437 for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL;
440 frame = frame->traverseNext(false)) { 438 frame = frame->traverseNext(false)) {
441 if (frame == frame_) 439 if (frame == frame_)
442 return frame; 440 return frame_;
443 } 441 }
444 return NULL; 442 return NULL;
445 } 443 }
446 444
447 blink::WebView* FrameReference::view() { 445 blink::WebView* FrameReference::view() {
448 return view_; 446 return view_;
449 } 447 }
450 448
451 // static - Not anonymous so that platform implementations can use it. 449 // static - Not anonymous so that platform implementations can use it.
452 void PrintWebViewHelper::PrintHeaderAndFooter( 450 void PrintWebViewHelper::PrintHeaderAndFooter(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 525 }
528 return frame->printPage(page_number, canvas); 526 return frame->printPage(page_number, canvas);
529 } 527 }
530 528
531 // Class that calls the Begin and End print functions on the frame and changes 529 // Class that calls the Begin and End print functions on the frame and changes
532 // the size of the view temporarily to support full page printing.. 530 // the size of the view temporarily to support full page printing..
533 class PrepareFrameAndViewForPrint : public blink::WebViewClient, 531 class PrepareFrameAndViewForPrint : public blink::WebViewClient,
534 public blink::WebFrameClient { 532 public blink::WebFrameClient {
535 public: 533 public:
536 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& params, 534 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& params,
537 blink::WebFrame* frame, 535 blink::WebLocalFrame* frame,
538 const blink::WebNode& node, 536 const blink::WebNode& node,
539 bool ignore_css_margins); 537 bool ignore_css_margins);
540 virtual ~PrepareFrameAndViewForPrint(); 538 virtual ~PrepareFrameAndViewForPrint();
541 539
542 // Optional. Replaces |frame_| with selection if needed. Will call |on_ready| 540 // Optional. Replaces |frame_| with selection if needed. Will call |on_ready|
543 // when completed. 541 // when completed.
544 void CopySelectionIfNeeded(const WebPreferences& preferences, 542 void CopySelectionIfNeeded(const WebPreferences& preferences,
545 const base::Closure& on_ready); 543 const base::Closure& on_ready);
546 544
547 // Prepares frame for printing. 545 // Prepares frame for printing.
548 void StartPrinting(); 546 void StartPrinting();
549 547
550 blink::WebFrame* frame() { 548 blink::WebLocalFrame* frame() { return frame_.GetFrame(); }
551 return frame_.GetFrame();
552 }
553 549
554 const blink::WebNode& node() const { 550 const blink::WebNode& node() const {
555 return node_to_print_; 551 return node_to_print_;
556 } 552 }
557 553
558 int GetExpectedPageCount() const { 554 int GetExpectedPageCount() const {
559 return expected_pages_count_; 555 return expected_pages_count_;
560 } 556 }
561 557
562 gfx::Size GetPrintCanvasSize() const; 558 gfx::Size GetPrintCanvasSize() const;
563 559
564 void FinishPrinting(); 560 void FinishPrinting();
565 561
566 bool IsLoadingSelection() { 562 bool IsLoadingSelection() {
567 // It's not selection if not |owns_web_view_|. 563 // It's not selection if not |owns_web_view_|.
568 return owns_web_view_ && frame() && frame()->isLoading(); 564 return owns_web_view_ && frame() && frame()->isLoading();
569 } 565 }
570 566
571 protected: 567 protected:
572 // blink::WebViewClient override: 568 // blink::WebViewClient override:
573 virtual void didStopLoading(); 569 virtual void didStopLoading();
574 570
575 // blink::WebFrameClient override: 571 // blink::WebFrameClient override:
576 virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent, 572 virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
577 const blink::WebString& name); 573 const blink::WebString& name);
578 virtual void frameDetached(blink::WebFrame* frame); 574 virtual void frameDetached(blink::WebFrame* frame);
579 575
580 private: 576 private:
581 void CallOnReady(); 577 void CallOnReady();
582 void ResizeForPrinting(); 578 void ResizeForPrinting();
583 void RestoreSize(); 579 void RestoreSize();
584 void CopySelection(const WebPreferences& preferences); 580 void CopySelection(const WebPreferences& preferences);
585 581
586 base::WeakPtrFactory<PrepareFrameAndViewForPrint> weak_ptr_factory_; 582 base::WeakPtrFactory<PrepareFrameAndViewForPrint> weak_ptr_factory_;
587 583
588 FrameReference frame_; 584 FrameReference frame_;
589 blink::WebNode node_to_print_; 585 blink::WebNode node_to_print_;
590 bool owns_web_view_; 586 bool owns_web_view_;
591 blink::WebPrintParams web_print_params_; 587 blink::WebPrintParams web_print_params_;
592 gfx::Size prev_view_size_; 588 gfx::Size prev_view_size_;
593 gfx::Size prev_scroll_offset_; 589 gfx::Size prev_scroll_offset_;
594 int expected_pages_count_; 590 int expected_pages_count_;
595 base::Closure on_ready_; 591 base::Closure on_ready_;
596 bool should_print_backgrounds_; 592 bool should_print_backgrounds_;
597 bool should_print_selection_only_; 593 bool should_print_selection_only_;
598 bool is_printing_started_; 594 bool is_printing_started_;
599 595
600 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); 596 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint);
601 }; 597 };
602 598
603 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( 599 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
604 const PrintMsg_Print_Params& params, 600 const PrintMsg_Print_Params& params,
605 blink::WebFrame* frame, 601 blink::WebLocalFrame* frame,
606 const blink::WebNode& node, 602 const blink::WebNode& node,
607 bool ignore_css_margins) 603 bool ignore_css_margins)
608 : weak_ptr_factory_(this), 604 : weak_ptr_factory_(this),
609 frame_(frame), 605 frame_(frame),
610 node_to_print_(node), 606 node_to_print_(node),
611 owns_web_view_(false), 607 owns_web_view_(false),
612 expected_pages_count_(0), 608 expected_pages_count_(0),
613 should_print_backgrounds_(params.should_print_backgrounds), 609 should_print_backgrounds_(params.should_print_backgrounds),
614 should_print_selection_only_(params.selection_only), 610 should_print_selection_only_(params.selection_only),
615 is_printing_started_(false) { 611 is_printing_started_(false) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 // Except that we disable javascript (don't want any active content running 684 // Except that we disable javascript (don't want any active content running
689 // on the page). 685 // on the page).
690 WebPreferences prefs = preferences; 686 WebPreferences prefs = preferences;
691 prefs.javascript_enabled = false; 687 prefs.javascript_enabled = false;
692 prefs.java_enabled = false; 688 prefs.java_enabled = false;
693 689
694 blink::WebView* web_view = blink::WebView::create(this); 690 blink::WebView* web_view = blink::WebView::create(this);
695 owns_web_view_ = true; 691 owns_web_view_ = true;
696 content::ApplyWebPreferences(prefs, web_view); 692 content::ApplyWebPreferences(prefs, web_view);
697 web_view->setMainFrame(blink::WebFrame::create(this)); 693 web_view->setMainFrame(blink::WebFrame::create(this));
698 frame_.Reset(web_view->mainFrame()); 694 frame_.Reset(web_view->mainFrame()->toWebLocalFrame());
699 node_to_print_.reset(); 695 node_to_print_.reset();
700 696
701 // When loading is done this will call didStopLoading() and that will do the 697 // When loading is done this will call didStopLoading() and that will do the
702 // actual printing. 698 // actual printing.
703 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); 699 frame()->loadRequest(blink::WebURLRequest(GURL(url_str)));
704 } 700 }
705 701
706 void PrepareFrameAndViewForPrint::didStopLoading() { 702 void PrepareFrameAndViewForPrint::didStopLoading() {
707 DCHECK(!on_ready_.is_null()); 703 DCHECK(!on_ready_.is_null());
708 // Don't call callback here, because it can delete |this| and WebView that is 704 // Don't call callback here, because it can delete |this| and WebView that is
709 // called didStopLoading. 705 // called didStopLoading.
710 base::MessageLoop::current()->PostTask( 706 base::MessageLoop::current()->PostTask(
711 FROM_HERE, 707 FROM_HERE,
712 base::Bind(&PrepareFrameAndViewForPrint::CallOnReady, 708 base::Bind(&PrepareFrameAndViewForPrint::CallOnReady,
713 weak_ptr_factory_.GetWeakPtr())); 709 weak_ptr_factory_.GetWeakPtr()));
714 } 710 }
715 711
716 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame( 712 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
717 blink::WebFrame* parent, 713 blink::WebLocalFrame* parent,
718 const blink::WebString& name) { 714 const blink::WebString& name) {
719 blink::WebFrame* frame = blink::WebFrame::create(this); 715 blink::WebFrame* frame = blink::WebLocalFrame::create(this);
720 parent->appendChild(frame); 716 parent->appendChild(frame);
721 return frame; 717 return frame;
722 } 718 }
723 719
724 void PrepareFrameAndViewForPrint::frameDetached(blink::WebFrame* frame) { 720 void PrepareFrameAndViewForPrint::frameDetached(blink::WebFrame* frame) {
725 if (frame->parent()) 721 if (frame->parent())
726 frame->parent()->removeChild(frame); 722 frame->parent()->removeChild(frame);
727 frame->close(); 723 frame->close();
728 } 724 }
729 725
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 void PrintWebViewHelper::DidStartLoading() { 805 void PrintWebViewHelper::DidStartLoading() {
810 is_loading_ = true; 806 is_loading_ = true;
811 } 807 }
812 808
813 void PrintWebViewHelper::DidStopLoading() { 809 void PrintWebViewHelper::DidStopLoading() {
814 is_loading_ = false; 810 is_loading_ = false;
815 ShowScriptedPrintPreview(); 811 ShowScriptedPrintPreview();
816 } 812 }
817 813
818 // Prints |frame| which called window.print(). 814 // Prints |frame| which called window.print().
819 void PrintWebViewHelper::PrintPage(blink::WebFrame* frame, 815 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
820 bool user_initiated) { 816 bool user_initiated) {
821 DCHECK(frame); 817 DCHECK(frame);
822 818
823 // Allow Prerendering to cancel this print request if necessary. 819 // Allow Prerendering to cancel this print request if necessary.
824 if (prerender::PrerenderHelper::IsPrerendering( 820 if (prerender::PrerenderHelper::IsPrerendering(
825 render_view()->GetMainRenderFrame())) { 821 render_view()->GetMainRenderFrame())) {
826 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); 822 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
827 return; 823 return;
828 } 824 }
829 825
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 blink::WebElement pdf_element = document.getElementById("pdf-viewer"); 872 blink::WebElement pdf_element = document.getElementById("pdf-viewer");
877 if (pdf_element.isNull()) { 873 if (pdf_element.isNull()) {
878 NOTREACHED(); 874 NOTREACHED();
879 return; 875 return;
880 } 876 }
881 877
882 // Set |print_for_preview_| flag and autoreset it to back to original 878 // Set |print_for_preview_| flag and autoreset it to back to original
883 // on return. 879 // on return.
884 base::AutoReset<bool> set_printing_flag(&print_for_preview_, true); 880 base::AutoReset<bool> set_printing_flag(&print_for_preview_, true);
885 881
886 blink::WebFrame* pdf_frame = pdf_element.document().frame(); 882 blink::WebLocalFrame* pdf_frame = pdf_element.document().frame();
887 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) { 883 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) {
888 LOG(ERROR) << "UpdatePrintSettings failed"; 884 LOG(ERROR) << "UpdatePrintSettings failed";
889 DidFinishPrinting(FAIL_PRINT); 885 DidFinishPrinting(FAIL_PRINT);
890 return; 886 return;
891 } 887 }
892 888
893 // Print page onto entire page not just printable area. Preview PDF already 889 // Print page onto entire page not just printable area. Preview PDF already
894 // has content in correct position taking into account page size and printable 890 // has content in correct position taking into account page size and printable
895 // area. 891 // area.
896 // TODO(vitalybuka) : Make this consistent on all platform. This change 892 // TODO(vitalybuka) : Make this consistent on all platform. This change
897 // affects Windows only. On Linux and OSX RenderPagesForPrint does not use 893 // affects Windows only. On Linux and OSX RenderPagesForPrint does not use
898 // printable_area. Also we can't change printable_area deeper inside 894 // printable_area. Also we can't change printable_area deeper inside
899 // RenderPagesForPrint for Windows, because it's used also by native 895 // RenderPagesForPrint for Windows, because it's used also by native
900 // printing and it expects real printable_area value. 896 // printing and it expects real printable_area value.
901 // See http://crbug.com/123408 897 // See http://crbug.com/123408
902 PrintMsg_Print_Params& print_params = print_pages_params_->params; 898 PrintMsg_Print_Params& print_params = print_pages_params_->params;
903 print_params.printable_area = gfx::Rect(print_params.page_size); 899 print_params.printable_area = gfx::Rect(print_params.page_size);
904 900
905 // Render Pages for printing. 901 // Render Pages for printing.
906 if (!RenderPagesForPrint(pdf_frame, pdf_element)) { 902 if (!RenderPagesForPrint(pdf_frame, pdf_element)) {
907 LOG(ERROR) << "RenderPagesForPrint failed"; 903 LOG(ERROR) << "RenderPagesForPrint failed";
908 DidFinishPrinting(FAIL_PRINT); 904 DidFinishPrinting(FAIL_PRINT);
909 } 905 }
910 } 906 }
911 907
912 bool PrintWebViewHelper::GetPrintFrame(blink::WebFrame** frame) { 908 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) {
913 DCHECK(frame); 909 DCHECK(frame);
914 blink::WebView* webView = render_view()->GetWebView(); 910 blink::WebView* webView = render_view()->GetWebView();
915 DCHECK(webView); 911 DCHECK(webView);
916 if (!webView) 912 if (!webView)
917 return false; 913 return false;
918 914
919 // If the user has selected text in the currently focused frame we print 915 // If the user has selected text in the currently focused frame we print
920 // only that frame (this makes print selection work for multiple frames). 916 // only that frame (this makes print selection work for multiple frames).
921 blink::WebFrame* focusedFrame = webView->focusedFrame(); 917 // TODO(dcheng): This code will almost certainly need to be adapted to work
922 *frame = focusedFrame->hasSelection() ? focusedFrame : webView->mainFrame(); 918 // correctly with out-of-process iframes. There are certainly cases where
919 // focused frame and main frame will not be in the same renderer, so we will
920 // need to make sure this is dispatched correctly.
jam 2014/04/05 00:12:39 nit: i'm a bit hesitant to start adding comments t
dcheng 2014/04/05 00:42:23 I don't usually add these comments, but there's an
921 blink::WebLocalFrame* focusedFrame =
922 webView->focusedFrame()->toWebLocalFrame();
923 *frame = focusedFrame->hasSelection()
924 ? focusedFrame
925 : webView->mainFrame()->toWebLocalFrame();
923 return true; 926 return true;
924 } 927 }
925 928
926 void PrintWebViewHelper::OnPrintPages() { 929 void PrintWebViewHelper::OnPrintPages() {
927 blink::WebFrame* frame; 930 blink::WebLocalFrame* frame;
928 if (GetPrintFrame(&frame)) 931 if (GetPrintFrame(&frame))
929 Print(frame, blink::WebNode()); 932 Print(frame, blink::WebNode());
930 } 933 }
931 934
932 void PrintWebViewHelper::OnPrintForSystemDialog() { 935 void PrintWebViewHelper::OnPrintForSystemDialog() {
933 blink::WebFrame* frame = print_preview_context_.source_frame(); 936 blink::WebLocalFrame* frame = print_preview_context_.source_frame();
934 if (!frame) { 937 if (!frame) {
935 NOTREACHED(); 938 NOTREACHED();
936 return; 939 return;
937 } 940 }
938 941
939 Print(frame, print_preview_context_.source_node()); 942 Print(frame, print_preview_context_.source_node());
940 } 943 }
941 944
942 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( 945 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
943 const PageSizeMargins& page_layout_in_points, 946 const PageSizeMargins& page_layout_in_points,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 LOG(ERROR) << "Failure in OnPrintingDone"; 1174 LOG(ERROR) << "Failure in OnPrintingDone";
1172 DidFinishPrinting(success ? OK : FAIL_PRINT); 1175 DidFinishPrinting(success ? OK : FAIL_PRINT);
1173 } 1176 }
1174 1177
1175 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { 1178 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) {
1176 is_scripted_printing_blocked_ = blocked; 1179 is_scripted_printing_blocked_ = blocked;
1177 } 1180 }
1178 1181
1179 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { 1182 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
1180 DCHECK(is_preview_enabled_); 1183 DCHECK(is_preview_enabled_);
1181 blink::WebFrame* frame = NULL; 1184 blink::WebLocalFrame* frame = NULL;
1182 GetPrintFrame(&frame); 1185 GetPrintFrame(&frame);
1183 DCHECK(frame); 1186 DCHECK(frame);
1184 print_preview_context_.InitWithFrame(frame); 1187 print_preview_context_.InitWithFrame(frame);
1185 RequestPrintPreview(selection_only ? 1188 RequestPrintPreview(selection_only ?
1186 PRINT_PREVIEW_USER_INITIATED_SELECTION : 1189 PRINT_PREVIEW_USER_INITIATED_SELECTION :
1187 PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); 1190 PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME);
1188 } 1191 }
1189 1192
1190 bool PrintWebViewHelper::IsPrintingEnabled() { 1193 bool PrintWebViewHelper::IsPrintingEnabled() {
1191 bool result = false; 1194 bool result = false;
(...skipping 23 matching lines...) Expand all
1215 print_preview_context_.InitWithNode(node); 1218 print_preview_context_.InitWithNode(node);
1216 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); 1219 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
1217 } else { 1220 } else {
1218 blink::WebNode duplicate_node(node); 1221 blink::WebNode duplicate_node(node);
1219 Print(duplicate_node.document().frame(), duplicate_node); 1222 Print(duplicate_node.document().frame(), duplicate_node);
1220 } 1223 }
1221 1224
1222 print_node_in_progress_ = false; 1225 print_node_in_progress_ = false;
1223 } 1226 }
1224 1227
1225 void PrintWebViewHelper::Print(blink::WebFrame* frame, 1228 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
1226 const blink::WebNode& node) { 1229 const blink::WebNode& node) {
1227 // If still not finished with earlier print request simply ignore. 1230 // If still not finished with earlier print request simply ignore.
1228 if (prep_frame_view_) 1231 if (prep_frame_view_)
1229 return; 1232 return;
1230 1233
1231 FrameReference frame_ref(frame); 1234 FrameReference frame_ref(frame);
1232 1235
1233 int expected_page_count = 0; 1236 int expected_page_count = 0;
1234 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { 1237 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) {
1235 DidFinishPrinting(FAIL_PRINT_INIT); 1238 DidFinishPrinting(FAIL_PRINT_INIT);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 blink::WebPrintScalingOptionSourceSize; 1413 blink::WebPrintScalingOptionSourceSize;
1411 if (fit_to_paper_size) { 1414 if (fit_to_paper_size) {
1412 settings.params.print_scaling_option = 1415 settings.params.print_scaling_option =
1413 blink::WebPrintScalingOptionFitToPrintableArea; 1416 blink::WebPrintScalingOptionFitToPrintableArea;
1414 } 1417 }
1415 1418
1416 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1419 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1417 return result; 1420 return result;
1418 } 1421 }
1419 1422
1420 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, 1423 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame,
1421 const blink::WebNode& node, 1424 const blink::WebNode& node,
1422 int* number_of_pages) { 1425 int* number_of_pages) {
1423 DCHECK(frame); 1426 DCHECK(frame);
1424 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); 1427 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
1425 if (!InitPrintSettings(fit_to_paper_size)) { 1428 if (!InitPrintSettings(fit_to_paper_size)) {
1426 notify_browser_of_print_failure_ = false; 1429 notify_browser_of_print_failure_ = false;
1427 render_view()->RunModalAlertDialog( 1430 render_view()->RunModalAlertDialog(
1428 frame, 1431 frame,
1429 l10n_util::GetStringUTF16(IDS_PRINT_INVALID_PRINTER_SETTINGS)); 1432 l10n_util::GetStringUTF16(IDS_PRINT_INVALID_PRINTER_SETTINGS));
1430 return false; 1433 return false;
1431 } 1434 }
1432 1435
1433 const PrintMsg_Print_Params& params = print_pages_params_->params; 1436 const PrintMsg_Print_Params& params = print_pages_params_->params;
1434 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); 1437 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_);
1435 prepare.StartPrinting(); 1438 prepare.StartPrinting();
1436 1439
1437 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), 1440 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
1438 params.document_cookie)); 1441 params.document_cookie));
1439 *number_of_pages = prepare.GetExpectedPageCount(); 1442 *number_of_pages = prepare.GetExpectedPageCount();
1440 return true; 1443 return true;
1441 } 1444 }
1442 1445
1443 bool PrintWebViewHelper::UpdatePrintSettings( 1446 bool PrintWebViewHelper::UpdatePrintSettings(
1444 blink::WebFrame* frame, 1447 blink::WebLocalFrame* frame,
1445 const blink::WebNode& node, 1448 const blink::WebNode& node,
1446 const base::DictionaryValue& passed_job_settings) { 1449 const base::DictionaryValue& passed_job_settings) {
1447 DCHECK(is_preview_enabled_); 1450 DCHECK(is_preview_enabled_);
1448 const base::DictionaryValue* job_settings = &passed_job_settings; 1451 const base::DictionaryValue* job_settings = &passed_job_settings;
1449 base::DictionaryValue modified_job_settings; 1452 base::DictionaryValue modified_job_settings;
1450 if (job_settings->empty()) { 1453 if (job_settings->empty()) {
1451 if (!print_for_preview_) 1454 if (!print_for_preview_)
1452 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); 1455 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
1453 return false; 1456 return false;
1454 } 1457 }
(...skipping 21 matching lines...) Expand all
1476 PrintMsg_PrintPages_Params settings; 1479 PrintMsg_PrintPages_Params settings;
1477 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, 1480 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings,
1478 &settings)); 1481 &settings));
1479 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1482 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1480 1483
1481 if (!PrintMsg_Print_Params_IsValid(settings.params)) { 1484 if (!PrintMsg_Print_Params_IsValid(settings.params)) {
1482 if (!print_for_preview_) { 1485 if (!print_for_preview_) {
1483 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); 1486 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
1484 } else { 1487 } else {
1485 // PrintForPrintPreview 1488 // PrintForPrintPreview
1486 blink::WebFrame* print_frame = NULL; 1489 blink::WebLocalFrame* print_frame = NULL;
1487 // This may not be the right frame, but the alert will be modal, 1490 // This may not be the right frame, but the alert will be modal,
1488 // therefore it works well enough. 1491 // therefore it works well enough.
1489 GetPrintFrame(&print_frame); 1492 GetPrintFrame(&print_frame);
1490 if (print_frame) { 1493 if (print_frame) {
1491 render_view()->RunModalAlertDialog( 1494 render_view()->RunModalAlertDialog(
1492 print_frame, 1495 print_frame,
1493 l10n_util::GetStringUTF16( 1496 l10n_util::GetStringUTF16(
1494 IDS_PRINT_INVALID_PRINTER_SETTINGS)); 1497 IDS_PRINT_INVALID_PRINTER_SETTINGS));
1495 } 1498 }
1496 } 1499 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 IPC::SyncMessage* msg = 1571 IPC::SyncMessage* msg =
1569 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); 1572 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings);
1570 msg->EnableMessagePumping(); 1573 msg->EnableMessagePumping();
1571 Send(msg); 1574 Send(msg);
1572 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); 1575 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings));
1573 1576
1574 print_pages_params_->params.print_scaling_option = scaling_option; 1577 print_pages_params_->params.print_scaling_option = scaling_option;
1575 return (print_settings.params.dpi && print_settings.params.document_cookie); 1578 return (print_settings.params.dpi && print_settings.params.document_cookie);
1576 } 1579 }
1577 1580
1578 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebFrame* frame, 1581 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
1579 const blink::WebNode& node) { 1582 const blink::WebNode& node) {
1580 if (!frame || prep_frame_view_) 1583 if (!frame || prep_frame_view_)
1581 return false; 1584 return false;
1582 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1585 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1583 const PrintMsg_Print_Params& print_params = params.params; 1586 const PrintMsg_Print_Params& print_params = params.params;
1584 prep_frame_view_.reset( 1587 prep_frame_view_.reset(
1585 new PrepareFrameAndViewForPrint(print_params, frame, node, 1588 new PrepareFrameAndViewForPrint(print_params, frame, node,
1586 ignore_css_margins_)); 1589 ignore_css_margins_));
1587 DCHECK(!print_pages_params_->params.selection_only || 1590 DCHECK(!print_pages_params_->params.selection_only ||
1588 print_pages_params_->pages.empty()); 1591 print_pages_params_->pages.empty());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 generate_draft_pages_(true), 1782 generate_draft_pages_(true),
1780 print_ready_metafile_page_count_(0), 1783 print_ready_metafile_page_count_(0),
1781 error_(PREVIEW_ERROR_NONE), 1784 error_(PREVIEW_ERROR_NONE),
1782 state_(UNINITIALIZED) { 1785 state_(UNINITIALIZED) {
1783 } 1786 }
1784 1787
1785 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { 1788 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() {
1786 } 1789 }
1787 1790
1788 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( 1791 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame(
1789 blink::WebFrame* web_frame) { 1792 blink::WebLocalFrame* web_frame) {
1790 DCHECK(web_frame); 1793 DCHECK(web_frame);
1791 DCHECK(!IsRendering()); 1794 DCHECK(!IsRendering());
1792 state_ = INITIALIZED; 1795 state_ = INITIALIZED;
1793 source_frame_.Reset(web_frame); 1796 source_frame_.Reset(web_frame);
1794 source_node_.reset(); 1797 source_node_.reset();
1795 } 1798 }
1796 1799
1797 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( 1800 void PrintWebViewHelper::PrintPreviewContext::InitWithNode(
1798 const blink::WebNode& web_node) { 1801 const blink::WebNode& web_node) {
1799 DCHECK(!web_node.isNull()); 1802 DCHECK(!web_node.isNull());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 bool generate_draft_pages) { 1958 bool generate_draft_pages) {
1956 DCHECK_EQ(INITIALIZED, state_); 1959 DCHECK_EQ(INITIALIZED, state_);
1957 generate_draft_pages_ = generate_draft_pages; 1960 generate_draft_pages_ = generate_draft_pages;
1958 } 1961 }
1959 1962
1960 void PrintWebViewHelper::PrintPreviewContext::set_error( 1963 void PrintWebViewHelper::PrintPreviewContext::set_error(
1961 enum PrintPreviewErrorBuckets error) { 1964 enum PrintPreviewErrorBuckets error) {
1962 error_ = error; 1965 error_ = error;
1963 } 1966 }
1964 1967
1965 blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() { 1968 blink::WebLocalFrame* PrintWebViewHelper::PrintPreviewContext::source_frame() {
1966 DCHECK(state_ != UNINITIALIZED); 1969 DCHECK(state_ != UNINITIALIZED);
1967 return source_frame_.GetFrame(); 1970 return source_frame_.GetFrame();
1968 } 1971 }
1969 1972
1970 const blink::WebNode& 1973 const blink::WebNode&
1971 PrintWebViewHelper::PrintPreviewContext::source_node() const { 1974 PrintWebViewHelper::PrintPreviewContext::source_node() const {
1972 DCHECK(state_ != UNINITIALIZED); 1975 DCHECK(state_ != UNINITIALIZED);
1973 return source_node_; 1976 return source_node_;
1974 } 1977 }
1975 1978
1976 blink::WebFrame* PrintWebViewHelper::PrintPreviewContext::prepared_frame() { 1979 blink::WebLocalFrame*
1980 PrintWebViewHelper::PrintPreviewContext::prepared_frame() {
1977 DCHECK(state_ != UNINITIALIZED); 1981 DCHECK(state_ != UNINITIALIZED);
1978 return prep_frame_view_->frame(); 1982 return prep_frame_view_->frame();
1979 } 1983 }
1980 1984
1981 const blink::WebNode& 1985 const blink::WebNode&
1982 PrintWebViewHelper::PrintPreviewContext::prepared_node() const { 1986 PrintWebViewHelper::PrintPreviewContext::prepared_node() const {
1983 DCHECK(state_ != UNINITIALIZED); 1987 DCHECK(state_ != UNINITIALIZED);
1984 return prep_frame_view_->node(); 1988 return prep_frame_view_->node();
1985 } 1989 }
1986 1990
(...skipping 21 matching lines...) Expand all
2008 } 2012 }
2009 2013
2010 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2014 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
2011 prep_frame_view_.reset(); 2015 prep_frame_view_.reset();
2012 metafile_.reset(); 2016 metafile_.reset();
2013 pages_to_render_.clear(); 2017 pages_to_render_.clear();
2014 error_ = PREVIEW_ERROR_NONE; 2018 error_ = PREVIEW_ERROR_NONE;
2015 } 2019 }
2016 2020
2017 } // namespace printing 2021 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698