c75af85905b11ef96cd2721abf456cf2209cc0b1
[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 "../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     // The frame's brand color has changed.
270     virtual void didChangeBrandColor() { }
271
272
273     // Misc ----------------------------------------------------------------
274
275     // Called to retrieve the provider of desktop notifications.
276     virtual WebNotificationPresenter* notificationPresenter() { return 0; }
277
278
279     // Editing -------------------------------------------------------------
280
281     // These methods allow the client to intercept and overrule editing
282     // operations.
283     virtual void didChangeSelection(bool isSelectionEmpty) { }
284
285
286     // Dialogs -------------------------------------------------------------
287
288     // This method opens the color chooser and returns a new WebColorChooser
289     // instance. If there is a WebColorChooser already from the last time this
290     // was called, it ends the color chooser by calling endChooser, and replaces
291     // it with the new one. The given list of suggestions can be used to show a
292     // simple interface with a limited set of choices.
293
294     virtual WebColorChooser* createColorChooser(
295         WebColorChooserClient*,
296         const WebColor&,
297         const WebVector<WebColorSuggestion>&) { return 0; }
298
299     // Displays a modal alert dialog containing the given message. Returns
300     // once the user dismisses the dialog.
301     virtual void runModalAlertDialog(const WebString& message) { }
302
303     // Displays a modal confirmation dialog with the given message as
304     // description and OK/Cancel choices. Returns true if the user selects
305     // 'OK' or false otherwise.
306     virtual bool runModalConfirmDialog(const WebString& message) { return false; }
307
308     // Displays a modal input dialog with the given message as description
309     // and OK/Cancel choices. The input field is pre-filled with
310     // defaultValue. Returns true if the user selects 'OK' or false
311     // otherwise. Upon returning true, actualValue contains the value of
312     // the input field.
313     virtual bool runModalPromptDialog(
314         const WebString& message, const WebString& defaultValue,
315         WebString* actualValue) { return false; }
316
317     // Displays a modal confirmation dialog containing the given message as
318     // description and OK/Cancel choices, where 'OK' means that it is okay
319     // to proceed with closing the view. Returns true if the user selects
320     // 'OK' or false otherwise.
321     virtual bool runModalBeforeUnloadDialog(
322         bool isReload, const WebString& message) { return true; }
323
324
325     // UI ------------------------------------------------------------------
326
327     // Shows a context menu with commands relevant to a specific element on
328     // the given frame. Additional context data is supplied.
329     virtual void showContextMenu(const WebContextMenuData&) { }
330
331     // Called when the data attached to the currently displayed context menu is
332     // invalidated. The context menu may be closed if possible.
333     virtual void clearContextMenu() { }
334
335
336     // Low-level resource notifications ------------------------------------
337
338     // An element will request a resource.
339     virtual void willRequestResource(WebLocalFrame*, const WebCachedURLRequest&) { }
340
341     // The request is after preconnect is triggered.
342     virtual void willRequestAfterPreconnect(WebLocalFrame*, WebURLRequest&) { }
343
344     // A request is about to be sent out, and the client may modify it.  Request
345     // is writable, and changes to the URL, for example, will change the request
346     // made.  If this request is the result of a redirect, then redirectResponse
347     // will be non-null and contain the response that triggered the redirect.
348     virtual void willSendRequest(
349         WebLocalFrame*, unsigned identifier, WebURLRequest&,
350         const WebURLResponse& redirectResponse) { }
351
352     // Response headers have been received for the resource request given
353     // by identifier.
354     virtual void didReceiveResponse(
355         WebLocalFrame*, unsigned identifier, const WebURLResponse&) { }
356
357     virtual void didChangeResourcePriority(
358         WebLocalFrame* webFrame, unsigned identifier, const blink::WebURLRequest::Priority& priority, int) { }
359
360     // The resource request given by identifier succeeded.
361     virtual void didFinishResourceLoad(
362         WebLocalFrame*, unsigned identifier) { }
363
364     // The specified request was satified from WebCore's memory cache.
365     virtual void didLoadResourceFromMemoryCache(
366         WebLocalFrame*, const WebURLRequest&, const WebURLResponse&) { }
367
368     // This frame has displayed inactive content (such as an image) from an
369     // insecure source.  Inactive content cannot spread to other frames.
370     virtual void didDisplayInsecureContent(WebLocalFrame*) { }
371
372     // The indicated security origin has run active content (such as a
373     // script) from an insecure source.  Note that the insecure content can
374     // spread to other frames in the same origin.
375     virtual void didRunInsecureContent(WebLocalFrame*, const WebSecurityOrigin&, const WebURL& insecureURL) { }
376
377     // A reflected XSS was encountered in the page and suppressed.
378     virtual void didDetectXSS(WebLocalFrame*, const WebURL&, bool didBlockEntirePage) { }
379
380     // A PingLoader was created, and a request dispatched to a URL.
381     virtual void didDispatchPingLoader(WebLocalFrame*, const WebURL&) { }
382
383     // The loaders in this frame have been stopped.
384     virtual void didAbortLoading(WebLocalFrame*) { }
385
386
387     // Script notifications ------------------------------------------------
388
389     // Notifies that a new script context has been created for this frame.
390     // This is similar to didClearWindowObject but only called once per
391     // frame context.
392     virtual void didCreateScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { }
393
394     // WebKit is about to release its reference to a v8 context for a frame.
395     virtual void willReleaseScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int worldId) { }
396
397
398     // Geometry notifications ----------------------------------------------
399
400     // The frame's document finished the initial non-empty layout of a page.
401     virtual void didFirstVisuallyNonEmptyLayout(WebLocalFrame*) { }
402
403     // The main frame scrolled.
404     virtual void didChangeScrollOffset(WebLocalFrame*) { }
405
406     // If the frame is loading an HTML document, this will be called to
407     // notify that the <body> will be attached soon.
408     virtual void willInsertBody(WebLocalFrame*) { }
409
410
411     // Find-in-page notifications ------------------------------------------
412
413     // Notifies how many matches have been found so far, for a given
414     // identifier.  |finalUpdate| specifies whether this is the last update
415     // (all frames have completed scoping).
416     virtual void reportFindInPageMatchCount(
417         int identifier, int count, bool finalUpdate) { }
418
419     // Notifies what tick-mark rect is currently selected.   The given
420     // identifier lets the client know which request this message belongs
421     // to, so that it can choose to ignore the message if it has moved on
422     // to other things.  The selection rect is expected to have coordinates
423     // relative to the top left corner of the web page area and represent
424     // where on the screen the selection rect is currently located.
425     virtual void reportFindInPageSelection(
426         int identifier, int activeMatchOrdinal, const WebRect& selection) { }
427
428
429     // Quota ---------------------------------------------------------
430
431     // Requests a new quota size for the origin's storage.
432     // |newQuotaInBytes| indicates how much storage space (in bytes) the
433     // caller expects to need.
434     // WebStorageQuotaCallbacks::didGrantStorageQuota will be called when
435     // a new quota is granted. WebStorageQuotaCallbacks::didFail
436     // is called with an error code otherwise.
437     // Note that the requesting quota size may not always be granted and
438     // a smaller amount of quota than requested might be returned.
439     virtual void requestStorageQuota(
440         WebLocalFrame*, WebStorageQuotaType,
441         unsigned long long newQuotaInBytes,
442         WebStorageQuotaCallbacks) { }
443
444     // WebSocket -----------------------------------------------------
445
446     // A WebSocket object is going to open a new socket stream connection. Used
447     // by the old WebSocket implementation.
448     virtual void willOpenSocketStream(WebSocketStreamHandle*) { }
449
450     // A WebSocket object is going to open a new WebSocket connection. Used by
451     // the new WebSocket implementation.
452     virtual void willOpenWebSocket(WebSocketHandle*) { }
453
454
455     // Geolocation ---------------------------------------------------------
456
457     // Access the embedder API for (client-based) geolocation client .
458     virtual WebGeolocationClient* geolocationClient() { return 0; }
459
460
461     // MediaStream -----------------------------------------------------
462
463     // A new WebRTCPeerConnectionHandler is created.
464     virtual void willStartUsingPeerConnectionHandler(WebLocalFrame*, WebRTCPeerConnectionHandler*) { }
465
466     virtual WebUserMediaClient* userMediaClient() { return 0; }
467
468
469     // Web MIDI -------------------------------------------------------------
470
471     virtual WebMIDIClient* webMIDIClient() { return 0; }
472
473
474     // Messages ------------------------------------------------------
475
476     // Notifies the embedder that a postMessage was issued on this frame, and
477     // gives the embedder a chance to handle it instead of WebKit. Returns true
478     // if the embedder handled it.
479     virtual bool willCheckAndDispatchMessageEvent(
480         WebLocalFrame* sourceFrame,
481         WebFrame* targetFrame,
482         WebSecurityOrigin target,
483         WebDOMMessageEvent event) { return false; }
484
485     // Asks the embedder if a specific user agent should be used for the given
486     // URL. Non-empty strings indicate an override should be used. Otherwise,
487     // Platform::current()->userAgent() will be called to provide one.
488     virtual WebString userAgentOverride(WebLocalFrame*, const WebURL& url) { return WebString(); }
489
490     // Asks the embedder what value the network stack will send for the DNT
491     // header. An empty string indicates that no DNT header will be send.
492     virtual WebString doNotTrackValue(WebLocalFrame*) { return WebString(); }
493
494
495     // WebGL ------------------------------------------------------
496
497     // Asks the embedder whether WebGL is allowed for the given WebFrame.
498     // This call is placed here instead of WebPermissionClient because this
499     // class is implemented in content/, and putting it here avoids adding
500     // more public content/ APIs.
501     virtual bool allowWebGL(WebLocalFrame*, bool defaultValue) { return defaultValue; }
502
503     // Notifies the client that a WebGL context was lost on this page with the
504     // given reason (one of the GL_ARB_robustness status codes; see
505     // Extensions3D.h in WebCore/platform/graphics).
506     virtual void didLoseWebGLContext(WebLocalFrame*, int) { }
507
508     // FIXME: Remove this method once we have input routing in the browser
509     // process. See http://crbug.com/339659.
510     virtual void forwardInputEvent(const WebInputEvent*) { }
511
512     // Send initial drawing parameters to a child frame that is being rendered out of process.
513     virtual void initializeChildFrame(const WebRect& frameRect, float scaleFactor) { }
514
515
516     // Screen Orientation --------------------------------------------------
517
518     // Access the embedder API for (client-based) screen orientation client .
519     virtual WebScreenOrientationClient* webScreenOrientationClient() { return 0; }
520
521 protected:
522     virtual ~WebFrameClient() { }
523 };
524
525 } // namespace blink
526
527 #endif