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