• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 "WebCommon.h"
35 #include "WebFileSystem.h"
36 #include "WebNavigationPolicy.h"
37 #include "WebNavigationType.h"
38 #include "WebStorageQuotaType.h"
39 #include "WebTextDirection.h"
40 #include "WebURLError.h"
41 
42 namespace WebKit {
43 
44 class WebApplicationCacheHost;
45 class WebApplicationCacheHostClient;
46 class WebCookieJar;
47 class WebDataSource;
48 class WebFormElement;
49 class WebFrame;
50 class WebMediaPlayer;
51 class WebMediaPlayerClient;
52 class WebNode;
53 class WebPlugin;
54 class WebSecurityOrigin;
55 class WebSharedWorker;
56 class WebStorageQuotaCallbacks;
57 class WebString;
58 class WebURL;
59 class WebURLRequest;
60 class WebURLResponse;
61 class WebWorker;
62 class WebWorkerClient;
63 struct WebPluginParams;
64 struct WebRect;
65 struct WebSize;
66 struct WebURLError;
67 
68 class WebFrameClient {
69 public:
70     // Factory methods -----------------------------------------------------
71 
72     // May return null.
createPlugin(WebFrame *,const WebPluginParams &)73     virtual WebPlugin* createPlugin(WebFrame*, const WebPluginParams&) { return 0; }
74 
75     // May return null.
createWorker(WebFrame *,WebWorkerClient *)76     virtual WebWorker* createWorker(WebFrame*, WebWorkerClient*) { return 0; }
77 
78     // May return null.
createSharedWorker(WebFrame *,const WebURL &,const WebString &,unsigned long long)79     virtual WebSharedWorker* createSharedWorker(WebFrame*, const WebURL&, const WebString&, unsigned long long) { return 0; }
80 
81     // May return null.
createMediaPlayer(WebFrame *,WebMediaPlayerClient *)82     virtual WebMediaPlayer* createMediaPlayer(WebFrame*, WebMediaPlayerClient*) { return 0; }
83 
84     // May return null.
createApplicationCacheHost(WebFrame *,WebApplicationCacheHostClient *)85     virtual WebApplicationCacheHost* createApplicationCacheHost(WebFrame*, WebApplicationCacheHostClient*) { return 0; }
86 
87 
88     // Services ------------------------------------------------------------
89 
90     // A frame specific cookie jar.  May return null, in which case
91     // WebKitClient::cookieJar() will be called to access cookies.
cookieJar(WebFrame *)92     virtual WebCookieJar* cookieJar(WebFrame*) { return 0; }
93 
94 
95     // General notifications -----------------------------------------------
96 
97     // This frame has been detached from the view.
98     //
99     // FIXME: Do not use this in new code. Currently this is used by code in
100     // Chromium that errantly caches WebKit objects.
frameDetached(WebFrame *)101     virtual void frameDetached(WebFrame*) { }
102 
103     // This frame is about to be closed.
willClose(WebFrame *)104     virtual void willClose(WebFrame*) { }
105 
106     // Controls whether plugins are allowed for this frame.
allowPlugins(WebFrame *,bool enabledPerSettings)107     virtual bool allowPlugins(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; }
108 
109     // Notifies the client that the frame would have instantiated a plug-in if plug-ins were enabled.
didNotAllowPlugins(WebFrame *)110     virtual void didNotAllowPlugins(WebFrame*) { }
111 
112     // Controls whether images are allowed for this frame.
allowImages(WebFrame *,bool enabledPerSettings)113     virtual bool allowImages(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; }
114 
115     // Notifies the client that continuous spell checking has been enabled or
116     // disabled.
didToggleContinuousSpellChecking(WebFrame *)117     virtual void didToggleContinuousSpellChecking(WebFrame*) { }
118 
119     // Load commands -------------------------------------------------------
120 
121     // The client should handle the navigation externally.
loadURLExternally(WebFrame *,const WebURLRequest &,WebNavigationPolicy)122     virtual void loadURLExternally(
123         WebFrame*, const WebURLRequest&, WebNavigationPolicy) { }
124 
125 
126     // Navigational queries ------------------------------------------------
127 
128     // The client may choose to alter the navigation policy.  Otherwise,
129     // defaultPolicy should just be returned.
decidePolicyForNavigation(WebFrame *,const WebURLRequest &,WebNavigationType,const WebNode & originatingNode,WebNavigationPolicy defaultPolicy,bool isRedirect)130     virtual WebNavigationPolicy decidePolicyForNavigation(
131         WebFrame*, const WebURLRequest&, WebNavigationType,
132         const WebNode& originatingNode,
133         WebNavigationPolicy defaultPolicy, bool isRedirect) { return defaultPolicy; }
134 
135     // Query if the specified request can be handled.
canHandleRequest(WebFrame *,const WebURLRequest & request)136     virtual bool canHandleRequest(
137         WebFrame*, const WebURLRequest& request) { return true; }
138 
139     // Returns an error corresponding to canHandledRequest() returning false.
cannotHandleRequestError(WebFrame *,const WebURLRequest & request)140     virtual WebURLError cannotHandleRequestError(
141         WebFrame*, const WebURLRequest& request) { return WebURLError(); }
142 
143     // Returns an error corresponding to a user cancellation event.
cancelledError(WebFrame *,const WebURLRequest & request)144     virtual WebURLError cancelledError(
145         WebFrame*, const WebURLRequest& request) { return WebURLError(); }
146 
147     // Notify that a URL cannot be handled.
unableToImplementPolicyWithError(WebFrame *,const WebURLError &)148     virtual void unableToImplementPolicyWithError(
149         WebFrame*, const WebURLError&) { }
150 
151 
152     // Navigational notifications ------------------------------------------
153 
154     // A form submission has been requested, but the page's submit event handler
155     // hasn't yet had a chance to run (and possibly alter/interrupt the submit.)
willSendSubmitEvent(WebFrame *,const WebFormElement &)156     virtual void willSendSubmitEvent(WebFrame*, const WebFormElement&) { }
157 
158     // A form submission is about to occur.
willSubmitForm(WebFrame *,const WebFormElement &)159     virtual void willSubmitForm(WebFrame*, const WebFormElement&) { }
160 
161     // A client-side redirect will occur.  This may correspond to a <META
162     // refresh> or some script activity.
willPerformClientRedirect(WebFrame *,const WebURL & from,const WebURL & to,double interval,double fireTime)163     virtual void willPerformClientRedirect(
164         WebFrame*, const WebURL& from, const WebURL& to,
165         double interval, double fireTime) { }
166 
167     // A client-side redirect was cancelled.
didCancelClientRedirect(WebFrame *)168     virtual void didCancelClientRedirect(WebFrame*) { }
169 
170     // A client-side redirect completed.
didCompleteClientRedirect(WebFrame *,const WebURL & fromURL)171     virtual void didCompleteClientRedirect(WebFrame*, const WebURL& fromURL) { }
172 
173     // A datasource has been created for a new navigation.  The given
174     // datasource will become the provisional datasource for the frame.
didCreateDataSource(WebFrame *,WebDataSource *)175     virtual void didCreateDataSource(WebFrame*, WebDataSource*) { }
176 
177     // A new provisional load has been started.
didStartProvisionalLoad(WebFrame *)178     virtual void didStartProvisionalLoad(WebFrame*) { }
179 
180     // The provisional load was redirected via a HTTP 3xx response.
didReceiveServerRedirectForProvisionalLoad(WebFrame *)181     virtual void didReceiveServerRedirectForProvisionalLoad(WebFrame*) { }
182 
183     // The provisional load failed.
didFailProvisionalLoad(WebFrame *,const WebURLError &)184     virtual void didFailProvisionalLoad(WebFrame*, const WebURLError&) { }
185 
186     // Notifies the client to commit data for the given frame.  The client
187     // may optionally prevent default processing by setting preventDefault
188     // to true before returning.  If default processing is prevented, then
189     // it is up to the client to manually call commitDocumentData on the
190     // WebFrame.  It is only valid to call commitDocumentData within a call
191     // to didReceiveDocumentData.  If commitDocumentData is not called,
192     // then an empty document will be loaded.
didReceiveDocumentData(WebFrame *,const char * data,size_t length,bool & preventDefault)193     virtual void didReceiveDocumentData(
194         WebFrame*, const char* data, size_t length, bool& preventDefault) { }
195 
196     // The provisional datasource is now committed.  The first part of the
197     // response body has been received, and the encoding of the response
198     // body is known.
didCommitProvisionalLoad(WebFrame *,bool isNewNavigation)199     virtual void didCommitProvisionalLoad(WebFrame*, bool isNewNavigation) { }
200 
201     // The window object for the frame has been cleared of any extra
202     // properties that may have been set by script from the previously
203     // loaded document.
didClearWindowObject(WebFrame *)204     virtual void didClearWindowObject(WebFrame*) { }
205 
206     // The document element has been created.
didCreateDocumentElement(WebFrame *)207     virtual void didCreateDocumentElement(WebFrame*) { }
208 
209     // The page title is available.
210     // FIXME: remove override once Chrome is updated to new API.
didReceiveTitle(WebFrame *,const WebString & title)211     virtual void didReceiveTitle(WebFrame*, const WebString& title) { }
didReceiveTitle(WebFrame * frame,const WebString & title,WebTextDirection direction)212     virtual void didReceiveTitle(WebFrame* frame, const WebString& title, WebTextDirection direction)
213     {
214         didReceiveTitle(frame, title);
215     }
216 
217     // The icons for the page have changed.
didChangeIcons(WebFrame *)218     virtual void didChangeIcons(WebFrame*) { }
219 
220     // The frame's document finished loading.
didFinishDocumentLoad(WebFrame *)221     virtual void didFinishDocumentLoad(WebFrame*) { }
222 
223     // The 'load' event was dispatched.
didHandleOnloadEvents(WebFrame *)224     virtual void didHandleOnloadEvents(WebFrame*) { }
225 
226     // The frame's document or one of its subresources failed to load.
didFailLoad(WebFrame *,const WebURLError &)227     virtual void didFailLoad(WebFrame*, const WebURLError&) { }
228 
229     // The frame's document and all of its subresources succeeded to load.
didFinishLoad(WebFrame *)230     virtual void didFinishLoad(WebFrame*) { }
231 
232     // The navigation resulted in no change to the documents within the page.
233     // For example, the navigation may have just resulted in scrolling to a
234     // named anchor or a PopState event may have been dispatched.
didNavigateWithinPage(WebFrame *,bool isNewNavigation)235     virtual void didNavigateWithinPage(WebFrame*, bool isNewNavigation) { }
236 
237     // The navigation resulted in scrolling the page to a named anchor instead
238     // of downloading a new document.
didChangeLocationWithinPage(WebFrame *)239     virtual void didChangeLocationWithinPage(WebFrame*) { }
240 
241     // Called upon update to scroll position, document state, and other
242     // non-navigational events related to the data held by WebHistoryItem.
243     // WARNING: This method may be called very frequently.
didUpdateCurrentHistoryItem(WebFrame *)244     virtual void didUpdateCurrentHistoryItem(WebFrame*) { }
245 
246 
247     // Low-level resource notifications ------------------------------------
248 
249     // An identifier was assigned to the specified request.  The client
250     // should remember this association if interested in subsequent events.
assignIdentifierToRequest(WebFrame *,unsigned identifier,const WebURLRequest &)251     virtual void assignIdentifierToRequest(
252         WebFrame*, unsigned identifier, const WebURLRequest&) { }
253 
254      // Remove the association between an identifier assigned to a request if
255      // the client keeps such an association.
removeIdentifierForRequest(unsigned identifier)256      virtual void removeIdentifierForRequest(unsigned identifier) { }
257 
258     // A request is about to be sent out, and the client may modify it.  Request
259     // is writable, and changes to the URL, for example, will change the request
260     // made.  If this request is the result of a redirect, then redirectResponse
261     // will be non-null and contain the response that triggered the redirect.
willSendRequest(WebFrame *,unsigned identifier,WebURLRequest &,const WebURLResponse & redirectResponse)262     virtual void willSendRequest(
263         WebFrame*, unsigned identifier, WebURLRequest&,
264         const WebURLResponse& redirectResponse) { }
265 
266     // Response headers have been received for the resource request given
267     // by identifier.
didReceiveResponse(WebFrame *,unsigned identifier,const WebURLResponse &)268     virtual void didReceiveResponse(
269         WebFrame*, unsigned identifier, const WebURLResponse&) { }
270 
271     // The resource request given by identifier succeeded.
didFinishResourceLoad(WebFrame *,unsigned identifier)272     virtual void didFinishResourceLoad(
273         WebFrame*, unsigned identifier) { }
274 
275     // The resource request given by identifier failed.
didFailResourceLoad(WebFrame *,unsigned identifier,const WebURLError &)276     virtual void didFailResourceLoad(
277         WebFrame*, unsigned identifier, const WebURLError&) { }
278 
279     // The specified request was satified from WebCore's memory cache.
didLoadResourceFromMemoryCache(WebFrame *,const WebURLRequest &,const WebURLResponse &)280     virtual void didLoadResourceFromMemoryCache(
281         WebFrame*, const WebURLRequest&, const WebURLResponse&) { }
282 
283     // This frame has displayed inactive content (such as an image) from an
284     // insecure source.  Inactive content cannot spread to other frames.
didDisplayInsecureContent(WebFrame *)285     virtual void didDisplayInsecureContent(WebFrame*) { }
286 
287     // The indicated security origin has run active content (such as a
288     // script) from an insecure source.  Note that the insecure content can
289     // spread to other frames in the same origin.
didRunInsecureContent(WebFrame *,const WebSecurityOrigin &,const WebURL & insecureURL)290     virtual void didRunInsecureContent(WebFrame*, const WebSecurityOrigin&, const WebURL& insecureURL) { }
291 
292 
293     // Script notifications ------------------------------------------------
294 
295     // Controls whether scripts are allowed to execute for this frame.
allowScript(WebFrame *,bool enabledPerSettings)296     virtual bool allowScript(WebFrame*, bool enabledPerSettings) { return enabledPerSettings; }
297 
298     // Controls whether access to Web Databases is allowed for this frame.
allowDatabase(WebFrame *,const WebString & name,const WebString & displayName,unsigned long estimatedSize)299     virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize) { return true; }
300 
301     // Notifies the client that the frame would have executed script if script were enabled.
didNotAllowScript(WebFrame *)302     virtual void didNotAllowScript(WebFrame*) { }
303 
304     // Script in the page tried to allocate too much memory.
didExhaustMemoryAvailableForScript(WebFrame *)305     virtual void didExhaustMemoryAvailableForScript(WebFrame*) { }
306 
307     // Notifies that a new script context has been created for this frame.
308     // This is similar to didClearWindowObject but only called once per
309     // frame context.
didCreateScriptContext(WebFrame *)310     virtual void didCreateScriptContext(WebFrame*) { }
311 
312     // Notifies that this frame's script context has been destroyed.
didDestroyScriptContext(WebFrame *)313     virtual void didDestroyScriptContext(WebFrame*) { }
314 
315     // Notifies that a garbage-collected context was created - content
316     // scripts.
didCreateIsolatedScriptContext(WebFrame *)317     virtual void didCreateIsolatedScriptContext(WebFrame*) { }
318 
319     // Controls whether the given script extension should run in a new script
320     // context in this frame. If extensionGroup is 0, the script context is the
321     // frame's main context. Otherwise, it is a context created by
322     // WebFrame::executeScriptInIsolatedWorld with that same extensionGroup
323     // value.
allowScriptExtension(WebFrame *,const WebString & extensionName,int extensionGroup)324     virtual bool allowScriptExtension(WebFrame*, const WebString& extensionName, int extensionGroup) { return true; }
325 
326 
327     // Geometry notifications ----------------------------------------------
328 
329     // The frame's document finished the initial layout of a page.
didFirstLayout(WebFrame *)330     virtual void didFirstLayout(WebFrame*) { }
331 
332     // The frame's document finished the initial non-empty layout of a page.
didFirstVisuallyNonEmptyLayout(WebFrame *)333     virtual void didFirstVisuallyNonEmptyLayout(WebFrame*) { }
334 
335     // The size of the content area changed.
didChangeContentsSize(WebFrame *,const WebSize &)336     virtual void didChangeContentsSize(WebFrame*, const WebSize&) { }
337 
338     // The main frame scrolled.
didChangeScrollOffset(WebFrame *)339     virtual void didChangeScrollOffset(WebFrame*) { }
340 
341 
342     // Find-in-page notifications ------------------------------------------
343 
344     // Notifies how many matches have been found so far, for a given
345     // identifier.  |finalUpdate| specifies whether this is the last update
346     // (all frames have completed scoping).
reportFindInPageMatchCount(int identifier,int count,bool finalUpdate)347     virtual void reportFindInPageMatchCount(
348         int identifier, int count, bool finalUpdate) { }
349 
350     // Notifies what tick-mark rect is currently selected.   The given
351     // identifier lets the client know which request this message belongs
352     // to, so that it can choose to ignore the message if it has moved on
353     // to other things.  The selection rect is expected to have coordinates
354     // relative to the top left corner of the web page area and represent
355     // where on the screen the selection rect is currently located.
reportFindInPageSelection(int identifier,int activeMatchOrdinal,const WebRect & selection)356     virtual void reportFindInPageSelection(
357         int identifier, int activeMatchOrdinal, const WebRect& selection) { }
358 
359     // FileSystem ----------------------------------------------------
360 
361     // Requests to open a FileSystem.
362     // |size| indicates how much storage space (in bytes) the caller expects
363     // to need.
364     // WebFileSystemCallbacks::didOpenFileSystem() must be called with
365     // a name and root path for the requested FileSystem when the operation
366     // is completed successfully. WebFileSystemCallbacks::didFail() must be
367     // called otherwise. The create bool is for indicating whether or not to
368     // create root path for file systems if it do not exist.
openFileSystem(WebFrame *,WebFileSystem::Type,long long size,bool create,WebFileSystemCallbacks *)369     virtual void openFileSystem(
370         WebFrame*, WebFileSystem::Type, long long size,
371         bool create, WebFileSystemCallbacks*) { }
372 
373     // Quota ---------------------------------------------------------
374 
375     // Queries the origin's storage usage and quota information.
376     // WebStorageQuotaCallbacks::didQueryStorageUsageAndQuota will be called
377     // with the current usage and quota information for the origin. When
378     // an error occurs WebStorageQuotaCallbacks::didFail is called with an
379     // error code.
380     // The callbacks object is deleted when the callback method is called
381     // and does not need to be (and should not be) deleted manually.
queryStorageUsageAndQuota(WebFrame *,WebStorageQuotaType,WebStorageQuotaCallbacks *)382     virtual void queryStorageUsageAndQuota(
383         WebFrame*, WebStorageQuotaType, WebStorageQuotaCallbacks*) { }
384 
385     // Requests a new quota size for the origin's storage.
386     // |newQuotaInBytes| indicates how much storage space (in bytes) the
387     // caller expects to need.
388     // WebStorageQuotaCallbacks::didGrantStorageQuota will be called when
389     // a new quota is granted. WebStorageQuotaCallbacks::didFail
390     // is called with an error code otherwise.
391     // Note that the requesting quota size may not always be granted and
392     // a smaller amount of quota than requested might be returned.
393     // The callbacks object is deleted when the callback method is called
394     // and does not need to be (and should not be) deleted manually.
requestStorageQuota(WebFrame *,WebStorageQuotaType,unsigned long long newQuotaInBytes,WebStorageQuotaCallbacks *)395     virtual void requestStorageQuota(
396         WebFrame*, WebStorageQuotaType,
397         unsigned long long newQuotaInBytes,
398         WebStorageQuotaCallbacks*) { }
399 
400 protected:
~WebFrameClient()401     ~WebFrameClient() { }
402 };
403 
404 } // namespace WebKit
405 
406 #endif
407