1 /* 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebFrameClient_h 32 #define WebFrameClient_h 33 34 #include "../platform/WebCommon.h" 35 #include "../platform/WebFileSystem.h" 36 #include "../platform/WebFileSystemType.h" 37 #include "../platform/WebURLError.h" 38 #include "../platform/WebURLRequest.h" 39 #include "WebDOMMessageEvent.h" 40 #include "WebDataSource.h" 41 #include "WebIconURL.h" 42 #include "WebNavigationPolicy.h" 43 #include "WebNavigationType.h" 44 #include "WebSecurityOrigin.h" 45 #include "WebStorageQuotaType.h" 46 #include "WebTextDirection.h" 47 #include <v8.h> 48 49 namespace WebKit { 50 51 class WebApplicationCacheHost; 52 class WebApplicationCacheHostClient; 53 class WebCachedURLRequest; 54 class WebCookieJar; 55 class WebDataSource; 56 class WebDOMEvent; 57 class WebFormElement; 58 class WebFrame; 59 class WebMediaPlayer; 60 class WebMediaPlayerClient; 61 class WebNode; 62 class WebPlugin; 63 class WebRTCPeerConnectionHandler; 64 class WebSharedWorker; 65 class WebSharedWorkerClient; 66 class WebSocketStreamHandle; 67 class WebStorageQuotaCallbacks; 68 class WebString; 69 class WebURL; 70 class WebURLLoader; 71 class WebURLResponse; 72 class WebWorker; 73 struct WebPluginParams; 74 struct WebRect; 75 struct WebSize; 76 struct WebURLError; 77 78 class WebFrameClient { 79 public: 80 // Factory methods ----------------------------------------------------- 81 82 // May return null. 83 virtual WebPlugin* createPlugin(WebFrame*, const WebPluginParams&) { return 0; } 84 85 // May return null. 86 virtual WebSharedWorker* createSharedWorker(WebFrame*, const WebURL&, const WebString&, unsigned long long) { return 0; } 87 88 // May return null. 89 virtual WebMediaPlayer* createMediaPlayer(WebFrame*, const WebURL&, WebMediaPlayerClient*) { return 0; } 90 91 // May return null. 92 virtual WebApplicationCacheHost* createApplicationCacheHost(WebFrame*, WebApplicationCacheHostClient*) { return 0; } 93 94 95 // Services ------------------------------------------------------------ 96 97 // A frame specific cookie jar. May return null, in which case 98 // WebKitPlatformSupport::cookieJar() will be called to access cookies. 99 virtual WebCookieJar* cookieJar(WebFrame*) { return 0; } 100 101 102 // General notifications ----------------------------------------------- 103 104 // Indicates that another page has accessed the DOM of the initial empty 105 // document of a main frame. After this, it is no longer safe to show a 106 // pending navigation's URL, because a URL spoof is possible. 107 virtual void didAccessInitialDocument(WebFrame*) { } 108 109 // A child frame was created in this frame. This is called when the frame 110 // is created and initialized. 111 virtual void didCreateFrame(WebFrame* parent, WebFrame* child) { } 112 113 // This frame set its opener to null, disowning it. 114 // See http://html.spec.whatwg.org/#dom-opener. 115 virtual void didDisownOpener(WebFrame*) { } 116 117 // This frame has been detached from the view, but has not been closed yet. 118 virtual void frameDetached(WebFrame*) { } 119 120 // This frame is about to be closed. This is called after frameDetached, 121 // when the document is being unloaded, due to new one committing. 122 virtual void willClose(WebFrame*) { } 123 124 // This frame's name has changed. 125 virtual void didChangeName(WebFrame*, const WebString&) { } 126 127 // Load commands ------------------------------------------------------- 128 129 // The client should handle the navigation externally. 130 virtual void loadURLExternally( 131 WebFrame*, const WebURLRequest&, WebNavigationPolicy) { } 132 virtual void loadURLExternally( 133 WebFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { } 134 135 136 // Navigational queries ------------------------------------------------ 137 138 // The client may choose to alter the navigation policy. Otherwise, 139 // defaultPolicy should just be returned. 140 virtual WebNavigationPolicy decidePolicyForNavigation( 141 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigationType, 142 WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; } 143 144 virtual bool shouldAbortNavigationAfterUrlResolve(const WebURL& base, const WebString& fragment, const WebURL& result) { return false; } 145 146 // Navigational notifications ------------------------------------------ 147 148 // A form submission has been requested, but the page's submit event handler 149 // hasn't yet had a chance to run (and possibly alter/interrupt the submit.) 150 virtual void willSendSubmitEvent(WebFrame*, const WebFormElement&) { } 151 152 // A form submission is about to occur. 153 virtual void willSubmitForm(WebFrame*, const WebFormElement&) { } 154 155 // A datasource has been created for a new navigation. The given 156 // datasource will become the provisional datasource for the frame. 157 virtual void didCreateDataSource(WebFrame*, WebDataSource*) { } 158 159 // A new provisional load has been started. 160 virtual void didStartProvisionalLoad(WebFrame*) { } 161 162 // The provisional load was redirected via a HTTP 3xx response. 163 virtual void didReceiveServerRedirectForProvisionalLoad(WebFrame*) { } 164 165 // The provisional load failed. 166 virtual void didFailProvisionalLoad(WebFrame*, const WebURLError&) { } 167 168 // The provisional datasource is now committed. The first part of the 169 // response body has been received, and the encoding of the response 170 // body is known. 171 virtual void didCommitProvisionalLoad(WebFrame*, bool isNewNavigation) { } 172 173 // The window object for the frame has been cleared of any extra 174 // properties that may have been set by script from the previously 175 // loaded document. 176 virtual void didClearWindowObject(WebFrame*) { } 177 178 // The document element has been created. 179 virtual void didCreateDocumentElement(WebFrame*) { } 180 181 // The page title is available. 182 virtual void didReceiveTitle(WebFrame* frame, const WebString& title, WebTextDirection direction) { } 183 184 // The icon for the page have changed. 185 virtual void didChangeIcon(WebFrame*, WebIconURL::Type) { } 186 187 // The frame's document finished loading. 188 virtual void didFinishDocumentLoad(WebFrame*) { } 189 190 // The 'load' event was dispatched. 191 virtual void didHandleOnloadEvents(WebFrame*) { } 192 193 // The frame's document or one of its subresources failed to load. 194 virtual void didFailLoad(WebFrame*, const WebURLError&) { } 195 196 // The frame's document and all of its subresources succeeded to load. 197 virtual void didFinishLoad(WebFrame*) { } 198 199 // The navigation resulted in no change to the documents within the page. 200 // For example, the navigation may have just resulted in scrolling to a 201 // named anchor or a PopState event may have been dispatched. 202 virtual void didNavigateWithinPage(WebFrame*, bool isNewNavigation) { } 203 204 // Called upon update to scroll position, document state, and other 205 // non-navigational events related to the data held by WebHistoryItem. 206 // WARNING: This method may be called very frequently. 207 virtual void didUpdateCurrentHistoryItem(WebFrame*) { } 208 209 210 // Low-level resource notifications ------------------------------------ 211 212 // An element will request a resource. 213 virtual void willRequestResource(WebFrame*, const WebCachedURLRequest&) { } 214 215 // The request is after preconnect is triggered. 216 virtual void willRequestAfterPreconnect(WebFrame*, WebURLRequest&) { } 217 218 // A request is about to be sent out, and the client may modify it. Request 219 // is writable, and changes to the URL, for example, will change the request 220 // made. If this request is the result of a redirect, then redirectResponse 221 // will be non-null and contain the response that triggered the redirect. 222 virtual void willSendRequest( 223 WebFrame*, unsigned identifier, WebURLRequest&, 224 const WebURLResponse& redirectResponse) { } 225 226 // Response headers have been received for the resource request given 227 // by identifier. 228 virtual void didReceiveResponse( 229 WebFrame*, unsigned identifier, const WebURLResponse&) { } 230 231 virtual void didChangeResourcePriority( 232 WebFrame*, unsigned identifier, const WebKit::WebURLRequest::Priority&) { } 233 234 // The resource request given by identifier succeeded. 235 virtual void didFinishResourceLoad( 236 WebFrame*, unsigned identifier) { } 237 238 // The specified request was satified from WebCore's memory cache. 239 virtual void didLoadResourceFromMemoryCache( 240 WebFrame*, const WebURLRequest&, const WebURLResponse&) { } 241 242 // This frame has displayed inactive content (such as an image) from an 243 // insecure source. Inactive content cannot spread to other frames. 244 virtual void didDisplayInsecureContent(WebFrame*) { } 245 246 // The indicated security origin has run active content (such as a 247 // script) from an insecure source. Note that the insecure content can 248 // spread to other frames in the same origin. 249 virtual void didRunInsecureContent(WebFrame*, const WebSecurityOrigin&, const WebURL& insecureURL) { } 250 251 // A reflected XSS was encountered in the page and suppressed. 252 virtual void didDetectXSS(WebFrame*, const WebURL&, bool didBlockEntirePage) { } 253 254 // A PingLoader was created, and a request dispatched to a URL. 255 virtual void didDispatchPingLoader(WebFrame*, const WebURL&) { } 256 257 // Script notifications ------------------------------------------------ 258 259 // Script in the page tried to allocate too much memory. 260 virtual void didExhaustMemoryAvailableForScript(WebFrame*) { } 261 262 // Notifies that a new script context has been created for this frame. 263 // This is similar to didClearWindowObject but only called once per 264 // frame context. 265 virtual void didCreateScriptContext(WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { } 266 267 // WebKit is about to release its reference to a v8 context for a frame. 268 virtual void willReleaseScriptContext(WebFrame*, v8::Handle<v8::Context>, int worldId) { } 269 270 // Geometry notifications ---------------------------------------------- 271 272 // The frame's document finished the initial layout of a page. 273 virtual void didFirstLayout(WebFrame*) { } 274 275 // The frame's document finished the initial non-empty layout of a page. 276 virtual void didFirstVisuallyNonEmptyLayout(WebFrame*) { } 277 278 // The size of the content area changed. 279 virtual void didChangeContentsSize(WebFrame*, const WebSize&) { } 280 281 // The main frame scrolled. 282 virtual void didChangeScrollOffset(WebFrame*) { } 283 284 // If the frame is loading an HTML document, this will be called to 285 // notify that the <body> will be attached soon. 286 virtual void willInsertBody(WebFrame*) { } 287 288 // Find-in-page notifications ------------------------------------------ 289 290 // Notifies how many matches have been found so far, for a given 291 // identifier. |finalUpdate| specifies whether this is the last update 292 // (all frames have completed scoping). 293 virtual void reportFindInPageMatchCount( 294 int identifier, int count, bool finalUpdate) { } 295 296 // Notifies what tick-mark rect is currently selected. The given 297 // identifier lets the client know which request this message belongs 298 // to, so that it can choose to ignore the message if it has moved on 299 // to other things. The selection rect is expected to have coordinates 300 // relative to the top left corner of the web page area and represent 301 // where on the screen the selection rect is currently located. 302 virtual void reportFindInPageSelection( 303 int identifier, int activeMatchOrdinal, const WebRect& selection) { } 304 305 // FileSystem ---------------------------------------------------- 306 307 // Requests to open a FileSystem. 308 // |size| indicates how much storage space (in bytes) the caller expects 309 // to need. 310 // WebFileSystemCallbacks::didOpenFileSystem() must be called with 311 // a name and root path for the requested FileSystem when the operation 312 // is completed successfully. WebFileSystemCallbacks::didFail() must be 313 // called otherwise. The create bool is for indicating whether or not to 314 // create root path for file systems if it do not exist. 315 virtual void openFileSystem( 316 WebFrame*, WebFileSystemType, long long size, 317 bool create, WebFileSystemCallbacks*) { } 318 319 // Deletes FileSystem. 320 // WebFileSystemCallbacks::didSucceed() must be called when the operation 321 // is completed successfully. WebFileSystemCallbacks::didFail() must be 322 // called otherwise. 323 // All in-flight operations and following operations may fail after the 324 // FileSystem is deleted. 325 virtual void deleteFileSystem( 326 WebFrame*, WebFileSystemType, WebFileSystemCallbacks*) { } 327 328 // Quota --------------------------------------------------------- 329 330 // Requests a new quota size for the origin's storage. 331 // |newQuotaInBytes| indicates how much storage space (in bytes) the 332 // caller expects to need. 333 // WebStorageQuotaCallbacks::didGrantStorageQuota will be called when 334 // a new quota is granted. WebStorageQuotaCallbacks::didFail 335 // is called with an error code otherwise. 336 // Note that the requesting quota size may not always be granted and 337 // a smaller amount of quota than requested might be returned. 338 // The callbacks object is deleted when the callback method is called 339 // and does not need to be (and should not be) deleted manually. 340 virtual void requestStorageQuota( 341 WebFrame*, WebStorageQuotaType, 342 unsigned long long newQuotaInBytes, 343 WebStorageQuotaCallbacks*) { } 344 345 // WebSocket ----------------------------------------------------- 346 347 // A WebSocket object is going to open new stream connection. 348 virtual void willOpenSocketStream(WebSocketStreamHandle*) { } 349 350 // MediaStream ----------------------------------------------------- 351 352 // A new WebRTCPeerConnectionHandler is created. 353 virtual void willStartUsingPeerConnectionHandler(WebFrame*, WebRTCPeerConnectionHandler*) { } 354 355 // Messages ------------------------------------------------------ 356 357 // Notifies the embedder that a postMessage was issued on this frame, and 358 // gives the embedder a chance to handle it instead of WebKit. Returns true 359 // if the embedder handled it. 360 virtual bool willCheckAndDispatchMessageEvent( 361 WebFrame* sourceFrame, 362 WebFrame* targetFrame, 363 WebSecurityOrigin target, 364 WebDOMMessageEvent event) { return false; } 365 366 // Asks the embedder if a specific user agent should be used for the given 367 // URL. Non-empty strings indicate an override should be used. Otherwise, 368 // Platform::current()->userAgent() will be called to provide one. 369 virtual WebString userAgentOverride(WebFrame*, const WebURL& url) { return WebString(); } 370 371 // Asks the embedder what value the network stack will send for the DNT 372 // header. An empty string indicates that no DNT header will be send. 373 virtual WebString doNotTrackValue(WebFrame*) { return WebString(); } 374 375 // WebGL ------------------------------------------------------ 376 377 // Asks the embedder whether WebGL is allowed for the given WebFrame. 378 // This call is placed here instead of WebPermissionClient because this 379 // class is implemented in content/, and putting it here avoids adding 380 // more public content/ APIs. 381 virtual bool allowWebGL(WebFrame*, bool defaultValue) { return defaultValue; } 382 383 // Notifies the client that a WebGL context was lost on this page with the 384 // given reason (one of the GL_ARB_robustness status codes; see 385 // Extensions3D.h in WebCore/platform/graphics). 386 virtual void didLoseWebGLContext(WebFrame*, int) { } 387 388 protected: 389 ~WebFrameClient() { } 390 }; 391 392 } // namespace WebKit 393 394 #endif 395