2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef WebFrameClient_h
32 #define WebFrameClient_h
34 #include "../platform/WebColor.h"
35 #include "WebDOMMessageEvent.h"
36 #include "WebDataSource.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"
56 class WebApplicationCacheHost;
57 class WebApplicationCacheHostClient;
58 class WebCachedURLRequest;
59 class WebColorChooser;
60 class WebColorChooserClient;
61 class WebContentDecryptionModule;
66 class WebGeolocationClient;
69 class WebMediaPlayerClient;
71 class WebNotificationPresenter;
72 class WebServiceWorkerProvider;
73 class WebServiceWorkerProviderClient;
74 class WebSocketHandle;
77 class WebRTCPeerConnectionHandler;
78 class WebScreenOrientationClient;
79 class WebSharedWorker;
80 class WebSharedWorkerClient;
81 class WebSocketStreamHandle;
86 class WebUserMediaClient;
87 class WebWorkerPermissionClientProxy;
88 struct WebColorSuggestion;
89 struct WebConsoleMessage;
90 struct WebContextMenuData;
91 struct WebPluginParams;
96 class WebFrameClient {
98 // Factory methods -----------------------------------------------------
101 virtual WebPlugin* createPlugin(WebLocalFrame*, const WebPluginParams&) { return 0; }
104 virtual WebMediaPlayer* createMediaPlayer(WebLocalFrame*, const WebURL&, WebMediaPlayerClient*) { return 0; }
107 virtual WebContentDecryptionModule* createContentDecryptionModule(WebLocalFrame*, const WebSecurityOrigin&, const WebString& keySystem) { return 0; }
110 virtual WebApplicationCacheHost* createApplicationCacheHost(WebLocalFrame*, WebApplicationCacheHostClient*) { return 0; }
113 virtual WebServiceWorkerProvider* createServiceWorkerProvider(WebLocalFrame* frame) { return 0; }
116 virtual WebWorkerPermissionClientProxy* createWorkerPermissionClientProxy(WebLocalFrame*) { return 0; }
119 // Services ------------------------------------------------------------
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; }
126 // General notifications -----------------------------------------------
128 // Indicates if creating a plugin without an associated renderer is supported.
129 virtual bool canCreatePluginWithoutRenderer(const WebString& mimeType) { return false; }
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*) { }
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
142 virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& frameName) { return 0; }
144 // This frame set its opener to null, disowning it.
145 // See http://html.spec.whatwg.org/#dom-opener.
146 virtual void didDisownOpener(WebLocalFrame*) { }
148 // This frame has been detached from the view, but has not been closed yet.
149 virtual void frameDetached(WebFrame*) { }
151 // This frame has become focused..
152 virtual void frameFocused() { }
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*) { }
158 // This frame's name has changed.
159 virtual void didChangeName(WebLocalFrame*, const WebString&) { }
161 // Called when a watched CSS selector matches or stops matching.
162 virtual void didMatchCSS(WebLocalFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) { }
165 // Console messages ----------------------------------------------------
167 // Whether or not we should report a detailed message for the given source.
168 virtual bool shouldReportDetailedMessageForSource(const WebString& source) { return false; }
170 // A new message was added to the console.
171 virtual void didAddMessageToConsole(const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine, const WebString& stackTrace) { }
174 // Load commands -------------------------------------------------------
176 // The client should handle the navigation externally.
177 virtual void loadURLExternally(
178 WebLocalFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { }
181 // Navigational queries ------------------------------------------------
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; }
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(); }
194 // Navigational notifications ------------------------------------------
196 // These notifications bracket any loading that occurs in the WebFrame.
197 virtual void didStartLoading(bool toDifferentDocument) { }
198 virtual void didStopLoading() { }
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
203 virtual void didChangeLoadProgress(double loadProgress) { }
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&) { }
209 // A form submission is about to occur.
210 virtual void willSubmitForm(WebLocalFrame*, const WebFormElement&) { }
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*) { }
216 // A new provisional load has been started.
217 virtual void didStartProvisionalLoad(WebLocalFrame*) { }
219 // The provisional load was redirected via a HTTP 3xx response.
220 virtual void didReceiveServerRedirectForProvisionalLoad(WebLocalFrame*) { }
222 // The provisional load failed.
223 virtual void didFailProvisionalLoad(WebLocalFrame*, const WebURLError&) { }
225 // The provisional datasource is now committed. The first part of the
226 // response body has been received, and the encoding of the response
228 virtual void didCommitProvisionalLoad(WebLocalFrame*, const WebHistoryItem&, WebHistoryCommitType) { }
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
233 virtual void didClearWindowObject(WebLocalFrame* frame) { }
235 // The document element has been created.
236 virtual void didCreateDocumentElement(WebLocalFrame*) { }
238 // The page title is available.
239 virtual void didReceiveTitle(WebLocalFrame* frame, const WebString& title, WebTextDirection direction) { }
241 // The icon for the page have changed.
242 virtual void didChangeIcon(WebLocalFrame*, WebIconURL::Type) { }
244 // The frame's document finished loading.
245 virtual void didFinishDocumentLoad(WebLocalFrame*) { }
247 // The 'load' event was dispatched.
248 virtual void didHandleOnloadEvents(WebLocalFrame*) { }
250 // The frame's document or one of its subresources failed to load.
251 virtual void didFailLoad(WebLocalFrame*, const WebURLError&) { }
253 // The frame's document and all of its subresources succeeded to load.
254 virtual void didFinishLoad(WebLocalFrame*) { }
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) { }
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*) { }
266 // The frame's manifest has changed.
267 virtual void didChangeManifest(WebLocalFrame*) { }
269 // The frame's brand color has changed.
270 virtual void didChangeBrandColor() { }
273 // Misc ----------------------------------------------------------------
275 // Called to retrieve the provider of desktop notifications.
276 virtual WebNotificationPresenter* notificationPresenter() { return 0; }
279 // Editing -------------------------------------------------------------
281 // These methods allow the client to intercept and overrule editing
283 virtual void didChangeSelection(bool isSelectionEmpty) { }
286 // Dialogs -------------------------------------------------------------
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.
294 virtual WebColorChooser* createColorChooser(
295 WebColorChooserClient*,
297 const WebVector<WebColorSuggestion>&) { return 0; }
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) { }
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; }
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
313 virtual bool runModalPromptDialog(
314 const WebString& message, const WebString& defaultValue,
315 WebString* actualValue) { return false; }
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; }
325 // UI ------------------------------------------------------------------
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&) { }
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() { }
336 // Low-level resource notifications ------------------------------------
338 // An element will request a resource.
339 virtual void willRequestResource(WebLocalFrame*, const WebCachedURLRequest&) { }
341 // The request is after preconnect is triggered.
342 virtual void willRequestAfterPreconnect(WebLocalFrame*, WebURLRequest&) { }
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) { }
352 // Response headers have been received for the resource request given
354 virtual void didReceiveResponse(
355 WebLocalFrame*, unsigned identifier, const WebURLResponse&) { }
357 virtual void didChangeResourcePriority(
358 WebLocalFrame* webFrame, unsigned identifier, const blink::WebURLRequest::Priority& priority, int) { }
360 // The resource request given by identifier succeeded.
361 virtual void didFinishResourceLoad(
362 WebLocalFrame*, unsigned identifier) { }
364 // The specified request was satified from WebCore's memory cache.
365 virtual void didLoadResourceFromMemoryCache(
366 WebLocalFrame*, const WebURLRequest&, const WebURLResponse&) { }
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*) { }
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) { }
377 // A reflected XSS was encountered in the page and suppressed.
378 virtual void didDetectXSS(WebLocalFrame*, const WebURL&, bool didBlockEntirePage) { }
380 // A PingLoader was created, and a request dispatched to a URL.
381 virtual void didDispatchPingLoader(WebLocalFrame*, const WebURL&) { }
383 // The loaders in this frame have been stopped.
384 virtual void didAbortLoading(WebLocalFrame*) { }
387 // Script notifications ------------------------------------------------
389 // Notifies that a new script context has been created for this frame.
390 // This is similar to didClearWindowObject but only called once per
392 virtual void didCreateScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { }
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) { }
398 // Geometry notifications ----------------------------------------------
400 // The frame's document finished the initial non-empty layout of a page.
401 virtual void didFirstVisuallyNonEmptyLayout(WebLocalFrame*) { }
403 // The main frame scrolled.
404 virtual void didChangeScrollOffset(WebLocalFrame*) { }
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*) { }
411 // Find-in-page notifications ------------------------------------------
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) { }
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) { }
429 // Quota ---------------------------------------------------------
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) { }
444 // WebSocket -----------------------------------------------------
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*) { }
450 // A WebSocket object is going to open a new WebSocket connection. Used by
451 // the new WebSocket implementation.
452 virtual void willOpenWebSocket(WebSocketHandle*) { }
455 // Geolocation ---------------------------------------------------------
457 // Access the embedder API for (client-based) geolocation client .
458 virtual WebGeolocationClient* geolocationClient() { return 0; }
461 // MediaStream -----------------------------------------------------
463 // A new WebRTCPeerConnectionHandler is created.
464 virtual void willStartUsingPeerConnectionHandler(WebLocalFrame*, WebRTCPeerConnectionHandler*) { }
466 virtual WebUserMediaClient* userMediaClient() { return 0; }
469 // Web MIDI -------------------------------------------------------------
471 virtual WebMIDIClient* webMIDIClient() { return 0; }
474 // Messages ------------------------------------------------------
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; }
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(); }
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(); }
495 // WebGL ------------------------------------------------------
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; }
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) { }
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*) { }
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) { }
516 // Screen Orientation --------------------------------------------------
518 // Access the embedder API for (client-based) screen orientation client .
519 virtual WebScreenOrientationClient* webScreenOrientationClient() { return 0; }
522 virtual ~WebFrameClient() { }