Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ios / web / public / web_state / ui / crw_web_delegate.h
blobe9d4411e23022614638f2ef5f7eb71677e2b4d2e
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_UI_CRW_WEB_DELEGATE_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_WEB_DELEGATE_H_
8 #import <UIKit/UIKit.h>
9 #include <vector>
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/ui/crw_native_content.h"
15 #include "ios/web/public/web_state/web_state.h"
16 #include "ui/base/page_transition_types.h"
18 class GURL;
19 @class CRWSessionEntry;
20 @class CRWWebController;
22 namespace net {
23 class HttpResponseHeaders;
24 class SSLInfo;
25 class X509Certificate;
28 namespace web {
29 class BlockedPopupInfo;
30 struct Referrer;
31 struct WebLoadParams;
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.
49 - (void)stopLoading;
51 // TODO(eugenebut): rename -[CRWWebController close] method to avoid confusion.
52 // Asks the delegate to be closed.
53 - (void)orderClose;
55 @end
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
72 // must be YES.
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
91 // know.
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
111 // LOAD_REQUESTED).
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
134 // document change.
135 - (void)webDidUpdateHistoryStateWithPageURL:(const GURL&)pageUrl;
136 // Called when a placeholder image should be displayed instead of the WebView.
137 - (void)webController:(CRWWebController*)webController
138 retrievePlaceholderOverlayImage:(void (^)(UIImage*))block;
139 // Consults the delegate whether a form should be resubmitted for a request.
140 // Occurs when a POST request is reached when navigating through history.
141 // Call |continueBlock| if a form should be resubmitted.
142 // Call |cancelBlock| if a form should not be resubmitted.
143 // Delegates must call either of these (just once) before the load will
144 // continue.
145 - (void)webController:(CRWWebController*)webController
146 onFormResubmissionForRequest:(NSURLRequest*)request
147 continueBlock:(ProceduralBlock)continueBlock
148 cancelBlock:(ProceduralBlock)cancelBlock;
149 // Returns the unique id of the download request and starts downloading the
150 // image at |url| without sending the cookies. Invokes |callback| on completion.
151 - (int)downloadImageAtUrl:(const GURL&)url
152 maxBitmapSize:(uint32_t)maxBitmapSize
153 callback:(const web::WebState::ImageDownloadCallback&)callback;
155 // ---------------------------------------------------------------------
156 // TODO(rohitrao): Eliminate as many of the following delegate methods as
157 // possible. They only exist because the Tab and CRWWebController logic was
158 // very intertwined. We should streamline the logic to jump between classes
159 // less, then remove any delegate method that becomes unneccessary as a result.
161 // Called when the page is reloaded.
162 - (void)webWillReload;
163 // Called when a page is loaded using loadWithParams. In
164 // |webWillInitiateLoadWithParams|, the |params| argument is non-const so that
165 // the delegate can make changes if necessary.
166 // TODO(rohitrao): This is not a great API. Clean it up.
167 - (void)webWillInitiateLoadWithParams:(web::WebLoadParams&)params;
168 - (void)webDidUpdateSessionForLoadWithParams:(const web::WebLoadParams&)params
169 wasInitialNavigation:(BOOL)initialNavigation;
170 // Called from finishHistoryNavigationFromEntry.
171 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry;
172 // Called when a page navigates backwards or forwards.
173 - (void)webWillGoDelta:(int)delta;
174 - (void)webDidPrepareForGoBack;
175 // ---------------------------------------------------------------------
178 @optional
180 // Called to ask CRWWebDelegate if |CRWWebController| should open the given URL.
181 // CRWWebDelegate can intercept the request by returning NO and processing URL
182 // in own way.
183 - (BOOL)webController:(CRWWebController*)webController
184 shouldOpenURL:(const GURL&)url
185 mainDocumentURL:(const GURL&)mainDocumentURL
186 linkClicked:(BOOL)linkClicked;
188 // Called to ask if external URL should be opened. External URL is one that
189 // cannot be presented by CRWWebController.
190 - (BOOL)webController:(CRWWebController*)webController
191 shouldOpenExternalURL:(const GURL&)URL;
193 // Called when |url| is deemed suitable to be opened in a matching native app.
194 // Needs to return whether |url| was opened in a matching native app.
195 // The return value indicates if the native app was launched, not if a native
196 // app was found.
197 // TODO(shreyasv): Instead of having the CRWWebDelegate handle an external URL,
198 // provide a hook/API to steal a URL navigation. That way the logic to determine
199 // a URL as triggering a native app launch can also be moved.
200 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url
201 sourceURL:(const GURL&)sourceURL;
203 // Called to ask the delegate for a controller to display the given url,
204 // which contained content that the UIWebView couldn't display. Returns
205 // the native controller to display if the delegate can handle the url,
206 // or nil otherwise.
207 - (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url;
209 // Called when the page supplies a new title.
210 - (void)webController:(CRWWebController*)webController
211 titleDidChange:(NSString*)title;
213 // Called when CRWWebController has detected a popup. If NO is returned then
214 // popup will be shown, otherwise |webController:didBlockPopup:| will be called
215 // and CRWWebDelegate will have a chance to unblock the popup later. NO is
216 // assumed by default if this method is not implemented.
217 - (BOOL)webController:(CRWWebController*)webController
218 shouldBlockPopupWithURL:(const GURL&)popupURL
219 sourceURL:(const GURL&)sourceURL;
221 // Called when CRWWebController has detected and blocked a popup. In order to
222 // allow the blocked pop up CRWWebDelegate must call
223 // |blockedPopupInfo.ShowPopup()| instead of attempting to open a new window.
224 - (void)webController:(CRWWebController*)webController
225 didBlockPopup:(const web::BlockedPopupInfo&)blockedPopupInfo;
227 // TODO(jimblackler): Create a DialogController and move dialog-related delegate
228 // methods to CRWWebControllerObserver.
230 // Called when CRWWebController will present a dialog (only if
231 // kNotifyBeforeOpeningDialogs policy is set via
232 // -[CRWWebController setPageDialogsOpenPolicy:] method).
233 - (void)webControllerWillShowDialog:(CRWWebController*)webController;
235 // Called when CRWWebController did suppress a dialog (only if kSuppressDialogs
236 // policy is set via -[CRWWebController setPageDialogsOpenPolicy:] method).
237 - (void)webControllerDidSuppressDialog:(CRWWebController*)webController;
239 // Called to get CRWWebController of a child window by name.
240 - (id<CRWWebControllerScripting>)webController:(CRWWebController*)webController
241 scriptingInterfaceForWindowNamed:(NSString*)windowName;
243 // Called to retrieve the height of any header that is overlaying on top of the
244 // web view. This can be used to implement, for e.g. a toolbar that changes
245 // height dynamically. Returning a non-zero height affects the visible frame
246 // shown by the CRWWebController. 0.0 is assumed if not implemented.
247 - (CGFloat)headerHeightForWebController:(CRWWebController*)webController;
249 // Called when CRWWebController updated the SSL status for the current
250 // NagivationItem.
251 - (void)webControllerDidUpdateSSLStatusForCurrentNavigationItem:
252 (CRWWebController*)webController;
254 // Called when CRWWebController did update page load progress.
255 - (void)webController:(CRWWebController*)webController
256 didUpdateProgress:(CGFloat)progress;
258 // Called when web view process has been terminated.
259 - (void)webControllerWebProcessDidCrash:(CRWWebController*)webController;
261 @end
263 #endif // IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_WEB_DELEGATE_H_