Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 7038028: Initial support for cloudprint in print preview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolved new conflictswq Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | printing/backend/print_backend_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/url_constants.h"
17 #include "chrome/renderer/prerender/prerender_helper.h" 18 #include "chrome/renderer/prerender/prerender_helper.h"
18 #include "content/renderer/render_view.h" 19 #include "content/renderer/render_view.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "printing/metafile.h" 21 #include "printing/metafile.h"
22 #include "printing/print_job_constants.h"
21 #include "printing/units.h" 23 #include "printing/units.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 29 #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/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"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
32 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
33 35
34 #if defined(OS_POSIX) 36 #if defined(OS_POSIX)
35 #include "content/common/view_messages.h" 37 #include "content/common/view_messages.h"
36 #endif 38 #endif
37 39
38 using printing::ConvertPixelsToPoint; 40 using printing::ConvertPixelsToPoint;
39 using printing::ConvertPixelsToPointDouble; 41 using printing::ConvertPixelsToPointDouble;
40 using printing::ConvertUnit; 42 using printing::ConvertUnit;
41 using printing::ConvertUnitDouble; 43 using printing::ConvertUnitDouble;
42 using WebKit::WebConsoleMessage; 44 using WebKit::WebConsoleMessage;
43 using WebKit::WebDocument; 45 using WebKit::WebDocument;
44 using WebKit::WebElement; 46 using WebKit::WebElement;
45 using WebKit::WebFrame; 47 using WebKit::WebFrame;
46 using WebKit::WebNode; 48 using WebKit::WebNode;
47 using WebKit::WebSize; 49 using WebKit::WebSize;
48 using WebKit::WebString; 50 using WebKit::WebString;
49 using WebKit::WebURLRequest; 51 using WebKit::WebURLRequest;
50 using WebKit::WebView; 52 using WebKit::WebView;
51 53
52 namespace { 54 namespace {
53 55
56 const double kMinDpi = 1.0;
57
54 int GetDPI(const PrintMsg_Print_Params* print_params) { 58 int GetDPI(const PrintMsg_Print_Params* print_params) {
55 #if defined(OS_MACOSX) 59 #if defined(OS_MACOSX)
56 // On the Mac, the printable area is in points, don't do any scaling based 60 // On the Mac, the printable area is in points, don't do any scaling based
57 // on dpi. 61 // on dpi.
58 return printing::kPointsPerInch; 62 return printing::kPointsPerInch;
59 #else 63 #else
60 return static_cast<int>(print_params->dpi); 64 return static_cast<int>(print_params->dpi);
61 #endif // defined(OS_MACOSX) 65 #endif // defined(OS_MACOSX)
62 } 66 }
63 67
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 params->margin_top = static_cast<int>(ConvertUnitDouble( 618 params->margin_top = static_cast<int>(ConvertUnitDouble(
615 margin_top_in_points, printing::kPointsPerInch, dpi)); 619 margin_top_in_points, printing::kPointsPerInch, dpi));
616 params->margin_left = static_cast<int>(ConvertUnitDouble( 620 params->margin_left = static_cast<int>(ConvertUnitDouble(
617 margin_left_in_points, printing::kPointsPerInch, dpi)); 621 margin_left_in_points, printing::kPointsPerInch, dpi));
618 } 622 }
619 623
620 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, 624 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
621 WebKit::WebNode* node) { 625 WebKit::WebNode* node) {
622 PrintMsg_PrintPages_Params settings; 626 PrintMsg_PrintPages_Params settings;
623 627
628 // TODO(abodenha@chromium.org) It doesn't make sense to do this if our
629 // "default" is a cloud based printer. Split InitPrintSettings up
630 // so that we can avoid the overhead of unneeded calls into the native
631 // print system.
624 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), 632 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
625 &settings.params)); 633 &settings.params));
626 // Check if the printer returned any settings, if the settings is empty, we 634 // Check if the printer returned any settings, if the settings is empty, we
627 // can safely assume there are no printer drivers configured. So we safely 635 // can safely assume there are no printer drivers configured. So we safely
628 // terminate. 636 // terminate.
629 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { 637 if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
630 render_view()->runModalAlertDialog( 638 render_view()->runModalAlertDialog(
631 frame, 639 frame,
632 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); 640 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING));
633 return false; 641 return false;
634 } 642 }
635 if (!settings.params.dpi || !settings.params.document_cookie) { 643 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) {
636 // Invalid print page settings. 644 // Invalid print page settings.
637 NOTREACHED(); 645 NOTREACHED();
638 return false; 646 return false;
639 } 647 }
640 UpdatePrintableSizeInPrintParameters(frame, node, &settings.params); 648 UpdatePrintableSizeInPrintParameters(frame, node, &settings.params);
641 settings.pages.clear(); 649 settings.pages.clear();
642 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 650 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
643 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), 651 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
644 settings.params.document_cookie)); 652 settings.params.document_cookie));
645 return true; 653 return true;
646 } 654 }
647 655
648 bool PrintWebViewHelper::UpdatePrintSettings( 656 bool PrintWebViewHelper::UpdatePrintSettingsCloud(
657 const DictionaryValue& job_settings) {
658 // Document cookie and pages are set by the
659 // PrintHostMsg_UpdatePrintSettings message above.
660 // TODO(abodenha@chromium.org) These numbers are for a letter sized
661 // page at 300dpi and half inch margins.
662 // Pull them from printer caps instead.
663 PrintMsg_PrintPages_Params settings;
664 settings.params.page_size = gfx::Size(2550, 3300);
665 settings.params.printable_size = gfx::Size(2250, 3000);
666 settings.params.margin_top = 150;
667 settings.params.margin_left = 150;
668 settings.params.dpi = 300.0;
669 settings.params.min_shrink = 1.25;
670 settings.params.max_shrink = 2.0;
671 settings.params.desired_dpi = 72;
672 settings.params.selection_only = false;
673 settings.params.supports_alpha_blend = false;
674 // TODO(abodenha@chromium.org) Parse page ranges from the job_settings.
675 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
676 return true;
677 }
678
679 bool PrintWebViewHelper::UpdatePrintSettingsLocal(
649 const DictionaryValue& job_settings) { 680 const DictionaryValue& job_settings) {
650 PrintMsg_PrintPages_Params settings; 681 PrintMsg_PrintPages_Params settings;
682
651 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), 683 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(),
652 print_pages_params_->params.document_cookie, job_settings, &settings)); 684 print_pages_params_->params.document_cookie, job_settings, &settings));
653 685
654 if (!settings.params.dpi || !settings.params.document_cookie) 686 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie)
655 return false; 687 return false;
656 688
657 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 689 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
658 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), 690 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
659 settings.params.document_cookie)); 691 settings.params.document_cookie));
660 return true; 692 return true;
661 } 693 }
662 694
695 bool PrintWebViewHelper::UpdatePrintSettings(
696 const DictionaryValue& job_settings) {
697 if (job_settings.HasKey(printing::kSettingCloudPrintId)) {
698 return UpdatePrintSettingsCloud(job_settings);
699 } else {
700 return UpdatePrintSettingsLocal(job_settings);
701 }
702 }
703
663 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, 704 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame,
664 int expected_pages_count, 705 int expected_pages_count,
665 bool use_browser_overlays) { 706 bool use_browser_overlays) {
666 PrintHostMsg_ScriptedPrint_Params params; 707 PrintHostMsg_ScriptedPrint_Params params;
667 PrintMsg_PrintPages_Params print_settings; 708 PrintMsg_PrintPages_Params print_settings;
668 709
669 // The routing id is sent across as it is needed to look up the 710 // The routing id is sent across as it is needed to look up the
670 // corresponding RenderViewHost instance to signal and reset the 711 // corresponding RenderViewHost instance to signal and reset the
671 // pump messages event. 712 // pump messages event.
672 params.routing_id = render_view()->routing_id(); 713 params.routing_id = render_view()->routing_id();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 Send(new PrintHostMsg_RequestPrintPreview(routing_id())); 856 Send(new PrintHostMsg_RequestPrintPreview(routing_id()));
816 } 857 }
817 858
818 bool PrintWebViewHelper::PreviewPageRendered(int page_number) { 859 bool PrintWebViewHelper::PreviewPageRendered(int page_number) {
819 bool cancel = false; 860 bool cancel = false;
820 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel)); 861 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel));
821 if (cancel) 862 if (cancel)
822 notify_browser_of_print_failure_ = false; 863 notify_browser_of_print_failure_ = false;
823 return !cancel; 864 return !cancel;
824 } 865 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | printing/backend/print_backend_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698