OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 PREVIEW_EVENT_MAX, | 60 PREVIEW_EVENT_MAX, |
61 }; | 61 }; |
62 | 62 |
63 const double kMinDpi = 1.0; | 63 const double kMinDpi = 1.0; |
64 | 64 |
65 const char kPageLoadScriptFormat[] = | 65 const char kPageLoadScriptFormat[] = |
66 "document.open(); document.write(%s); document.close();"; | 66 "document.open(); document.write(%s); document.close();"; |
67 | 67 |
68 const char kPageSetupScriptFormat[] = "setup(%s);"; | 68 const char kPageSetupScriptFormat[] = "setup(%s);"; |
69 | 69 |
70 #if defined(ENABLE_FULL_PRINTING) | 70 #if defined(ENABLE_PRINT_PREVIEW) |
71 bool g_is_preview_enabled_ = true; | 71 bool g_is_preview_enabled_ = true; |
72 #else | 72 #else |
73 bool g_is_preview_enabled_ = false; | 73 bool g_is_preview_enabled_ = false; |
74 #endif | 74 #endif |
75 | 75 |
76 void ExecuteScript(blink::WebFrame* frame, | 76 void ExecuteScript(blink::WebFrame* frame, |
77 const char* script_format, | 77 const char* script_format, |
78 const base::Value& parameters) { | 78 const base::Value& parameters) { |
79 std::string json; | 79 std::string json; |
80 base::JSONWriter::Write(¶meters, &json); | 80 base::JSONWriter::Write(¶meters, &json); |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 Print(frame, blink::WebNode()); | 842 Print(frame, blink::WebNode()); |
843 } else { | 843 } else { |
844 print_preview_context_.InitWithFrame(frame); | 844 print_preview_context_.InitWithFrame(frame); |
845 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 845 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
846 } | 846 } |
847 } | 847 } |
848 | 848 |
849 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 849 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
850 bool handled = true; | 850 bool handled = true; |
851 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 851 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
852 #if !defined(DISABLE_BASIC_PRINTING) | 852 #if defined(ENABLE_BASIC_PRINTING) |
853 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 853 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
854 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 854 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
855 #endif // !DISABLE_BASIC_PRINTING | 855 #endif // ENABLE_BASIC_PRINTING |
856 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 856 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
857 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 857 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
858 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 858 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
859 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 859 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
860 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, | 860 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, |
861 SetScriptedPrintBlocked) | 861 SetScriptedPrintBlocked) |
862 IPC_MESSAGE_UNHANDLED(handled = false) | 862 IPC_MESSAGE_UNHANDLED(handled = false) |
863 IPC_END_MESSAGE_MAP() | 863 IPC_END_MESSAGE_MAP() |
864 return handled; | 864 return handled; |
865 } | 865 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 // If the user has selected text in the currently focused frame we print | 942 // If the user has selected text in the currently focused frame we print |
943 // only that frame (this makes print selection work for multiple frames). | 943 // only that frame (this makes print selection work for multiple frames). |
944 blink::WebLocalFrame* focusedFrame = | 944 blink::WebLocalFrame* focusedFrame = |
945 webView->focusedFrame()->toWebLocalFrame(); | 945 webView->focusedFrame()->toWebLocalFrame(); |
946 *frame = focusedFrame->hasSelection() | 946 *frame = focusedFrame->hasSelection() |
947 ? focusedFrame | 947 ? focusedFrame |
948 : webView->mainFrame()->toWebLocalFrame(); | 948 : webView->mainFrame()->toWebLocalFrame(); |
949 return true; | 949 return true; |
950 } | 950 } |
951 | 951 |
952 #if !defined(DISABLE_BASIC_PRINTING) | 952 #if defined(ENABLE_BASIC_PRINTING) |
953 void PrintWebViewHelper::OnPrintPages() { | 953 void PrintWebViewHelper::OnPrintPages() { |
954 blink::WebLocalFrame* frame; | 954 blink::WebLocalFrame* frame; |
955 if (GetPrintFrame(&frame)) | 955 if (GetPrintFrame(&frame)) |
956 Print(frame, blink::WebNode()); | 956 Print(frame, blink::WebNode()); |
957 } | 957 } |
958 | 958 |
959 void PrintWebViewHelper::OnPrintForSystemDialog() { | 959 void PrintWebViewHelper::OnPrintForSystemDialog() { |
960 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 960 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
961 if (!frame) { | 961 if (!frame) { |
962 NOTREACHED(); | 962 NOTREACHED(); |
963 return; | 963 return; |
964 } | 964 } |
965 Print(frame, print_preview_context_.source_node()); | 965 Print(frame, print_preview_context_.source_node()); |
966 } | 966 } |
967 #endif // !DISABLE_BASIC_PRINTING | 967 #endif // ENABLE_BASIC_PRINTING |
968 | 968 |
969 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 969 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
970 const PageSizeMargins& page_layout_in_points, | 970 const PageSizeMargins& page_layout_in_points, |
971 gfx::Size* page_size, | 971 gfx::Size* page_size, |
972 gfx::Rect* content_area) { | 972 gfx::Rect* content_area) { |
973 *page_size = gfx::Size( | 973 *page_size = gfx::Size( |
974 page_layout_in_points.content_width + | 974 page_layout_in_points.content_width + |
975 page_layout_in_points.margin_right + | 975 page_layout_in_points.margin_right + |
976 page_layout_in_points.margin_left, | 976 page_layout_in_points.margin_left, |
977 page_layout_in_points.content_height + | 977 page_layout_in_points.content_height + |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2021 blink::WebConsoleMessage::LevelWarning, message)); | 2021 blink::WebConsoleMessage::LevelWarning, message)); |
2022 return false; | 2022 return false; |
2023 } | 2023 } |
2024 | 2024 |
2025 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2025 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2026 // Reset counter on successful print. | 2026 // Reset counter on successful print. |
2027 count_ = 0; | 2027 count_ = 0; |
2028 } | 2028 } |
2029 | 2029 |
2030 } // namespace printing | 2030 } // namespace printing |
OLD | NEW |