Changeset 211160 in webkit


Ignore:
Timestamp:
Jan 25, 2017 12:48:41 PM (7 years ago)
Author:
aestes@apple.com
Message:

[iOS] Move WKPDFView's password view to WKWebView
https://bugs.webkit.org/show_bug.cgi?id=167401

Reviewed by Tim Horton.

r210943 moved the PDF password view into the new class WKPasswordView but left it as a
subview of the WKPDFView. To show the password view for Web content, my original plan was to
teach WKContentView to host its own password view, but this turned out not to work. Since
QuickLook needs to unlock a document before determining its preview's MIME type, we have to
ask for a password during provisional navigation, but if the still-committed document is a
PDF then the WKContentView will not be in the view hierarchy.

To ensure password view visibility, this patch moves the ownership of WKPasswordView to
WKWebView and creates an internal API for showing and hiding it. When
-_showPasswordViewWithDocumentName:passwordHandler: is called, WKWebView inserts a new
WKPasswordView as a subview of the scroll view and hides the current content view. The
password view is removed and the current content view is unhidden by -_hidePasswordView.

This also fixes a bug in WKPDFView where a PDF document is laid out incorrectly if the view
size changes while the password view is displayed.

  • UIProcess/API/Cocoa/WKWebView.mm: Declared _passwordView.

(-[WKWebView _processDidExit]): Hid the password view.
(-[WKWebView _didCommitLayerTree:]): Ignored if not showing the standard content view.
(-[WKWebView _restorePageScrollPosition:scrollOrigin:previousObscuredInset:scale:]): Ditto.
(-[WKWebView _restorePageStateToUnobscuredCenter:scale:]): Ditto.
(-[WKWebView usesStandardContentView]): Changed to return false if _passwordView is non-nil.
(-[WKWebView _updateContentRectsWithState:]): Updated _passwordView's frame with the current
bounds size.
(-[WKWebView _showPasswordViewWithDocumentName:passwordHandler:]): Created a WKPasswordView,
called -showInScrollView:, and hid _currentContentView.
(-[WKWebView _hidePasswordView]): Removed _passwordView from its superview, set
_passwordView to nil, and unhid _currentContentView.
(-[WKWebView _passwordView]): Returned _passwordView.
(-[WKWebView _beginAnimatedResizeWithUpdates:]): Called -usesStandardContentView instead of
checking for a non-nil _customContentView when deciding whether to do a non-animated resize.

  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/ios/WKPDFView.mm: Removed _passwordView.

(-[WKPDFView web_setMinimumSize:]): Set m_minimumSize and updated the frame size even when a
password view is displayed.
(-[WKPDFView _computePageAndDocumentFrames]): Removed password view code.
(-[WKPDFView _showPasswordEntryField]): Ditto.
(-[WKPDFView _passwordViewFrame]): Deleted.

  • UIProcess/ios/WKPasswordView.h:
  • UIProcess/ios/WKPasswordView.mm:

