Chromium Code Reviews| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/print_messages.h" | 15 #include "chrome/common/print_messages.h" |
| 16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/renderer/prerender/prerender_helper.h" | 17 #include "chrome/renderer/prerender/prerender_helper.h" |
| 18 #include "content/renderer/render_view.h" | 18 #include "content/renderer/render_view.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "printing/metafile.h" | 20 #include "printing/metafile.h" |
| 21 #include "printing/print_job_constants.h" | |
| 21 #include "printing/units.h" | 22 #include "printing/units.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 if (old_print_pages_params_.get() && | 372 if (old_print_pages_params_.get() && |
| 372 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, | 373 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, |
| 373 *print_pages_params_)) { | 374 *print_pages_params_)) { |
| 374 PrintHostMsg_DidPreviewDocument_Params preview_params; | 375 PrintHostMsg_DidPreviewDocument_Params preview_params; |
| 375 preview_params.reuse_existing_data = true; | 376 preview_params.reuse_existing_data = true; |
| 376 preview_params.data_size = 0; | 377 preview_params.data_size = 0; |
| 377 preview_params.document_cookie = | 378 preview_params.document_cookie = |
| 378 print_pages_params_->params.document_cookie; | 379 print_pages_params_->params.document_cookie; |
| 379 preview_params.expected_pages_count = preview_page_count_; | 380 preview_params.expected_pages_count = preview_page_count_; |
| 380 preview_params.modifiable = IsModifiable(frame, node); | 381 preview_params.modifiable = IsModifiable(frame, node); |
| 382 settings.GetInteger(printing::kPreviewRequestID, | |
|
Lei Zhang
2011/07/12 23:19:30
Actually, why do we have to do this again here? Di
dpapad
2011/07/12 23:42:29
This handles the case when there is no rerendering
Lei Zhang
2011/07/12 23:58:40
We just called UpdatePrintSettings(), which should
dpapad
2011/07/13 00:15:45
Done, you are right, I confused the order of execu
| |
| 383 &preview_params.preview_request_id); | |
| 381 | 384 |
| 382 Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params)); | 385 Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params)); |
| 383 return; | 386 return; |
| 384 } | 387 } |
| 385 | 388 |
| 386 // Render Pages for preview. | 389 // Render Pages for preview. |
| 387 if (!RenderPagesForPreview(frame, node)) | 390 if (!RenderPagesForPreview(frame, node)) |
| 388 DidFinishPrinting(FAIL_PREVIEW); | 391 DidFinishPrinting(FAIL_PREVIEW); |
| 389 } | 392 } |
| 390 | 393 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 settings.pages.clear(); | 644 settings.pages.clear(); |
| 642 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 645 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 643 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 646 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 644 settings.params.document_cookie)); | 647 settings.params.document_cookie)); |
| 645 return true; | 648 return true; |
| 646 } | 649 } |
| 647 | 650 |
| 648 bool PrintWebViewHelper::UpdatePrintSettings( | 651 bool PrintWebViewHelper::UpdatePrintSettings( |
| 649 const DictionaryValue& job_settings) { | 652 const DictionaryValue& job_settings) { |
| 650 PrintMsg_PrintPages_Params settings; | 653 PrintMsg_PrintPages_Params settings; |
| 654 if (!job_settings.GetInteger(printing::kPreviewRequestID, | |
| 655 &settings.params.preview_request_id)) { | |
| 656 NOTREACHED(); | |
| 657 } | |
| 658 | |
| 651 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 659 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 652 print_pages_params_->params.document_cookie, job_settings, &settings)); | 660 print_pages_params_->params.document_cookie, job_settings, &settings)); |
| 653 | 661 |
| 654 if (!settings.params.dpi || !settings.params.document_cookie) | 662 if (!settings.params.dpi || !settings.params.document_cookie) |
| 655 return false; | 663 return false; |
| 656 | 664 |
| 665 job_settings.GetInteger(printing::kPreviewRequestID, | |
| 666 &settings.params.preview_request_id); | |
|
dpapad
2011/07/12 23:02:11
I still have to do this, because it seems that |se
Lei Zhang
2011/07/12 23:19:30
Oh, in that case just ignore my comment about doin
dpapad
2011/07/12 23:42:29
Done.
| |
| 667 | |
| 657 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 668 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 658 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 669 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 659 settings.params.document_cookie)); | 670 settings.params.document_cookie)); |
| 660 return true; | 671 return true; |
| 661 } | 672 } |
| 662 | 673 |
| 663 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 674 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 664 int expected_pages_count, | 675 int expected_pages_count, |
| 665 bool use_browser_overlays) { | 676 bool use_browser_overlays) { |
| 666 PrintHostMsg_ScriptedPrint_Params params; | 677 PrintHostMsg_ScriptedPrint_Params params; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 Send(new PrintHostMsg_RequestPrintPreview(routing_id())); | 826 Send(new PrintHostMsg_RequestPrintPreview(routing_id())); |
| 816 } | 827 } |
| 817 | 828 |
| 818 bool PrintWebViewHelper::PreviewPageRendered(int page_number) { | 829 bool PrintWebViewHelper::PreviewPageRendered(int page_number) { |
| 819 bool cancel = false; | 830 bool cancel = false; |
| 820 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel)); | 831 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel)); |
| 821 if (cancel) | 832 if (cancel) |
| 822 notify_browser_of_print_failure_ = false; | 833 notify_browser_of_print_failure_ = false; |
| 823 return !cancel; | 834 return !cancel; |
| 824 } | 835 } |
| OLD | NEW |