| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 : PrintingContext(delegate) { | 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 int max_pages, | 83 int max_pages, |
| 84 bool has_selection, | 84 bool has_selection, |
| 85 bool is_scripted, |
| 85 const PrintSettingsCallback& callback) { | 86 const PrintSettingsCallback& callback) { |
| 86 // This method is always run in the UI thread. | 87 // This method is always run in the UI thread. |
| 87 callback_ = callback; | 88 callback_ = callback; |
| 88 | 89 |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 90 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 if (j_printing_context_.is_null()) { | 91 if (j_printing_context_.is_null()) { |
| 91 j_printing_context_.Reset(Java_PrintingContext_create( | 92 j_printing_context_.Reset(Java_PrintingContext_create( |
| 92 env, | 93 env, |
| 93 reinterpret_cast<intptr_t>(this))); | 94 reinterpret_cast<intptr_t>(this))); |
| 94 } | 95 } |
| 95 | 96 |
| 96 Java_PrintingContext_pageCountEstimationDone(env, | 97 if (is_scripted) { |
| 97 j_printing_context_.obj(), | 98 Java_PrintingContext_showPrintDialog(env, j_printing_context_.obj()); |
| 98 max_pages); | 99 } else { |
| 100 Java_PrintingContext_pageCountEstimationDone(env, |
| 101 j_printing_context_.obj(), |
| 102 max_pages); |
| 103 } |
| 99 } | 104 } |
| 100 | 105 |
| 101 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env, | 106 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env, |
| 102 jobject obj, | 107 jobject obj, |
| 103 jboolean success) { | 108 jboolean success) { |
| 104 if (!success) { | 109 if (!success) { |
| 105 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. | 110 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. |
| 106 callback_.Run(FAILED); | 111 callback_.Run(FAILED); |
| 107 return; | 112 return; |
| 108 } | 113 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 125 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); | 130 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); |
| 126 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); | 131 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); |
| 127 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); | 132 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); |
| 128 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); | 133 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); |
| 129 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); | 134 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); |
| 130 SetSizes(&settings_, dpi, width, height); | 135 SetSizes(&settings_, dpi, width, height); |
| 131 | 136 |
| 132 callback_.Run(OK); | 137 callback_.Run(OK); |
| 133 } | 138 } |
| 134 | 139 |
| 140 void PrintingContextAndroid::ShowSystemDialogDone(JNIEnv* env, |
| 141 jobject obj) { |
| 142 // Settings are not updated, callback is called only to unblock javascript. |
| 143 callback_.Run(CANCEL); |
| 144 } |
| 145 |
| 135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { | 146 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { |
| 136 DCHECK(!in_print_job_); | 147 DCHECK(!in_print_job_); |
| 137 | 148 |
| 138 ResetSettings(); | 149 ResetSettings(); |
| 139 settings_.set_dpi(kDefaultPdfDpi); | 150 settings_.set_dpi(kDefaultPdfDpi); |
| 140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); | 151 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); |
| 141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), | 152 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), |
| 142 physical_size.height()); | 153 physical_size.height()); |
| 143 return OK; | 154 return OK; |
| 144 } | 155 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Intentional No-op. | 250 // Intentional No-op. |
| 240 return NULL; | 251 return NULL; |
| 241 } | 252 } |
| 242 | 253 |
| 243 // static | 254 // static |
| 244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { | 255 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { |
| 245 return RegisterNativesImpl(env); | 256 return RegisterNativesImpl(env); |
| 246 } | 257 } |
| 247 | 258 |
| 248 } // namespace printing | 259 } // namespace printing |
| OLD | NEW |