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