1 /* 2 * Copyright (C) 2009 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 "WebCommon.h" 35 #include "WebNavigationPolicy.h" 36 #include "WebNavigationType.h" 37 #include "WebURLError.h" 38 39 namespace WebKit { 40 41 class WebDataSource; 42 class WebFormElement; 43 class WebFrame; 44 class WebMediaPlayer; 45 class WebMediaPlayerClient; 46 class WebNode; 47 class WebPlugin; 48 class WebSecurityOrigin; 49 class WebSharedWorker; 50 class WebString; 51 class WebURL; 52 class WebURLRequest; 53 class WebURLResponse; 54 class WebWorker; 55 class WebWorkerClient; 56 struct WebPluginParams; 57 struct WebRect; 58 struct WebSize; 59 struct WebURLError; 60 61 class WebFrameClient { 62 public: 63 // Factory methods ----------------------------------------------------- 64 65 // May return null. createPlugin(WebFrame *,const WebPluginParams &)66 virtual WebPlugin* createPlugin(WebFrame*, const WebPluginParams&) { return 0; } 67 68 // May return null. createWorker(WebFrame *,WebWorkerClient *)69 virtual WebWorker* createWorker(WebFrame*, WebWorkerClient*) { return 0; } 70 71 // May return null. createSharedWorker(WebFrame *,const WebURL &,const WebString &,unsigned long long)72 virtual WebSharedWorker* createSharedWorker(WebFrame*, const WebURL&, const WebString&, unsigned long long) { return 0; } 73 74 // May return null. createMediaPlayer(WebFrame *,WebMediaPlayerClient *)75 virtual WebMediaPlayer* createMediaPlayer(WebFrame*, WebMediaPlayerClient*) { return 0; } 76 77 78 // General notifications ----------------------------------------------- 79 80 // This frame is about to be closed. willClose(WebFrame *)81 virtual void willClose(WebFrame*) { } 82 83 // Controls whether plugins are allowed for this frame. allowPlugins(WebFrame *,bool enabledPerSettings)84 virtual bool allowPlugins(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; } 85 86 // Controls whether images are allowed for this frame. allowImages(WebFrame *,bool enabledPerSettings)87 virtual bool allowImages(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; } 88 89 90 // Load commands ------------------------------------------------------- 91 92 // The client should handle the navigation externally. loadURLExternally(WebFrame *,const WebURLRequest &,WebNavigationPolicy)93 virtual void loadURLExternally( 94 WebFrame*, const WebURLRequest&, WebNavigationPolicy) { } 95 96 97 // Navigational queries ------------------------------------------------ 98 99 // The client may choose to alter the navigation policy. Otherwise, 100 // defaultPolicy should just be returned. decidePolicyForNavigation(WebFrame *,const WebURLRequest &,WebNavigationType,const WebNode & originatingNode,WebNavigationPolicy defaultPolicy,bool isRedirect)101 virtual WebNavigationPolicy decidePolicyForNavigation( 102 WebFrame*, const WebURLRequest&, WebNavigationType, 103 const WebNode& originatingNode, 104 WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; } 105 106 // Query if the specified request can be handled. canHandleRequest(WebFrame *,const WebURLRequest & request)107 virtual bool canHandleRequest( 108 WebFrame*, const WebURLRequest& request) { return true; } 109 110 // Returns an error corresponding to canHandledRequest() returning false. cannotHandleRequestError(WebFrame *,const WebURLRequest & request)111 virtual WebURLError cannotHandleRequestError( 112 WebFrame*, const WebURLRequest& request) { return WebURLError(); } 113 114 // Returns an error corresponding to a user cancellation event. cancelledError(WebFrame *,const WebURLRequest & request)115 virtual WebURLError cancelledError( 116 WebFrame*, const WebURLRequest& request) { return WebURLError(); } 117 118 // Notify that a URL cannot be handled. unableToImplementPolicyWithError(WebFrame *,const WebURLError &)119 virtual void unableToImplementPolicyWithError( 120 WebFrame*, const WebURLError&) { } 121 122 123 // Navigational notifications ------------------------------------------ 124 125 // A form submission is about to occur. willSubmitForm(WebFrame *,const WebFormElement &)126 virtual void willSubmitForm(WebFrame*, const WebFormElement&) { } 127 128 // A client-side redirect will occur. This may correspond to a <META 129 // refresh> or some script activity. willPerformClientRedirect(WebFrame *,const WebURL & from,const WebURL & to,double interval,double fireTime)130 virtual void willPerformClientRedirect( 131 WebFrame*, const WebURL& from, const WebURL& to, 132 double interval, double fireTime) { } 133 134 // A client-side redirect was cancelled. didCancelClientRedirect(WebFrame *)135 virtual void didCancelClientRedirect(WebFrame*) { } 136 137 // A client-side redirect completed. didCompleteClientRedirect(WebFrame *,const WebURL & fromURL)138 virtual void didCompleteClientRedirect(WebFrame*, const WebURL& fromURL) { } 139 140 // A datasource has been created for a new navigation. The given 141 // datasource will become the provisional datasource for the frame. didCreateDataSource(WebFrame *,WebDataSource *)142 virtual void didCreateDataSource(WebFrame*, WebDataSource*) { } 143 144 // A new provisional load has been started. didStartProvisionalLoad(WebFrame *)145 virtual void didStartProvisionalLoad(WebFrame*) { } 146 147 // The provisional load was redirected via a HTTP 3xx response. didReceiveServerRedirectForProvisionalLoad(WebFrame *)148 virtual void didReceiveServerRedirectForProvisionalLoad(WebFrame*) { } 149 150 // The provisional load failed. didFailProvisionalLoad(WebFrame *,const WebURLError &)151 virtual void didFailProvisionalLoad(WebFrame*, const WebURLError&) { } 152 153 // Notifies the client to commit data for the given frame. The client 154 // may optionally prevent default processing by setting preventDefault 155 // to true before returning. If default processing is prevented, then 156 // it is up to the client to manually call commitDocumentData on the 157 // WebFrame. It is only valid to call commitDocumentData within a call 158 // to didReceiveDocumentData. If commitDocumentData is not called, 159 // then an empty document will be loaded. didReceiveDocumentData(WebFrame *,const char * data,size_t length,bool & preventDefault)160 virtual void didReceiveDocumentData( 161 WebFrame*, const char* data, size_t length, bool& preventDefault) { } 162 163 // The provisional datasource is now committed. The first part of the 164 // response body has been received, and the encoding of the response 165 // body is known. didCommitProvisionalLoad(WebFrame *,bool isNewNavigation)166 virtual void didCommitProvisionalLoad(WebFrame*, bool isNewNavigation) { } 167 168 // The window object for the frame has been cleared of any extra 169 // properties that may have been set by script from the previously 170 // loaded document. didClearWindowObject(WebFrame *)171 virtual void didClearWindowObject(WebFrame*) { } 172 173 // The document element has been created. didCreateDocumentElement(WebFrame *)174 virtual void didCreateDocumentElement(WebFrame*) { } 175 176 // The page title is available. didReceiveTitle(WebFrame *,const WebString & title)177 virtual void didReceiveTitle(WebFrame*, const WebString& title) { } 178 179 // The frame's document finished loading. didFinishDocumentLoad(WebFrame *)180 virtual void didFinishDocumentLoad(WebFrame*) { } 181 182 // The 'load' event was dispatched. didHandleOnloadEvents(WebFrame *)183 virtual void didHandleOnloadEvents(WebFrame*) { } 184 185 // The frame's document or one of its subresources failed to load. didFailLoad(WebFrame *,const WebURLError &)186 virtual void didFailLoad(WebFrame*, const WebURLError&) { } 187 188 // The frame's document and all of its subresources succeeded to load. didFinishLoad(WebFrame *)189 virtual void didFinishLoad(WebFrame*) { } 190 191 // The navigation resulted in scrolling the page to a named anchor instead 192 // of downloading a new document. didChangeLocationWithinPage(WebFrame *,bool isNewNavigation)193 virtual void didChangeLocationWithinPage(WebFrame*, bool isNewNavigation) { } 194 195 // Called upon update to scroll position, document state, and other 196 // non-navigational events related to the data held by WebHistoryItem. 197 // WARNING: This method may be called very frequently. didUpdateCurrentHistoryItem(WebFrame *)198 virtual void didUpdateCurrentHistoryItem(WebFrame*) { } 199 200 201 // Low-level resource notifications ------------------------------------ 202 203 // An identifier was assigned to the specified request. The client 204 // should remember this association if interested in subsequent events. assignIdentifierToRequest(WebFrame *,unsigned identifier,const WebURLRequest &)205 virtual void assignIdentifierToRequest( 206 WebFrame*, unsigned identifier, const WebURLRequest&) { } 207 208 // A request is about to be sent out, and the client may modify it. Request 209 // is writable, and changes to the URL, for example, will change the request 210 // made. If this request is the result of a redirect, then redirectResponse 211 // will be non-null and contain the response that triggered the redirect. willSendRequest(WebFrame *,unsigned identifier,WebURLRequest &,const WebURLResponse & redirectResponse)212 virtual void willSendRequest( 213 WebFrame*, unsigned identifier, WebURLRequest&, 214 const WebURLResponse& redirectResponse) { } 215 216 // Response headers have been received for the resource request given 217 // by identifier. didReceiveResponse(WebFrame *,unsigned identifier,const WebURLResponse &)218 virtual void didReceiveResponse( 219 WebFrame*, unsigned identifier, const WebURLResponse&) { } 220 221 // The resource request given by identifier succeeded. didFinishResourceLoad(WebFrame *,unsigned identifier)222 virtual void didFinishResourceLoad( 223 WebFrame*, unsigned identifier) { } 224 225 // The resource request given by identifier failed. didFailResourceLoad(WebFrame *,unsigned identifier,const WebURLError &)226 virtual void didFailResourceLoad( 227 WebFrame*, unsigned identifier, const WebURLError&) { } 228 229 // The specified request was satified from WebCore's memory cache. didLoadResourceFromMemoryCache(WebFrame *,const WebURLRequest &,const WebURLResponse &)230 virtual void didLoadResourceFromMemoryCache( 231 WebFrame*, const WebURLRequest&, const WebURLResponse&) { } 232 233 // This frame has displayed inactive content (such as an image) from an 234 // insecure source. Inactive content cannot spread to other frames. didDisplayInsecureContent(WebFrame *)235 virtual void didDisplayInsecureContent(WebFrame*) { } 236 237 // The indicated security origin has run active content (such as a 238 // script) from an insecure source. Note that the insecure content can 239 // spread to other frames in the same origin. didRunInsecureContent(WebFrame *,const WebSecurityOrigin &)240 virtual void didRunInsecureContent(WebFrame*, const WebSecurityOrigin&) { } 241 242 243 // Script notifications ------------------------------------------------ 244 245 // Controls whether scripts are allowed to execute for this frame. allowScript(WebFrame *,bool enabledPerSettings)246 virtual bool allowScript(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; } 247 248 // Script in the page tried to allocate too much memory. didExhaustMemoryAvailableForScript(WebFrame *)249 virtual void didExhaustMemoryAvailableForScript(WebFrame*) { } 250 251 // Notifies that a new script context has been created for this frame. 252 // This is similar to didClearWindowObject but only called once per 253 // frame context. didCreateScriptContext(WebFrame *)254 virtual void didCreateScriptContext(WebFrame*) { } 255 256 // Notifies that this frame's script context has been destroyed. didDestroyScriptContext(WebFrame *)257 virtual void didDestroyScriptContext(WebFrame*) { } 258 259 // Notifies that a garbage-collected context was created - content 260 // scripts. didCreateIsolatedScriptContext(WebFrame *)261 virtual void didCreateIsolatedScriptContext(WebFrame*) { } 262 263 264 // Geometry notifications ---------------------------------------------- 265 266 // The size of the content area changed. didChangeContentsSize(WebFrame *,const WebSize &)267 virtual void didChangeContentsSize(WebFrame*, const WebSize&) { } 268 269 // The main frame scrolled. didChangeScrollOffset(WebFrame *)270 virtual void didChangeScrollOffset(WebFrame*) { } 271 272 273 // Find-in-page notifications ------------------------------------------ 274 275 // Notifies how many matches have been found so far, for a given 276 // identifier. |finalUpdate| specifies whether this is the last update 277 // (all frames have completed scoping). reportFindInPageMatchCount(int identifier,int count,bool finalUpdate)278 virtual void reportFindInPageMatchCount( 279 int identifier, int count, bool finalUpdate) { } 280 281 // Notifies what tick-mark rect is currently selected. The given 282 // identifier lets the client know which request this message belongs 283 // to, so that it can choose to ignore the message if it has moved on 284 // to other things. The selection rect is expected to have coordinates 285 // relative to the top left corner of the web page area and represent 286 // where on the screen the selection rect is currently located. reportFindInPageSelection(int identifier,int activeMatchOrdinal,const WebRect & selection)287 virtual void reportFindInPageSelection( 288 int identifier, int activeMatchOrdinal, const WebRect& selection) { } 289 290 protected: ~WebFrameClient()291 ~WebFrameClient() { } 292 }; 293 294 } // namespace WebKit 295 296 #endif 297