1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_CRW_WEB_DELEGATE_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_CRW_WEB_DELEGATE_H_
8 #import <UIKit/UIKit.h>
11 #include "base/ios/block_types.h"
12 #include "ios/web/public/favicon_url.h"
13 #include "ios/web/public/ssl_status.h"
14 #import "ios/web/public/web_state/crw_native_content.h"
15 #include "ios/web/public/web_state/web_state.h"
16 #include "ui/base/page_transition_types.h"
19 @
class CRWSessionEntry
;
20 @
class CRWWebController
;
23 class HttpResponseHeaders
;
25 class X509Certificate
;
29 class BlockedPopupInfo
;
34 // Callback for -presentSSLError:forSSLStatus:onUrl:recoverable:callback:
35 typedef void (^SSLErrorCallback
)(BOOL
);
37 // Interface to perform cross window scripting on CRWWebController.
38 @protocol CRWWebControllerScripting
40 // Loads the HTML into the page.
41 - (void)loadHTML
:(NSString
*)html
;
43 // Loads HTML in the page and presents it as if it was originating from the
44 // URL itself. Should be used only in specific cases, where the injected html
45 // is guaranteed to be some derived representation of the original content.
46 - (void)loadHTMLForCurrentURL
:(NSString
*)html
;
48 // Stops loading the page.
51 // TODO(eugenebut): rename -[CRWWebController close] method to avoid confusion.
52 // Asks the delegate to be closed.
57 // Methods implemented by the delegate of the CRWWebController.
58 @protocol CRWWebDelegate
<NSObject
>
60 // Called when the page wants to open a new window by DOM (e.g. with
61 // |window.open| JavaScript call or by clicking a link with |_blank| target) or
62 // wants to open a window with a new tab. |inBackground| allows a page to force
63 // a new window to open in the background. CRWSessionController's openedByDOM
64 // property of the returned CRWWebController must be YES.
65 - (CRWWebController
*)webPageOrderedOpen
:(const GURL
&)url
66 referrer
:(const web::Referrer
&)referrer
67 windowName
:(NSString
*)windowName
68 inBackground
:(BOOL
)inBackground
;
70 // Called when the page wants to open a new window by DOM.
71 // CRWSessionController's openedByDOM property of the returned CRWWebController
73 - (CRWWebController
*)webPageOrderedOpenBlankWithReferrer
:
74 (const web::Referrer
&)referrer
75 inBackground
:(BOOL
)inBackground
;
77 // Called when the page calls window.close() on itself. Begin the shut-down
78 // sequence for this controller.
79 - (void)webPageOrderedClose
;
80 // Navigate forwards or backwards by delta pages.
81 - (void)goDelta
:(int)delta
;
82 // Opens a URL with the given parameters.
83 - (void)openURLWithParams
:(const web::WebState::OpenURLParams
&)params
;
84 // Called when a link to an external app needs to be opened. Returns YES iff
85 // |url| is launched in an external app.
86 - (BOOL
)openExternalURL
:(const GURL
&)url
;
88 // This method is called when a network request has an issue with the SSL
89 // connection to present it to the user. The user will decide if the request
90 // should continue or not and the callback should be invoked to let the backend
92 // The callback is safe to call until CRWWebController is closed.
93 - (void)presentSSLError
:(const net::SSLInfo
&)info
94 forSSLStatus
:(const web::SSLStatus
&)status
95 recoverable
:(BOOL
)recoverable
96 callback
:(SSLErrorCallback
)shouldContinue
;
97 // Asked the delegate to present an error to the user because the
98 // CRWWebController cannot verify the URL of the current page.
99 - (void)presentSpoofingError
;
100 // This method is invoked whenever the system believes the URL is about to
101 // change, or immediately after any unexpected change of the URL, prior to
102 // updating the navigation manager's pending entry.
103 // Phase will be LOAD_REQUESTED.
104 - (void)webWillAddPendingURL
:(const GURL
&)url
105 transition
:(ui::PageTransition
)transition
;
106 // This method is invoked after an update to the navigation manager's pending
107 // URL, triggered whenever the system believes the URL is about to
108 // change, or immediately after any unexpected change of the URL.
109 // This can be followed by a call to webDidStartLoading (phase PAGE_LOADING) or
110 // another call to webWillAddPendingURL and webDidAddPendingURL (phase still
112 - (void)webDidAddPendingURL
;
113 // Called when webWillStartLoadingURL was called, but something went wrong, and
114 // webDidStartLoadingURL will now never be called.
115 - (void)webCancelStartLoadingRequest
;
116 // Called when the page URL has changed. Phase will be PAGE_LOADING. Can be
117 // followed by webDidFinishWithURL or webWillStartLoadingURL.
118 // |updateHistory| is YES if the URL should be added to the history DB.
119 // TODO(stuartmorgan): Remove or rename the history param; the history DB
120 // isn't a web concept, so this shoud be expressed differently.
121 - (void)webDidStartLoadingURL
:(const GURL
&)url
122 shouldUpdateHistory
:(BOOL
)updateHistory
;
123 // Called when the page finishes loading, with the URL, page title and load
124 // success status. Phase will be PAGE_LOADED.
125 // On the next navigation event, this will be followed by a call to
126 // webWillStartLoadingURL.
127 - (void)webDidFinishWithURL
:(const GURL
&)url
128 loadSuccess
:(BOOL
)loadSuccess
;
129 // Called when the page load was cancelled by page activity (before a success /
130 // failure state is known). Phase will be PAGE_LOADED.
131 - (void)webLoadCancelled
:(const GURL
&)url
;
132 // Called when a page updates its history stack using pushState or replaceState.
133 // TODO(stuartmorgan): Generalize this to cover any change of URL without page
135 - (void)webDidUpdateHistoryStateWithPageURL
:(const GURL
&)pageUrl
;
136 // Called when the page updates its icons.
137 // TODO(sdefresne): this method will be removed once WebFaviconDriver is
138 // introduced. Do not add anything there, instead use a WebStateObvserver.
139 // http://crbug.com/472117
140 - (void)onUpdateFavicons
:(const std::vector
<web::FaviconURL
>&)icons
;
141 // Called when a placeholder image should be displayed instead of the WebView.
142 - (void)webController
:(CRWWebController
*)webController
143 retrievePlaceholderOverlayImage
:(void (^)(UIImage
*))block
;
144 // Consults the delegate whether a form should be resubmitted for a request.
145 // Occurs when a POST request is reached when navigating through history.
146 // Call |continueBlock| if a form should be resubmitted.
147 // Call |cancelBlock| if a form should not be resubmitted.
148 // Delegates must call either of these (just once) before the load will
150 - (void)webController
:(CRWWebController
*)webController
151 onFormResubmissionForRequest
:(NSURLRequest
*)request
152 continueBlock
:(ProceduralBlock
)continueBlock
153 cancelBlock
:(ProceduralBlock
)cancelBlock
;
154 // Returns the unique id of the download request and starts downloading the
155 // image at |url| without sending the cookies. Invokes |callback| on completion.
156 - (int)downloadImageAtUrl
:(const GURL
&)url
157 maxBitmapSize
:(uint32_t)maxBitmapSize
158 callback
:(const web::WebState::ImageDownloadCallback
&)callback
;
160 // ---------------------------------------------------------------------
161 // TODO(rohitrao): Eliminate as many of the following delegate methods as
162 // possible. They only exist because the Tab and CRWWebController logic was
163 // very intertwined. We should streamline the logic to jump between classes
164 // less, then remove any delegate method that becomes unneccessary as a result.
166 // Called when the page is reloaded.
167 - (void)webWillReload
;
168 // Called when a page is loaded using loadWithParams. In
169 // |webWillInitiateLoadWithParams|, the |params| argument is non-const so that
170 // the delegate can make changes if necessary.
171 // TODO(rohitrao): This is not a great API. Clean it up.
172 - (void)webWillInitiateLoadWithParams
:(web::WebLoadParams
&)params
;
173 - (void)webDidUpdateSessionForLoadWithParams
:(const web::WebLoadParams
&)params
174 wasInitialNavigation
:(BOOL
)initialNavigation
;
175 // Called from finishHistoryNavigationFromEntry.
176 - (void)webWillFinishHistoryNavigationFromEntry
:(CRWSessionEntry
*)fromEntry
;
177 // Called when a page navigates backwards or forwards.
178 - (void)webWillGoDelta
:(int)delta
;
179 - (void)webDidPrepareForGoBack
;
180 // ---------------------------------------------------------------------
185 // Called to ask CRWWebDelegate if |CRWWebController| should open the given URL.
186 // CRWWebDelegate can intercept the request by returning NO and processing URL
188 - (BOOL
)webController
:(CRWWebController
*)webController
189 shouldOpenURL
:(const GURL
&)url
190 mainDocumentURL
:(const GURL
&)mainDocumentURL
191 linkClicked
:(BOOL
)linkClicked
;
193 // Called to ask if external URL should be opened. External URL is one that
194 // cannot be presented by CRWWebController.
195 - (BOOL
)webController
:(CRWWebController
*)webController
196 shouldOpenExternalURL
:(const GURL
&)url
;
199 // Called when |url| is deemed suitable to be opened in a matching native app.
200 // Needs to return whether |url| was opened in a matching native app.
201 // The return value indicates if the native app was launched, not if a native
203 // TODO(shreyasv): Instead of having the CRWWebDelegate handle an external URL,
204 // provide a hook/API to steal a URL navigation. That way the logic to determine
205 // a URL as triggering a native app launch can also be moved.
206 - (BOOL
)urlTriggersNativeAppLaunch
:(const GURL
&)url
207 sourceURL
:(const GURL
&)sourceURL
;
209 // Called to ask the delegate for a controller to display the given url,
210 // which contained content that the UIWebView couldn't display. Returns
211 // the native controller to display if the delegate can handle the url,
213 - (id
<CRWNativeContent
>)controllerForUnhandledContentAtURL
:(const GURL
&)url
;
215 // Called when the page supplies a new title.
216 - (void)webController
:(CRWWebController
*)webController
217 titleDidChange
:(NSString
*)title
;
219 // Called when CRWWebController has detected a popup. If NO is returned then
220 // popup will be shown, otherwise |webController:didBlockPopup:| will be called
221 // and CRWWebDelegate will have a chance to unblock the popup later. NO is
222 // assumed by default if this method is not implemented.
223 - (BOOL
)webController
:(CRWWebController
*)webController
224 shouldBlockPopupWithURL
:(const GURL
&)popupURL
225 sourceURL
:(const GURL
&)sourceURL
;
227 // Called when CRWWebController has detected and blocked a popup. In order to
228 // allow the blocked pop up CRWWebDelegate must call
229 // |blockedPopupInfo.ShowPopup()| instead of attempting to open a new window.
230 - (void)webController
:(CRWWebController
*)webController
231 didBlockPopup
:(const web::BlockedPopupInfo
&)blockedPopupInfo
;
233 // TODO(jimblackler): Create a DialogController and move dialog-related delegate
234 // methods to CRWWebControllerObserver.
236 // Called when CRWWebController will present a dialog (only if
237 // kNotifyBeforeOpeningDialogs policy is set via
238 // -[CRWWebController setPageDialogsOpenPolicy:] method).
239 - (void)webControllerWillShowDialog
:(CRWWebController
*)webController
;
241 // Called when CRWWebController did suppress a dialog (only if kSuppressDialogs
242 // policy is set via -[CRWWebController setPageDialogsOpenPolicy:] method).
243 - (void)webControllerDidSuppressDialog
:(CRWWebController
*)webController
;
245 // Called to get CRWWebController of a child window by name.
246 - (id
<CRWWebControllerScripting
>)webController
:(CRWWebController
*)webController
247 scriptingInterfaceForWindowNamed
:(NSString
*)windowName
;
249 // Called to retrieve the height of any header that is overlaying on top of the
250 // web view. This can be used to implement, for e.g. a toolbar that changes
251 // height dynamically. Returning a non-zero height affects the visible frame
252 // shown by the CRWWebController. 0.0 is assumed if not implemented.
253 - (CGFloat
)headerHeightForWebController
:(CRWWebController
*)webController
;
255 // Called when CRWWebController updated the SSL status for the current
257 - (void)webControllerDidUpdateSSLStatusForCurrentNavigationItem
:
258 (CRWWebController
*)webController
;
260 // Called when CRWWebController did update page load progress.
261 - (void)webController
:(CRWWebController
*)webController
262 didUpdateProgress
:(CGFloat
)progress
;
264 // Called when web view process has been terminated.
265 - (void)webControllerWebProcessDidCrash
:(CRWWebController
*)webController
;
269 #endif // IOS_WEB_PUBLIC_WEB_STATE_CRW_WEB_DELEGATE_H_