| 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/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/gfx/size.h" | 9 #include "base/gfx/size.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/native_metafile.h" | 13 #include "printing/native_metafile.h" |
| 14 #include "printing/units.h" | 14 #include "printing/units.h" |
| 15 #include "webkit/api/public/WebConsoleMessage.h" | 15 #include "webkit/api/public/WebConsoleMessage.h" |
| 16 #include "webkit/api/public/WebRect.h" |
| 16 #include "webkit/api/public/WebScreenInfo.h" | 17 #include "webkit/api/public/WebScreenInfo.h" |
| 17 #include "webkit/api/public/WebSize.h" | 18 #include "webkit/api/public/WebSize.h" |
| 18 #include "webkit/api/public/WebURL.h" | 19 #include "webkit/api/public/WebURL.h" |
| 19 #include "webkit/api/public/WebURLRequest.h" | 20 #include "webkit/api/public/WebURLRequest.h" |
| 20 #include "webkit/glue/webframe.h" | 21 #include "webkit/glue/webframe.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "skia/ext/vector_canvas.h" | 24 #include "skia/ext/vector_canvas.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 using WebKit::WebConsoleMessage; | 27 using WebKit::WebConsoleMessage; |
| 28 using WebKit::WebRect; |
| 29 using WebKit::WebScreenInfo; |
| 27 using WebKit::WebString; | 30 using WebKit::WebString; |
| 28 using WebKit::WebURLRequest; | 31 using WebKit::WebURLRequest; |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; | 35 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; |
| 33 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 2 * 60; // 2 Minutes. | 36 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 2 * 60; // 2 Minutes. |
| 34 | 37 |
| 35 // Class that calls the Begin and End print functions on the frame and changes | 38 // Class that calls the Begin and End print functions on the frame and changes |
| 36 // the size of the view temporarily to support full page printing.. | 39 // the size of the view temporarily to support full page printing.. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 | 58 |
| 56 // Layout page according to printer page size. Since WebKit shrinks the | 59 // Layout page according to printer page size. Since WebKit shrinks the |
| 57 // size of the page automatically (from 125% to 200%) we trick it to | 60 // size of the page automatically (from 125% to 200%) we trick it to |
| 58 // think the page is 125% larger so the size of the page is correct for | 61 // think the page is 125% larger so the size of the page is correct for |
| 59 // minimum (default) scaling. | 62 // minimum (default) scaling. |
| 60 // This is important for sites that try to fill the page. | 63 // This is important for sites that try to fill the page. |
| 61 gfx::Size print_layout_size(print_canvas_size_); | 64 gfx::Size print_layout_size(print_canvas_size_); |
| 62 print_layout_size.set_height(static_cast<int>( | 65 print_layout_size.set_height(static_cast<int>( |
| 63 static_cast<double>(print_layout_size.height()) * 1.25)); | 66 static_cast<double>(print_layout_size.height()) * 1.25)); |
| 64 | 67 |
| 65 prev_view_size_ = web_view->GetSize(); | 68 prev_view_size_ = web_view->size(); |
| 66 | 69 |
| 67 web_view->Resize(print_layout_size); | 70 web_view->resize(print_layout_size); |
| 68 | 71 |
| 69 expected_pages_count_ = frame->PrintBegin(print_canvas_size_); | 72 expected_pages_count_ = frame->PrintBegin(print_canvas_size_); |
| 70 } | 73 } |
| 71 | 74 |
| 72 int GetExpectedPageCount() const { | 75 int GetExpectedPageCount() const { |
| 73 return expected_pages_count_; | 76 return expected_pages_count_; |
| 74 } | 77 } |
| 75 | 78 |
| 76 gfx::Size GetPrintCanvasSize() const { | 79 gfx::Size GetPrintCanvasSize() const { |
| 77 return print_canvas_size_; | 80 return print_canvas_size_; |
| 78 } | 81 } |
| 79 | 82 |
| 80 ~PrepareFrameAndViewForPrint() { | 83 ~PrepareFrameAndViewForPrint() { |
| 81 frame_->PrintEnd(); | 84 frame_->PrintEnd(); |
| 82 web_view_->Resize(prev_view_size_); | 85 web_view_->resize(prev_view_size_); |
| 83 } | 86 } |
| 84 | 87 |
| 85 private: | 88 private: |
| 86 WebFrame* frame_; | 89 WebFrame* frame_; |
| 87 WebView* web_view_; | 90 WebView* web_view_; |
| 88 gfx::Size print_canvas_size_; | 91 gfx::Size print_canvas_size_; |
| 89 gfx::Size prev_view_size_; | 92 gfx::Size prev_view_size_; |
| 90 int expected_pages_count_; | 93 int expected_pages_count_; |
| 91 | 94 |
| 92 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 95 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 WebView* web_view = print_web_view_.get(); | 226 WebView* web_view = print_web_view_.get(); |
| 224 if (!web_view) | 227 if (!web_view) |
| 225 web_view = render_view_->webview(); | 228 web_view = render_view_->webview(); |
| 226 | 229 |
| 227 // TODO: Create an async alert (http://crbug.com/14918). | 230 // TODO: Create an async alert (http://crbug.com/14918). |
| 228 render_view_->RunJavaScriptAlert(web_view->GetMainFrame(), | 231 render_view_->RunJavaScriptAlert(web_view->GetMainFrame(), |
| 229 l10n_util::GetString(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); | 232 l10n_util::GetString(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); |
| 230 } | 233 } |
| 231 | 234 |
| 232 if (print_web_view_.get()) { | 235 if (print_web_view_.get()) { |
| 233 print_web_view_->Close(); | 236 print_web_view_->close(); |
| 234 print_web_view_.release(); // Close deletes object. | 237 print_web_view_.release(); // Close deletes object. |
| 235 print_pages_params_.reset(); | 238 print_pages_params_.reset(); |
| 236 } | 239 } |
| 237 | 240 |
| 238 } | 241 } |
| 239 | 242 |
| 240 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params, | 243 bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params, |
| 241 WebFrame* web_frame) { | 244 WebFrame* web_frame) { |
| 242 // Create a new WebView with the same settings as the current display one. | 245 // Create a new WebView with the same settings as the current display one. |
| 243 // Except that we disable javascript (don't want any active content running | 246 // Except that we disable javascript (don't want any active content running |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 407 } |
| 405 | 408 |
| 406 bool PrintWebViewHelper::Send(IPC::Message* msg) { | 409 bool PrintWebViewHelper::Send(IPC::Message* msg) { |
| 407 return render_view_->Send(msg); | 410 return render_view_->Send(msg); |
| 408 } | 411 } |
| 409 | 412 |
| 410 int32 PrintWebViewHelper::routing_id() { | 413 int32 PrintWebViewHelper::routing_id() { |
| 411 return render_view_->routing_id(); | 414 return render_view_->routing_id(); |
| 412 } | 415 } |
| 413 | 416 |
| 417 WebRect PrintWebViewHelper::windowRect() { |
| 418 NOTREACHED(); |
| 419 return WebRect(); |
| 420 } |
| 421 |
| 422 WebRect PrintWebViewHelper::windowResizerRect() { |
| 423 NOTREACHED(); |
| 424 return WebRect(); |
| 425 } |
| 426 |
| 427 WebRect PrintWebViewHelper::rootWindowRect() { |
| 428 NOTREACHED(); |
| 429 return WebRect(); |
| 430 } |
| 431 |
| 432 WebScreenInfo PrintWebViewHelper::screenInfo() { |
| 433 NOTREACHED(); |
| 434 return WebScreenInfo(); |
| 435 } |
| 436 |
| 414 void PrintWebViewHelper::DidStopLoading(WebView* webview) { | 437 void PrintWebViewHelper::DidStopLoading(WebView* webview) { |
| 415 DCHECK(print_pages_params_.get() != NULL); | 438 DCHECK(print_pages_params_.get() != NULL); |
| 416 DCHECK_EQ(webview, print_web_view_.get()); | 439 DCHECK_EQ(webview, print_web_view_.get()); |
| 417 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); | 440 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); |
| 418 } | 441 } |
| 419 | |
| 420 void PrintWebViewHelper::GetWindowRect(WebWidget* webwidget, | |
| 421 WebKit::WebRect* rect) { | |
| 422 NOTREACHED(); | |
| 423 } | |
| 424 | |
| 425 WebKit::WebScreenInfo PrintWebViewHelper::GetScreenInfo(WebWidget* webwidget) { | |
| 426 WebKit::WebScreenInfo info; | |
| 427 NOTREACHED(); | |
| 428 return info; | |
| 429 } | |
| 430 | |
| 431 bool PrintWebViewHelper::IsHidden(WebWidget* webwidget) { | |
| 432 NOTREACHED(); | |
| 433 return true; | |
| 434 } | |
| OLD | NEW |