| OLD | NEW |
| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "webkit/glue/webkit_glue.h" | 28 #include "webkit/glue/webkit_glue.h" |
| 29 | 29 |
| 30 using printing::ConvertPixelsToPoint; | 30 using printing::ConvertPixelsToPoint; |
| 31 using printing::ConvertPixelsToPointDouble; | 31 using printing::ConvertPixelsToPointDouble; |
| 32 using printing::ConvertUnit; | 32 using printing::ConvertUnit; |
| 33 using printing::ConvertUnitDouble; | 33 using printing::ConvertUnitDouble; |
| 34 using WebKit::WebConsoleMessage; | 34 using WebKit::WebConsoleMessage; |
| 35 using WebKit::WebDocument; |
| 36 using WebKit::WebElement; |
| 35 using WebKit::WebFrame; | 37 using WebKit::WebFrame; |
| 36 using WebKit::WebNode; | 38 using WebKit::WebNode; |
| 37 using WebKit::WebRect; | 39 using WebKit::WebRect; |
| 38 using WebKit::WebSize; | 40 using WebKit::WebSize; |
| 39 using WebKit::WebScreenInfo; | 41 using WebKit::WebScreenInfo; |
| 40 using WebKit::WebString; | 42 using WebKit::WebString; |
| 41 using WebKit::WebURLRequest; | 43 using WebKit::WebURLRequest; |
| 42 using WebKit::WebView; | 44 using WebKit::WebView; |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 116 |
| 115 void PrintWebViewHelper::PrintNode(WebNode* node, | 117 void PrintWebViewHelper::PrintNode(WebNode* node, |
| 116 bool script_initiated, | 118 bool script_initiated, |
| 117 bool is_preview) { | 119 bool is_preview) { |
| 118 Print(node->document().frame(), node, script_initiated, is_preview); | 120 Print(node->document().frame(), node, script_initiated, is_preview); |
| 119 } | 121 } |
| 120 | 122 |
| 121 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 123 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 122 bool handled = true; | 124 bool handled = true; |
| 123 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 125 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 126 IPC_MESSAGE_HANDLER(ViewMsg_PrintForPrintPreview, |
| 127 OnPrintForPrintPreview) |
| 124 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) | 128 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
| 125 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) | 129 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
| 126 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview) | 130 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview) |
| 127 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu, | 131 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu, |
| 128 OnPrintNodeUnderContextMenu) | 132 OnPrintNodeUnderContextMenu) |
| 129 IPC_MESSAGE_UNHANDLED(handled = false) | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
| 130 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
| 131 return handled; | 135 return handled; |
| 132 } | 136 } |
| 133 | 137 |
| 138 void PrintWebViewHelper::OnPrintForPrintPreview() { |
| 139 if (!render_view()->webview()) |
| 140 return; |
| 141 WebFrame* main_frame = render_view()->webview()->mainFrame(); |
| 142 if (!main_frame) |
| 143 return; |
| 144 |
| 145 WebDocument document = main_frame->document(); |
| 146 // <object> with id="pdf-viewer" is created in |
| 147 // chrome/browser/resources/print_preview.js |
| 148 WebElement element = document.getElementById("pdf-viewer"); |
| 149 if (element.isNull()) { |
| 150 NOTREACHED(); |
| 151 return; |
| 152 } |
| 153 |
| 154 PrintNode(&element, false, false); |
| 155 } |
| 156 |
| 134 void PrintWebViewHelper::OnPrint(bool is_preview) { | 157 void PrintWebViewHelper::OnPrint(bool is_preview) { |
| 135 DCHECK(render_view()->webview()); | 158 DCHECK(render_view()->webview()); |
| 136 if (!render_view()->webview()) | 159 if (!render_view()->webview()) |
| 137 return; | 160 return; |
| 138 | 161 |
| 139 // If the user has selected text in the currently focused frame we print | 162 // If the user has selected text in the currently focused frame we print |
| 140 // only that frame (this makes print selection work for multiple frames). | 163 // only that frame (this makes print selection work for multiple frames). |
| 141 if (render_view()->webview()->focusedFrame()->hasSelection()) | 164 if (render_view()->webview()->focusedFrame()->hasSelection()) |
| 142 PrintFrame(render_view()->webview()->focusedFrame(), false, is_preview); | 165 PrintFrame(render_view()->webview()->focusedFrame(), false, is_preview); |
| 143 else | 166 else |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), | 598 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), |
| 576 shared_mem_handle); | 599 shared_mem_handle); |
| 577 return true; | 600 return true; |
| 578 } | 601 } |
| 579 } | 602 } |
| 580 } | 603 } |
| 581 NOTREACHED(); | 604 NOTREACHED(); |
| 582 return false; | 605 return false; |
| 583 } | 606 } |
| 584 #endif | 607 #endif |
| OLD | NEW |