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