| OLD | NEW |
| 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/gfx/codec/jpeg_codec.h" | 7 #include "app/gfx/codec/jpeg_codec.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| 11 #include "chrome/renderer/render_view.h" | 11 #include "chrome/renderer/render_view.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "printing/units.h" | 13 #include "printing/units.h" |
| 14 #include "webkit/api/public/WebFrame.h" | 14 #include "webkit/api/public/WebFrame.h" |
| 15 #include "webkit/api/public/WebRect.h" | 15 #include "webkit/api/public/WebRect.h" |
| 16 #include "webkit/api/public/WebScreenInfo.h" | 16 #include "webkit/api/public/WebScreenInfo.h" |
| 17 #include "webkit/api/public/WebSize.h" | 17 #include "webkit/api/public/WebSize.h" |
| 18 #include "webkit/api/public/WebURLRequest.h" | 18 #include "webkit/api/public/WebURLRequest.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 | 20 |
| 21 using WebKit::WebFrame; | 21 using WebKit::WebFrame; |
| 22 using WebKit::WebRect; | 22 using WebKit::WebRect; |
| 23 using WebKit::WebScreenInfo; | 23 using WebKit::WebScreenInfo; |
| 24 using WebKit::WebString; | 24 using WebKit::WebString; |
| 25 using WebKit::WebURLRequest; | 25 using WebKit::WebURLRequest; |
| 26 using WebKit::WebView; |
| 26 | 27 |
| 27 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 28 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 28 const ViewMsg_Print_Params& print_params, | 29 const ViewMsg_Print_Params& print_params, |
| 29 WebFrame* frame, | 30 WebFrame* frame, |
| 30 WebView* web_view) | 31 WebView* web_view) |
| 31 : frame_(frame), web_view_(web_view), expected_pages_count_(0) { | 32 : frame_(frame), web_view_(web_view), expected_pages_count_(0) { |
| 32 print_canvas_size_.set_width( | 33 print_canvas_size_.set_width( |
| 33 printing::ConvertUnit(print_params.printable_size.width(), | 34 printing::ConvertUnit(print_params.printable_size.width(), |
| 34 static_cast<int>(print_params.dpi), | 35 static_cast<int>(print_params.dpi), |
| 35 print_params.desired_dpi)); | 36 print_params.desired_dpi)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 56 } | 57 } |
| 57 | 58 |
| 58 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 59 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 59 frame_->printEnd(); | 60 frame_->printEnd(); |
| 60 web_view_->resize(prev_view_size_); | 61 web_view_->resize(prev_view_size_); |
| 61 } | 62 } |
| 62 | 63 |
| 63 | 64 |
| 64 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) | 65 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) |
| 65 : render_view_(render_view), | 66 : render_view_(render_view), |
| 67 print_web_view_(NULL), |
| 66 user_cancelled_scripted_print_count_(0) {} | 68 user_cancelled_scripted_print_count_(0) {} |
| 67 | 69 |
| 68 PrintWebViewHelper::~PrintWebViewHelper() {} | 70 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 69 | 71 |
| 70 void PrintWebViewHelper::DidFinishPrinting(bool success) { | 72 void PrintWebViewHelper::DidFinishPrinting(bool success) { |
| 71 if (!success) { | 73 if (!success) { |
| 72 WebView* web_view = print_web_view_.get(); | 74 WebView* web_view = print_web_view_; |
| 73 if (!web_view) | 75 if (!web_view) |
| 74 web_view = render_view_->webview(); | 76 web_view = render_view_->webview(); |
| 75 | 77 |
| 76 // TODO: Create an async alert (http://crbug.com/14918). | 78 // TODO: Create an async alert (http://crbug.com/14918). |
| 77 render_view_->runModalAlertDialog( | 79 render_view_->runModalAlertDialog( |
| 78 web_view->mainFrame(), | 80 web_view->mainFrame(), |
| 79 WideToUTF16Hack( | 81 WideToUTF16Hack( |
| 80 l10n_util::GetString(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT))); | 82 l10n_util::GetString(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT))); |
| 81 } | 83 } |
| 82 | 84 |
| 83 if (print_web_view_.get()) { | 85 if (print_web_view_) { |
| 84 print_web_view_->close(); | 86 print_web_view_->close(); |
| 85 print_web_view_.release(); // Close deletes object. | 87 print_web_view_ = NULL; |
| 86 print_pages_params_.reset(); | 88 print_pages_params_.reset(); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 90 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params, | 92 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params, |
| 91 WebFrame* web_frame) { | 93 WebFrame* web_frame) { |
| 92 // Create a new WebView with the same settings as the current display one. | 94 // Create a new WebView with the same settings as the current display one. |
| 93 // Except that we disable javascript (don't want any active content running | 95 // Except that we disable javascript (don't want any active content running |
| 94 // on the page). | 96 // on the page). |
| 95 WebPreferences prefs = render_view_->webkit_preferences(); | 97 WebPreferences prefs = render_view_->webkit_preferences(); |
| 96 prefs.javascript_enabled = false; | 98 prefs.javascript_enabled = false; |
| 97 prefs.java_enabled = false; | 99 prefs.java_enabled = false; |
| 98 | 100 |
| 99 print_web_view_.reset(WebView::Create(this)); | 101 print_web_view_ = WebView::create(this); |
| 100 prefs.Apply(print_web_view_.get()); | 102 prefs.Apply(print_web_view_); |
| 101 print_web_view_->initializeMainFrame(NULL); | 103 print_web_view_->initializeMainFrame(NULL); |
| 102 | 104 |
| 103 print_pages_params_.reset(new ViewMsg_PrintPages_Params(params)); | 105 print_pages_params_.reset(new ViewMsg_PrintPages_Params(params)); |
| 104 print_pages_params_->pages.clear(); // Print all pages of selection. | 106 print_pages_params_->pages.clear(); // Print all pages of selection. |
| 105 | 107 |
| 106 std::string html = web_frame->selectionAsMarkup().utf8(); | 108 std::string html = web_frame->selectionAsMarkup().utf8(); |
| 107 std::string url_str = "data:text/html;charset=utf-8,"; | 109 std::string url_str = "data:text/html;charset=utf-8,"; |
| 108 url_str.append(html); | 110 url_str.append(html); |
| 109 GURL url(url_str); | 111 GURL url(url_str); |
| 110 | 112 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 181 |
| 180 WebRect PrintWebViewHelper::rootWindowRect() { | 182 WebRect PrintWebViewHelper::rootWindowRect() { |
| 181 NOTREACHED(); | 183 NOTREACHED(); |
| 182 return WebRect(); | 184 return WebRect(); |
| 183 } | 185 } |
| 184 | 186 |
| 185 WebScreenInfo PrintWebViewHelper::screenInfo() { | 187 WebScreenInfo PrintWebViewHelper::screenInfo() { |
| 186 NOTREACHED(); | 188 NOTREACHED(); |
| 187 return WebScreenInfo(); | 189 return WebScreenInfo(); |
| 188 } | 190 } |
| OLD | NEW |