| // Copyright 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef IOS_WEB_PUBLIC_WEB_STATE_DELEGATE_BRIDGE_H_ |
| #define IOS_WEB_PUBLIC_WEB_STATE_DELEGATE_BRIDGE_H_ |
| |
| #import <Foundation/Foundation.h> |
| #import <UIKit/UIKit.h> |
| |
| #import "ios/web/public/web_state_delegate.h" |
| |
| @class UIViewController; |
| |
| // Objective-C interface for web::WebStateDelegate. |
| @protocol CRWWebStateDelegate <NSObject> |
| @optional |
| |
| // Called when |webState| wants to open a new window. |url| is the URL of |
| // the new window; |opener_url| is the URL of the page which requested a |
| // window to be open; |initiated_by_user| is true if action was caused by the |
| // user. |webState| will not open a window if this method returns nil. This |
| // method can not return |webState|. |
| - (web::WebState*)webState:(web::WebState*)webState |
| createNewWebStateForURL:(const GURL&)URL |
| openerURL:(const GURL&)openerURL |
| initiatedByUser:(BOOL)initiatedByUser; |
| |
| // Called when the page calls wants to close self by calling window.close() |
| // JavaScript API. |
| - (void)closeWebState:(web::WebState*)webState; |
| |
| // Returns the WebState the URL is opened in, or nullptr if the URL wasn't |
| // opened immediately. |
| - (web::WebState*)webState:(web::WebState*)webState |
| openURLWithParams:(const web::WebState::OpenURLParams&)params; |
| |
| // Called when the user triggers the context menu with the given |
| // |ContextMenuParams|. If this method is not implemented, no context menu will |
| // be displayed. |
| - (void)webState:(web::WebState*)webState |
| handleContextMenu:(const web::ContextMenuParams&)params; |
| |
| // Requests the repost form confirmation dialog. Clients must call |handler| |
| // with YES to allow repost and with NO to cancel the repost. If this method is |
| // not implemented then WebState will repost the form. |
| - (void)webState:(web::WebState*)webState |
| runRepostFormDialogWithCompletionHandler:(void (^)(BOOL))handler; |
| |
| // Returns a pointer to a service to manage dialogs. May return null in which |
| // case dialogs aren't shown. |
| - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: |
| (web::WebState*)webState; |
| |
| // Called when a request receives an authentication challenge specified by |
| // |protectionSpace|, and is unable to respond using cached credentials. |
| // Clients must call |handler| even if they want to cancel authentication |
| // (in which case |username| or |password| should be nil). |
| - (void)webState:(web::WebState*)webState |
| didRequestHTTPAuthForProtectionSpace:(NSURLProtectionSpace*)protectionSpace |
| proposedCredential:(NSURLCredential*)proposedCredential |
| completionHandler:(void (^)(NSString* username, |
| NSString* password))handler; |
| |
| // Called to know the size of the view containing the WebView. |
| - (UIView*)webViewContainerForWebState:(web::WebState*)webState; |
| |
| // Called when iOS13+ context menu is triggered and now it is required to |
| // provide a UIContextMenuConfiguration to |completion_handler| to generate the |
| // context menu. |
| - (void)webState:(web::WebState*)webState |
| contextMenuConfigurationForParams:(const web::ContextMenuParams&)params |
| completionHandler: |
| (void (^)(UIContextMenuConfiguration*))completionHandler |
| API_AVAILABLE(ios(13.0)); |
| |
| // Called when iOS13+ context menu is ready to be showed. |
| - (void)webState:(web::WebState*)webState |
| contextMenuWillPresentForLinkWithURL:(const GURL&)linkURL |
| API_AVAILABLE(ios(13.0)); |
| |
| // Called when iOS13+ context menu will commit with animator. |
| - (void)webState:(web::WebState*)webState |
| contextMenuForLinkWithURL:(const GURL&)linkURL |
| willCommitWithAnimator: |
| (id<UIContextMenuInteractionCommitAnimating>)animator |
| API_AVAILABLE(ios(13.0)); |
| |
| // Called when iOS13+ context menu will present. |
| - (void)webState:(web::WebState*)webState |
| contextMenuDidEndForLinkWithURL:(const GURL&)linkURL |
| API_AVAILABLE(ios(13.0)); |
| |
| // This API can be used to show custom input views in the web view. |
| - (id<CRWResponderInputView>)webStateInputViewProvider:(web::WebState*)webState; |
| |
| @end |
| |
| namespace web { |
| |
| // Adapter to use an id<CRWWebStateDelegate> as a web::WebStateDelegate. |
| class WebStateDelegateBridge : public web::WebStateDelegate { |
| public: |
| explicit WebStateDelegateBridge(id<CRWWebStateDelegate> delegate); |
| |
| WebStateDelegateBridge(const WebStateDelegateBridge&) = delete; |
| WebStateDelegateBridge& operator=(const WebStateDelegateBridge&) = delete; |
| |
| ~WebStateDelegateBridge() override; |
| |
| // web::WebStateDelegate methods. |
| WebState* CreateNewWebState(WebState* source, |
| const GURL& url, |
| const GURL& opener_url, |
| bool initiated_by_user) override; |
| void CloseWebState(WebState* source) override; |
| WebState* OpenURLFromWebState(WebState*, |
| const WebState::OpenURLParams&) override; |
| void HandleContextMenu(WebState* source, |
| const ContextMenuParams& params) override; |
| void ShowRepostFormWarningDialog( |
| WebState* source, |
| base::OnceCallback<void(bool)> callback) override; |
| JavaScriptDialogPresenter* GetJavaScriptDialogPresenter( |
| WebState* source) override; |
| void OnAuthRequired(WebState* source, |
| NSURLProtectionSpace* protection_space, |
| NSURLCredential* proposed_credential, |
| AuthCallback callback) override; |
| UIView* GetWebViewContainer(WebState* source) override; |
| void ContextMenuConfiguration( |
| WebState* source, |
| const ContextMenuParams& params, |
| void (^completion_handler)(UIContextMenuConfiguration*)) |
| API_AVAILABLE(ios(13.0)) override; |
| void ContextMenuDidEnd(WebState* source, const GURL& link_url) |
| API_AVAILABLE(ios(13.0)) override; |
| void ContextMenuWillCommitWithAnimator( |
| WebState* source, |
| const GURL& link_url, |
| id<UIContextMenuInteractionCommitAnimating> animator) |
| API_AVAILABLE(ios(13.0)) override; |
| void ContextMenuWillPresent(WebState* source, const GURL& link_url) |
| API_AVAILABLE(ios(13.0)) override; |
| |
| id<CRWResponderInputView> GetResponderInputView(WebState* source) override; |
| |
| private: |
| // CRWWebStateDelegate which receives forwarded calls. |
| __weak id<CRWWebStateDelegate> delegate_ = nil; |
| }; |
| |
| } // web |
| |
| #endif // IOS_WEB_PUBLIC_WEB_STATE_DELEGATE_BRIDGE_H_ |