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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwPdfExporter.java

Issue 2770713003: Enable page selection for WebView printing (Closed)
Patch Set: review fixes Created 3 years, 9 months 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 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.os.CancellationSignal; 8 import android.os.CancellationSignal;
9 import android.os.ParcelFileDescriptor; 9 import android.os.ParcelFileDescriptor;
10 import android.print.PrintAttributes; 10 import android.print.PrintAttributes;
(...skipping 28 matching lines...) Expand all
39 private ViewGroup mContainerView; 39 private ViewGroup mContainerView;
40 40
41 AwPdfExporter(ViewGroup containerView) { 41 AwPdfExporter(ViewGroup containerView) {
42 setContainerView(containerView); 42 setContainerView(containerView);
43 } 43 }
44 44
45 public void setContainerView(ViewGroup containerView) { 45 public void setContainerView(ViewGroup containerView) {
46 mContainerView = containerView; 46 mContainerView = containerView;
47 } 47 }
48 48
49 public void exportToPdf(final ParcelFileDescriptor fd, PrintAttributes attri butes, 49 public void exportToPdf(final ParcelFileDescriptor fd, PrintAttributes attri butes, int[] pages,
50 ValueCallback<Boolean> resultCallback, CancellationSignal cancellati onSignal) { 50 ValueCallback<Boolean> resultCallback, CancellationSignal cancellati onSignal) {
51
52 if (fd == null) { 51 if (fd == null) {
53 throw new IllegalArgumentException("fd cannot be null"); 52 throw new IllegalArgumentException("fd cannot be null");
54 } 53 }
55 if (resultCallback == null) { 54 if (resultCallback == null) {
56 throw new IllegalArgumentException("resultCallback cannot be null"); 55 throw new IllegalArgumentException("resultCallback cannot be null");
57 } 56 }
58 if (mResultCallback != null) { 57 if (mResultCallback != null) {
59 throw new IllegalStateException("printing is already pending"); 58 throw new IllegalStateException("printing is already pending");
60 } 59 }
61 if (attributes.getMediaSize() == null) { 60 if (attributes.getMediaSize() == null) {
62 throw new IllegalArgumentException("attributes must specify a media size"); 61 throw new IllegalArgumentException("attributes must specify a media size");
63 } 62 }
64 if (attributes.getResolution() == null) { 63 if (attributes.getResolution() == null) {
65 throw new IllegalArgumentException("attributes must specify print re solution"); 64 throw new IllegalArgumentException("attributes must specify print re solution");
66 } 65 }
67 if (attributes.getMinMargins() == null) { 66 if (attributes.getMinMargins() == null) {
68 throw new IllegalArgumentException("attributes must specify margins" ); 67 throw new IllegalArgumentException("attributes must specify margins" );
69 } 68 }
70 if (mNativeAwPdfExporter == 0) { 69 if (mNativeAwPdfExporter == 0) {
71 resultCallback.onReceiveValue(false); 70 resultCallback.onReceiveValue(false);
72 return; 71 return;
73 } 72 }
74 mResultCallback = resultCallback; 73 mResultCallback = resultCallback;
75 mAttributes = attributes; 74 mAttributes = attributes;
76 mFd = fd; 75 mFd = fd;
77 nativeExportToPdf(mNativeAwPdfExporter, mFd.getFd(), cancellationSignal) ; 76 nativeExportToPdf(mNativeAwPdfExporter, mFd.getFd(), pages, cancellation Signal);
78 } 77 }
79 78
80 @CalledByNative 79 @CalledByNative
81 private void setNativeAwPdfExporter(long nativePdfExporter) { 80 private void setNativeAwPdfExporter(long nativePdfExporter) {
82 mNativeAwPdfExporter = nativePdfExporter; 81 mNativeAwPdfExporter = nativePdfExporter;
83 // Handle the cornercase that the native side is destroyed (for example 82 // Handle the cornercase that the native side is destroyed (for example
84 // via Webview.Destroy) before it has a chance to complete the pdf expor ting. 83 // via Webview.Destroy) before it has a chance to complete the pdf expor ting.
85 if (nativePdfExporter == 0 && mResultCallback != null) { 84 if (nativePdfExporter == 0 && mResultCallback != null) {
86 try { 85 try {
87 mResultCallback.onReceiveValue(false); 86 mResultCallback.onReceiveValue(false);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 @CalledByNative 141 @CalledByNative
143 private int getTopMargin() { 142 private int getTopMargin() {
144 return mAttributes.getMinMargins().getTopMils(); 143 return mAttributes.getMinMargins().getTopMils();
145 } 144 }
146 145
147 @CalledByNative 146 @CalledByNative
148 private int getBottomMargin() { 147 private int getBottomMargin() {
149 return mAttributes.getMinMargins().getBottomMils(); 148 return mAttributes.getMinMargins().getBottomMils();
150 } 149 }
151 150
152 private native void nativeExportToPdf(long nativeAwPdfExporter, int fd, 151 private native void nativeExportToPdf(
153 CancellationSignal cancellationSignal); 152 long nativeAwPdfExporter, int fd, int[] pages, CancellationSignal ca ncellationSignal);
154 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698