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 "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" | 5 #include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/browser/content_browser_client.h" | |
9 #include "content/public/common/content_client.h" | |
10 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
11 #include "printing/printing_context.h" | 9 #include "printing/printing_context.h" |
12 #include "printing/units.h" | 10 #include "printing/units.h" |
13 | 11 |
14 namespace content { | 12 namespace content { |
15 | 13 |
16 namespace { | 14 namespace { |
17 | 15 |
18 #if defined(ENABLE_FULL_PRINTING) | 16 #if defined(ENABLE_FULL_PRINTING) |
19 // Print units conversion functions. | 17 // Print units conversion functions. |
(...skipping 17 matching lines...) Expand all Loading... |
37 PP_Rect result; | 35 PP_Rect result; |
38 result.point.x = | 36 result.point.x = |
39 DeviceUnitsInPoints(print_area.origin().x(), device_units_per_inch); | 37 DeviceUnitsInPoints(print_area.origin().x(), device_units_per_inch); |
40 result.point.y = | 38 result.point.y = |
41 DeviceUnitsInPoints(print_area.origin().y(), device_units_per_inch); | 39 DeviceUnitsInPoints(print_area.origin().y(), device_units_per_inch); |
42 result.size = | 40 result.size = |
43 PrintSizeToPPPrintSize(print_area.size(), device_units_per_inch); | 41 PrintSizeToPPPrintSize(print_area.size(), device_units_per_inch); |
44 return result; | 42 return result; |
45 } | 43 } |
46 | 44 |
47 class PrintingContextDelegate : public printing::PrintingContext::Delegate { | |
48 public: | |
49 // PrintingContext::Delegate methods. | |
50 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } | |
51 virtual std::string GetAppLocale() OVERRIDE { | |
52 return GetContentClient()->browser()->GetApplicationLocale(); | |
53 } | |
54 }; | |
55 | |
56 PepperPrintSettingsManager::Result ComputeDefaultPrintSettings() { | 45 PepperPrintSettingsManager::Result ComputeDefaultPrintSettings() { |
57 // This function should run on the UI thread because |PrintingContext| methods | 46 // This function should run on the UI thread because |PrintingContext| methods |
58 // call into platform APIs. | 47 // call into platform APIs. |
59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
60 | |
61 PrintingContextDelegate delegate; | |
62 scoped_ptr<printing::PrintingContext> context( | 49 scoped_ptr<printing::PrintingContext> context( |
63 printing::PrintingContext::Create(&delegate)); | 50 printing::PrintingContext::Create(std::string())); |
64 if (!context.get() || | 51 if (!context.get() || |
65 context->UseDefaultSettings() != printing::PrintingContext::OK) { | 52 context->UseDefaultSettings() != printing::PrintingContext::OK) { |
66 return PepperPrintSettingsManager::Result(PP_PrintSettings_Dev(), | 53 return PepperPrintSettingsManager::Result(PP_PrintSettings_Dev(), |
67 PP_ERROR_FAILED); | 54 PP_ERROR_FAILED); |
68 } | 55 } |
69 const printing::PrintSettings& print_settings = context->settings(); | 56 const printing::PrintSettings& print_settings = context->settings(); |
70 const printing::PageSetup& page_setup = | 57 const printing::PageSetup& page_setup = |
71 print_settings.page_setup_device_units(); | 58 print_settings.page_setup_device_units(); |
72 int device_units_per_inch = print_settings.device_units_per_inch(); | 59 int device_units_per_inch = print_settings.device_units_per_inch(); |
73 if (device_units_per_inch <= 0) { | 60 if (device_units_per_inch <= 0) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void PepperPrintSettingsManagerImpl::GetDefaultPrintSettings( | 95 void PepperPrintSettingsManagerImpl::GetDefaultPrintSettings( |
109 PepperPrintSettingsManager::Callback callback) { | 96 PepperPrintSettingsManager::Callback callback) { |
110 BrowserThread::PostTaskAndReplyWithResult( | 97 BrowserThread::PostTaskAndReplyWithResult( |
111 BrowserThread::UI, | 98 BrowserThread::UI, |
112 FROM_HERE, | 99 FROM_HERE, |
113 base::Bind(ComputeDefaultPrintSettings), | 100 base::Bind(ComputeDefaultPrintSettings), |
114 callback); | 101 callback); |
115 } | 102 } |
116 | 103 |
117 } // namespace content | 104 } // namespace content |
OLD | NEW |