Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: printing/printing_context_android.cc

Issue 740983002: Implement window.print() on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate) 74 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate)
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::SetPrintSettingsCallback(
83 const PrintSettingsCallback& callback) {
84 LOG(INFO) << "DGN - Set cb - this: " << this << ", callback_: " << &callback;
85 callback_ = callback;
86 }
87
82 void PrintingContextAndroid::AskUserForSettings( 88 void PrintingContextAndroid::AskUserForSettings(
83 int max_pages, 89 int max_pages,
84 bool has_selection, 90 bool has_selection,
85 const PrintSettingsCallback& callback) { 91 const PrintSettingsCallback& callback) {
86 // This method is always run in the UI thread. 92 // This method is always run in the UI thread.
87 callback_ = callback; 93 callback_ = callback;
88 94
89 JNIEnv* env = base::android::AttachCurrentThread(); 95 JNIEnv* env = base::android::AttachCurrentThread();
90 if (j_printing_context_.is_null()) { 96 if (j_printing_context_.is_null()) {
91 j_printing_context_.Reset(Java_PrintingContext_create( 97 j_printing_context_.Reset(Java_PrintingContext_create(
92 env, 98 env,
93 reinterpret_cast<intptr_t>(this))); 99 reinterpret_cast<intptr_t>(this)));
94 } 100 }
95 101
102 LOG(INFO) << "DGN - AskUserForSettings - this: " << this
103 << ", callback_: " << &callback;
96 Java_PrintingContext_pageCountEstimationDone(env, 104 Java_PrintingContext_pageCountEstimationDone(env,
97 j_printing_context_.obj(), 105 j_printing_context_.obj(),
98 max_pages); 106 max_pages);
99 } 107 }
100 108
101 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env, 109 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env,
102 jobject obj, 110 jobject obj,
103 jboolean success) { 111 jboolean success) {
104 if (!success) { 112 if (!success) {
105 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. 113 // TODO(cimamoglu): Differentiate between FAILED And CANCEL.
106 callback_.Run(FAILED); 114 callback_.Run(FAILED);
115 LOG(INFO) << "DGN - AskUserForSettingsReply - FAILED or CANCEL";
107 return; 116 return;
108 } 117 }
109 118
119 LOG(INFO) << "DGN - AskUserForSettingsReply - SUCCESS";
120
110 // 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
111 // but necessary. Since device name is not necessary for the upstream 122 // but necessary. Since device name is not necessary for the upstream
112 // printing code for Android, this is harmless. 123 // printing code for Android, this is harmless.
113 int fd = Java_PrintingContext_getFileDescriptor(env, 124 int fd = Java_PrintingContext_getFileDescriptor(env,
114 j_printing_context_.obj()); 125 j_printing_context_.obj());
115 settings_.set_device_name(base::IntToString16(fd)); 126 settings_.set_device_name(base::IntToString16(fd));
116 127
117 ScopedJavaLocalRef<jintArray> intArr = 128 ScopedJavaLocalRef<jintArray> intArr =
118 Java_PrintingContext_getPages(env, j_printing_context_.obj()); 129 Java_PrintingContext_getPages(env, j_printing_context_.obj());
119 if (intArr.obj() != NULL) { 130 if (intArr.obj() != NULL) {
120 PageRanges range_vector; 131 PageRanges range_vector;
121 GetPageRanges(env, intArr.obj(), range_vector); 132 GetPageRanges(env, intArr.obj(), range_vector);
122 settings_.set_ranges(range_vector); 133 settings_.set_ranges(range_vector);
123 } 134 }
124 135
125 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); 136 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj());
126 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); 137 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj());
127 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); 138 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj());
128 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); 139 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi);
129 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); 140 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi);
130 SetSizes(&settings_, dpi, width, height); 141 SetSizes(&settings_, dpi, width, height);
131 142
132 callback_.Run(OK); 143 callback_.Run(OK);
133 } 144 }
134 145
146 void PrintingContextAndroid::ShowSystemDialogDone(JNIEnv* env,
147 jobject obj) {
148 LOG(INFO) << "DGN - ShowSystemDialogDone - Running callback with 'TEST'";
149 LOG(INFO) << "DGN - this: " << this << ", callback_: " << &callback_;
150 callback_.Run(TEST);
151 }
152
135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { 153 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() {
136 DCHECK(!in_print_job_); 154 DCHECK(!in_print_job_);
137 155
138 ResetSettings(); 156 ResetSettings();
139 settings_.set_dpi(kDefaultPdfDpi); 157 settings_.set_dpi(kDefaultPdfDpi);
140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); 158 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), 159 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(),
142 physical_size.height()); 160 physical_size.height());
143 return OK; 161 return OK;
144 } 162 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Intentional No-op. 257 // Intentional No-op.
240 return NULL; 258 return NULL;
241 } 259 }
242 260
243 // static 261 // static
244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { 262 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) {
245 return RegisterNativesImpl(env); 263 return RegisterNativesImpl(env);
246 } 264 }
247 265
248 } // namespace printing 266 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698