1/*
2 * Copyright (C) 2009 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 WebFrame_h
32#define WebFrame_h
33
34#include "WebCompositionUnderline.h"
35#include "WebHistoryItem.h"
36#include "WebIconURL.h"
37#include "WebNode.h"
38#include "WebURLLoaderOptions.h"
39#include "public/platform/WebCanvas.h"
40#include "public/platform/WebMessagePortChannel.h"
41#include "public/platform/WebPrivateOwnPtr.h"
42#include "public/platform/WebReferrerPolicy.h"
43#include "public/platform/WebURL.h"
44#include "public/platform/WebURLRequest.h"
45
46struct NPObject;
47
48namespace v8 {
49class Context;
50class Function;
51class Object;
52class Value;
53template <class T> class Handle;
54template <class T> class Local;
55}
56
57namespace blink {
58
59class Frame;
60class OpenedFrameTracker;
61class Visitor;
62class WebData;
63class WebDataSource;
64class WebDocument;
65class WebElement;
66class WebFormElement;
67class WebFrameClient;
68class WebInputElement;
69class WebLayer;
70class WebLocalFrame;
71class WebPerformance;
72class WebPermissionClient;
73class WebRange;
74class WebRemoteFrame;
75class WebSecurityOrigin;
76class WebSharedWorkerRepositoryClient;
77class WebString;
78class WebURL;
79class WebURLLoader;
80class WebURLRequest;
81class WebView;
82struct WebConsoleMessage;
83struct WebFindOptions;
84struct WebFloatPoint;
85struct WebFloatRect;
86struct WebPoint;
87struct WebPrintParams;
88struct WebRect;
89struct WebScriptSource;
90struct WebSize;
91struct WebURLLoaderOptions;
92
93template <typename T> class WebVector;
94
95// Frames may be rendered in process ('local') or out of process ('remote').
96// A remote frame is always cross-site; a local frame may be either same-site or
97// cross-site.
98// WebFrame is the base class for both WebLocalFrame and WebRemoteFrame and
99// contains methods that are valid on both local and remote frames, such as
100// getting a frame's parent or its opener.
101class WebFrame {
102public:
103    // Control of renderTreeAsText output
104    enum RenderAsTextControl {
105        RenderAsTextNormal = 0,
106        RenderAsTextDebug = 1 << 0,
107        RenderAsTextPrinting = 1 << 1
108    };
109    typedef unsigned RenderAsTextControls;
110
111    // Returns the number of live WebFrame objects, used for leak checking.
112    BLINK_EXPORT static int instanceCount();
113
114    virtual bool isWebLocalFrame() const = 0;
115    virtual WebLocalFrame* toWebLocalFrame() = 0;
116    virtual bool isWebRemoteFrame() const = 0;
117    virtual WebRemoteFrame* toWebRemoteFrame() = 0;
118
119    BLINK_EXPORT bool swap(WebFrame*);
120
121    // This method closes and deletes the WebFrame. This is typically called by
122    // the embedder in response to a frame detached callback to the WebFrame
123    // client.
124    virtual void close() = 0;
125
126    // Called by the embedder when it needs to detach the subtree rooted at this
127    // frame.
128    BLINK_EXPORT void detach();
129
130    // Basic properties ---------------------------------------------------
131
132    // The unique name of this frame.
133    virtual WebString uniqueName() const = 0;
134
135    // The name of this frame. If no name is given, empty string is returned.
136    virtual WebString assignedName() const = 0;
137
138    // Sets the name of this frame. For child frames (frames that are not a
139    // top-most frame) the actual name may have a suffix appended to make the
140    // frame name unique within the hierarchy.
141    virtual void setName(const WebString&) = 0;
142
143    // The urls of the given combination types of favicon (if any) specified by
144    // the document loaded in this frame. The iconTypesMask is a bit-mask of
145    // WebIconURL::Type values, used to select from the available set of icon
146    // URLs
147    virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const = 0;
148
149    // Notify the WebFrame as to whether its frame will be rendered in a
150    // separate renderer process.
151    virtual void setIsRemote(bool) = 0;
152
153    // For a WebFrame with contents being rendered in another process, this
154    // sets a layer for use by the in-process compositor. WebLayer should be
155    // null if the content is being rendered in the current process.
156    virtual void setRemoteWebLayer(WebLayer*) = 0;
157
158    // Initializes the various client interfaces.
159    virtual void setPermissionClient(WebPermissionClient*) = 0;
160    virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) = 0;
161
162    // Geometry -----------------------------------------------------------
163
164    // NOTE: These routines do not force page layout so their results may
165    // not be accurate if the page layout is out-of-date.
166
167    // If set to false, do not draw scrollbars on this frame's view.
168    virtual void setCanHaveScrollbars(bool) = 0;
169
170    // The scroll offset from the top-left corner of the frame in pixels.
171    virtual WebSize scrollOffset() const = 0;
172    virtual void setScrollOffset(const WebSize&) = 0;
173
174    // The minimum and maxium scroll positions in pixels.
175    virtual WebSize minimumScrollOffset() const = 0;
176    virtual WebSize maximumScrollOffset() const = 0;
177
178    // The size of the contents area.
179    virtual WebSize contentsSize() const = 0;
180
181    // Returns true if the contents (minus scrollbars) has non-zero area.
182    virtual bool hasVisibleContent() const = 0;
183
184    // Returns the visible content rect (minus scrollbars, in absolute coordinate)
185    virtual WebRect visibleContentRect() const = 0;
186
187    virtual bool hasHorizontalScrollbar() const = 0;
188    virtual bool hasVerticalScrollbar() const = 0;
189
190    // Hierarchy ----------------------------------------------------------
191
192    // Returns the containing view.
193    virtual WebView* view() const = 0;
194
195    // Returns the frame that opened this frame or 0 if there is none.
196    BLINK_EXPORT WebFrame* opener() const;
197
198    // Sets the frame that opened this one or 0 if there is none.
199    virtual void setOpener(WebFrame*);
200
201    // Reset the frame that opened this frame to 0.
202    // This is executed between layout tests runs
203    void clearOpener() { setOpener(0); }
204
205    // Adds the given frame as a child of this frame.
206    BLINK_EXPORT void appendChild(WebFrame*);
207
208    // Removes the given child from this frame.
209    virtual void removeChild(WebFrame*);
210
211    // Returns the parent frame or 0 if this is a top-most frame.
212    BLINK_EXPORT WebFrame* parent() const;
213
214    // Returns the top-most frame in the hierarchy containing this frame.
215    BLINK_EXPORT WebFrame* top() const;
216
217    // Returns the first/last child frame.
218    BLINK_EXPORT WebFrame* firstChild() const;
219    BLINK_EXPORT WebFrame* lastChild() const;
220
221    // Returns the previous/next sibling frame.
222    BLINK_EXPORT WebFrame* previousSibling() const;
223    BLINK_EXPORT WebFrame* nextSibling() const;
224
225    // Returns the previous/next frame in "frame traversal order",
226    // optionally wrapping around.
227    BLINK_EXPORT WebFrame* traversePrevious(bool wrap) const;
228    BLINK_EXPORT WebFrame* traverseNext(bool wrap) const;
229
230    // Returns the child frame identified by the given name.
231    BLINK_EXPORT WebFrame* findChildByName(const WebString& name) const;
232
233
234    // Content ------------------------------------------------------------
235
236    virtual WebDocument document() const = 0;
237
238    virtual WebPerformance performance() const = 0;
239
240
241    // Closing -------------------------------------------------------------
242
243    // Runs beforeunload handlers for this frame, returning false if a
244    // handler suppressed unloading.
245    virtual bool dispatchBeforeUnloadEvent() = 0;
246
247    // Runs unload handlers for this frame.
248    virtual void dispatchUnloadEvent() = 0;
249
250
251    // Scripting ----------------------------------------------------------
252
253    // Returns a NPObject corresponding to this frame's DOMWindow.
254    virtual NPObject* windowObject() const = 0;
255
256    // Binds a NPObject as a property of this frame's DOMWindow.
257    virtual void bindToWindowObject(const WebString& name, NPObject*) = 0;
258    virtual void bindToWindowObject(
259        const WebString& name, NPObject*, void*) = 0;
260
261    // Executes script in the context of the current page.
262    virtual void executeScript(const WebScriptSource&) = 0;
263
264    // Executes JavaScript in a new world associated with the web frame.
265    // The script gets its own global scope and its own prototypes for
266    // intrinsic JavaScript objects (String, Array, and so-on). It also
267    // gets its own wrappers for all DOM nodes and DOM constructors.
268    // extensionGroup is an embedder-provided specifier that controls which
269    // v8 extensions are loaded into the new context - see
270    // blink::registerExtension for the corresponding specifier.
271    //
272    // worldID must be > 0 (as 0 represents the main world).
273    // worldID must be < EmbedderWorldIdLimit, high number used internally.
274    virtual void executeScriptInIsolatedWorld(
275        int worldID, const WebScriptSource* sources, unsigned numSources,
276        int extensionGroup) = 0;
277
278    // Associates an isolated world (see above for description) with a security
279    // origin. XMLHttpRequest instances used in that world will be considered
280    // to come from that origin, not the frame's.
281    virtual void setIsolatedWorldSecurityOrigin(
282        int worldID, const WebSecurityOrigin&) = 0;
283
284    // Associates a content security policy with an isolated world. This policy
285    // should be used when evaluating script in the isolated world, and should
286    // also replace a protected resource's CSP when evaluating resources
287    // injected into the DOM.
288    //
289    // FIXME: Setting this simply bypasses the protected resource's CSP. It
290    //     doesn't yet restrict the isolated world to the provided policy.
291    virtual void setIsolatedWorldContentSecurityPolicy(
292        int worldID, const WebString&) = 0;
293
294    // Logs to the console associated with this frame.
295    virtual void addMessageToConsole(const WebConsoleMessage&) = 0;
296
297    // Calls window.gc() if it is defined.
298    virtual void collectGarbage() = 0;
299
300    // Check if the scripting URL represents a mixed content condition relative
301    // to this frame.
302    virtual bool checkIfRunInsecureContent(const WebURL&) const = 0;
303
304    // Executes script in the context of the current page and returns the value
305    // that the script evaluated to.
306    virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
307        const WebScriptSource&) = 0;
308
309    // worldID must be > 0 (as 0 represents the main world).
310    // worldID must be < EmbedderWorldIdLimit, high number used internally.
311    virtual void executeScriptInIsolatedWorld(
312        int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
313        int extensionGroup, WebVector<v8::Local<v8::Value> >* results) = 0;
314
315    // Call the function with the given receiver and arguments, bypassing
316    // canExecute().
317    virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
318        v8::Handle<v8::Function>,
319        v8::Handle<v8::Value>,
320        int argc,
321        v8::Handle<v8::Value> argv[]) = 0;
322
323    // Returns the V8 context for associated with the main world and this
324    // frame. There can be many V8 contexts associated with this frame, one for
325    // each isolated world and one for the main world. If you don't know what
326    // the "main world" or an "isolated world" is, then you probably shouldn't
327    // be calling this API.
328    virtual v8::Local<v8::Context> mainWorldScriptContext() const = 0;
329
330    // Navigation ----------------------------------------------------------
331
332    // Reload the current document.
333    // True |ignoreCache| explicitly bypasses caches.
334    // False |ignoreCache| revalidates any existing cache entries.
335    virtual void reload(bool ignoreCache = false) = 0;
336
337    // This is used for situations where we want to reload a different URL because of a redirect.
338    virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache = false) = 0;
339
340    // Load the given URL.
341    virtual void loadRequest(const WebURLRequest&) = 0;
342
343    // Load the given history state, corresponding to a back/forward
344    // navigation of a frame. Multiple frames may be navigated via separate calls.
345    virtual void loadHistoryItem(
346        const WebHistoryItem&,
347        WebHistoryLoadType,
348        WebURLRequest::CachePolicy = WebURLRequest::UseProtocolCachePolicy) = 0;
349
350    // Loads the given data with specific mime type and optional text
351    // encoding.  For HTML data, baseURL indicates the security origin of
352    // the document and is used to resolve links.  If specified,
353    // unreachableURL is reported via WebDataSource::unreachableURL.  If
354    // replace is false, then this data will be loaded as a normal
355    // navigation.  Otherwise, the current history item will be replaced.
356    virtual void loadData(const WebData& data,
357                          const WebString& mimeType,
358                          const WebString& textEncoding,
359                          const WebURL& baseURL,
360                          const WebURL& unreachableURL = WebURL(),
361                          bool replace = false) = 0;
362
363    // This method is short-hand for calling LoadData, where mime_type is
364    // "text/html" and text_encoding is "UTF-8".
365    virtual void loadHTMLString(const WebData& html,
366                                const WebURL& baseURL,
367                                const WebURL& unreachableURL = WebURL(),
368                                bool replace = false) = 0;
369
370    // Stops any pending loads on the frame and its children.
371    virtual void stopLoading() = 0;
372
373    // Returns the data source that is currently loading.  May be null.
374    virtual WebDataSource* provisionalDataSource() const = 0;
375
376    // Returns the data source that is currently loaded.
377    virtual WebDataSource* dataSource() const = 0;
378
379    // View-source rendering mode.  Set this before loading an URL to cause
380    // it to be rendered in view-source mode.
381    virtual void enableViewSourceMode(bool) = 0;
382    virtual bool isViewSourceModeEnabled() const = 0;
383
384    // Sets the referrer for the given request to be the specified URL or
385    // if that is null, then it sets the referrer to the referrer that the
386    // frame would use for subresources.  NOTE: This method also filters
387    // out invalid referrers (e.g., it is invalid to send a HTTPS URL as
388    // the referrer for a HTTP request).
389    virtual void setReferrerForRequest(WebURLRequest&, const WebURL&) = 0;
390
391    // Called to associate the WebURLRequest with this frame.  The request
392    // will be modified to inherit parameters that allow it to be loaded.
393    // This method ends up triggering WebFrameClient::willSendRequest.
394    // DEPRECATED: Please use createAssociatedURLLoader instead.
395    virtual void dispatchWillSendRequest(WebURLRequest&) = 0;
396
397    // Returns a WebURLLoader that is associated with this frame.  The loader
398    // will, for example, be cancelled when WebFrame::stopLoading is called.
399    // FIXME: stopLoading does not yet cancel an associated loader!!
400    virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions& = WebURLLoaderOptions()) = 0;
401
402    // Returns the number of registered unload listeners.
403    virtual unsigned unloadListenerCount() const = 0;
404
405
406    // Editing -------------------------------------------------------------
407
408    // Replaces the selection with the given text.
409    virtual void replaceSelection(const WebString& text) = 0;
410
411    virtual void insertText(const WebString& text) = 0;
412
413    virtual void setMarkedText(const WebString& text, unsigned location, unsigned length) = 0;
414    virtual void unmarkText() = 0;
415    virtual bool hasMarkedText() const = 0;
416
417    virtual WebRange markedRange() const = 0;
418
419    // Returns the frame rectangle in window coordinate space of the given text
420    // range.
421    virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const = 0;
422
423    // Returns the index of a character in the Frame's text stream at the given
424    // point. The point is in the window coordinate space. Will return
425    // WTF::notFound if the point is invalid.
426    virtual size_t characterIndexForPoint(const WebPoint&) const = 0;
427
428    // Supports commands like Undo, Redo, Cut, Copy, Paste, SelectAll,
429    // Unselect, etc. See EditorCommand.cpp for the full list of supported
430    // commands.
431    virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) = 0;
432    virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) = 0;
433    virtual bool isCommandEnabled(const WebString&) const = 0;
434
435    // Spell-checking support.
436    virtual void enableContinuousSpellChecking(bool) = 0;
437    virtual bool isContinuousSpellCheckingEnabled() const = 0;
438    virtual void requestTextChecking(const WebElement&) = 0;
439    virtual void replaceMisspelledRange(const WebString&) = 0;
440    virtual void removeSpellingMarkers() = 0;
441
442    // Selection -----------------------------------------------------------
443
444    virtual bool hasSelection() const = 0;
445
446    virtual WebRange selectionRange() const = 0;
447
448    virtual WebString selectionAsText() const = 0;
449    virtual WebString selectionAsMarkup() const = 0;
450
451    // Expands the selection to a word around the caret and returns
452    // true. Does nothing and returns false if there is no caret or
453    // there is ranged selection.
454    virtual bool selectWordAroundCaret() = 0;
455
456    // DEPRECATED: Use moveRangeSelection.
457    virtual void selectRange(const WebPoint& base, const WebPoint& extent) = 0;
458
459    virtual void selectRange(const WebRange&) = 0;
460
461    // Move the current selection to the provided window point/points. If the
462    // current selection is editable, the new selection will be restricted to
463    // the root editable element.
464    virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) = 0;
465    virtual void moveCaretSelection(const WebPoint&) = 0;
466
467    virtual bool setEditableSelectionOffsets(int start, int end) = 0;
468    virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) = 0;
469    virtual void extendSelectionAndDelete(int before, int after) = 0;
470
471    virtual void setCaretVisible(bool) = 0;
472
473    // Printing ------------------------------------------------------------
474
475    // Reformats the WebFrame for printing. WebPrintParams specifies the printable
476    // content size, paper size, printable area size, printer DPI and print
477    // scaling option. If constrainToNode node is specified, then only the given node
478    // is printed (for now only plugins are supported), instead of the entire frame.
479    // Returns the number of pages that can be printed at the given
480    // page size.
481    virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode = WebNode()) = 0;
482
483    // Returns the page shrinking factor calculated by webkit (usually
484    // between 1/1.25 and 1/2). Returns 0 if the page number is invalid or
485    // not in printing mode.
486    virtual float getPrintPageShrink(int page) = 0;
487
488    // Prints one page, and returns the calculated page shrinking factor
489    // (usually between 1/1.25 and 1/2).  Returns 0 if the page number is
490    // invalid or not in printing mode.
491    virtual float printPage(int pageToPrint, WebCanvas*) = 0;
492
493    // Reformats the WebFrame for screen display.
494    virtual void printEnd() = 0;
495
496    // If the frame contains a full-frame plugin or the given node refers to a
497    // plugin whose content indicates that printed output should not be scaled,
498    // return true, otherwise return false.
499    virtual bool isPrintScalingDisabledForPlugin(const WebNode& = WebNode()) = 0;
500
501    // Returns the number of copies to be printed.
502    virtual int getPrintCopiesForPlugin(const WebNode& = WebNode()) = 0;
503
504    // CSS3 Paged Media ----------------------------------------------------
505
506    // Returns true if page box (margin boxes and page borders) is visible.
507    virtual bool isPageBoxVisible(int pageIndex) = 0;
508
509    // Returns true if the page style has custom size information.
510    virtual bool hasCustomPageSizeStyle(int pageIndex) = 0;
511
512    // Returns the preferred page size and margins in pixels, assuming 96
513    // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
514    // marginLeft must be initialized to the default values that are used if
515    // auto is specified.
516    virtual void pageSizeAndMarginsInPixels(int pageIndex,
517                                            WebSize& pageSize,
518                                            int& marginTop,
519                                            int& marginRight,
520                                            int& marginBottom,
521                                            int& marginLeft) = 0;
522
523    // Returns the value for a page property that is only defined when printing.
524    // printBegin must have been called before this method.
525    virtual WebString pageProperty(const WebString& propertyName, int pageIndex) = 0;
526
527    // Find-in-page --------------------------------------------------------
528
529    // Searches a frame for a given string.
530    //
531    // If a match is found, this function will select it (scrolling down to
532    // make it visible if needed) and fill in selectionRect with the
533    // location of where the match was found (in window coordinates).
534    //
535    // If no match is found, this function clears all tickmarks and
536    // highlighting.
537    //
538    // Returns true if the search string was found, false otherwise.
539    virtual bool find(int identifier,
540                      const WebString& searchText,
541                      const WebFindOptions& options,
542                      bool wrapWithinFrame,
543                      WebRect* selectionRect) = 0;
544
545    // Notifies the frame that we are no longer interested in searching.
546    // This will abort any asynchronous scoping effort already under way
547    // (see the function scopeStringMatches for details) and erase all
548    // tick-marks and highlighting from the previous search.  If
549    // clearSelection is true, it will also make sure the end state for the
550    // find operation does not leave a selection.  This can occur when the
551    // user clears the search string but does not close the find box.
552    virtual void stopFinding(bool clearSelection) = 0;
553
554    // Counts how many times a particular string occurs within the frame.
555    // It also retrieves the location of the string and updates a vector in
556    // the frame so that tick-marks and highlighting can be drawn.  This
557    // function does its work asynchronously, by running for a certain
558    // time-slice and then scheduling itself (co-operative multitasking) to
559    // be invoked later (repeating the process until all matches have been
560    // found).  This allows multiple frames to be searched at the same time
561    // and provides a way to cancel at any time (see
562    // cancelPendingScopingEffort).  The parameter searchText specifies
563    // what to look for and |reset| signals whether this is a brand new
564    // request or a continuation of the last scoping effort.
565    virtual void scopeStringMatches(int identifier,
566                                    const WebString& searchText,
567                                    const WebFindOptions& options,
568                                    bool reset) = 0;
569
570    // Cancels any outstanding requests for scoping string matches on a frame.
571    virtual void cancelPendingScopingEffort() = 0;
572
573    // This function is called on the main frame during the scoping effort
574    // to keep a running tally of the accumulated total match-count for all
575    // frames.  After updating the count it will notify the WebViewClient
576    // about the new count.
577    virtual void increaseMatchCount(int count, int identifier) = 0;
578
579    // This function is called on the main frame to reset the total number
580    // of matches found during the scoping effort.
581    virtual void resetMatchCount() = 0;
582
583    // Returns a counter that is incremented when the find-in-page markers are
584    // changed on any frame. Switching the active marker doesn't change the
585    // current version. Should be called only on the main frame.
586    virtual int findMatchMarkersVersion() const = 0;
587
588    // Returns the bounding box of the active find-in-page match marker or an
589    // empty rect if no such marker exists. The rect is returned in find-in-page
590    // coordinates whatever frame the active marker is.
591    // Should be called only on the main frame.
592    virtual WebFloatRect activeFindMatchRect() = 0;
593
594    // Swaps the contents of the provided vector with the bounding boxes of the
595    // find-in-page match markers from all frames. The bounding boxes are returned
596    // in find-in-page coordinates. This method should be called only on the main frame.
597    virtual void findMatchRects(WebVector<WebFloatRect>&) = 0;
598
599    // Selects the find-in-page match in the appropriate frame closest to the
600    // provided point in find-in-page coordinates. Returns the ordinal of such
601    // match or -1 if none could be found. If not null, selectionRect is set to
602    // the bounding box of the selected match in window coordinates.
603    // This method should be called only on the main frame.
604    virtual int selectNearestFindMatch(const WebFloatPoint&,
605                                       WebRect* selectionRect) = 0;
606
607
608    // Set the tickmarks for the frame. This will override the default tickmarks
609    // generated by find results. If this is called with an empty array, the
610    // default behavior will be restored.
611    virtual void setTickmarks(const WebVector<WebRect>&) = 0;
612
613    // Events --------------------------------------------------------------
614
615    // Dispatches a message event on the current DOMWindow in this WebFrame.
616    virtual void dispatchMessageEventWithOriginCheck(
617        const WebSecurityOrigin& intendedTargetOrigin,
618        const WebDOMEvent&) = 0;
619
620
621    // Utility -------------------------------------------------------------
622
623    // Returns the contents of this frame as a string.  If the text is
624    // longer than maxChars, it will be clipped to that length.  WARNING:
625    // This function may be slow depending on the number of characters
626    // retrieved and page complexity.  For a typically sized page, expect
627    // it to take on the order of milliseconds.
628    //
629    // If there is room, subframe text will be recursively appended. Each
630    // frame will be separated by an empty line.
631    virtual WebString contentAsText(size_t maxChars) const = 0;
632
633    // Returns HTML text for the contents of this frame.  This is generated
634    // from the DOM.
635    virtual WebString contentAsMarkup() const = 0;
636
637    // Returns a text representation of the render tree.  This method is used
638    // to support layout tests.
639    virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const = 0;
640
641    // Calls markerTextForListItem() defined in WebCore/rendering/RenderTreeAsText.h.
642    virtual WebString markerTextForListItem(const WebElement&) const = 0;
643
644    // Prints all of the pages into the canvas, with page boundaries drawn as
645    // one pixel wide blue lines. This method exists to support layout tests.
646    virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) = 0;
647
648    // Returns the bounds rect for current selection. If selection is performed
649    // on transformed text, the rect will still bound the selection but will
650    // not be transformed itself. If no selection is present, the rect will be
651    // empty ((0,0), (0,0)).
652    virtual WebRect selectionBoundsRect() const = 0;
653
654    // Only for testing purpose:
655    // Returns true if selection.anchorNode has a marker on range from |from| with |length|.
656    virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const = 0;
657
658    // Dumps the layer tree, used by the accelerated compositor, in
659    // text form. This is used only by layout tests.
660    virtual WebString layerTreeAsText(bool showDebugInfo = false) const = 0;
661
662#if BLINK_IMPLEMENTATION
663    static WebFrame* fromFrame(Frame*);
664    static void traceChildren(Visitor*, WebFrame*);
665#endif
666
667protected:
668    explicit WebFrame();
669    virtual ~WebFrame();
670
671private:
672    friend class OpenedFrameTracker;
673
674    WebFrame* m_parent;
675    WebFrame* m_previousSibling;
676    WebFrame* m_nextSibling;
677    WebFrame* m_firstChild;
678    WebFrame* m_lastChild;
679
680    WebFrame* m_opener;
681    WebPrivateOwnPtr<OpenedFrameTracker> m_openedFrameTracker;
682};
683
684#if BLINK_IMPLEMENTATION
685Frame* toCoreFrame(const WebFrame*);
686#endif
687
688} // namespace blink
689
690#endif
691