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 "WebDOMMessageEvent.h" 35 #include "WebDataSource.h" 36 #include "WebIconURL.h" 37 #include "WebNavigationPolicy.h" 38 #include "WebNavigationType.h" 39 #include "WebSecurityOrigin.h" 40 #include "WebTextDirection.h" 41 #include "public/platform/WebCommon.h" 42 #include "public/platform/WebFileSystem.h" 43 #include "public/platform/WebFileSystemType.h" 44 #include "public/platform/WebStorageQuotaType.h" 45 #include "public/platform/WebURLError.h" 46 #include "public/platform/WebURLRequest.h" 47 #include <v8.h> 48 49 namespace blink { 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 WebServiceWorkerProvider; 62 class WebServiceWorkerProviderClient; 63 class WebNode; 64 class WebPlugin; 65 class WebRTCPeerConnectionHandler; 66 class WebSharedWorker; 67 class WebSharedWorkerClient; 68 class WebSocketStreamHandle; 69 class WebStorageQuotaCallbacks; 70 class WebString; 71 class WebURL; 72 class WebURLLoader; 73 class WebURLResponse; 74 class WebWorkerPermissionClientProxy; 75 struct WebPluginParams; 76 struct WebRect; 77 struct WebSize; 78 struct WebURLError; 79 80 class WebFrameClient { 81 public: 82 // Factory methods ----------------------------------------------------- 83 84 // May return null. 85 virtual WebPlugin* createPlugin(WebFrame*, const WebPluginParams&) { return 0; } 86 87 // May return null. 88 virtual WebMediaPlayer* createMediaPlayer(WebFrame*, const WebURL&, WebMediaPlayerClient*) { return 0; } 89 90 // May return null. 91 virtual WebApplicationCacheHost* createApplicationCacheHost(WebFrame*, WebApplicationCacheHostClient*) { return 0; } 92 93 // May return null. Takes ownership of the client. 94 virtual WebServiceWorkerProvider* createServiceWorkerProvider(WebFrame*, WebServiceWorkerProviderClient*) { return 0; } 95 96 // May return null. 97 virtual WebWorkerPermissionClientProxy* createWorkerPermissionClientProxy(WebFrame*) { return 0; } 98 99 100 // Services ------------------------------------------------------------ 101 102 // A frame specific cookie jar. May return null, in which case 103 // WebKitPlatformSupport::cookieJar() will be called to access cookies. 104 virtual WebCookieJar* cookieJar(WebFrame*) { return 0; } 105 106 107 // General notifications ----------------------------------------------- 108 109 // Indicates that another page has accessed the DOM of the initial empty 110 // document of a main frame. After this, it is no longer safe to show a 111 // pending navigation's URL, because a URL spoof is possible. 112 virtual void didAccessInitialDocument(WebFrame*) { } 113 114 // A child frame was created in this frame. This is called when the frame 115 // is created and initialized. Takes the name of the new frame, the parent 116 // frame and returns a new WebFrame. The WebFrame is considered in-use 117 // until frameDetached() is called on it. 118 virtual WebFrame* createChildFrame(WebFrame* parent, const WebString& frameName) { return 0; } 119 // FIXME: Remove when all embedders use createChildFrame(). 120 virtual void didCreateFrame(WebFrame* parent, WebFrame* child) { } 121 122 // This frame set its opener to null, disowning it. 123 // See http://html.spec.whatwg.org/#dom-opener. 124 virtual void didDisownOpener(WebFrame*) { } 125 126 // This frame has been detached from the view, but has not been closed yet. 127 virtual void frameDetached(WebFrame*) { } 128 129 // This frame is about to be closed. This is called after frameDetached, 130 // when the document is being unloaded, due to new one committing. 131 virtual void willClose(WebFrame*) { } 132 133 // This frame's name has changed. 134 virtual void didChangeName(WebFrame*, const WebString&) { } 135 136 // Called when a watched CSS selector matches or stops matching. 137 virtual void didMatchCSS(WebFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) { } 138 139 // Load commands ------------------------------------------------------- 140 141 // The client should handle the navigation externally. 142 virtual void loadURLExternally( 143 WebFrame*, const WebURLRequest&, WebNavigationPolicy) { } 144 virtual void loadURLExternally( 145 WebFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { } 146 147 148 // Navigational queries ------------------------------------------------ 149 150 // The client may choose to alter the navigation policy. Otherwise, 151 // defaultPolicy should just be returned. 152 virtual WebNavigationPolicy decidePolicyForNavigation( 153 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigationType, 154 WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; } 155 156 157 // Navigational notifications ------------------------------------------ 158 159 // A form submission has been requested, but the page's submit event handler 160 // hasn't yet had a chance to run (and possibly alter/interrupt the submit.) 161 virtual void willSendSubmitEvent(WebFrame*, const WebFormElement&) { } 162 163 // A form submission is about to occur. 164 virtual void willSubmitForm(WebFrame*, const WebFormElement&) { } 165 166 // A datasource has been created for a new navigation. The given 167 // datasource will become the provisional datasource for the frame. 168 virtual void didCreateDataSource(WebFrame*, WebDataSource*) { } 169 170 // A new provisional load has been started. 171 virtual void didStartProvisionalLoad(WebFrame*) { } 172 173 // The provisional load was redirected via a HTTP 3xx response. 174 virtual void didReceiveServerRedirectForProvisionalLoad(WebFrame*) { } 175 176 // The provisional load failed. 177 virtual void didFailProvisionalLoad(WebFrame*, const WebURLError&) { } 178 179 // The provisional datasource is now committed. The first part of the 180 // response body has been received, and the encoding of the response 181 // body is known. 182 virtual void didCommitProvisionalLoad(WebFrame*, bool isNewNavigation) { } 183 184 // The window object for the frame has been cleared of any extra 185 // properties that may have been set by script from the previously 186 // loaded document. 187 virtual void didClearWindowObject(WebFrame*) { } 188 189 // The document element has been created. 190 virtual void didCreateDocumentElement(WebFrame*) { } 191 192 // The page title is available. 193 virtual void didReceiveTitle(WebFrame* frame, const WebString& title, WebTextDirection direction) { } 194 195 // The icon for the page have changed. 196 virtual void didChangeIcon(WebFrame*, WebIconURL::Type) { } 197 198 // The frame's document finished loading. 199 virtual void didFinishDocumentLoad(WebFrame*) { } 200 201 // The 'load' event was dispatched. 202 virtual void didHandleOnloadEvents(WebFrame*) { } 203 204 // The frame's document or one of its subresources failed to load. 205 virtual void didFailLoad(WebFrame*, const WebURLError&) { } 206 207 // The frame's document and all of its subresources succeeded to load. 208 virtual void didFinishLoad(WebFrame*) { } 209 210 // The navigation resulted in no change to the documents within the page. 211 // For example, the navigation may have just resulted in scrolling to a 212 // named anchor or a PopState event may have been dispatched. 213 virtual void didNavigateWithinPage(WebFrame*, bool isNewNavigation) { } 214 215 // Called upon update to scroll position, document state, and other 216 // non-navigational events related to the data held by WebHistoryItem. 217 // WARNING: This method may be called very frequently. 218 virtual void didUpdateCurrentHistoryItem(WebFrame*) { } 219 220 221 // Low-level resource notifications ------------------------------------ 222 223 // An element will request a resource. 224 virtual void willRequestResource(WebFrame*, const WebCachedURLRequest&) { } 225 226 // The request is after preconnect is triggered. 227 virtual void willRequestAfterPreconnect(WebFrame*, WebURLRequest&) { } 228 229 // A request is about to be sent out, and the client may modify it. Request 230 // is writable, and changes to the URL, for example, will change the request 231 // made. If this request is the result of a redirect, then redirectResponse 232 // will be non-null and contain the response that triggered the redirect. 233 virtual void willSendRequest( 234 WebFrame*, unsigned identifier, WebURLRequest&, 235 const WebURLResponse& redirectResponse) { } 236 237 // Response headers have been received for the resource request given 238 // by identifier. 239 virtual void didReceiveResponse( 240 WebFrame*, unsigned identifier, const WebURLResponse&) { } 241 242 virtual void didChangeResourcePriority( 243 WebFrame*, unsigned identifier, const blink::WebURLRequest::Priority&) { } 244 245 // The resource request given by identifier succeeded. 246 virtual void didFinishResourceLoad( 247 WebFrame*, unsigned identifier) { } 248 249 // The specified request was satified from WebCore's memory cache. 250 virtual void didLoadResourceFromMemoryCache( 251 WebFrame*, const WebURLRequest&, const WebURLResponse&) { } 252 253 // This frame has displayed inactive content (such as an image) from an 254 // insecure source. Inactive content cannot spread to other frames. 255 virtual void didDisplayInsecureContent(WebFrame*) { } 256 257 // The indicated security origin has run active content (such as a 258 // script) from an insecure source. Note that the insecure content can 259 // spread to other frames in the same origin. 260 virtual void didRunInsecureContent(WebFrame*, const WebSecurityOrigin&, const WebURL& insecureURL) { } 261 262 // A reflected XSS was encountered in the page and suppressed. 263 virtual void didDetectXSS(WebFrame*, const WebURL&, bool didBlockEntirePage) { } 264 265 // A PingLoader was created, and a request dispatched to a URL. 266 virtual void didDispatchPingLoader(WebFrame*, const WebURL&) { } 267 268 // The loaders in this frame have been stopped. 269 virtual void didAbortLoading(WebFrame*) { } 270 271 // Script notifications ------------------------------------------------ 272 273 // Script in the page tried to allocate too much memory. 274 virtual void didExhaustMemoryAvailableForScript(WebFrame*) { } 275 276 // Notifies that a new script context has been created for this frame. 277 // This is similar to didClearWindowObject but only called once per 278 // frame context. 279 virtual void didCreateScriptContext(WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { } 280 281 // WebKit is about to release its reference to a v8 context for a frame. 282 virtual void willReleaseScriptContext(WebFrame*, v8::Handle<v8::Context>, int worldId) { } 283 284 // Geometry notifications ---------------------------------------------- 285 286 // The frame's document finished the initial non-empty layout of a page. 287 virtual void didFirstVisuallyNonEmptyLayout(WebFrame*) { } 288 289 // The size of the content area changed. 290 virtual void didChangeContentsSize(WebFrame*, const WebSize&) { } 291 292 // The main frame scrolled. 293 virtual void didChangeScrollOffset(WebFrame*) { } 294 295 // If the frame is loading an HTML document, this will be called to 296 // notify that the <body> will be attached soon. 297 virtual void willInsertBody(WebFrame*) { } 298 299 // Find-in-page notifications ------------------------------------------ 300 301 // Notifies how many matches have been found so far, for a given 302 // identifier. |finalUpdate| specifies whether this is the last update 303 // (all frames have completed scoping). 304 virtual void reportFindInPageMatchCount( 305 int identifier, int count, bool finalUpdate) { } 306 307 // Notifies what tick-mark rect is currently selected. The given 308 // identifier lets the client know which request this message belongs 309 // to, so that it can choose to ignore the message if it has moved on 310 // to other things. The selection rect is expected to have coordinates 311 // relative to the top left corner of the web page area and represent 312 // where on the screen the selection rect is currently located. 313 virtual void reportFindInPageSelection( 314 int identifier, int activeMatchOrdinal, const WebRect& selection) { } 315 316 // Quota --------------------------------------------------------- 317 318 // Requests a new quota size for the origin's storage. 319 // |newQuotaInBytes| indicates how much storage space (in bytes) the 320 // caller expects to need. 321 // WebStorageQuotaCallbacks::didGrantStorageQuota will be called when 322 // a new quota is granted. WebStorageQuotaCallbacks::didFail 323 // is called with an error code otherwise. 324 // Note that the requesting quota size may not always be granted and 325 // a smaller amount of quota than requested might be returned. 326 // The callbacks object is deleted when the callback method is called 327 // and does not need to be (and should not be) deleted manually. 328 virtual void requestStorageQuota( 329 WebFrame*, WebStorageQuotaType, 330 unsigned long long newQuotaInBytes, 331 WebStorageQuotaCallbacks*) { } 332 333 // WebSocket ----------------------------------------------------- 334 335 // A WebSocket object is going to open new stream connection. 336 virtual void willOpenSocketStream(WebSocketStreamHandle*) { } 337 338 // MediaStream ----------------------------------------------------- 339 340 // A new WebRTCPeerConnectionHandler is created. 341 virtual void willStartUsingPeerConnectionHandler(WebFrame*, WebRTCPeerConnectionHandler*) { } 342 343 // Messages ------------------------------------------------------ 344 345 // Notifies the embedder that a postMessage was issued on this frame, and 346 // gives the embedder a chance to handle it instead of WebKit. Returns true 347 // if the embedder handled it. 348 virtual bool willCheckAndDispatchMessageEvent( 349 WebFrame* sourceFrame, 350 WebFrame* targetFrame, 351 WebSecurityOrigin target, 352 WebDOMMessageEvent event) { return false; } 353 354 // Asks the embedder if a specific user agent should be used for the given 355 // URL. Non-empty strings indicate an override should be used. Otherwise, 356 // Platform::current()->userAgent() will be called to provide one. 357 virtual WebString userAgentOverride(WebFrame*, const WebURL& url) { return WebString(); } 358 359 // Asks the embedder what value the network stack will send for the DNT 360 // header. An empty string indicates that no DNT header will be send. 361 virtual WebString doNotTrackValue(WebFrame*) { return WebString(); } 362 363 // WebGL ------------------------------------------------------ 364 365 // Asks the embedder whether WebGL is allowed for the given WebFrame. 366 // This call is placed here instead of WebPermissionClient because this 367 // class is implemented in content/, and putting it here avoids adding 368 // more public content/ APIs. 369 virtual bool allowWebGL(WebFrame*, bool defaultValue) { return defaultValue; } 370 371 // Notifies the client that a WebGL context was lost on this page with the 372 // given reason (one of the GL_ARB_robustness status codes; see 373 // Extensions3D.h in WebCore/platform/graphics). 374 virtual void didLoseWebGLContext(WebFrame*, int) { } 375 376 protected: 377 ~WebFrameClient() { } 378 }; 379 380 } // namespace blink 381 382 #endif 383