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 "android_webview/native/aw_pdf_exporter.h" | 5 #include "android_webview/native/aw_pdf_exporter.h" |
6 | 6 |
7 #include "android_webview/browser/aw_print_manager.h" | 7 #include "android_webview/browser/aw_print_manager.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "jni/AwPdfExporter_jni.h" | 10 #include "jni/AwPdfExporter_jni.h" |
11 #include "printing/print_settings.h" | 11 #include "printing/print_settings.h" |
12 #include "printing/units.h" | 12 #include "printing/units.h" |
13 | 13 |
14 using base::android::JavaParamRef; | 14 using base::android::JavaParamRef; |
| 15 using base::android::JavaRef; |
15 using base::android::ScopedJavaLocalRef; | 16 using base::android::ScopedJavaLocalRef; |
16 | 17 |
17 namespace android_webview { | 18 namespace android_webview { |
18 | 19 |
19 AwPdfExporter::AwPdfExporter(JNIEnv* env, | 20 AwPdfExporter::AwPdfExporter(JNIEnv* env, |
20 jobject obj, | 21 const JavaRef<jobject>& obj, |
21 content::WebContents* web_contents) | 22 content::WebContents* web_contents) |
22 : java_ref_(env, obj), | 23 : java_ref_(env, obj), web_contents_(web_contents) { |
23 web_contents_(web_contents) { | 24 DCHECK(!obj.is_null()); |
24 DCHECK(obj); | |
25 Java_AwPdfExporter_setNativeAwPdfExporter( | 25 Java_AwPdfExporter_setNativeAwPdfExporter( |
26 env, obj, reinterpret_cast<intptr_t>(this)); | 26 env, obj, reinterpret_cast<intptr_t>(this)); |
27 } | 27 } |
28 | 28 |
29 AwPdfExporter::~AwPdfExporter() { | 29 AwPdfExporter::~AwPdfExporter() { |
30 JNIEnv* env = base::android::AttachCurrentThread(); | 30 JNIEnv* env = base::android::AttachCurrentThread(); |
31 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 31 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
32 if (obj.is_null()) | 32 if (obj.is_null()) |
33 return; | 33 return; |
34 // Clear the Java peer's weak pointer to |this| object. | 34 // Clear the Java peer's weak pointer to |this| object. |
(...skipping 17 matching lines...) Expand all Loading... |
52 } | 52 } |
53 | 53 |
54 namespace { | 54 namespace { |
55 // Converts from 1/1000 of inches to device units using DPI. | 55 // Converts from 1/1000 of inches to device units using DPI. |
56 int MilsToDots(int val, int dpi) { | 56 int MilsToDots(int val, int dpi) { |
57 return static_cast<int>(printing::ConvertUnitDouble(val, 1000.0, dpi)); | 57 return static_cast<int>(printing::ConvertUnitDouble(val, 1000.0, dpi)); |
58 } | 58 } |
59 } // anonymous namespace | 59 } // anonymous namespace |
60 | 60 |
61 void AwPdfExporter::InitPdfSettings(JNIEnv* env, | 61 void AwPdfExporter::InitPdfSettings(JNIEnv* env, |
62 jobject obj, | 62 const JavaRef<jobject>& obj, |
63 printing::PrintSettings& settings) { | 63 printing::PrintSettings& settings) { |
64 int dpi = Java_AwPdfExporter_getDpi(env, obj); | 64 int dpi = Java_AwPdfExporter_getDpi(env, obj); |
65 int width = Java_AwPdfExporter_getPageWidth(env, obj); | 65 int width = Java_AwPdfExporter_getPageWidth(env, obj); |
66 int height = Java_AwPdfExporter_getPageHeight(env, obj); | 66 int height = Java_AwPdfExporter_getPageHeight(env, obj); |
67 gfx::Size physical_size_device_units; | 67 gfx::Size physical_size_device_units; |
68 int width_in_dots = MilsToDots(width, dpi); | 68 int width_in_dots = MilsToDots(width, dpi); |
69 int height_in_dots = MilsToDots(height, dpi); | 69 int height_in_dots = MilsToDots(height, dpi); |
70 physical_size_device_units.SetSize(width_in_dots, height_in_dots); | 70 physical_size_device_units.SetSize(width_in_dots, height_in_dots); |
71 | 71 |
72 gfx::Rect printable_area_device_units; | 72 gfx::Rect printable_area_device_units; |
(...skipping 26 matching lines...) Expand all Loading... |
99 if (obj.is_null()) | 99 if (obj.is_null()) |
100 return; | 100 return; |
101 Java_AwPdfExporter_didExportPdf(env, obj, success); | 101 Java_AwPdfExporter_didExportPdf(env, obj, success); |
102 } | 102 } |
103 | 103 |
104 bool RegisterAwPdfExporter(JNIEnv* env) { | 104 bool RegisterAwPdfExporter(JNIEnv* env) { |
105 return RegisterNativesImpl(env); | 105 return RegisterNativesImpl(env); |
106 } | 106 } |
107 | 107 |
108 } // namespace android_webview | 108 } // namespace android_webview |
OLD | NEW |