blob: b0cfc8f016e1e148ceeaaf7e337a3daaa2ed4e16 [file] [log] [blame]
// 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.
#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>
// 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
// 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:
// 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
completionHandler:(void (^)(NSString* username,
NSString* password))handler;
// Determines whether the given link with |linkURL| should show a preview on
// force touch.
- (BOOL)webState:(web::WebState*)webState
shouldPreviewLinkWithURL:(const GURL&)linkURL;
// Called when the user performs a peek action on a link with |linkURL| with
// force touch. Returns a view controller shown as a pop-up. Uses Webkit's
// default preview behavior when it returns nil.
- (UIViewController*)webState:(web::WebState*)webState
previewingViewControllerForLinkWithURL:(const GURL&)linkURL;
// Called when the user performs a pop action on the preview on force touch.
// |previewing_view_controller| is the view controller that is popped.
// It should display |previewingViewController| inside the app.
- (void)webState:(web::WebState*)webState
// 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. |previewProvider| is used to show a custom ViewController to
// preview the page.
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
(void (^)(UIContextMenuConfiguration*))completionHandler
// Called when iOS13+ context menu is ready to be showed.
- (void)webState:(web::WebState*)webState
contextMenuWillPresentForLinkWithURL:(const GURL&)linkURL
// Called when iOS13+ context menu will commit with animator.
- (void)webState:(web::WebState*)webState
contextMenuForLinkWithURL:(const GURL&)linkURL
// Called when iOS13+ context menu will present.
- (void)webState:(web::WebState*)webState
contextMenuDidEndForLinkWithURL:(const GURL&)linkURL
// This API can be used to show custom input views in the web view.
- (id<CRWResponderInputView>)webStateInputViewProvider:(web::WebState*)webState;
namespace web {
// Adapter to use an id<CRWWebStateDelegate> as a web::WebStateDelegate.
class WebStateDelegateBridge : public web::WebStateDelegate {
explicit WebStateDelegateBridge(id<CRWWebStateDelegate> delegate);
~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;
bool ShouldPreviewLink(WebState* web_state, const GURL& link_url) override;
UIViewController* GetPreviewingViewController(WebState* source,
const GURL& link_url) override;
void CommitPreviewingViewController(
WebState* source,
UIViewController* previewing_view_controller) override;
UIView* GetWebViewContainer(WebState* source) override;
void ContextMenuConfiguration(
WebState* source,
const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
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;
// CRWWebStateDelegate which receives forwarded calls.
__weak id<CRWWebStateDelegate> delegate_ = nil;
} // web