Changeset 211160 in webkit
- Timestamp:
- Jan 25, 2017 12:48:41 PM (7 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r211158 r211160 1 2017-01-25 Andy Estes <aestes@apple.com> 2 3 [iOS] Move WKPDFView's password view to WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=167401 5 6 Reviewed by Tim Horton. 7 8 r210943 moved the PDF password view into the new class WKPasswordView but left it as a 9 subview of the WKPDFView. To show the password view for Web content, my original plan was to 10 teach WKContentView to host its own password view, but this turned out not to work. Since 11 QuickLook needs to unlock a document before determining its preview's MIME type, we have to 12 ask for a password during provisional navigation, but if the still-committed document is a 13 PDF then the WKContentView will not be in the view hierarchy. 14 15 To ensure password view visibility, this patch moves the ownership of WKPasswordView to 16 WKWebView and creates an internal API for showing and hiding it. When 17 -_showPasswordViewWithDocumentName:passwordHandler: is called, WKWebView inserts a new 18 WKPasswordView as a subview of the scroll view and hides the current content view. The 19 password view is removed and the current content view is unhidden by -_hidePasswordView. 20 21 This also fixes a bug in WKPDFView where a PDF document is laid out incorrectly if the view 22 size changes while the password view is displayed. 23 24 * UIProcess/API/Cocoa/WKWebView.mm: Declared _passwordView. 25 (-[WKWebView _processDidExit]): Hid the password view. 26 (-[WKWebView _didCommitLayerTree:]): Ignored if not showing the standard content view. 27 (-[WKWebView _restorePageScrollPosition:scrollOrigin:previousObscuredInset:scale:]): Ditto. 28 (-[WKWebView _restorePageStateToUnobscuredCenter:scale:]): Ditto. 29 (-[WKWebView usesStandardContentView]): Changed to return false if _passwordView is non-nil. 30 (-[WKWebView _updateContentRectsWithState:]): Updated _passwordView's frame with the current 31 bounds size. 32 (-[WKWebView _showPasswordViewWithDocumentName:passwordHandler:]): Created a WKPasswordView, 33 called -showInScrollView:, and hid _currentContentView. 34 (-[WKWebView _hidePasswordView]): Removed _passwordView from its superview, set 35 _passwordView to nil, and unhid _currentContentView. 36 (-[WKWebView _passwordView]): Returned _passwordView. 37 (-[WKWebView _beginAnimatedResizeWithUpdates:]): Called -usesStandardContentView instead of 38 checking for a non-nil _customContentView when deciding whether to do a non-animated resize. 39 * UIProcess/API/Cocoa/WKWebViewInternal.h: 40 * UIProcess/ios/WKPDFView.mm: Removed _passwordView. 41 (-[WKPDFView web_setMinimumSize:]): Set m_minimumSize and updated the frame size even when a 42 password view is displayed. 43 (-[WKPDFView _computePageAndDocumentFrames]): Removed password view code. 44 (-[WKPDFView _showPasswordEntryField]): Ditto. 45 (-[WKPDFView _passwordViewFrame]): Deleted. 46 * UIProcess/ios/WKPasswordView.h: 47 * UIProcess/ios/WKPasswordView.mm: 48 (-[WKPasswordView initWithFrame:documentName:]): Stored a copy of documentName in 49 _documentName. 50 (-[WKPasswordView documentName]): Added. Returns _documentName. 51 (-[WKPasswordView showInScrollView:]): Renamed from displayInContentView:. Started saving 52 zoomScale and contentSize. 53 (-[WKPasswordView hide]): Started restoring zoomeScale and contentSize. 54 (-[WKPasswordView showPasswordFailureAlert]): Renamed from -displayPasswordFailureAlert. 55 (-[WKPasswordView displayInContentView:]): Renamed to -showInScrollView: 56 (-[WKPasswordView displayPasswordFailureAlert]): Renamed to -showPasswordFailureAlert. 57 1 58 2017-01-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 59 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
r211126 r211160 58 58 #import "WKNavigationDelegate.h" 59 59 #import "WKNavigationInternal.h" 60 #import "WKPasswordView.h" 60 61 #import "WKPreferencesInternal.h" 61 62 #import "WKProcessPoolInternal.h" … … 274 275 Vector<std::function<void ()>> _snapshotsDeferredDuringResize; 275 276 RetainPtr<NSMutableArray> _stableStatePresentationUpdateCallbacks; 277 278 RetainPtr<WKPasswordView> _passwordView; 276 279 #endif 277 280 #if PLATFORM(MAC) … … 1193 1196 - (void)_processDidExit 1194 1197 { 1198 [self _hidePasswordView]; 1195 1199 if (!_customContentView && _dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) { 1196 1200 NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()]; … … 1269 1273 - (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 1270 1274 { 1271 if ( _customContentView)1275 if (![self usesStandardContentView]) 1272 1276 return; 1273 1277 … … 1407 1411 return; 1408 1412 1409 if ( _customContentView)1413 if (![self usesStandardContentView]) 1410 1414 return; 1411 1415 … … 1424 1428 return; 1425 1429 1426 if ( _customContentView)1430 if (![self usesStandardContentView]) 1427 1431 return; 1428 1432 … … 1835 1839 - (BOOL)usesStandardContentView 1836 1840 { 1837 return !_customContentView ;1841 return !_customContentView && !_passwordView; 1838 1842 } 1839 1843 … … 2112 2116 { 2113 2117 if (![self usesStandardContentView]) { 2118 [_passwordView setFrame:self.bounds]; 2114 2119 [_customContentView web_computedContentInsetDidChange]; 2115 2120 return; … … 2330 2335 _frozenVisibleContentRect = std::nullopt; 2331 2336 _frozenUnobscuredContentRect = std::nullopt; 2337 } 2338 2339 - (void)_showPasswordViewWithDocumentName:(NSString *)documentName passwordHandler:(void (^)(NSString *))passwordHandler 2340 { 2341 ASSERT(!_passwordView); 2342 _passwordView = adoptNS([[WKPasswordView alloc] initWithFrame:self.bounds documentName:documentName]); 2343 [_passwordView setUserDidEnterPassword:passwordHandler]; 2344 [_passwordView showInScrollView:_scrollView.get()]; 2345 self._currentContentView.hidden = YES; 2346 } 2347 2348 - (void)_hidePasswordView 2349 { 2350 self._currentContentView.hidden = NO; 2351 [_passwordView removeFromSuperview]; 2352 _passwordView = nil; 2353 } 2354 2355 - (WKPasswordView *)_passwordView 2356 { 2357 return _passwordView.get(); 2332 2358 } 2333 2359 … … 4213 4239 WebCore::FloatRect oldUnobscuredContentRect = _page->unobscuredContentRect(); 4214 4240 4215 if ( _customContentView|| !_hasCommittedLoadForMainFrame || CGRectIsEmpty(oldBounds) || oldUnobscuredContentRect.isEmpty()) {4241 if (![self usesStandardContentView] || !_hasCommittedLoadForMainFrame || CGRectIsEmpty(oldBounds) || oldUnobscuredContentRect.isEmpty()) { 4216 4242 updateBlock(); 4217 4243 return; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h
r211121 r211160 57 57 58 58 @class WKWebViewContentProviderRegistry; 59 @class WKPasswordView; 59 60 @class _WKFrameHandle; 60 61 @protocol _WKWebViewPrintProvider; … … 117 118 - (BOOL)_isNavigationSwipeGestureRecognizer:(UIGestureRecognizer *)recognizer; 118 119 120 - (void)_showPasswordViewWithDocumentName:(NSString *)documentName passwordHandler:(void (^)(NSString *))passwordHandler; 121 - (void)_hidePasswordView; 122 123 @property (nonatomic, readonly) WKPasswordView *_passwordView; 124 119 125 @property (nonatomic, readonly) BOOL _isBackground; 120 126 -
trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm
r210943 r211160 77 77 RetainPtr<WKPDFPageNumberIndicator> _pageNumberIndicator; 78 78 79 RetainPtr<WKPasswordView> _passwordView;80 81 79 Vector<PDFPageInfo> _pages; 82 80 unsigned _centerPageNumber; … … 206 204 - (void)web_setMinimumSize:(CGSize)size 207 205 { 208 if (_passwordView) {209 [_passwordView setFrame:[self _passwordViewFrame]];210 return;211 }212 213 206 _minimumSize = size; 207 208 if (_webView._passwordView) { 209 self.frame = { self.frame.origin, size }; 210 return; 211 } 214 212 215 213 CGFloat oldDocumentLeftFraction = 0; … … 362 360 - (void)_computePageAndDocumentFrames 363 361 { 364 if (_passwordView)365 return;366 367 362 NSUInteger pageCount = [_pdfDocument numberOfPages]; 368 363 [_pageNumberIndicator setPageCount:pageCount]; … … 747 742 #pragma mark Password protection UI 748 743 749 - (CGRect)_passwordViewFrame750 {751 CGRect webViewBounds = _webView.bounds;752 return CGRectMake(0, 0, webViewBounds.size.width, webViewBounds.size.height);753 }754 755 744 - (void)_showPasswordEntryField 756 745 { 757 _passwordView = adoptNS([[WKPasswordView alloc] initWithFrame:[self _passwordViewFrame] documentName:_suggestedFilename.get()]); 758 759 [_passwordView setUserDidEnterPassword:[retainedSelf = retainPtr(self)](NSString *password) { 746 [_webView _showPasswordViewWithDocumentName:_suggestedFilename.get() passwordHandler:[retainedSelf = retainPtr(self), webView = retainPtr(_webView)](NSString *password) { 760 747 if (!CGPDFDocumentUnlockWithPassword(retainedSelf->_cgPDFDocument.get(), password.UTF8String)) { 761 [ retainedSelf->_passwordView displayPasswordFailureAlert];748 [[webView _passwordView] showPasswordFailureAlert]; 762 749 return; 763 750 } 764 751 765 [retainedSelf->_passwordView hide]; 766 retainedSelf->_passwordView = nil; 752 [webView _hidePasswordView]; 767 753 [retainedSelf _didLoadPDFDocument]; 768 754 }]; 769 770 [_passwordView displayInContentView:self];771 755 } 772 756 -
trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.h
r210943 r211160 31 31 32 32 - (instancetype)initWithFrame:(CGRect)frame documentName:(NSString *)documentName; 33 - (void) displayInContentView:(UIView *)contentView;33 - (void)showInScrollView:(UIScrollView *)scrollView; 34 34 - (void)hide; 35 - (void) displayPasswordFailureAlert;35 - (void)showPasswordFailureAlert; 36 36 37 @property (nonatomic, readonly) NSString *documentName; 37 38 @property (nonatomic, copy) void (^userDidEnterPassword)(NSString *); 38 39 -
trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.mm
r210943 r211160 42 42 43 43 @implementation WKPasswordView { 44 RetainPtr<NSString> _documentName; 44 45 RetainPtr<UIScrollView> _scrollView; 45 46 RetainPtr<UIDocumentPasswordView> _passwordView; 46 47 CGFloat _savedMinimumZoomScale; 47 48 CGFloat _savedMaximumZoomScale; 49 CGFloat _savedZoomScale; 50 CGSize _savedContentSize; 48 51 RetainPtr<UIColor> _savedBackgroundColor; 49 52 } … … 55 58 return nil; 56 59 57 _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:documentName]); 60 _documentName = adoptNS([documentName copy]); 61 _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:_documentName.get()]); 58 62 [_passwordView setFrame:self.bounds]; 59 63 [_passwordView setPasswordDelegate:self]; … … 66 70 } 67 71 72 - (NSString *)documentName 73 { 74 return _documentName.get(); 75 } 76 68 77 - (void)layoutSubviews 69 78 { … … 72 81 } 73 82 74 - (void) displayInContentView:(UIView *)contentView83 - (void)showInScrollView:(UIScrollView *)scrollView 75 84 { 76 ASSERT([contentView isKindOfClass:[WKContentView class]] || [contentView conformsToProtocol:@protocol(WKWebViewContentProvider)]); 77 ASSERT([contentView.superview isKindOfClass:[UIScrollView class]]); 78 _scrollView = (UIScrollView *)contentView.superview; 85 _scrollView = scrollView; 79 86 80 87 _savedMinimumZoomScale = [_scrollView minimumZoomScale]; 81 88 _savedMaximumZoomScale = [_scrollView maximumZoomScale]; 89 _savedZoomScale = [_scrollView zoomScale]; 90 _savedContentSize = [_scrollView contentSize]; 82 91 _savedBackgroundColor = [_scrollView backgroundColor]; 83 92 84 93 [_scrollView setMinimumZoomScale:1]; 85 94 [_scrollView setMaximumZoomScale:1]; 95 [_scrollView setZoomScale:1]; 86 96 [_scrollView setContentSize:self.frame.size]; 87 97 [_scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]]; 88 98 89 [ contentView addSubview:self];99 [scrollView addSubview:self]; 90 100 } 91 101 … … 94 104 [_scrollView setMinimumZoomScale:_savedMinimumZoomScale]; 95 105 [_scrollView setMaximumZoomScale:_savedMaximumZoomScale]; 106 [_scrollView setZoomScale:_savedZoomScale]; 107 [_scrollView setContentSize:_savedContentSize]; 96 108 [_scrollView setBackgroundColor:_savedBackgroundColor.get()]; 97 109 … … 102 114 } 103 115 104 - (void) displayPasswordFailureAlert116 - (void)showPasswordFailureAlert 105 117 { 106 118 [[_passwordView passwordField] setText:@""];
Note: See TracChangeset
for help on using the changeset viewer.