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

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

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/renderer/render_view.h" 10 #include "chrome/renderer/render_view.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "printing/units.h" 12 #include "printing/units.h"
13 #include "webkit/api/public/WebFrame.h"
13 #include "webkit/api/public/WebRect.h" 14 #include "webkit/api/public/WebRect.h"
14 #include "webkit/api/public/WebScreenInfo.h" 15 #include "webkit/api/public/WebScreenInfo.h"
15 #include "webkit/api/public/WebSize.h" 16 #include "webkit/api/public/WebSize.h"
16 #include "webkit/api/public/WebURLRequest.h" 17 #include "webkit/api/public/WebURLRequest.h"
17 #include "webkit/glue/webframe.h"
18 18
19 using WebKit::WebFrame;
19 using WebKit::WebRect; 20 using WebKit::WebRect;
20 using WebKit::WebScreenInfo; 21 using WebKit::WebScreenInfo;
21 using WebKit::WebString; 22 using WebKit::WebString;
22 using WebKit::WebURLRequest; 23 using WebKit::WebURLRequest;
23 24
24 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( 25 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
25 const ViewMsg_Print_Params& print_params, 26 const ViewMsg_Print_Params& print_params,
26 WebFrame* frame, 27 WebFrame* frame,
27 WebView* web_view) 28 WebView* web_view)
28 : frame_(frame), web_view_(web_view), expected_pages_count_(0) { 29 : frame_(frame), web_view_(web_view), expected_pages_count_(0) {
(...skipping 14 matching lines...) Expand all
43 // minimum (default) scaling. 44 // minimum (default) scaling.
44 // This is important for sites that try to fill the page. 45 // This is important for sites that try to fill the page.
45 gfx::Size print_layout_size(print_canvas_size_); 46 gfx::Size print_layout_size(print_canvas_size_);
46 print_layout_size.set_height(static_cast<int>( 47 print_layout_size.set_height(static_cast<int>(
47 static_cast<double>(print_layout_size.height()) * 1.25)); 48 static_cast<double>(print_layout_size.height()) * 1.25));
48 49
49 prev_view_size_ = web_view->size(); 50 prev_view_size_ = web_view->size();
50 51
51 web_view->resize(print_layout_size); 52 web_view->resize(print_layout_size);
52 53
53 expected_pages_count_ = frame->PrintBegin(print_canvas_size_); 54 expected_pages_count_ = frame->printBegin(print_canvas_size_);
54 } 55 }
55 56
56 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 57 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
57 frame_->PrintEnd(); 58 frame_->printEnd();
58 web_view_->resize(prev_view_size_); 59 web_view_->resize(prev_view_size_);
59 } 60 }
60 61
61 62
62 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) 63 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view)
63 : render_view_(render_view), 64 : render_view_(render_view),
64 user_cancelled_scripted_print_count_(0) {} 65 user_cancelled_scripted_print_count_(0) {}
65 66
66 PrintWebViewHelper::~PrintWebViewHelper() {} 67 PrintWebViewHelper::~PrintWebViewHelper() {}
67 68
(...skipping 13 matching lines...) Expand all
81 print_web_view_.release(); // Close deletes object. 82 print_web_view_.release(); // Close deletes object.
82 print_pages_params_.reset(); 83 print_pages_params_.reset();
83 } 84 }
84 } 85 }
85 86
86 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params, 87 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params,
87 WebFrame* web_frame) { 88 WebFrame* web_frame) {
88 // Create a new WebView with the same settings as the current display one. 89 // Create a new WebView with the same settings as the current display one.
89 // Except that we disable javascript (don't want any active content running 90 // Except that we disable javascript (don't want any active content running
90 // on the page). 91 // on the page).
91 WebPreferences prefs = web_frame->GetView()->GetPreferences(); 92 WebPreferences prefs = web_frame->view()->GetPreferences();
92 prefs.javascript_enabled = false; 93 prefs.javascript_enabled = false;
93 prefs.java_enabled = false; 94 prefs.java_enabled = false;
94 print_web_view_.reset(WebView::Create(this, prefs)); 95 print_web_view_.reset(WebView::Create(this, prefs));
95 96
96 print_pages_params_.reset(new ViewMsg_PrintPages_Params(params)); 97 print_pages_params_.reset(new ViewMsg_PrintPages_Params(params));
97 print_pages_params_->pages.clear(); // Print all pages of selection. 98 print_pages_params_->pages.clear(); // Print all pages of selection.
98 99
99 std::string html = web_frame->GetSelection(true); 100 std::string html = web_frame->selectionAsMarkup().utf8();
100 std::string url_str = "data:text/html;charset=utf-8,"; 101 std::string url_str = "data:text/html;charset=utf-8,";
101 url_str.append(html); 102 url_str.append(html);
102 GURL url(url_str); 103 GURL url(url_str);
103 104
104 // When loading is done this will call DidStopLoading that will do the 105 // When loading is done this will call DidStopLoading that will do the
105 // actual printing. 106 // actual printing.
106 print_web_view_->GetMainFrame()->LoadRequest(WebURLRequest(url)); 107 print_web_view_->GetMainFrame()->loadRequest(WebURLRequest(url));
107 108
108 return true; 109 return true;
109 } 110 }
110 111
111 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, 112 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params,
112 WebFrame* frame) { 113 WebFrame* frame) {
113 PrepareFrameAndViewForPrint prep_frame_view(params.params, 114 PrepareFrameAndViewForPrint prep_frame_view(params.params,
114 frame, 115 frame,
115 frame->GetView()); 116 frame->view());
116 int page_count = prep_frame_view.GetExpectedPageCount(); 117 int page_count = prep_frame_view.GetExpectedPageCount();
117 118
118 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(), 119 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(),
119 params.params.document_cookie, 120 params.params.document_cookie,
120 page_count)); 121 page_count));
121 if (page_count) { 122 if (page_count) {
122 ViewMsg_PrintPage_Params page_params; 123 ViewMsg_PrintPage_Params page_params;
123 page_params.params = params.params; 124 page_params.params = params.params;
124 if (params.pages.empty()) { 125 if (params.pages.empty()) {
125 for (int i = 0; i < page_count; ++i) { 126 for (int i = 0; i < page_count; ++i) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 WebScreenInfo PrintWebViewHelper::screenInfo() { 162 WebScreenInfo PrintWebViewHelper::screenInfo() {
162 NOTREACHED(); 163 NOTREACHED();
163 return WebScreenInfo(); 164 return WebScreenInfo();
164 } 165 }
165 166
166 void PrintWebViewHelper::DidStopLoading(WebView* webview) { 167 void PrintWebViewHelper::DidStopLoading(WebView* webview) {
167 DCHECK(print_pages_params_.get() != NULL); 168 DCHECK(print_pages_params_.get() != NULL);
168 DCHECK_EQ(webview, print_web_view_.get()); 169 DCHECK_EQ(webview, print_web_view_.get());
169 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); 170 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame());
170 } 171 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698