Skip to content

Commit

Permalink
Cherry-pick eb5c280. rdar://121461105
Browse files Browse the repository at this point in the history
    Add UIViewController to _WKWebExtensionAction.
    https://webkit.org/b/270099
    rdar://121461105

    Reviewed by Brian Weinstein.

    The logic for popups is complex on iOS, we should vend a UIViewController instead of just the WKWebView.
    This also overrides the viewport to accommodate desktop extenions better on mobile.

    * Source/WebKit/Platform/spi/ios/UIKitSPI.h:
    * Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionAction.h:
    * Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionAction.mm:
    (-[_WKWebExtensionAction popupViewController]):
    * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm:
    (-[_WKWebExtensionActionWebViewDelegate initWithWebExtensionAction:]):
    (-[_WKWebExtensionActionWebViewDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
    (-[_WKWebExtensionActionWebView initWithFrame:configuration:webExtensionAction:]):
    (-[_WKWebExtensionActionWebView dealloc]):
    (-[_WKWebExtensionActionWebView invalidateIntrinsicContentSize]):
    (-[_WKWebExtensionActionWebView observeValueForKeyPath:ofObject:change:context:]):
    (-[_WKWebExtensionActionWebView _contentSize]):
    (-[_WKWebExtensionActionWebView _contentSizeDidChange]):
    (-[_WKWebExtensionActionWebView _checkIfContentSizeStabilizedAndPresentPopup]):
    (-[_WKWebExtensionActionViewController initWithWebExtensionAction:]):
    (-[_WKWebExtensionActionViewController viewIsAppearing:]):
    (-[_WKWebExtensionActionViewController adaptivePresentationStyleForPresentationController:traitCollection:]):
    (-[_WKWebExtensionActionViewController presentationController:prepareAdaptivePresentationController:]):
    (-[_WKWebExtensionActionViewController presentationController:viewControllerForAdaptivePresentationStyle:]):
    (-[_WKWebExtensionActionViewController _viewControllerDismissalTransitionDidEnd:]):
    (-[_WKWebExtensionActionViewController _updatePopoverContentSize]):
    (-[_WKWebExtensionActionViewController _updateDetentForSheetPresentationController:]):
    (-[_WKWebExtensionActionViewController _dismissPopup]):
    (WebKit::WebExtensionAction::popupViewController):
    (WebKit::WebExtensionAction::popupWebView):
    (WebKit::WebExtensionAction::readyToPresentPopup):
    (WebKit::WebExtensionAction::popupSizeDidChange):
    (WebKit::WebExtensionAction::popupDidClose):
    (WebKit::WebExtensionAction::closePopupWebView):
    * Source/WebKit/UIProcess/Extensions/WebExtensionAction.h:
    * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIAction.mm:
    (TestWebKitAPI::TEST): Check that popupViewController is non-null.

    Canonical link: https://commits.webkit.org/275337@main
  • Loading branch information
xeenon authored and Mohsin Qureshi committed Mar 5, 2024
1 parent 6dedc42 commit 75d1637
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 29 deletions.
8 changes: 8 additions & 0 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ typedef struct CGSVGDocument *CGSVGDocumentRef;
@class FBSDisplayConfiguration;
@interface UIScreen ()
@property (nonatomic, readonly, retain) FBSDisplayConfiguration *displayConfiguration;
@property (nonatomic, readonly) CGRect _referenceBounds;
@end

@interface UIScrollView ()
Expand Down Expand Up @@ -545,6 +546,13 @@ typedef enum {
@property (readonly) NSString *_hostApplicationBundleIdentifier;
@end

@interface UIViewController (Private)
- (/* nullable */ UIPresentationController *)_existingPresentationControllerImmediate:(BOOL)immediate effective:(BOOL)effective;
@end

extern NSString * const UIPresentationControllerDismissalTransitionDidEndNotification;
extern NSString * const UIPresentationControllerDismissalTransitionDidEndCompletedKey;

@interface _UIViewControllerTransitionContext : NSObject <UIViewControllerContextTransitioning>
@end

Expand Down
17 changes: 15 additions & 2 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#if TARGET_OS_IPHONE
@class UIImage;
@class UIMenuElement;
@class UIViewController;
#else
@class NSImage;
@class NSMenuItem;
Expand Down Expand Up @@ -126,11 +127,23 @@ NS_SWIFT_NAME(_WKWebExtension.Action)
*/
@property (nonatomic, readonly) BOOL presentsPopup;

#if TARGET_OS_IPHONE
/*!
@abstract A view controller that presents a web view loaded with the popup page for this action, or `nil` if no popup is specified.
@discussion The view controller adaptively adjusts its presentation style based on where it is presented from, preferring popover.
It contains a web view preloaded with the popup page and automatically adjusts tis `preferredContentSize` to fit the web view's
content size. The `presentsPopup` property should be checked to determine the availability of a popup before accessing this property.
Dismissing the view controller will close the web view.
@seealso presentsPopup
*/
@property (nonatomic, readonly, nullable) UIViewController *popupViewController;
#endif

/*!
@abstract A web view loaded with the popup page for this action, or `nil` if no popup is specified.
@discussion The web view will be preloaded with the popup page upon first access or after it has been closed. Use the `hasPopup`
@discussion The web view will be preloaded with the popup page upon first access or after it has been closed. Use the `presentsPopup`
property to determine whether a popup should be displayed before accessing this property.
@seealso hasPopup
@seealso presentsPopup
*/
@property (nonatomic, readonly, nullable) WKWebView *popupWebView;

Expand Down
14 changes: 14 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionAction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ - (BOOL)presentsPopup
return _webExtensionAction->presentsPopup();
}

#if PLATFORM(IOS_FAMILY)
- (UIViewController *)popupViewController
{
return _webExtensionAction->popupViewController();
}
#endif

- (WKWebView *)popupWebView
{
return _webExtensionAction->popupWebView();
Expand Down Expand Up @@ -192,6 +199,13 @@ - (BOOL)presentsPopup
return NO;
}

#if PLATFORM(IOS_FAMILY)
- (UIViewController *)popupViewController
{
return nil;
}
#endif

- (WKWebView *)popupWebView
{
return nil;
Expand Down
Loading

0 comments on commit 75d1637

Please sign in to comment.