[iOS] Try to unlock PDF documents before printing them
https://bugs.webkit.org/show_bug.cgi?id=185084
<rdar://problem/39356622>
Reviewed by Dan Bernstein.
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView pdfHostViewController:documentDidUnlockWithPassword:]):
Stored the password that successfully unlocked the current PDF document.
(-[WKPDFView _wk_printedDocument]):
Used the stored password to unlock the CGPDFDocument we create for printing.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231157 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 2ca3cdf..b45b9c8 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,20 @@
+2018-04-30 Andy Estes <aestes@apple.com>
+
+ [iOS] Try to unlock PDF documents before printing them
+ https://bugs.webkit.org/show_bug.cgi?id=185084
+ <rdar://problem/39356622>
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/ios/WKPDFView.mm:
+ (-[WKPDFView pdfHostViewController:documentDidUnlockWithPassword:]):
+
+ Stored the password that successfully unlocked the current PDF document.
+
+ (-[WKPDFView _wk_printedDocument]):
+
+ Used the stored password to unlock the CGPDFDocument we create for printing.
+
2018-04-28 Andy Estes <aestes@apple.com>
[iOS] Present an action sheet when long-pressing on PDF links
diff --git a/Source/WebKit/UIProcess/ios/WKPDFView.mm b/Source/WebKit/UIProcess/ios/WKPDFView.mm
index 2a0c100..5cbe8ce 100644
--- a/Source/WebKit/UIProcess/ios/WKPDFView.mm
+++ b/Source/WebKit/UIProcess/ios/WKPDFView.mm
@@ -57,6 +57,7 @@
RetainPtr<PDFHostViewController> _hostViewController;
CGSize _overlaidAccessoryViewsInset;
RetainPtr<UIView> _pageNumberIndicator;
+ RetainPtr<NSString> _password;
WebKit::InteractionInformationAtPosition _positionInformation;
RetainPtr<NSString> _suggestedFilename;
WebKit::WeakObjCPtr<WKWebView> _webView;
@@ -359,6 +360,11 @@
[self _scrollToURLFragment:[_webView URL].fragment];
}
+- (void)pdfHostViewController:(PDFHostViewController *)controller documentDidUnlockWithPassword:(NSString *)password
+{
+ _password = adoptNS([password copy]);
+}
+
- (void)pdfHostViewController:(PDFHostViewController *)controller findStringUpdate:(NSUInteger)numFound done:(BOOL)done
{
// FIXME: We should stop searching once numFound exceeds _findStringMaxCount, but PDFKit doesn't
@@ -498,7 +504,10 @@
- (CGPDFDocumentRef)_wk_printedDocument
{
auto dataProvider = adoptCF(CGDataProviderCreateWithCFData((CFDataRef)_data.get()));
- return adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get())).autorelease();
+ auto pdfDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
+ if (!CGPDFDocumentIsUnlocked(pdfDocument.get()))
+ CGPDFDocumentUnlockWithPassword(pdfDocument.get(), [_password UTF8String]);
+ return pdfDocument.autorelease();
}
@end