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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 callback_ = callback; | 94 callback_ = callback; |
95 | 95 |
96 JNIEnv* env = base::android::AttachCurrentThread(); | 96 JNIEnv* env = base::android::AttachCurrentThread(); |
97 if (j_printing_context_.is_null()) { | 97 if (j_printing_context_.is_null()) { |
98 j_printing_context_.Reset(Java_PrintingContext_create( | 98 j_printing_context_.Reset(Java_PrintingContext_create( |
99 env, | 99 env, |
100 reinterpret_cast<intptr_t>(this))); | 100 reinterpret_cast<intptr_t>(this))); |
101 } | 101 } |
102 | 102 |
103 if (is_scripted) { | 103 if (is_scripted) { |
104 Java_PrintingContext_showPrintDialog(env, j_printing_context_.obj()); | 104 Java_PrintingContext_showPrintDialog(env, j_printing_context_); |
105 } else { | 105 } else { |
106 Java_PrintingContext_pageCountEstimationDone(env, | 106 Java_PrintingContext_pageCountEstimationDone(env, j_printing_context_, |
107 j_printing_context_.obj(), | |
108 max_pages); | 107 max_pages); |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 void PrintingContextAndroid::AskUserForSettingsReply( | 111 void PrintingContextAndroid::AskUserForSettingsReply( |
113 JNIEnv* env, | 112 JNIEnv* env, |
114 const JavaParamRef<jobject>& obj, | 113 const JavaParamRef<jobject>& obj, |
115 jboolean success) { | 114 jboolean success) { |
116 if (!success) { | 115 if (!success) { |
117 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. | 116 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. |
118 callback_.Run(FAILED); | 117 callback_.Run(FAILED); |
119 return; | 118 return; |
120 } | 119 } |
121 | 120 |
122 // We use device name variable to store the file descriptor. This is hacky | 121 // We use device name variable to store the file descriptor. This is hacky |
123 // but necessary. Since device name is not necessary for the upstream | 122 // but necessary. Since device name is not necessary for the upstream |
124 // printing code for Android, this is harmless. | 123 // printing code for Android, this is harmless. |
125 int fd = Java_PrintingContext_getFileDescriptor(env, | 124 int fd = Java_PrintingContext_getFileDescriptor(env, j_printing_context_); |
126 j_printing_context_.obj()); | |
127 settings_.set_device_name(base::IntToString16(fd)); | 125 settings_.set_device_name(base::IntToString16(fd)); |
128 | 126 |
129 ScopedJavaLocalRef<jintArray> intArr = | 127 ScopedJavaLocalRef<jintArray> intArr = |
130 Java_PrintingContext_getPages(env, j_printing_context_.obj()); | 128 Java_PrintingContext_getPages(env, j_printing_context_); |
131 if (intArr.obj() != NULL) { | 129 if (intArr.obj() != NULL) { |
132 PageRanges range_vector; | 130 PageRanges range_vector; |
133 GetPageRanges(env, intArr.obj(), range_vector); | 131 GetPageRanges(env, intArr.obj(), range_vector); |
134 settings_.set_ranges(range_vector); | 132 settings_.set_ranges(range_vector); |
135 } | 133 } |
136 | 134 |
137 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); | 135 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_); |
138 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); | 136 int width = Java_PrintingContext_getWidth(env, j_printing_context_); |
139 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); | 137 int height = Java_PrintingContext_getHeight(env, j_printing_context_); |
140 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); | 138 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); |
141 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); | 139 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); |
142 SetSizes(&settings_, dpi, width, height); | 140 SetSizes(&settings_, dpi, width, height); |
143 | 141 |
144 callback_.Run(OK); | 142 callback_.Run(OK); |
145 } | 143 } |
146 | 144 |
147 void PrintingContextAndroid::ShowSystemDialogDone( | 145 void PrintingContextAndroid::ShowSystemDialogDone( |
148 JNIEnv* env, | 146 JNIEnv* env, |
149 const JavaParamRef<jobject>& obj) { | 147 const JavaParamRef<jobject>& obj) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // Intentional No-op. | 257 // Intentional No-op. |
260 return NULL; | 258 return NULL; |
261 } | 259 } |
262 | 260 |
263 // static | 261 // static |
264 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { | 262 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { |
265 return RegisterNativesImpl(env); | 263 return RegisterNativesImpl(env); |
266 } | 264 } |
267 | 265 |
268 } // namespace printing | 266 } // namespace printing |
OLD | NEW |