OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "printing/printing_context_android.h" | 5 #include "printing/printing_context_android.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 range.to = *it; | 54 range.to = *it; |
55 range_vector.push_back(range); | 55 range_vector.push_back(range); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 namespace printing { | 61 namespace printing { |
62 | 62 |
63 // static | 63 // static |
64 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 64 scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { |
65 return new PrintingContextAndroid(app_locale); | 65 return make_scoped_ptr<PrintingContext>(new PrintingContextAndroid(delegate)); |
66 } | 66 } |
67 | 67 |
68 // static | 68 // static |
69 void PrintingContextAndroid::PdfWritingDone(int fd, bool success) { | 69 void PrintingContextAndroid::PdfWritingDone(int fd, bool success) { |
70 JNIEnv* env = base::android::AttachCurrentThread(); | 70 JNIEnv* env = base::android::AttachCurrentThread(); |
71 Java_PrintingContext_pdfWritingDone(env, fd, success); | 71 Java_PrintingContext_pdfWritingDone(env, fd, success); |
72 } | 72 } |
73 | 73 |
74 PrintingContextAndroid::PrintingContextAndroid(const std::string& app_locale) | 74 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate) |
75 : PrintingContext(app_locale) { | 75 : PrintingContext(delegate) { |
76 // The constructor is run in the IO thread. | 76 // The constructor is run in the IO thread. |
77 } | 77 } |
78 | 78 |
79 PrintingContextAndroid::~PrintingContextAndroid() { | 79 PrintingContextAndroid::~PrintingContextAndroid() { |
80 } | 80 } |
81 | 81 |
82 void PrintingContextAndroid::AskUserForSettings( | 82 void PrintingContextAndroid::AskUserForSettings( |
83 gfx::NativeView parent_view, | |
84 int max_pages, | 83 int max_pages, |
85 bool has_selection, | 84 bool has_selection, |
86 const PrintSettingsCallback& callback) { | 85 const PrintSettingsCallback& callback) { |
87 // This method is always run in the UI thread. | 86 // This method is always run in the UI thread. |
88 callback_ = callback; | 87 callback_ = callback; |
89 | 88 |
90 JNIEnv* env = base::android::AttachCurrentThread(); | 89 JNIEnv* env = base::android::AttachCurrentThread(); |
91 if (j_printing_context_.is_null()) { | 90 if (j_printing_context_.is_null()) { |
92 j_printing_context_.Reset(Java_PrintingContext_create( | 91 j_printing_context_.Reset(Java_PrintingContext_create( |
93 env, | 92 env, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), | 141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), |
143 physical_size.height()); | 142 physical_size.height()); |
144 return OK; | 143 return OK; |
145 } | 144 } |
146 | 145 |
147 gfx::Size PrintingContextAndroid::GetPdfPaperSizeDeviceUnits() { | 146 gfx::Size PrintingContextAndroid::GetPdfPaperSizeDeviceUnits() { |
148 // NOTE: This implementation is the same as in PrintingContextNoSystemDialog. | 147 // NOTE: This implementation is the same as in PrintingContextNoSystemDialog. |
149 int32_t width = 0; | 148 int32_t width = 0; |
150 int32_t height = 0; | 149 int32_t height = 0; |
151 UErrorCode error = U_ZERO_ERROR; | 150 UErrorCode error = U_ZERO_ERROR; |
152 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); | 151 ulocdata_getPaperSize( |
| 152 delegate_->GetAppLocale().c_str(), &height, &width, &error); |
153 if (error > U_ZERO_ERROR) { | 153 if (error > U_ZERO_ERROR) { |
154 // If the call failed, assume a paper size of 8.5 x 11 inches. | 154 // If the call failed, assume a paper size of 8.5 x 11 inches. |
155 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " | 155 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " |
156 << error; | 156 << error; |
157 width = static_cast<int>( | 157 width = static_cast<int>( |
158 kLetterWidthInch * settings_.device_units_per_inch()); | 158 kLetterWidthInch * settings_.device_units_per_inch()); |
159 height = static_cast<int>( | 159 height = static_cast<int>( |
160 kLetterHeightInch * settings_.device_units_per_inch()); | 160 kLetterHeightInch * settings_.device_units_per_inch()); |
161 } else { | 161 } else { |
162 // ulocdata_getPaperSize returns the width and height in mm. | 162 // ulocdata_getPaperSize returns the width and height in mm. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Intentional No-op. | 237 // Intentional No-op. |
238 return NULL; | 238 return NULL; |
239 } | 239 } |
240 | 240 |
241 // static | 241 // static |
242 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { | 242 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { |
243 return RegisterNativesImpl(env); | 243 return RegisterNativesImpl(env); |
244 } | 244 } |
245 | 245 |
246 } // namespace printing | 246 } // namespace printing |
OLD | NEW |