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