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 WebNotificationPermissionCallback;
72 class WebNotificationPresenter;
73 class WebServiceWorkerProvider;
74 class WebServiceWorkerProviderClient;
75 class WebSocketHandle;
78 class WebRTCPeerConnectionHandler;
79 class WebScreenOrientationClient;
80 class WebSharedWorker;
81 class WebSharedWorkerClient;
82 class WebSocketStreamHandle;
87 class WebUserMediaClient;
88 class WebWorkerPermissionClientProxy;
89 struct WebColorSuggestion;
90 struct WebConsoleMessage;
91 struct WebContextMenuData;
92 struct WebPluginParams;
97 class WebFrameClient {
99 // Factory methods -----------------------------------------------------
102 virtual WebPlugin* createPlugin(WebLocalFrame*, const WebPluginParams&) { return 0; }
105 virtual WebMediaPlayer* createMediaPlayer(WebLocalFrame*, const WebURL&, WebMediaPlayerClient*) { return 0; }
108 virtual WebContentDecryptionModule* createContentDecryptionModule(WebLocalFrame*, const WebSecurityOrigin&, const WebString& keySystem) { return 0; }
111 virtual WebApplicationCacheHost* createApplicationCacheHost(WebLocalFrame*, WebApplicationCacheHostClient*) { return 0; }
114 virtual WebServiceWorkerProvider* createServiceWorkerProvider(WebLocalFrame* frame) { return 0; }
117 virtual WebWorkerPermissionClientProxy* createWorkerPermissionClientProxy(WebLocalFrame*) { return 0; }
120 // Services ------------------------------------------------------------
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; }
127 // General notifications -----------------------------------------------
129 // Indicates if creating a plugin without an associated renderer is supported.
130 virtual bool canCreatePluginWithoutRenderer(const WebString& mimeType) { return false; }
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*) { }
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
143 virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& frameName) { return 0; }
145 // This frame set its opener to null, disowning it.
146 // See http://html.spec.whatwg.org/#dom-opener.
147 virtual void didDisownOpener(WebLocalFrame*) { }
149 // This frame has been detached from the view, but has not been closed yet.
150 virtual void frameDetached(WebFrame*) { }
152 // This frame has become focused..
153 virtual void frameFocused() { }
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*) { }
159 // This frame's name has changed.
160 virtual void didChangeName(WebLocalFrame*, const WebString&) { }
162 // Called when a watched CSS selector matches or stops matching.
163 virtual void didMatchCSS(WebLocalFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) { }
166 // Console messages ----------------------------------------------------
168 // Whether or not we should report a detailed message for the given source.
169 virtual bool shouldReportDetailedMessageForSource(const WebString& source) { return false; }
171 // A new message was added to the console.
172 virtual void didAddMessageToConsole(const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine, const WebString& stackTrace) { }
175 // Load commands -------------------------------------------------------
177 // The client should handle the navigation externally.
178 virtual void loadURLExternally(
179 WebLocalFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { }
182 // Navigational queries ------------------------------------------------
184 // The client may choose to alter the navigation policy. Otherwise,
185 // defaultPolicy should just be returned.
187 struct NavigationPolicyInfo {
188 WebLocalFrame* frame;
189 WebDataSource::ExtraData* extraData;
190 const WebURLRequest& urlRequest;
191 WebNavigationType navigationType;
192 WebNavigationPolicy defaultPolicy;
194 bool isTransitionNavigation;
196 NavigationPolicyInfo(const WebURLRequest& urlRequest)
199 , urlRequest(urlRequest)
200 , navigationType(WebNavigationTypeOther)
201 , defaultPolicy(WebNavigationPolicyIgnore)
203 , isTransitionNavigation(false) { }
206 virtual WebNavigationPolicy decidePolicyForNavigation(const NavigationPolicyInfo& info)
208 return decidePolicyForNavigation(info.frame, info.extraData, info.urlRequest, info.navigationType, info.defaultPolicy, info.isRedirect);
212 virtual WebNavigationPolicy decidePolicyForNavigation(
213 WebLocalFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigationType,
214 WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; }
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(); }
221 // Navigational notifications ------------------------------------------
223 // These notifications bracket any loading that occurs in the WebFrame.
224 virtual void didStartLoading(bool toDifferentDocument) { }
225 virtual void didStopLoading() { }
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
230 virtual void didChangeLoadProgress(double loadProgress) { }
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&) { }
236 // A form submission is about to occur.
237 virtual void willSubmitForm(WebLocalFrame*, const WebFormElement&) { }
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*) { }
243 // A new provisional load has been started.
244 virtual void didStartProvisionalLoad(WebLocalFrame* localFrame, bool isTransitionNavigation) { }
246 // The provisional load was redirected via a HTTP 3xx response.
247 virtual void didReceiveServerRedirectForProvisionalLoad(WebLocalFrame*) { }
249 // The provisional load failed.
250 virtual void didFailProvisionalLoad(WebLocalFrame*, const WebURLError&) { }
252 // The provisional datasource is now committed. The first part of the
253 // response body has been received, and the encoding of the response
255 virtual void didCommitProvisionalLoad(WebLocalFrame*, const WebHistoryItem&, WebHistoryCommitType) { }
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
260 virtual void didClearWindowObject(WebLocalFrame* frame) { }
262 // The document element has been created.
263 virtual void didCreateDocumentElement(WebLocalFrame*) { }
265 // The page title is available.
266 virtual void didReceiveTitle(WebLocalFrame* frame, const WebString& title, WebTextDirection direction) { }
268 // The icon for the page have changed.
269 virtual void didChangeIcon(WebLocalFrame*, WebIconURL::Type) { }
271 // The frame's document finished loading.
272 virtual void didFinishDocumentLoad(WebLocalFrame*) { }
274 // The 'load' event was dispatched.
275 virtual void didHandleOnloadEvents(WebLocalFrame*) { }
277 // The frame's document or one of its subresources failed to load.
278 virtual void didFailLoad(WebLocalFrame*, const WebURLError&) { }
280 // The frame's document and all of its subresources succeeded to load.
281 virtual void didFinishLoad(WebLocalFrame*) { }
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) { }
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*) { }
293 // The frame's manifest has changed.
294 virtual void didChangeManifest(WebLocalFrame*) { }
296 // The frame's theme color has changed.
297 virtual void didChangeThemeColor() { }
300 // Transition navigations -----------------------------------------------
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) { }
306 // Web Notifications ---------------------------------------------------
308 // Requests permission to display platform notifications on the origin of this frame.
309 virtual void requestNotificationPermission(const WebSecurityOrigin&, WebNotificationPermissionCallback* callback) { }
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; }
316 // Editing -------------------------------------------------------------
318 // These methods allow the client to intercept and overrule editing
320 virtual void didChangeSelection(bool isSelectionEmpty) { }
323 // Dialogs -------------------------------------------------------------
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.
331 virtual WebColorChooser* createColorChooser(
332 WebColorChooserClient*,
334 const WebVector<WebColorSuggestion>&) { return 0; }
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) { }
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; }
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
350 virtual bool runModalPromptDialog(
351 const WebString& message, const WebString& defaultValue,
352 WebString* actualValue) { return false; }
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; }
362 // UI ------------------------------------------------------------------
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&) { }
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() { }
373 // Low-level resource notifications ------------------------------------
375 // An element will request a resource.
376 virtual void willRequestResource(WebLocalFrame*, const WebCachedURLRequest&) { }
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) { }
386 // Response headers have been received for the resource request given
388 virtual void didReceiveResponse(
389 WebLocalFrame*, unsigned identifier, const WebURLResponse&) { }
391 virtual void didChangeResourcePriority(
392 WebLocalFrame* webFrame, unsigned identifier, const WebURLRequest::Priority& priority, int) { }
394 // The resource request given by identifier succeeded.
395 virtual void didFinishResourceLoad(
396 WebLocalFrame*, unsigned identifier) { }
398 // The specified request was satified from WebCore's memory cache.
399 virtual void didLoadResourceFromMemoryCache(
400 WebLocalFrame*, const WebURLRequest&, const WebURLResponse&) { }
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*) { }
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) { }
411 // A reflected XSS was encountered in the page and suppressed.
412 virtual void didDetectXSS(WebLocalFrame*, const WebURL&, bool didBlockEntirePage) { }
414 // A PingLoader was created, and a request dispatched to a URL.
415 virtual void didDispatchPingLoader(WebLocalFrame*, const WebURL&) { }
417 // The loaders in this frame have been stopped.
418 virtual void didAbortLoading(WebLocalFrame*) { }
421 // Script notifications ------------------------------------------------
423 // Notifies that a new script context has been created for this frame.
424 // This is similar to didClearWindowObject but only called once per
426 virtual void didCreateScriptContext(WebLocalFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId) { }
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) { }
432 // Geometry notifications ----------------------------------------------
434 // The frame's document finished the initial non-empty layout of a page.
435 virtual void didFirstVisuallyNonEmptyLayout(WebLocalFrame*) { }
437 // The main frame scrolled.
438 virtual void didChangeScrollOffset(WebLocalFrame*) { }
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*) { }
445 // Find-in-page notifications ------------------------------------------
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) { }
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) { }
463 // Quota ---------------------------------------------------------
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) { }
478 // WebSocket -----------------------------------------------------
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*) { }
484 // A WebSocket object is going to open a new WebSocket connection. Used by
485 // the new WebSocket implementation.
486 virtual void willOpenWebSocket(WebSocketHandle*) { }
489 // Geolocation ---------------------------------------------------------
491 // Access the embedder API for (client-based) geolocation client .
492 virtual WebGeolocationClient* geolocationClient() { return 0; }
495 // MediaStream -----------------------------------------------------
497 // A new WebRTCPeerConnectionHandler is created.
498 virtual void willStartUsingPeerConnectionHandler(WebLocalFrame*, WebRTCPeerConnectionHandler*) { }
500 virtual WebUserMediaClient* userMediaClient() { return 0; }
503 // Web MIDI -------------------------------------------------------------
505 virtual WebMIDIClient* webMIDIClient() { return 0; }
508 // Messages ------------------------------------------------------
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; }
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(); }
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(); }
529 // WebGL ------------------------------------------------------
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; }
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) { }
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*) { }
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) { }
550 // Screen Orientation --------------------------------------------------
552 // Access the embedder API for (client-based) screen orientation client .
553 virtual WebScreenOrientationClient* webScreenOrientationClient() { return 0; }
556 virtual ~WebFrameClient() { }