(-[WKPasswordView initWithFrame:documentName:]): Stored a copy of documentName in
_documentName.
(-[WKPasswordView documentName]): Added. Returns _documentName.
(-[WKPasswordView showInScrollView:]): Renamed from displayInContentView:. Started saving
zoomScale and contentSize.
(-[WKPasswordView hide]): Started restoring zoomeScale and contentSize.
(-[WKPasswordView showPasswordFailureAlert]): Renamed from -displayPasswordFailureAlert.
(-[WKPasswordView displayInContentView:]): Renamed to -showInScrollView:
(-[WKPasswordView displayPasswordFailureAlert]): Renamed to -showPasswordFailureAlert.

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r211158 r211160  
     12017-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
    1582017-01-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    259
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r211126 r211160  
    5858#import "WKNavigationDelegate.h"
    5959#import "WKNavigationInternal.h"
     60#import "WKPasswordView.h"
    6061#import "WKPreferencesInternal.h"
    6162#import "WKProcessPoolInternal.h"
     
    274275    Vector<std::function<void ()>> _snapshotsDeferredDuringResize;
    275276    RetainPtr<NSMutableArray> _stableStatePresentationUpdateCallbacks;
     277
     278    RetainPtr<WKPasswordView> _passwordView;
    276279#endif
    277280#if PLATFORM(MAC)
     
    11931196- (void)_processDidExit
    11941197{
     1198    [self _hidePasswordView];
    11951199    if (!_customContentView && _dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
    11961200        NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
     
    12691273- (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
    12701274{
    1271     if (_customContentView)
     1275    if (![self usesStandardContentView])
    12721276        return;
    12731277
     
    14071411        return;
    14081412
    1409     if (_customContentView)
     1413    if (![self usesStandardContentView])
    14101414        return;
    14111415
     
    14241428        return;
    14251429
    1426     if (_customContentView)
     1430    if (![self usesStandardContentView])
    14271431        return;
    14281432
     
    18351839- (BOOL)usesStandardContentView
    18361840{
    1837     return !_customContentView;
     1841    return !_customContentView && !_passwordView;
    18381842}
    18391843
     
    21122116{
    21132117    if (![self usesStandardContentView]) {
     2118        [_passwordView setFrame:self.bounds];
    21142119        [_customContentView web_computedContentInsetDidChange];
    21152120        return;
     
    23302335    _frozenVisibleContentRect = std::nullopt;
    23312336    _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();
    23322358}
    23332359
     
    42134239    WebCore::FloatRect oldUnobscuredContentRect = _page->unobscuredContentRect();
    42144240
    4215     if (_customContentView || !_hasCommittedLoadForMainFrame || CGRectIsEmpty(oldBounds) || oldUnobscuredContentRect.isEmpty()) {
     4241    if (![self usesStandardContentView] || !_hasCommittedLoadForMainFrame || CGRectIsEmpty(oldBounds) || oldUnobscuredContentRect.isEmpty()) {
    42164242        updateBlock();
    42174243        return;
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h

    r211121 r211160  
    5757
    5858@class WKWebViewContentProviderRegistry;
     59@class WKPasswordView;
    5960@class _WKFrameHandle;
    6061@protocol _WKWebViewPrintProvider;
     
    117118- (BOOL)_isNavigationSwipeGestureRecognizer:(UIGestureRecognizer *)recognizer;
    118119
     120- (void)_showPasswordViewWithDocumentName:(NSString *)documentName passwordHandler:(void (^)(NSString *))passwordHandler;
     121- (void)_hidePasswordView;
     122
     123@property (nonatomic, readonly) WKPasswordView *_passwordView;
     124
    119125@property (nonatomic, readonly) BOOL _isBackground;
    120126
  • trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm

    r210943 r211160  
    7777    RetainPtr<WKPDFPageNumberIndicator> _pageNumberIndicator;
    7878
    79     RetainPtr<WKPasswordView> _passwordView;
    80 
    8179    Vector<PDFPageInfo> _pages;
    8280    unsigned _centerPageNumber;
     
    206204- (void)web_setMinimumSize:(CGSize)size
    207205{
    208     if (_passwordView) {
    209         [_passwordView setFrame:[self _passwordViewFrame]];
    210         return;
    211     }
    212 
    213206    _minimumSize = size;
     207
     208    if (_webView._passwordView) {
     209        self.frame = { self.frame.origin, size };
     210        return;
     211    }
    214212
    215213    CGFloat oldDocumentLeftFraction = 0;
     
    362360- (void)_computePageAndDocumentFrames
    363361{
    364     if (_passwordView)
    365         return;
    366 
    367362    NSUInteger pageCount = [_pdfDocument numberOfPages];
    368363    [_pageNumberIndicator setPageCount:pageCount];
     
    747742#pragma mark Password protection UI
    748743
    749 - (CGRect)_passwordViewFrame
    750 {
    751     CGRect webViewBounds = _webView.bounds;
    752     return CGRectMake(0, 0, webViewBounds.size.width, webViewBounds.size.height);
    753 }
    754 
    755744- (void)_showPasswordEntryField
    756745{
    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) {
    760747        if (!CGPDFDocumentUnlockWithPassword(retainedSelf->_cgPDFDocument.get(), password.UTF8String)) {
    761             [retainedSelf->_passwordView displayPasswordFailureAlert];
     748            [[webView _passwordView] showPasswordFailureAlert];
    762749            return;
    763750        }
    764751
    765         [retainedSelf->_passwordView hide];
    766         retainedSelf->_passwordView = nil;
     752        [webView _hidePasswordView];
    767753        [retainedSelf _didLoadPDFDocument];
    768754    }];
    769 
    770     [_passwordView displayInContentView:self];
    771755}
    772756
  • trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.h

    r210943 r211160  
    3131
    3232- (instancetype)initWithFrame:(CGRect)frame documentName:(NSString *)documentName;
    33 - (void)displayInContentView:(UIView *)contentView;
     33- (void)showInScrollView:(UIScrollView *)scrollView;
    3434- (void)hide;
    35 - (void)displayPasswordFailureAlert;
     35- (void)showPasswordFailureAlert;
    3636
     37@property (nonatomic, readonly) NSString *documentName;
    3738@property (nonatomic, copy) void (^userDidEnterPassword)(NSString *);
    3839
  • trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.mm

    r210943 r211160  
    4242
    4343@implementation WKPasswordView {
     44    RetainPtr<NSString> _documentName;
    4445    RetainPtr<UIScrollView> _scrollView;
    4546    RetainPtr<UIDocumentPasswordView> _passwordView;
    4647    CGFloat _savedMinimumZoomScale;
    4748    CGFloat _savedMaximumZoomScale;
     49    CGFloat _savedZoomScale;
     50    CGSize _savedContentSize;
    4851    RetainPtr<UIColor> _savedBackgroundColor;
    4952}
     
    5558        return nil;
    5659
    57     _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:documentName]);
     60    _documentName = adoptNS([documentName copy]);
     61    _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:_documentName.get()]);
    5862    [_passwordView setFrame:self.bounds];
    5963    [_passwordView setPasswordDelegate:self];
     
    6670}
    6771
     72- (NSString *)documentName
     73{
     74    return _documentName.get();
     75}
     76
    6877- (void)layoutSubviews
    6978{
     
    7281}
    7382
    74 - (void)displayInContentView:(UIView *)contentView
     83- (void)showInScrollView:(UIScrollView *)scrollView
    7584{
    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;
    7986
    8087    _savedMinimumZoomScale = [_scrollView minimumZoomScale];
    8188    _savedMaximumZoomScale = [_scrollView maximumZoomScale];
     89    _savedZoomScale = [_scrollView zoomScale];
     90    _savedContentSize = [_scrollView contentSize];
    8291    _savedBackgroundColor = [_scrollView backgroundColor];
    8392
    8493    [_scrollView setMinimumZoomScale:1];
    8594    [_scrollView setMaximumZoomScale:1];
     95    [_scrollView setZoomScale:1];
    8696    [_scrollView setContentSize:self.frame.size];
    8797    [_scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    8898
    89     [contentView addSubview:self];
     99    [scrollView addSubview:self];
    90100}
    91101
     
    94104    [_scrollView setMinimumZoomScale:_savedMinimumZoomScale];
    95105    [_scrollView setMaximumZoomScale:_savedMaximumZoomScale];
     106    [_scrollView setZoomScale:_savedZoomScale];
     107    [_scrollView setContentSize:_savedContentSize];
    96108    [_scrollView setBackgroundColor:_savedBackgroundColor.get()];
    97109
     
    102114}
    103115
    104 - (void)displayPasswordFailureAlert
     116- (void)showPasswordFailureAlert
    105117{
    106118    [[_passwordView passwordField] setText:@""];
Note: See TracChangeset for help on using the changeset viewer.