Home | History | Annotate | Download | only in web
      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/WebColor.h"
     35 #include "WebDOMMessageEvent.h"
     36 #include "WebDataSource.h"
     37 #include "WebFrame.h"
     38 #include "WebHistoryCommitType.h"
     39 #include "WebHistoryItem.h"
     40 #include "WebIconURL.h"
     41 #include "WebNavigationPolicy.h"
     42 #include "WebNavigationType.h"
     43 #include "WebSecurityOrigin.h"
     44 #include "WebTextDirection.h"
     45 #include "public/platform/WebCommon.h"
     46 #include "public/platform/WebFileSystem.h"
     47 #include "public/platform/WebFileSystemType.h"
     48 #include "public/platform/WebStorageQuotaCallbacks.h"
     49 #include "public/platform/WebStorageQuotaType.h"
     50 #include "public/platform/WebURLError.h"
     51 #include "public/platform/WebURLRequest.h"
     52 #include <v8.h>
     53 
     54 namespace blink {
     55 
     56 class WebApplicationCacheHost;
     57 class WebApplicationCacheHostClient;
     58 class WebCachedURLRequest;
     59 class WebColorChooser;
     60 class WebColorChooserClient;
     61 class WebContentDecryptionModule;
     62 class WebCookieJar;
     63 class WebDataSource;
     64 class WebDOMEvent;
     65 class WebFormElement;
     66 class WebGeolocationClient;
     67 class WebInputEvent;
     68 class WebMediaPlayer;
     69 class WebMediaPlayerClient;
     70 class WebMIDIClient;
     71 class WebNotificationPresenter;
     72 class WebServiceWorkerProvider;
     73 class WebServiceWorkerProviderClient;
     74 class WebSocketHandle;
     75 class WebNode;
     76 class WebPlugin;
     77 class WebRTCPeerConnectionHandler;
     78 class WebScreenOrientationClient;
     79 class WebSharedWorker;
     80 class WebSharedWorkerClient;
     81 class WebSocketStreamHandle;
     82 class WebString;
     83 class WebURL;
     84 class WebURLLoader;
     85 class WebURLResponse;
     86 class WebUserMediaClient;
     87 class WebWorkerPermissionClientProxy;
     88 struct WebColorSuggestion;
     89 struct WebConsoleMessage;
     90 struct WebContextMenuData;
     91 struct WebPluginParams;
     92 struct WebRect;
     93 struct WebSize;
     94 struct WebURLError;
     95 
     96 class WebFrameClient {
     97 public:
     98     // Factory methods -----------------------------------------------------
     99 
    100     // May return null.
    101     virtual WebPlugin* createPlugin(WebLocalFrame*, const WebPluginParams&) { return 0; }
    102 
    103     // May return null.
    104     virtual WebMediaPlayer* createMediaPlayer(WebLocalFrame*, const WebURL&, WebMediaPlayerClient*) { return 0; }
    105 
    106     // May return null.
    107     virtual WebContentDecryptionModule* createContentDecryptionModule(WebLocalFrame*, const WebSecurityOrigin&, const WebString& keySystem) { return 0; }
    108 
    109     // May return null.
    110     virtual WebApplicationCacheHost* createApplicationCacheHost(WebLocalFrame*, WebApplicationCacheHostClient*) { return 0; }
    111 
    112     // May return null.
    113     virtual WebServiceWorkerProvider* createServiceWorkerProvider(WebLocalFrame* frame) { return 0; }
    114 
    115     // May return null.
    116     virtual WebWorkerPermissionClientProxy* createWorkerPermissionClientProxy(WebLocalFrame*) { return 0; }
    117 
    118 
    119     // Services ------------------------------------------------------------
    120 
    121     // A frame specific cookie jar.  May return null, in which case
    122     // WebKitPlatformSupport::cookieJar() will be called to access cookies.
    123     virtual WebCookieJar* cookieJar(WebLocalFrame*) { return 0; }
    124 
    125 
    126     // General notifications -----------------------------------------------
    127 
    128     // Indicates if creating a plugin without an associated renderer is supported.
    129     virtual bool canCreatePluginWithoutRenderer(const WebString& mimeType) { return false; }
    130 
    131     // Indicates that another page has accessed the DOM of the initial empty
    132     // document of a main frame. After this, it is no longer safe to show a
    133     // pending navigation's URL, because a URL spoof is possible.
    134     virtual void didAccessInitialDocument(WebLocalFrame*) { }
    135 
    136     // A child frame was created in this frame. This is called when the frame
    137     // is created and initialized. Takes the name of the new frame, the parent
    138     // frame and returns a new WebFrame. The WebFrame is considered in-use
    139     // until frameDetached() is called on it.
    140     // Note: If you override this, you should almost certainly be overriding
    141     // frameDetached().
    142     virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& frameName) { return 0; }
    143 
    144     // This frame set its opener to null, disowning it.
    145     // See http://html.spec.whatwg.org/#dom-opener.
    146     virtual void didDisownOpener(WebLocalFrame*) { }
    147 
    148     // This frame has been detached from the view, but has not been closed yet.
    149     virtual void frameDetached(WebFrame*) { }
    150 
    151     // This frame has become focused..
    152     virtual void frameFocused() { }
    153 
    154     // This frame is about to be closed. This is called after frameDetached,
    155     // when the document is being unloaded, due to new one committing.
    156     virtual void willClose(WebFrame*) { }
    157 
    158     // This frame's name has changed.
    159     virtual void didChangeName(WebLocalFrame*, const WebString&) { }
    160 
    161     // Called when a watched CSS selector matches or stops matching.
    162     virtual void didMatchCSS(WebLocalFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) { }
    163 
    164 
    165     // Console messages ----------------------------------------------------
    166 
    167     // Whether or not we should report a detailed message for the given source.
    168     virtual bool shouldReportDetailedMessageForSource(const WebString& source) { return false; }
    169 
    170     // A new message was added to the console.
    171     virtual void didAddMessageToConsole(const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine, const WebString& stackTrace) { }
    172 
    173 
    174     // Load commands -------------------------------------------------------
    175 
    176     // The client should handle the navigation externally.
    177     virtual void loadURLExternally(
    178         WebLocalFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { }
    179 
    180 
    181     // Navigational queries ------------------------------------------------
    182 
    183     // The client may choose to alter the navigation policy.  Otherwise,
    184     // defaultPolicy should just be returned.
    185     virtual WebNavigationPolicy decidePolicyForNavigation(
    186         WebLocalFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigationType,
    187         WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; }
    188 
    189     // During a history navigation, we may choose to load new subframes from history as well.
    190     // This returns such a history item if appropriate.
    191     virtual WebHistoryItem historyItemForNewChildFrame(WebFrame*) { return WebHistoryItem(); }
    192 
    193 
    194     // Navigational notifications ------------------------------------------
    195 
    196     // These notifications bracket any loading that occurs in the WebFrame.
    197     virtual void didStartLoading(bool toDifferentDocument) { }
    198     virtual void didStopLoading() { }
    199 
    200     // Notification that some progress was made loading the current frame.
    201     // loadProgress is a value between 0 (nothing loaded) and 1.0 (frame fully
    202     // loaded).
    203     virtual void didChangeLoadProgress(double loadProgress) { }
    204 
    205     // A form submission has been requested, but the page's submit event handler
    206     // hasn't yet had a chance to run (and possibly alter/interrupt the submit.)
    207     virtual void willSendSubmitEvent(WebLocalFrame*, const WebFormElement&) { }
    208 
    209     // A form submission is about to occur.
    210     virtual void willSubmitForm(WebLocalFrame*, const WebFormElement&) { }
    211 
    212     // A datasource has been created for a new navigation.  The given
    213     // datasource will become the provisional datasource for the frame.
    214     virtual void didCreateDataSource(WebLocalFrame*, WebDataSource*) { }
    215 
    216     // A new provisional load has been started.
    217     virtual void didStartProvisionalLoad(WebLocalFrame*) { }
    218 
    219     // The provisional load was redirected via a HTTP 3xx response.
    220     virtual void didReceiveServerRedirectForProvisionalLoad(WebLocalFrame*) { }
    221 
    222     // The provisional load failed.
    223     virtual void didFailProvisionalLoad(WebLocalFrame*, const WebURLError&) { }
    224 
    225     // The provisional datasource is now committed.  The first part of the
    226     // response body has been received, and the encoding of the response
    227     // body is known.
    228     virtual void didCommitProvisionalLoad(WebLocalFrame*, const WebHistoryItem&, WebHistoryCommitType) { }
    229 
    230     // The window object for the frame has been cleared of any extra
    231     // properties that may have been set by script from the previously
    232     // loaded document.
    233     virtual void didClearWindowObject(WebLocalFrame* frame) { }
    234 
    235     // The document element has been created.
    236     virtual void didCreateDocumentElement(WebLocalFrame*) { }
    237 
    238     // The page title is available.
    239     virtual void didReceiveTitle(WebLocalFrame* frame, const WebString& title, WebTextDirection direction) { }
    240 
    241     // The icon for the page have changed.
    242     virtual void didChangeIcon(WebLocalFrame*, WebIconURL::Type) { }
    243 
    244     // The frame's document finished loading.
    245     virtual void didFinishDocumentLoad(WebLocalFrame*) { }
    246 
    247     // The 'load' event was dispatched.
    248     virtual void didHandleOnloadEvents(WebLocalFrame*) { }
    249 
    250     // The frame's document or one of its subresources failed to load.
    251     virtual void didFailLoad(WebLocalFrame*, const WebURLError&) { }
    252 
    253     // The frame's document and all of its subresources succeeded to load.
    254     virtual void didFinishLoad(WebLocalFrame*) { }
    255 
    256     // The navigation resulted in no change to the documents within the page.
    257     // For example, the navigation may have just resulted in scrolling to a
    258     // named anchor or a PopState event may have been dispatched.
    259     virtual void didNavigateWithinPage(WebLocalFrame*, const WebHistoryItem&, WebHistoryCommitType) { }
    260 
    261     // Called upon update to scroll position, document state, and other
    262     // non-navigational events related to the data held by WebHistoryItem.
    263     // WARNING: This method may be called very frequently.
    264     virtual void didUpdateCurrentHistoryItem(WebLocalFrame*) { }
    265 
    266     // The frame's manifest has changed.
    267     virtual void didChangeManifest(WebLocalFrame*) { }
    268 
    269     // TODO: Remove when chromium is changed to use didChangeThemeColor().
    270     virtual void didChangeBrandColor() { }
    271 
    272     // The frame's theme color has changed.
    273     virtual void didChangeThemeColor() { }
    274 
    275     // Misc ----------------------------------------------------------------
    276 
    277     // Called to retrieve the provider of desktop notifications.
    278     virtual WebNotificationPresenter* notificationPresenter() { return 0; }
    279 
    280 
    281     // Editing -------------------------------------------------------------
    282 
    283     // These methods allow the client to intercept and overrule editing
    284     // operations.
    285     virtual void didChangeSelection(bool isSelectionEmpty) { }
    286 
    287 
    288     // Dialogs -------------------------------------------------------------
    289 
    290     // This method opens the color chooser and returns a new WebColorChooser
    291     // instance. If there is a WebColorChooser already from the last time this
    292     // was called, it ends the color chooser by calling endChooser, and replaces
    293     // it with the new one. The given list of suggestions can be used to show a
    294     // simple interface with a limited set of choices.
    295 
    296     virtual WebColorChooser* createColorChooser(
    297         WebColorChooserClient*,
    298         const WebColor&,
    299         const WebVector<WebColorSuggestion>&) { return 0; }
    300 
    301     // Displays a modal alert dialog containing the given message. Returns
    302     // once the user dismisses the dialog.
    303     virtual void runModalAlertDialog(const WebString& message) { }
    304 
    305     // Displays a modal confirmation dialog with the given message as
    306     // description and OK/Cancel choices. Returns true if the user selects
    307     // 'OK' or false otherwise.
    308     virtual bool runModalConfirmDialog(const WebString& message) { return false; }
    309 
    310     // Displays a modal input dialog with the given message as description
    311     // and OK/Cancel choices. The input field is pre-filled with
    312     // defaultValue. Returns true if the user selects 'OK' or false
    313     // otherwise. Upon returning true, actualValue contains the value of
    314     // the input field.
    315     virtual bool runModalPromptDialog(
    316         const WebString& message, const WebString& defaultValue,
    317         WebString* actualValue) { return false; }
    318 
    319     // Displays a modal confirmation dialog containing the given message as
    320     // description and OK/Cancel choices, where 'OK' means that it is okay
    321     // to proceed with closing the view. Returns true if the user selects
    322     // 'OK' or false otherwise.
    323     virtual bool runModalBeforeUnloadDialog(
    324         bool isReload, const WebString& message) { return true; }
    325 
    326 
    327     // UI ------------------------------------------------------------------
    328 
    329     // Shows a context menu with commands relevant to a specific element on
    330     // the given frame. Additional context data is supplied.
    331     virtual void showContextMenu(const WebContextMenuData&) { }
    332 
    333     // Called when the data attached to the currently displayed context menu is
    334     // invalidated. The context menu may be closed if possible.
    335     virtual void clearContextMenu() { }
    336 
    337 
    338     // Low-level resource notifications ------------------------------------
    339 
    340     // An element will request a resource.
    341     virtual void willRequestResource(WebLocalFrame*, const WebCachedURLRequest&) { }
    342 
    343     // The request is after preconnect is triggered.
    344     virtual void willRequestAfterPreconnect(WebLocalFrame*, WebURLRequest&) { }
    345 
    346     // A request is about to be sent out, and the client may modify it.  Request
    347     // is writable, and changes to the URL, for example, will change the request
    348     // made.  If this request is the result of a redirect, then redirectResponse
    349     // will be non-null and contain the response that triggered the redirect.
    350     virtual void willSendRequest(
    351         WebLocalFrame*, unsigned identifier, WebURLRequest&,
    352         const WebURLResponse& redirectResponse) { }
    353 
    354     // Response headers have been received for the resource request given
    355     // by identifier.
    356     virtual void didReceiveResponse(
    357         WebLocalFrame*, unsigned identifier, const WebURLResponse&) { }
    358 
    359     virtual void didChangeResourcePriority(
    360         WebLocalFrame* webFrame, unsigned identifier, const blink::WebURLRequest::Priority& priority, int) { }
    361 
    362     // The resource request given by identifier succeeded.
    363     virtual void didFinishResourceLoad(
    364         WebLocalFrame*, unsigned identifier) { }
    365 
    366     // The specified request was satified from WebCore's memory cache.
    367     virtual void didLoadResourceFromMemoryCache(
    368         WebLocalFrame*, const WebURLRequest&, const WebURLResponse&) { }
    369 
    370     // This frame has displayed inactive content (such as an image) from an
    371     // insecure source.  Inactive content cannot spread to other frames.
    372     virtual void didDisplayInsecureContent(WebLocalFrame*) { }
    373 
    374     // The indicated security origin has run active content (such as a
    375     // script) from an insecure source.  Note that the insecure content can
    376     // spread to other frames in the same origin.
    377     virtual void didRunInsecureContent(WebLocalFrame*, const WebSecurityOrigin&, const WebURL& insecureURL) { }
    378 
    379     // A reflected XSS was encountered in the page and suppressed.
    380     virtual void didDetectXSS(WebLocalFrame*, const WebURL&, bool didBlockEntirePage) { }
    381 
    382     // A PingLoader was created, and a request dispatched to a URL.
    383     virtual void didDispatchPingLoader(WebLocalFrame*, const WebURL&) { }
    384 
    385     // The loaders in this frame have been stopped.
    386     virtual void didAbortLoading(WebLocalFrame*) { }
    387 
    388 
    389     // Script notifications ------------------------------------------------
    390 
    391     // Notifies that a new script context has been created for this frame.
    392     // This is similar to didClearWindowObject but only called once per
    393     // frame context.
    394     virtual void didCreateScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { }
    395 
    396     // WebKit is about to release its reference to a v8 context for a frame.
    397     virtual void willReleaseScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int worldId) { }
    398 
    399 
    400     // Geometry notifications ----------------------------------------------
    401 
    402     // The frame's document finished the initial non-empty layout of a page.
    403     virtual void didFirstVisuallyNonEmptyLayout(WebLocalFrame*) { }
    404 
    405     // The main frame scrolled.
    406     virtual void didChangeScrollOffset(WebLocalFrame*) { }
    407 
    408     // If the frame is loading an HTML document, this will be called to
    409     // notify that the <body> will be attached soon.
    410     virtual void willInsertBody(WebLocalFrame*) { }
    411 
    412 
    413     // Find-in-page notifications ------------------------------------------
    414 
    415     // Notifies how many matches have been found so far, for a given
    416     // identifier.  |finalUpdate| specifies whether this is the last update
    417     // (all frames have completed scoping).
    418     virtual void reportFindInPageMatchCount(
    419         int identifier, int count, bool finalUpdate) { }
    420 
    421     // Notifies what tick-mark rect is currently selected.   The given
    422     // identifier lets the client know which request this message belongs
    423     // to, so that it can choose to ignore the message if it has moved on
    424     // to other things.  The selection rect is expected to have coordinates
    425     // relative to the top left corner of the web page area and represent
    426     // where on the screen the selection rect is currently located.
    427     virtual void reportFindInPageSelection(
    428         int identifier, int activeMatchOrdinal, const WebRect& selection) { }
    429 
    430 
    431     // Quota ---------------------------------------------------------
    432 
    433     // Requests a new quota size for the origin's storage.
    434     // |newQuotaInBytes| indicates how much storage space (in bytes) the
    435     // caller expects to need.
    436     // WebStorageQuotaCallbacks::didGrantStorageQuota will be called when
    437     // a new quota is granted. WebStorageQuotaCallbacks::didFail
    438     // is called with an error code otherwise.
    439     // Note that the requesting quota size may not always be granted and
    440     // a smaller amount of quota than requested might be returned.
    441     virtual void requestStorageQuota(
    442         WebLocalFrame*, WebStorageQuotaType,
    443         unsigned long long newQuotaInBytes,
    444         WebStorageQuotaCallbacks) { }
    445 
    446     // WebSocket -----------------------------------------------------
    447 
    448     // A WebSocket object is going to open a new socket stream connection. Used
    449     // by the old WebSocket implementation.
    450     virtual void willOpenSocketStream(WebSocketStreamHandle*) { }
    451 
    452     // A WebSocket object is going to open a new WebSocket connection. Used by
    453     // the new WebSocket implementation.
    454     virtual void willOpenWebSocket(WebSocketHandle*) { }
    455 
    456 
    457     // Geolocation ---------------------------------------------------------
    458 
    459     // Access the embedder API for (client-based) geolocation client .
    460     virtual WebGeolocationClient* geolocationClient() { return 0; }
    461 
    462 
    463     // MediaStream -----------------------------------------------------
    464 
    465     // A new WebRTCPeerConnectionHandler is created.
    466     virtual void willStartUsingPeerConnectionHandler(WebLocalFrame*, WebRTCPeerConnectionHandler*) { }
    467 
    468     virtual WebUserMediaClient* userMediaClient() { return 0; }
    469 
    470 
    471     // Web MIDI -------------------------------------------------------------
    472 
    473     virtual WebMIDIClient* webMIDIClient() { return 0; }
    474 
    475 
    476     // Messages ------------------------------------------------------
    477 
    478     // Notifies the embedder that a postMessage was issued on this frame, and
    479     // gives the embedder a chance to handle it instead of WebKit. Returns true
    480     // if the embedder handled it.
    481     virtual bool willCheckAndDispatchMessageEvent(
    482         WebLocalFrame* sourceFrame,
    483         WebFrame* targetFrame,
    484         WebSecurityOrigin target,
    485         WebDOMMessageEvent event) { return false; }
    486 
    487     // Asks the embedder if a specific user agent should be used for the given
    488     // URL. Non-empty strings indicate an override should be used. Otherwise,
    489     // Platform::current()->userAgent() will be called to provide one.
    490     virtual WebString userAgentOverride(WebLocalFrame*, const WebURL& url) { return WebString(); }
    491 
    492     // Asks the embedder what value the network stack will send for the DNT
    493     // header. An empty string indicates that no DNT header will be send.
    494     virtual WebString doNotTrackValue(WebLocalFrame*) { return WebString(); }
    495 
    496 
    497     // WebGL ------------------------------------------------------
    498 
    499     // Asks the embedder whether WebGL is allowed for the given WebFrame.
    500     // This call is placed here instead of WebPermissionClient because this
    501     // class is implemented in content/, and putting it here avoids adding
    502     // more public content/ APIs.
    503     virtual bool allowWebGL(WebLocalFrame*, bool defaultValue) { return defaultValue; }
    504 
    505     // Notifies the client that a WebGL context was lost on this page with the
    506     // given reason (one of the GL_ARB_robustness status codes; see
    507     // Extensions3D.h in WebCore/platform/graphics).
    508     virtual void didLoseWebGLContext(WebLocalFrame*, int) { }
    509 
    510     // FIXME: Remove this method once we have input routing in the browser
    511     // process. See http://crbug.com/339659.
    512     virtual void forwardInputEvent(const WebInputEvent*) { }
    513 
    514     // Send initial drawing parameters to a child frame that is being rendered out of process.
    515     virtual void initializeChildFrame(const WebRect& frameRect, float scaleFactor) { }
    516 
    517 
    518     // Screen Orientation --------------------------------------------------
    519 
    520     // Access the embedder API for (client-based) screen orientation client .
    521     virtual WebScreenOrientationClient* webScreenOrientationClient() { return 0; }
    522 
    523 protected:
    524     virtual ~WebFrameClient() { }
    525 };
    526 
    527 } // namespace blink
    528 
    529 #endif
    530