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