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

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

Issue 9139024: Adding functionality to print PDF embedded in the html page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 936
937 void PrintWebViewHelper::OnPrintingDone(bool success) { 937 void PrintWebViewHelper::OnPrintingDone(bool success) {
938 notify_browser_of_print_failure_ = false; 938 notify_browser_of_print_failure_ = false;
939 if (!success) 939 if (!success)
940 LOG(ERROR) << "Failure in OnPrintingDone"; 940 LOG(ERROR) << "Failure in OnPrintingDone";
941 DidFinishPrinting(success ? OK : FAIL_PRINT); 941 DidFinishPrinting(success ? OK : FAIL_PRINT);
942 } 942 }
943 943
944 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { 944 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() {
945 const WebNode& context_menu_node = render_view()->GetContextMenuNode(); 945 const WebNode& context_menu_node = render_view()->GetContextMenuNode();
946 if (context_menu_node.isNull()) { 946 PrintNode(context_menu_node);
947 }
948
949 void PrintWebViewHelper::OnInitiatePrintPreview() {
950 DCHECK(is_preview_enabled_);
951 WebFrame* frame;
952 if (GetPrintFrame(&frame)) {
953 print_preview_context_.InitWithFrame(frame);
954 RequestPrintPreview();
955 }
956 }
957
958 void PrintWebViewHelper::PrintNode(const WebNode& node) {
959 if (node.isNull()) {
947 NOTREACHED(); 960 NOTREACHED();
948 return; 961 return;
949 } 962 }
950 963
951 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets 964 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets
952 // its |context_menu_node_|. 965 // its |context_menu_node_|.
953 if (is_preview_enabled_) { 966 if (is_preview_enabled_) {
954 print_preview_context_.InitWithNode(context_menu_node); 967 print_preview_context_.InitWithNode(node);
955 RequestPrintPreview(); 968 RequestPrintPreview();
956 } else { 969 } else {
957 WebNode duplicate_node(context_menu_node); 970 WebNode duplicate_node(node);
958 Print(duplicate_node.document().frame(), duplicate_node); 971 Print(duplicate_node.document().frame(), duplicate_node);
959 } 972 }
960 } 973 }
961 974
962 void PrintWebViewHelper::OnInitiatePrintPreview() {
963 DCHECK(is_preview_enabled_);
964 WebFrame* frame;
965 if (GetPrintFrame(&frame)) {
966 print_preview_context_.InitWithFrame(frame);
967 RequestPrintPreview();
968 }
969 }
970
971 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, 975 void PrintWebViewHelper::Print(WebKit::WebFrame* frame,
972 const WebKit::WebNode& node) { 976 const WebKit::WebNode& node) {
973 // If still not finished with earlier print request simply ignore. 977 // If still not finished with earlier print request simply ignore.
974 if (print_web_view_) 978 if (print_web_view_)
975 return; 979 return;
976 980
977 // Initialize print settings. 981 // Initialize print settings.
978 scoped_ptr<PrepareFrameAndViewForPrint> prepare; 982 scoped_ptr<PrepareFrameAndViewForPrint> prepare;
979 if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare)) { 983 if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare)) {
980 DidFinishPrinting(FAIL_PRINT); 984 DidFinishPrinting(FAIL_PRINT);
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 DCHECK(IsRendering()); 1729 DCHECK(IsRendering());
1726 return prep_frame_view_->GetPrintCanvasSize(); 1730 return prep_frame_view_->GetPrintCanvasSize();
1727 } 1731 }
1728 1732
1729 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1733 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1730 prep_frame_view_.reset(); 1734 prep_frame_view_.reset();
1731 metafile_.reset(); 1735 metafile_.reset();
1732 pages_to_render_.clear(); 1736 pages_to_render_.clear();
1733 error_ = PREVIEW_ERROR_NONE; 1737 error_ = PREVIEW_ERROR_NONE;
1734 } 1738 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698