Diff
Modified: trunk/Source/WTF/ChangeLog (230486 => 230487)
--- trunk/Source/WTF/ChangeLog 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WTF/ChangeLog 2018-04-10 19:42:35 UTC (rev 230487)
@@ -1,3 +1,12 @@
+2018-04-10 Andy Estes <[email protected]>
+
+ [iOS] Use PDFKit to render PDFs in WKWebView
+ https://bugs.webkit.org/show_bug.cgi?id=184387
+
+ Reviewed by Beth Dakin.
+
+ * wtf/FeatureDefines.h: Defined ENABLE_WKLEGACYPDFVIEW and ENABLE_WKPDFVIEW.
+
2018-04-09 Mark Lam <[email protected]>
Decorate method table entries to support pointer profiling.
Modified: trunk/Source/WTF/wtf/FeatureDefines.h (230486 => 230487)
--- trunk/Source/WTF/wtf/FeatureDefines.h 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WTF/wtf/FeatureDefines.h 2018-04-10 19:42:35 UTC (rev 230487)
@@ -166,8 +166,14 @@
#define ENABLE_DOWNLOAD_ATTRIBUTE 0
#endif
+#if !defined(ENABLE_WKLEGACYPDFVIEW)
+#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !ENABLE(MINIMAL_SIMULATOR)
+#define ENABLE_WKLEGACYPDFVIEW 1
+#endif
+#endif
+
#if !defined(ENABLE_WKPDFVIEW)
-#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !ENABLE(MINIMAL_SIMULATOR)
+#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && !ENABLE(MINIMAL_SIMULATOR) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
#define ENABLE_WKPDFVIEW 1
#endif
#endif
Modified: trunk/Source/WebKit/ChangeLog (230486 => 230487)
--- trunk/Source/WebKit/ChangeLog 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/ChangeLog 2018-04-10 19:42:35 UTC (rev 230487)
@@ -1,3 +1,145 @@
+2018-04-10 Andy Estes <[email protected]>
+
+ [iOS] Use PDFKit to render PDFs in WKWebView
+ https://bugs.webkit.org/show_bug.cgi?id=184387
+
+ Reviewed by Beth Dakin.
+
+ Adopted PDFHostViewController for rendering PDFs in WKWebView.
+
+ This patch implements rendering the PDF document and page number indicator. Link
+ navigation, find-in-page, and printing will be implemented in follow-up patches.
+
+ WKLegacyPDFView is still the default PDF view.
+
+ * Configurations/WebKit.xcconfig:
+
+ Linked WebKit with PDFKit on iOS.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _currentContentView]):
+ (-[WKWebView viewForZoomingInScrollView:]):
+
+ When WKPDFView loads a PDF document, it replaces itself with a view vended by
+ PDFHostViewController as the WKScrollView's content view. Abstracted WKWebView's
+ concept of the "current content view" to be either the WKContentView or a view of
+ the custom content view's choosing (-web_contentView).
+
+ (-[WKWebView scrollViewWillBeginZooming:withView:]):
+ (-[WKWebView scrollViewDidZoom:]):
+ (-[WKWebView scrollViewDidEndZooming:withView:atScale:]):
+
+ Forwarded these calls to _customContentView if it responds to the equivalent
+ WKWebViewContentProvider selectors.
+
+ * UIProcess/Cocoa/WKWebViewContentProvider.h:
+
+ Defined new protocol selectors.
+
+ * UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
+ (-[WKWebViewContentProviderRegistry init]):
+ * UIProcess/ios/WKLegacyPDFView.h:
+ * UIProcess/ios/WKLegacyPDFView.mm:
+
+ Changed ENABLE(WKPDFVIEW) to ENABLE(WKLEGACYPDFVIEW).
+
+ (-[WKLegacyPDFView web_contentView]):
+
+ Added. Returns self as the content view.
+
+ * UIProcess/ios/WKPDFView.h: Added.
+ * UIProcess/ios/WKPDFView.mm: Added.
+ (-[WKPDFView dealloc]):
+
+ Removed the host view and page number indicator from their superviews.
+
+ (-[WKPDFView gestureRecognizerShouldBegin:]):
+
+ Forwarded to _hostViewController.
+
+ (-[WKPDFView web_initWithFrame:webView:]):
+
+ Set ours and the scroll view's background color to UIColor.grayColor to match
+ WKLegacyPDFView.
+
+ (-[WKPDFView web_setContentProviderData:suggestedFilename:]):
+
+ Created a PDFHostViewController and set its root view as the scroll view's content
+ view after removing the WKPDFView itself. This allows WKPDFView to act as a
+ placeholder content view until the PDF is loaded. Added the host view controller's
+ page number indicator to the fixed overlay view. Finally, loaded the PDF document
+ by calling -[PDFHostViewController setDocumentData:withScrollView:].
+
+ (-[WKPDFView _offsetForPageNumberIndicator]):
+
+ Computed an offset for the page number indicator like WKLegacyPDFView did, taking
+ into account the overlaid accessory views inset, computed unobscured safe area
+ inset, and computed obscured inset.
+
+ (-[WKPDFView _movePageNumberIndicatorToPoint:animated:]):
+
+ Moved the page number indicator using the margin and animation duration from
+ WKLegacyPDFView.
+
+ (-[WKPDFView _updateLayoutAnimated:]):
+
+ Added a convenience method to update the PDF view layout and position the page
+ number indicator.
+
+ (-[WKPDFView web_setMinimumSize:]):
+
+ Updated our own frame in case we are still the placeholder content view.
+ Called -_updateLayoutAnimated:.
+
+ (-[WKPDFView web_setOverlaidAccessoryViewsInset:]):
+
+ Stored the inset and called -_updateLayoutAnimated:.
+
+ (-[WKPDFView web_computedContentInsetDidChange]):
+
+ Called -_updateLayoutAnimated:.
+
+ (-[WKPDFView web_setFixedOverlayView:]):
+
+ Stored the fixed overlay view.
+
+ (-[WKPDFView web_didSameDocumentNavigation:]):
+ (-[WKPDFView web_countStringMatches:options:maxCount:]):
+ (-[WKPDFView web_findString:options:maxCount:]):
+ (-[WKPDFView web_hideFindUI]):
+
+ Added FIXMEs.
+
+ (-[WKPDFView web_contentView]):
+
+ If there is a host view controller, return its root view. Otherwise, return self.
+
+ (-[WKPDFView web_scrollViewDidScroll:]):
+ (-[WKPDFView web_scrollViewWillBeginZooming:withView:]):
+ (-[WKPDFView web_scrollViewDidEndZooming:withView:atScale:]):
+ (-[WKPDFView web_scrollViewDidZoom:]):
+
+ Called -[PDFHostViewController updatePDFViewLayout].
+
+ (-[WKPDFView web_dataRepresentation]):
+
+ Returned _data.
+
+ (-[WKPDFView web_suggestedFilename]):
+
+ Returned _suggestedFilename.
+
+ (-[WKPDFView web_isBackground]):
+
+ Returned self.isBackground.
+
+ * UIProcess/ios/WKSystemPreviewView.mm:
+ (-[WKSystemPreviewView web_contentView]):
+
+ Added. Returns self as the content view.
+
+ * WebKit.xcodeproj/project.pbxproj:
+
2018-04-10 Miguel Gomez <[email protected]>
[GTK][WPE] Race condition when destroying webprocesses
Modified: trunk/Source/WebKit/Configurations/WebKit.xcconfig (230486 => 230487)
--- trunk/Source/WebKit/Configurations/WebKit.xcconfig 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/Configurations/WebKit.xcconfig 2018-04-10 19:42:35 UTC (rev 230487)
@@ -90,6 +90,12 @@
WK_OPENGL_LDFLAGS_appletvsimulator = $(WK_OPENGL_LDFLAGS_iphonesimulator);
WK_OPENGL_LDFLAGS_macosx = -framework OpenGL;
+WK_PDFKIT_LDFLAGS = $(WK_PDFKIT_LDFLAGS_$(WK_PLATFORM_NAME));
+WK_PDFKIT_LDFLAGS_iphoneos = -framework PDFKit;
+WK_PDFKIT_LDFLAGS_iphonesimulator = $(WK_PDFKIT_LDFLAGS_iphoneos);
+WK_PDFKIT_LDFLAGS_iphoneos[sdk=iphone*11.*] = ;
+WK_PDFKIT_LDFLAGS_iphonesimulator[sdk=iphone*11.*] = ;
+
WK_SAFE_BROWSING_LDFLAGS = $(WK_SAFE_BROWSING_LDFLAGS_$(WK_PLATFORM_NAME));
WK_SAFE_BROWSING_LDFLAGS_iphoneos = -framework SafariSafeBrowsing;
WK_SAFE_BROWSING_LDFLAGS_iphonesimulator = -framework SafariSafeBrowsing;
@@ -101,7 +107,7 @@
WK_UIKIT_LDFLAGS = $(WK_UIKIT_LDFLAGS_$(WK_COCOA_TOUCH));
WK_UIKIT_LDFLAGS_cocoatouch = -framework UIKit;
-FRAMEWORK_AND_LIBRARY_LDFLAGS = -lobjc -framework CFNetwork -framework CoreAudio -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework ImageIO -framework IOKit -framework WebKitLegacy $(WK_ACCESSIBILITY_LDFLAGS) $(WK_APPKIT_LDFLAGS) $(WK_ASSERTION_SERVICES_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_PDF_LDFLAGS) $(WK_CORE_PREDICTION_LDFLAGS) $(WK_CORE_SERVICES_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_SAFE_BROWSING_LDFLAGS) $(WK_UIKIT_LDFLAGS);
+FRAMEWORK_AND_LIBRARY_LDFLAGS = -lobjc -framework CFNetwork -framework CoreAudio -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework ImageIO -framework IOKit -framework WebKitLegacy $(WK_ACCESSIBILITY_LDFLAGS) $(WK_APPKIT_LDFLAGS) $(WK_ASSERTION_SERVICES_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_PDF_LDFLAGS) $(WK_CORE_PREDICTION_LDFLAGS) $(WK_CORE_SERVICES_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SAFE_BROWSING_LDFLAGS) $(WK_UIKIT_LDFLAGS);
// Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
UNEXPORTED_SYMBOL_LDFLAGS = -Wl,-unexported_symbol -Wl,__ZTISt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTISt9exception -Wl,-unexported_symbol -Wl,__ZTSSt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTSSt9exception -Wl,-unexported_symbol -Wl,__ZdlPvS_ -Wl,-unexported_symbol -Wl,__ZnwmPv -Wl,-unexported_symbol -Wl,__Znwm -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC2EOS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC1EOS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEaSEDn -Wl,-unexported_symbol, -Wl,__ZNKSt3__18functionIFvN7WebCore12PolicyActionEEEclES2_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEE4swapERS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC1ERKS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC2ERKS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12Policy
ActionEEED1Ev -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEED2Ev -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEaSERKS4_ -Wl,-unexported_symbol, -Wl,__ZTVNSt3__117bad_function_callE;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-04-10 19:42:35 UTC (rev 230487)
@@ -1431,7 +1431,7 @@
- (UIView *)_currentContentView
{
- return _customContentView ? _customContentView.get() : _contentView.get();
+ return _customContentView ? [_customContentView web_contentView] : _contentView.get();
}
- (WKWebViewContentProviderRegistry *)_contentProviderRegistry
@@ -2357,17 +2357,16 @@
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
ASSERT(_scrollView == scrollView);
-
- if (_customContentView)
- return _customContentView.get();
-
- return _contentView.get();
+ return self._currentContentView;
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
- if (![self usesStandardContentView])
+ if (![self usesStandardContentView]) {
+ if ([_customContentView respondsToSelector:@selector(web_scrollViewWillBeginZooming:withView:)])
+ [_customContentView web_scrollViewWillBeginZooming:scrollView withView:view];
return;
+ }
if (scrollView.pinchGestureRecognizer.state == UIGestureRecognizerStateBegan) {
_page->willStartUserTriggeredZooming();
@@ -2460,6 +2459,9 @@
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
+ if (![self usesStandardContentView] && [_customContentView respondsToSelector:@selector(web_scrollViewDidZoom:)])
+ [_customContentView web_scrollViewDidZoom:scrollView];
+
[self _updateScrollViewBackground];
[self _scheduleVisibleContentRectUpdateAfterScrollInView:scrollView];
}
@@ -2466,6 +2468,9 @@
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
+ if (![self usesStandardContentView] && [_customContentView respondsToSelector:@selector(web_scrollViewDidEndZooming:withView:atScale:)])
+ [_customContentView web_scrollViewDidEndZooming:scrollView withView:view atScale:scale];
+
ASSERT(scrollView == _scrollView);
// FIXME: remove when rdar://problem/36065495 is fixed.
// When rotating with two fingers down, UIScrollView can set a bogus content view position.
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProvider.h 2018-04-10 19:42:35 UTC (rev 230487)
@@ -52,9 +52,13 @@
- (void)web_countStringMatches:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount;
- (void)web_findString:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount;
- (void)web_hideFindUI;
+@property (nonatomic, readonly) UIView *web_contentView;
@optional
- (void)web_scrollViewDidScroll:(UIScrollView *)scrollView;
+- (void)web_scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view;
+- (void)web_scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale;
+- (void)web_scrollViewDidZoom:(UIScrollView *)scrollView;
@property (nonatomic, readonly) NSData *web_dataRepresentation;
@property (nonatomic, readonly) NSString *web_suggestedFilename;
@property (nonatomic, readonly) BOOL web_isBackground;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm 2018-04-10 19:42:35 UTC (rev 230487)
@@ -56,7 +56,7 @@
if (!(self = [super init]))
return nil;
-#if ENABLE(WKPDFVIEW)
+#if ENABLE(WKLEGACYPDFVIEW)
for (auto& mimeType : WebCore::MIMETypeRegistry::getPDFMIMETypes())
[self registerProvider:[WKLegacyPDFView class] forMIMEType:mimeType];
#endif
Modified: trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.h (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.h 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.h 2018-04-10 19:42:35 UTC (rev 230487)
@@ -23,7 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#if PLATFORM(IOS) && ENABLE(WKPDFVIEW)
+#if ENABLE(WKLEGACYPDFVIEW)
#import "CorePDFSPI.h"
#import "WKActionSheetAssistant.h"
@@ -33,4 +33,4 @@
@interface WKLegacyPDFView : WKApplicationStateTrackingView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate, WKActionSheetAssistantDelegate>
@end
-#endif // PLATFORM(IOS) && ENABLE(WKPDFVIEW)
+#endif // ENABLE(WKLEGACYPDFVIEW)
Modified: trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.mm (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.mm 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.mm 2018-04-10 19:42:35 UTC (rev 230487)
@@ -26,7 +26,7 @@
#import "config.h"
#import "WKLegacyPDFView.h"
-#if PLATFORM(IOS) && ENABLE(WKPDFVIEW)
+#if ENABLE(WKLEGACYPDFVIEW)
#import "APIFindClient.h"
#import "APIUIClient.h"
@@ -383,6 +383,11 @@
[self _scrollToFragment:_webView.URL.fragment];
}
+- (UIView *)web_contentView
+{
+ return self;
+}
+
- (void)_computePageAndDocumentFrames
{
UIEdgeInsets safeAreaInsets = _webView._computedUnobscuredSafeAreaInset;
@@ -857,4 +862,4 @@
#pragma clang diagnostic pop
-#endif // PLATFORM(IOS) && ENABLE(WKPDFVIEW)
+#endif // ENABLE(WKLEGACYPDFVIEW)
Copied: trunk/Source/WebKit/UIProcess/ios/WKPDFView.h (from rev 230486, trunk/Source/WebKit/UIProcess/ios/WKLegacyPDFView.h) (0 => 230487)
--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.h 2018-04-10 19:42:35 UTC (rev 230487)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(WKPDFVIEW)
+
+#import "WKApplicationStateTrackingView.h"
+#import "WKWebViewContentProvider.h"
+
+@interface WKPDFView : WKApplicationStateTrackingView <WKWebViewContentProvider>
+
+@end
+
+#endif // ENABLE(WKPDFVIEW)
Added: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (0 => 230487)
--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm 2018-04-10 19:42:35 UTC (rev 230487)
@@ -0,0 +1,226 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKPDFView.h"
+
+#if ENABLE(WKPDFVIEW)
+
+#import "WKWebViewInternal.h"
+#import "WeakObjCPtr.h"
+#import "WebPageProxy.h"
+#import <PDFKit/PDFHostViewController.h>
+#import <wtf/MainThread.h>
+#import <wtf/RetainPtr.h>
+
+@interface WKPDFView () <PDFHostViewControllerDelegate>
+@end
+
+@implementation WKPDFView {
+ CGSize _overlaidAccessoryViewsInset;
+ RetainPtr<NSData> _data;
+ RetainPtr<NSString> _suggestedFilename;
+ RetainPtr<PDFHostViewController> _hostViewController;
+ RetainPtr<UIView> _fixedOverlayView;
+ RetainPtr<UIView> _pageNumberIndicator;
+ WebKit::WeakObjCPtr<WKWebView> _webView;
+}
+
+- (void)dealloc
+{
+ [[_hostViewController view] removeFromSuperview];
+ [_pageNumberIndicator removeFromSuperview];
+ [super dealloc];
+}
+
+- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
+{
+ return [_hostViewController gestureRecognizerShouldBegin:gestureRecognizer];
+}
+
+#pragma mark WKWebViewContentProvider
+
+- (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
+{
+ if (!(self = [super initWithFrame:frame webView:webView]))
+ return nil;
+
+ self.backgroundColor = UIColor.grayColor;
+ webView.scrollView.backgroundColor = UIColor.grayColor;
+
+ _webView = webView;
+ return self;
+}
+
+- (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *)filename
+{
+ _data = adoptNS([data copy]);
+ _suggestedFilename = adoptNS([filename copy]);
+
+ [PDFHostViewController createHostView:^(PDFHostViewController * _Nullable hostViewController) {
+ ASSERT(isMainThread());
+
+ WKWebView *webView = _webView.getAutoreleased();
+ if (!webView)
+ return;
+
+ if (!hostViewController)
+ return;
+ _hostViewController = hostViewController;
+
+ UIView *hostView = hostViewController.view;
+ hostView.frame = webView.bounds;
+ hostView.backgroundColor = UIColor.grayColor;
+
+ UIScrollView *scrollView = webView.scrollView;
+ [self removeFromSuperview];
+ [scrollView addSubview:hostView];
+
+ _pageNumberIndicator = hostViewController.pageNumberIndicator;
+ [_fixedOverlayView addSubview:_pageNumberIndicator.get()];
+
+ hostViewController.delegate = self;
+ [hostViewController setDocumentData:_data.get() withScrollView:scrollView];
+ } forExtensionIdentifier:nil];
+}
+
+- (CGPoint)_offsetForPageNumberIndicator
+{
+ WKWebView *webView = _webView.getAutoreleased();
+ if (!webView)
+ return CGPointZero;
+
+ UIEdgeInsets insets = UIEdgeInsetsAdd(webView._computedUnobscuredSafeAreaInset, webView._computedObscuredInset, UIRectEdgeAll);
+ return CGPointMake(insets.left, insets.top + _overlaidAccessoryViewsInset.height);
+}
+
+- (void)_movePageNumberIndicatorToPoint:(CGPoint)point animated:(BOOL)animated
+{
+ void (^setFrame)() = ^{
+ static const CGFloat margin = 20;
+ const CGRect frame = { CGPointMake(point.x + margin, point.y + margin), [_pageNumberIndicator frame].size };
+ [_pageNumberIndicator setFrame:frame];
+ };
+
+ if (animated) {
+ static const NSTimeInterval duration = 0.3;
+ [UIView animateWithDuration:duration animations:setFrame];
+ return;
+ }
+
+ setFrame();
+}
+
+- (void)_updateLayoutAnimated:(BOOL)animated
+{
+ [_hostViewController updatePDFViewLayout];
+ [self _movePageNumberIndicatorToPoint:self._offsetForPageNumberIndicator animated:animated];
+}
+
+- (void)web_setMinimumSize:(CGSize)size
+{
+ self.frame = { self.frame.origin, size };
+ [self _updateLayoutAnimated:NO];
+}
+
+- (void)web_setOverlaidAccessoryViewsInset:(CGSize)inset
+{
+ _overlaidAccessoryViewsInset = inset;
+ [self _updateLayoutAnimated:YES];
+}
+
+- (void)web_computedContentInsetDidChange
+{
+ [self _updateLayoutAnimated:NO];
+}
+
+- (void)web_setFixedOverlayView:(UIView *)fixedOverlayView
+{
+ _fixedOverlayView = fixedOverlayView;
+}
+
+- (void)web_didSameDocumentNavigation:(WKSameDocumentNavigationType)navigationType
+{
+ // FIXME: Implement page number navigations.
+}
+
+- (void)web_countStringMatches:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount
+{
+ // FIXME: Implement find-in-page.
+}
+
+- (void)web_findString:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount
+{
+ // FIXME: Implement find-in-page.
+}
+
+- (void)web_hideFindUI
+{
+ // FIXME: Implement find-in-page.
+}
+
+- (UIView *)web_contentView
+{
+ return _hostViewController ? [_hostViewController view] : self;
+}
+
+- (void)web_scrollViewDidScroll:(UIScrollView *)scrollView
+{
+ [_hostViewController updatePDFViewLayout];
+}
+
+- (void)web_scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
+{
+ [_hostViewController updatePDFViewLayout];
+}
+
+- (void)web_scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
+{
+ [_hostViewController updatePDFViewLayout];
+}
+
+- (void)web_scrollViewDidZoom:(UIScrollView *)scrollView
+{
+ [_hostViewController updatePDFViewLayout];
+}
+
+- (NSData *)web_dataRepresentation
+{
+ return _data.get();
+}
+
+- (NSString *)web_suggestedFilename
+{
+ return _suggestedFilename.get();
+}
+
+- (BOOL)web_isBackground
+{
+ return self.isBackground;
+}
+
+@end
+
+#endif // ENABLE(WKPDFVIEW)
Modified: trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm (230486 => 230487)
--- trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm 2018-04-10 19:42:35 UTC (rev 230487)
@@ -116,6 +116,11 @@
{
}
+- (UIView *)web_contentView
+{
+ return self;
+}
+
#pragma mark Find-in-Page
- (void)web_countStringMatches:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (230486 => 230487)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-04-10 18:04:07 UTC (rev 230486)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2018-04-10 19:42:35 UTC (rev 230487)
@@ -1551,6 +1551,8 @@
9FB5F394169E6A80002C25BF /* WKContextPrivateMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */; };
9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
A102A7081EC0EEE900D81D82 /* com.macromedia.Flash Player ESR.plugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7A5E39491D5BD8A700B4B7CE /* com.macromedia.Flash Player ESR.plugin.sb */; };
+ A1046EA12079263100F0C5D8 /* WKPDFView.h in Headers */ = {isa = PBXBuildFile; fileRef = A1046E9F2079263100F0C5D8 /* WKPDFView.h */; };
+ A1046EA22079263100F0C5D8 /* WKPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1046EA02079263100F0C5D8 /* WKPDFView.mm */; };
A115DC71191D82D700DA8072 /* _WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A115DC6D191D82AB00DA8072 /* _WKWebViewPrintFormatter.mm */; };
A115DC72191D82DA00DA8072 /* _WKWebViewPrintFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = A115DC6E191D82AB00DA8072 /* _WKWebViewPrintFormatter.h */; settings = {ATTRIBUTES = (Private, ); }; };
A118A9EE1907AD6F00F7C92B /* QuickLookDocumentData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */; };
@@ -4039,6 +4041,8 @@
9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginProcessManagerMac.mm; sourceTree = "<group>"; };
9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKContextPrivateMac.mm; path = mac/WKContextPrivateMac.mm; sourceTree = "<group>"; };
9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = "<group>"; };
+ A1046E9F2079263100F0C5D8 /* WKPDFView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKPDFView.h; path = ios/WKPDFView.h; sourceTree = "<group>"; };
+ A1046EA02079263100F0C5D8 /* WKPDFView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFView.mm; path = ios/WKPDFView.mm; sourceTree = "<group>"; };
A115DC6D191D82AB00DA8072 /* _WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKWebViewPrintFormatter.mm; sourceTree = "<group>"; };
A115DC6E191D82AB00DA8072 /* _WKWebViewPrintFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebViewPrintFormatter.h; sourceTree = "<group>"; };
A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = QuickLookDocumentData.cpp; path = ios/QuickLookDocumentData.cpp; sourceTree = "<group>"; };
@@ -5840,6 +5844,8 @@
A15EEDE31E301CEE000069B0 /* WKPasswordView.mm */,
2D6AB53F192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h */,
2D6AB540192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm */,
+ A1046E9F2079263100F0C5D8 /* WKPDFView.h */,
+ A1046EA02079263100F0C5D8 /* WKPDFView.mm */,
0FCB4E4418BBE044000FCFC9 /* WKScrollView.h */,
0FCB4E4518BBE044000FCFC9 /* WKScrollView.mm */,
26F10BE619187E2E001D0E68 /* WKSyntheticClickTapGestureRecognizer.h */,
@@ -9651,6 +9657,7 @@
A5EFD38C16B0E88C00B2F0E8 /* WKPageVisibilityTypes.h in Headers */,
A15EEDE61E301CEE000069B0 /* WKPasswordView.h in Headers */,
2D6AB541192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h in Headers */,
+ A1046EA12079263100F0C5D8 /* WKPDFView.h in Headers */,
7C135AA9173B0BCA00586AE2 /* WKPluginInformation.h in Headers */,
2DABA7741A817EE600EF0F1A /* WKPluginLoadPolicy.h in Headers */,
1AFDD3171891C94700153970 /* WKPreferences.h in Headers */,
@@ -11339,6 +11346,7 @@
BCE17B7D1381F1170012A641 /* WKPagePrivateMac.mm in Sources */,
A15EEDE51E301CEE000069B0 /* WKPasswordView.mm in Sources */,
2D6AB542192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm in Sources */,
+ A1046EA22079263100F0C5D8 /* WKPDFView.mm in Sources */,
7C135AA8173B0BCA00586AE2 /* WKPluginInformation.cpp in Sources */,
BCD597D1112B56AC00EC8C23 /* WKPreferences.cpp in Sources */,
1AFDD3191891CA1200153970 /* WKPreferences.mm in Sources */,