2 * Copyright (C) 2009 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 WebFrameImpl_h
32 #define WebFrameImpl_h
34 #include "WebAnimationControllerImpl.h"
38 #include "FrameLoaderClientImpl.h"
39 #include "PlatformString.h"
40 #include <wtf/OwnPtr.h>
41 #include <wtf/RefCounted.h>
44 class GraphicsContext;
45 class HTMLInputElement;
51 struct WindowFeatures;
55 class ChromePrintContext;
56 class WebDataSourceImpl;
57 class WebInputElement;
60 class WebPluginContainerImpl;
64 // Implementation of WebFrame, note that this is a reference counted object.
65 class WebFrameImpl : public WebFrame, public RefCounted<WebFrameImpl> {
68 virtual WebString name() const;
69 virtual void setName(const WebString&);
70 virtual long long identifier() const;
71 virtual WebVector<WebIconURL> iconURLs(int iconTypes) const;
72 virtual WebSize scrollOffset() const;
73 virtual void setScrollOffset(const WebSize&);
74 virtual WebSize minimumScrollOffset() const;
75 virtual WebSize maximumScrollOffset() const;
76 virtual WebSize contentsSize() const;
77 virtual int contentsPreferredWidth() const;
78 virtual int documentElementScrollHeight() const;
79 virtual bool hasVisibleContent() const;
80 virtual bool hasHorizontalScrollbar() const;
81 virtual bool hasVerticalScrollbar() const;
82 virtual WebView* view() const;
83 virtual WebFrame* opener() const;
84 virtual void clearOpener();
85 virtual WebFrame* parent() const;
86 virtual WebFrame* top() const;
87 virtual WebFrame* firstChild() const;
88 virtual WebFrame* lastChild() const;
89 virtual WebFrame* nextSibling() const;
90 virtual WebFrame* previousSibling() const;
91 virtual WebFrame* traverseNext(bool wrap) const;
92 virtual WebFrame* traversePrevious(bool wrap) const;
93 virtual WebFrame* findChildByName(const WebString&) const;
94 virtual WebFrame* findChildByExpression(const WebString&) const;
95 virtual WebDocument document() const;
96 virtual WebAnimationController* animationController();
97 virtual WebPerformance performance() const;
98 virtual NPObject* windowObject() const;
99 virtual void bindToWindowObject(const WebString& name, NPObject*);
100 virtual void executeScript(const WebScriptSource&);
101 virtual void executeScriptInIsolatedWorld(
102 int worldID, const WebScriptSource* sources, unsigned numSources,
104 virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&);
105 virtual void addMessageToConsole(const WebConsoleMessage&);
106 virtual void collectGarbage();
107 virtual bool checkIfRunInsecureContent(const WebURL&) const;
109 virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
110 const WebScriptSource&);
111 virtual v8::Local<v8::Context> mainWorldScriptContext() const;
112 virtual v8::Handle<v8::Value> createFileSystem(WebFileSystem::Type,
113 const WebString& name,
114 const WebString& path);
115 virtual v8::Handle<v8::Value> createFileEntry(WebFileSystem::Type,
116 const WebString& fileSystemName,
117 const WebString& fileSystemPath,
118 const WebString& filePath,
121 virtual void reload(bool ignoreCache);
122 virtual void loadRequest(const WebURLRequest&);
123 virtual void loadHistoryItem(const WebHistoryItem&);
124 virtual void loadData(
125 const WebData&, const WebString& mimeType, const WebString& textEncoding,
126 const WebURL& baseURL, const WebURL& unreachableURL, bool replace);
127 virtual void loadHTMLString(
128 const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
130 virtual bool isLoading() const;
131 virtual void stopLoading();
132 virtual WebDataSource* provisionalDataSource() const;
133 virtual WebDataSource* dataSource() const;
134 virtual WebHistoryItem previousHistoryItem() const;
135 virtual WebHistoryItem currentHistoryItem() const;
136 virtual void enableViewSourceMode(bool enable);
137 virtual bool isViewSourceModeEnabled() const;
138 virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer);
139 virtual void dispatchWillSendRequest(WebURLRequest&);
140 virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&);
141 virtual void commitDocumentData(const char* data, size_t length);
142 virtual unsigned unloadListenerCount() const;
143 virtual bool isProcessingUserGesture() const;
144 virtual bool willSuppressOpenerInNewFrame() const;
145 virtual void replaceSelection(const WebString&);
146 virtual void insertText(const WebString&);
147 virtual void setMarkedText(const WebString&, unsigned location, unsigned length);
148 virtual void unmarkText();
149 virtual bool hasMarkedText() const;
150 virtual WebRange markedRange() const;
151 virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const;
152 virtual size_t characterIndexForPoint(const WebPoint&) const;
153 virtual bool executeCommand(const WebString&, const WebNode& = WebNode());
154 virtual bool executeCommand(const WebString&, const WebString& value);
155 virtual bool isCommandEnabled(const WebString&) const;
156 virtual void enableContinuousSpellChecking(bool);
157 virtual bool isContinuousSpellCheckingEnabled() const;
158 virtual bool hasSelection() const;
159 virtual WebRange selectionRange() const;
160 virtual WebString selectionAsText() const;
161 virtual WebString selectionAsMarkup() const;
162 virtual bool selectWordAroundCaret();
163 virtual void selectRange(const WebPoint& start, const WebPoint& end);
164 virtual int printBegin(const WebSize& pageSize,
165 const WebNode& constrainToNode,
167 bool* useBrowserOverlays);
168 virtual float printPage(int pageToPrint, WebCanvas*);
169 virtual float getPrintPageShrink(int page);
170 virtual void printEnd();
171 virtual bool isPageBoxVisible(int pageIndex);
172 virtual void pageSizeAndMarginsInPixels(int pageIndex,
179 int identifier, const WebString& searchText, const WebFindOptions&,
180 bool wrapWithinFrame, WebRect* selectionRect);
181 virtual void stopFinding(bool clearSelection);
182 virtual void scopeStringMatches(
183 int identifier, const WebString& searchText, const WebFindOptions&,
185 virtual void cancelPendingScopingEffort();
186 virtual void increaseMatchCount(int count, int identifier);
187 virtual void resetMatchCount();
189 virtual WebString contentAsText(size_t maxChars) const;
190 virtual WebString contentAsMarkup() const;
191 virtual WebString renderTreeAsText(bool showDebugInfo = false) const;
192 virtual WebString counterValueForElementById(const WebString& id) const;
193 virtual WebString markerTextForListItem(const WebElement&) const;
194 virtual int pageNumberForElementById(const WebString& id,
195 float pageWidthInPixels,
196 float pageHeightInPixels) const;
197 virtual WebRect selectionBoundsRect() const;
199 virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const;
200 virtual bool pauseSVGAnimation(const WebString& animationId,
202 const WebString& elementId);
203 virtual WebString layerTreeAsText(bool showDebugInfo = false) const;
205 static PassRefPtr<WebFrameImpl> create(WebFrameClient* client);
206 virtual ~WebFrameImpl();
208 // Called by the WebViewImpl to initialize its main frame:
209 void initializeAsMainFrame(WebViewImpl*);
211 PassRefPtr<WebCore::Frame> createChildFrame(
212 const WebCore::FrameLoadRequest&, WebCore::HTMLFrameOwnerElement*);
215 void paint(WebCanvas*, const WebRect&);
216 void paintWithContext(WebCore::GraphicsContext&, const WebRect&);
217 void createFrameView();
219 static WebFrameImpl* fromFrame(WebCore::Frame* frame);
220 static WebFrameImpl* fromFrameOwnerElement(WebCore::Element* element);
222 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
223 // that hosts the plugin.
224 static WebPluginContainerImpl* pluginContainerFromFrame(WebCore::Frame*);
226 WebViewImpl* viewImpl() const;
228 WebCore::Frame* frame() const { return m_frame; }
229 WebCore::FrameView* frameView() const { return m_frame ? m_frame->view() : 0; }
231 // Getters for the impls corresponding to Get(Provisional)DataSource. They
232 // may return 0 if there is no corresponding data source.
233 WebDataSourceImpl* dataSourceImpl() const;
234 WebDataSourceImpl* provisionalDataSourceImpl() const;
236 // Returns which frame has an active match. This function should only be
237 // called on the main frame, as it is the only frame keeping track. Returned
238 // value can be 0 if no frame has an active match.
239 const WebFrameImpl* activeMatchFrame() const { return m_activeMatchFrame; }
241 // When a Find operation ends, we want to set the selection to what was active
242 // and set focus to the first focusable node we find (starting with the first
243 // node in the matched range and going up the inheritance chain). If we find
244 // nothing to focus we focus the first focusable node in the range. This
245 // allows us to set focus to a link (when we find text inside a link), which
246 // allows us to navigate by pressing Enter after closing the Find box.
247 void setFindEndstateFocusAndSelection();
249 void didFail(const WebCore::ResourceError&, bool wasProvisional);
251 // Sets whether the WebFrameImpl allows its document to be scrolled.
252 // If the parameter is true, allow the document to be scrolled.
253 // Otherwise, disallow scrolling.
254 void setCanHaveScrollbars(bool);
256 WebFrameClient* client() const { return m_client; }
257 void setClient(WebFrameClient* client) { m_client = client; }
259 static void selectWordAroundPosition(WebCore::Frame*, WebCore::VisiblePosition);
262 class DeferredScopeStringMatches;
263 friend class DeferredScopeStringMatches;
264 friend class FrameLoaderClientImpl;
266 // A bit mask specifying area of the frame to invalidate.
267 enum AreaToInvalidate {
269 InvalidateContentArea,
270 InvalidateScrollbar, // Vertical scrollbar only.
271 InvalidateAll // Both content area and the scrollbar.
274 WebFrameImpl(WebFrameClient*);
276 // Informs the WebFrame that the Frame is being closed, called by the
277 // WebFrameLoaderClient
280 // Notifies the delegate about a new selection rect.
281 void reportFindInPageSelection(
282 const WebRect& selectionRect, int activeMatchOrdinal, int identifier);
284 // Invalidates a certain area within the frame.
285 void invalidateArea(AreaToInvalidate);
287 // Add a WebKit TextMatch-highlight marker to nodes in a range.
288 void addMarker(WebCore::Range*, bool activeMatch);
290 // Sets the markers within a range as active or inactive.
291 void setMarkerActive(WebCore::Range*, bool active);
293 // Returns the ordinal of the first match in the frame specified. This
294 // function enumerates the frames, starting with the main frame and up to (but
295 // not including) the frame passed in as a parameter and counts how many
296 // matches have been found.
297 int ordinalOfFirstMatchForFrame(WebFrameImpl*) const;
299 // Determines whether the scoping effort is required for a particular frame.
300 // It is not necessary if the frame is invisible, for example, or if this
301 // is a repeat search that already returned nothing last time the same prefix
303 bool shouldScopeMatches(const WTF::String& searchText);
305 // Queue up a deferred call to scopeStringMatches.
306 void scopeStringMatchesSoon(
307 int identifier, const WebString& searchText, const WebFindOptions&,
310 // Called by a DeferredScopeStringMatches instance.
311 void callScopeStringMatches(
312 DeferredScopeStringMatches*, int identifier, const WebString& searchText,
313 const WebFindOptions&, bool reset);
315 // Determines whether to invalidate the content area and scrollbar.
316 void invalidateIfNecessary();
318 void loadJavaScriptURL(const WebCore::KURL&);
320 // Returns a hit-tested VisiblePosition for the given point
321 WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
323 FrameLoaderClientImpl m_frameLoaderClient;
325 WebFrameClient* m_client;
327 // This is a weak pointer to our corresponding WebCore frame. A reference to
328 // ourselves is held while frame_ is valid. See our Closing method.
329 WebCore::Frame* m_frame;
331 // A way for the main frame to keep track of which frame has an active
332 // match. Should be 0 for all other frames.
333 WebFrameImpl* m_activeMatchFrame;
335 // The range of the active match for the current frame.
336 RefPtr<WebCore::Range> m_activeMatch;
338 // The index of the active match.
339 int m_activeMatchIndex;
341 // This flag is used by the scoping effort to determine if we need to figure
342 // out which rectangle is the active match. Once we find the active
343 // rectangle we clear this flag.
344 bool m_locatingActiveRect;
346 // The scoping effort can time out and we need to keep track of where we
347 // ended our last search so we can continue from where we left of.
348 RefPtr<WebCore::Range> m_resumeScopingFromRange;
350 // Keeps track of the last string this frame searched for. This is used for
351 // short-circuiting searches in the following scenarios: When a frame has
352 // been searched and returned 0 results, we don't need to search that frame
353 // again if the user is just adding to the search (making it more specific).
354 WTF::String m_lastSearchString;
356 // Keeps track of how many matches this frame has found so far, so that we
357 // don't loose count between scoping efforts, and is also used (in conjunction
358 // with m_lastSearchString and m_scopingComplete) to figure out if we need to
359 // search the frame again.
360 int m_lastMatchCount;
362 // This variable keeps a cumulative total of matches found so far for ALL the
363 // frames on the page, and is only incremented by calling IncreaseMatchCount
364 // (on the main frame only). It should be -1 for all other frames.
365 int m_totalMatchCount;
367 // This variable keeps a cumulative total of how many frames are currently
368 // scoping, and is incremented/decremented on the main frame only.
369 // It should be -1 for all other frames.
370 int m_framesScopingCount;
372 // Keeps track of whether the scoping effort was completed (the user may
373 // interrupt it before it completes by submitting a new search).
374 bool m_scopingComplete;
376 // Keeps track of when the scoping effort should next invalidate the scrollbar
377 // and the frame area.
378 int m_nextInvalidateAfter;
380 // A list of all of the pending calls to scopeStringMatches.
381 Vector<DeferredScopeStringMatches*> m_deferredScopingWork;
383 // Valid between calls to BeginPrint() and EndPrint(). Containts the print
384 // information. Is used by PrintPage().
385 OwnPtr<ChromePrintContext> m_printContext;
387 // Keeps a reference to the frame's WebAnimationController.
388 WebAnimationControllerImpl m_animationController;
390 // The identifier of this frame.
391 long long m_identifier;
393 // Ensure we don't overwrite valid history data during same document loads
395 bool m_inSameDocumentHistoryLoad;
398 } // namespace WebKit