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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) | 132 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
133 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) | 133 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
134 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview) | 134 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview) |
135 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu, | 135 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu, |
136 OnPrintNodeUnderContextMenu) | 136 OnPrintNodeUnderContextMenu) |
137 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
138 IPC_END_MESSAGE_MAP() | 138 IPC_END_MESSAGE_MAP() |
139 return handled; | 139 return handled; |
140 } | 140 } |
141 | 141 |
142 void PrintWebViewHelper::OnPrintForPrintPreview() { | 142 void PrintWebViewHelper::OnPrintForPrintPreview( |
| 143 const DictionaryValue& job_settings) { |
| 144 #if defined(OS_MACOSX) |
| 145 // If still not finished with earlier print request simply ignore. |
| 146 if (print_web_view_) |
| 147 return; |
| 148 |
143 if (!render_view()->webview()) | 149 if (!render_view()->webview()) |
144 return; | 150 return; |
145 WebFrame* main_frame = render_view()->webview()->mainFrame(); | 151 WebFrame* main_frame = render_view()->webview()->mainFrame(); |
146 if (!main_frame) | 152 if (!main_frame) |
147 return; | 153 return; |
148 | 154 |
149 WebDocument document = main_frame->document(); | 155 WebDocument document = main_frame->document(); |
150 // <object> with id="pdf-viewer" is created in | 156 // <object> with id="pdf-viewer" is created in |
151 // chrome/browser/resources/print_preview.js | 157 // chrome/browser/resources/print_preview.js |
152 WebElement element = document.getElementById("pdf-viewer"); | 158 WebElement element = document.getElementById("pdf-viewer"); |
153 if (element.isNull()) { | 159 if (element.isNull()) { |
154 NOTREACHED(); | 160 NOTREACHED(); |
155 return; | 161 return; |
156 } | 162 } |
157 | 163 |
158 PrintNode(&element, false, false); | 164 if (!InitPrintSettings(element.document().frame(), &element)) { |
| 165 NOTREACHED() << "Failed to initialize print page settings"; |
| 166 return; |
| 167 } |
| 168 |
| 169 if (!UpdatePrintSettings(job_settings)) { |
| 170 NOTREACHED() << "Failed to update print page settings"; |
| 171 DidFinishPrinting(true); // Release all printing resources. |
| 172 return; |
| 173 } |
| 174 |
| 175 // Render Pages for printing. |
| 176 RenderPagesForPrint(element.document().frame(), &element); |
| 177 #endif |
159 } | 178 } |
160 | 179 |
161 void PrintWebViewHelper::OnPrint(bool is_preview) { | 180 void PrintWebViewHelper::OnPrint(bool is_preview) { |
162 DCHECK(render_view()->webview()); | 181 DCHECK(render_view()->webview()); |
163 if (!render_view()->webview()) | 182 if (!render_view()->webview()) |
164 return; | 183 return; |
165 | 184 |
166 // If the user has selected text in the currently focused frame we print | 185 // If the user has selected text in the currently focused frame we print |
167 // only that frame (this makes print selection work for multiple frames). | 186 // only that frame (this makes print selection work for multiple frames). |
168 if (render_view()->webview()->focusedFrame()->hasSelection()) | 187 if (render_view()->webview()->focusedFrame()->hasSelection()) |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 WebNode* node) { | 511 WebNode* node) { |
493 ViewMsg_PrintPages_Params settings; | 512 ViewMsg_PrintPages_Params settings; |
494 if (GetDefaultPrintSettings(frame, node, &settings.params)) { | 513 if (GetDefaultPrintSettings(frame, node, &settings.params)) { |
495 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); | 514 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); |
496 print_pages_params_->pages.clear(); | 515 print_pages_params_->pages.clear(); |
497 return true; | 516 return true; |
498 } | 517 } |
499 return false; | 518 return false; |
500 } | 519 } |
501 | 520 |
502 bool PrintWebViewHelper::GetDefaultPrintSettings( | 521 bool PrintWebViewHelper::UpdatePrintSettings( |
503 WebFrame* frame, | 522 const DictionaryValue& job_settings) { |
504 WebNode* node, | 523 ViewMsg_PrintPages_Params settings; |
505 ViewMsg_Print_Params* params) { | 524 if (!render_view()->Send(new ViewHostMsg_UpdatePrintSettings( |
| 525 render_view()->routing_id(), |
| 526 print_pages_params_->params.document_cookie, |
| 527 job_settings, &settings.params))) { |
| 528 NOTREACHED(); |
| 529 return false; |
| 530 } |
| 531 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); |
| 532 return true; |
| 533 } |
| 534 |
| 535 bool PrintWebViewHelper::GetDefaultPrintSettings(WebFrame* frame, |
| 536 WebNode* node, |
| 537 ViewMsg_Print_Params* params) { |
506 if (!render_view()->Send(new ViewHostMsg_GetDefaultPrintSettings( | 538 if (!render_view()->Send(new ViewHostMsg_GetDefaultPrintSettings( |
507 render_view()->routing_id(), params))) { | 539 render_view()->routing_id(), params))) { |
508 NOTREACHED(); | 540 NOTREACHED(); |
509 return false; | 541 return false; |
510 } | 542 } |
511 // Check if the printer returned any settings, if the settings is empty, we | 543 // Check if the printer returned any settings, if the settings is empty, we |
512 // can safely assume there are no printer drivers configured. So we safely | 544 // can safely assume there are no printer drivers configured. So we safely |
513 // terminate. | 545 // terminate. |
514 if (params->IsEmpty()) { | 546 if (params->IsEmpty()) { |
515 render_view()->runModalAlertDialog( | 547 render_view()->runModalAlertDialog( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), | 623 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), |
592 shared_mem_handle); | 624 shared_mem_handle); |
593 return true; | 625 return true; |
594 } | 626 } |
595 } | 627 } |
596 } | 628 } |
597 NOTREACHED(); | 629 NOTREACHED(); |
598 return false; | 630 return false; |
599 } | 631 } |
600 #endif // defined(OS_POSIX) | 632 #endif // defined(OS_POSIX) |
OLD | NEW |