|
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 WebFrameImpl_h |
|
32 #define WebFrameImpl_h |
|
33 |
|
34 #include "WebAnimationControllerImpl.h" |
|
35 #include "WebFrame.h" |
|
36 |
|
37 #include "Frame.h" |
|
38 #include "FrameLoaderClientImpl.h" |
|
39 #include "PlatformString.h" |
|
40 #include <wtf/OwnPtr.h> |
|
41 #include <wtf/RefCounted.h> |
|
42 |
|
43 namespace WebCore { |
|
44 class GraphicsContext; |
|
45 class HistoryItem; |
|
46 class KURL; |
|
47 class Node; |
|
48 class Range; |
|
49 class SubstituteData; |
|
50 struct WindowFeatures; |
|
51 } |
|
52 |
|
53 namespace WebKit { |
|
54 class ChromePrintContext; |
|
55 class WebDataSourceImpl; |
|
56 class WebInputElement; |
|
57 class WebFrameClient; |
|
58 class WebPasswordAutocompleteListener; |
|
59 class WebPluginContainerImpl; |
|
60 class WebView; |
|
61 class WebViewImpl; |
|
62 |
|
63 // Implementation of WebFrame, note that this is a reference counted object. |
|
64 class WebFrameImpl : public WebFrame, public RefCounted<WebFrameImpl> { |
|
65 public: |
|
66 // WebFrame methods: |
|
67 virtual WebString name() const; |
|
68 virtual void setName(const WebString&); |
|
69 virtual WebURL url() const; |
|
70 virtual WebURL favIconURL() const; |
|
71 virtual WebURL openSearchDescriptionURL() const; |
|
72 virtual WebString encoding() const; |
|
73 virtual WebSize scrollOffset() const; |
|
74 virtual WebSize contentsSize() const; |
|
75 virtual int contentsPreferredWidth() const; |
|
76 virtual int documentElementScrollHeight() const; |
|
77 virtual bool hasVisibleContent() const; |
|
78 virtual WebView* view() const; |
|
79 virtual WebFrame* opener() const; |
|
80 virtual WebFrame* parent() const; |
|
81 virtual WebFrame* top() const; |
|
82 virtual WebFrame* firstChild() const; |
|
83 virtual WebFrame* lastChild() const; |
|
84 virtual WebFrame* nextSibling() const; |
|
85 virtual WebFrame* previousSibling() const; |
|
86 virtual WebFrame* traverseNext(bool wrap) const; |
|
87 virtual WebFrame* traversePrevious(bool wrap) const; |
|
88 virtual WebFrame* findChildByName(const WebString&) const; |
|
89 virtual WebFrame* findChildByExpression(const WebString&) const; |
|
90 virtual WebDocument document() const; |
|
91 virtual void forms(WebVector<WebFormElement>&) const; |
|
92 virtual WebAnimationController* animationController(); |
|
93 virtual WebSecurityOrigin securityOrigin() const; |
|
94 virtual void grantUniversalAccess(); |
|
95 virtual NPObject* windowObject() const; |
|
96 virtual void bindToWindowObject(const WebString& name, NPObject*); |
|
97 virtual void executeScript(const WebScriptSource&); |
|
98 virtual void executeScriptInIsolatedWorld( |
|
99 int worldId, const WebScriptSource* sources, unsigned numSources, |
|
100 int extensionGroup); |
|
101 virtual void addMessageToConsole(const WebConsoleMessage&); |
|
102 virtual void collectGarbage(); |
|
103 #if WEBKIT_USING_V8 |
|
104 virtual v8::Handle<v8::Value> executeScriptAndReturnValue( |
|
105 const WebScriptSource&); |
|
106 virtual v8::Local<v8::Context> mainWorldScriptContext() const; |
|
107 #endif |
|
108 virtual bool insertStyleText(const WebString& css, const WebString& id); |
|
109 virtual void reload(bool ignoreCache); |
|
110 virtual void loadRequest(const WebURLRequest&); |
|
111 virtual void loadHistoryItem(const WebHistoryItem&); |
|
112 virtual void loadData( |
|
113 const WebData&, const WebString& mimeType, const WebString& textEncoding, |
|
114 const WebURL& baseURL, const WebURL& unreachableURL, bool replace); |
|
115 virtual void loadHTMLString( |
|
116 const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL, |
|
117 bool replace); |
|
118 virtual bool isLoading() const; |
|
119 virtual void stopLoading(); |
|
120 virtual WebDataSource* provisionalDataSource() const; |
|
121 virtual WebDataSource* dataSource() const; |
|
122 virtual WebHistoryItem previousHistoryItem() const; |
|
123 virtual WebHistoryItem currentHistoryItem() const; |
|
124 virtual void enableViewSourceMode(bool enable); |
|
125 virtual bool isViewSourceModeEnabled() const; |
|
126 virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer); |
|
127 virtual void dispatchWillSendRequest(WebURLRequest&); |
|
128 virtual void commitDocumentData(const char* data, size_t length); |
|
129 virtual unsigned unloadListenerCount() const; |
|
130 virtual bool isProcessingUserGesture() const; |
|
131 virtual bool willSuppressOpenerInNewFrame() const; |
|
132 virtual void replaceSelection(const WebString&); |
|
133 virtual void insertText(const WebString&); |
|
134 virtual void setMarkedText(const WebString&, unsigned location, unsigned length); |
|
135 virtual void unmarkText(); |
|
136 virtual bool hasMarkedText() const; |
|
137 virtual WebRange markedRange() const; |
|
138 virtual bool executeCommand(const WebString&); |
|
139 virtual bool executeCommand(const WebString&, const WebString& value); |
|
140 virtual bool isCommandEnabled(const WebString&) const; |
|
141 virtual void enableContinuousSpellChecking(bool); |
|
142 virtual bool isContinuousSpellCheckingEnabled() const; |
|
143 virtual bool hasSelection() const; |
|
144 virtual WebRange selectionRange() const; |
|
145 virtual WebString selectionAsText() const; |
|
146 virtual WebString selectionAsMarkup() const; |
|
147 virtual bool selectWordAroundCaret(); |
|
148 virtual int printBegin(const WebSize& pageSize, int printerDPI, |
|
149 bool* useBrowserOverlays); |
|
150 virtual float printPage(int pageToPrint, WebCanvas*); |
|
151 virtual float getPrintPageShrink(int page); |
|
152 virtual void printEnd(); |
|
153 virtual bool isPageBoxVisible(int pageIndex); |
|
154 virtual void pageSizeAndMarginsInPixels(int pageIndex, |
|
155 WebSize& pageSize, |
|
156 int& marginTop, |
|
157 int& marginRight, |
|
158 int& marginBottom, |
|
159 int& marginLeft); |
|
160 virtual bool find( |
|
161 int identifier, const WebString& searchText, const WebFindOptions&, |
|
162 bool wrapWithinFrame, WebRect* selectionRect); |
|
163 virtual void stopFinding(bool clearSelection); |
|
164 virtual void scopeStringMatches( |
|
165 int identifier, const WebString& searchText, const WebFindOptions&, |
|
166 bool reset); |
|
167 virtual void cancelPendingScopingEffort(); |
|
168 virtual void increaseMatchCount(int count, int identifier); |
|
169 virtual void resetMatchCount(); |
|
170 virtual bool registerPasswordListener( |
|
171 WebInputElement, WebPasswordAutocompleteListener*); |
|
172 virtual void notifiyPasswordListenerOfAutocomplete( |
|
173 const WebInputElement&); |
|
174 |
|
175 virtual WebString contentAsText(size_t maxChars) const; |
|
176 virtual WebString contentAsMarkup() const; |
|
177 virtual WebString renderTreeAsText() const; |
|
178 virtual WebString counterValueForElementById(const WebString& id) const; |
|
179 virtual int pageNumberForElementById(const WebString& id, |
|
180 float pageWidthInPixels, |
|
181 float pageHeightInPixels) const; |
|
182 virtual WebRect selectionBoundsRect() const; |
|
183 |
|
184 static PassRefPtr<WebFrameImpl> create(WebFrameClient* client); |
|
185 ~WebFrameImpl(); |
|
186 |
|
187 // Called by the WebViewImpl to initialize its main frame: |
|
188 void initializeAsMainFrame(WebViewImpl*); |
|
189 |
|
190 PassRefPtr<WebCore::Frame> createChildFrame( |
|
191 const WebCore::FrameLoadRequest&, WebCore::HTMLFrameOwnerElement*); |
|
192 |
|
193 void layout(); |
|
194 void paint(WebCanvas*, const WebRect&); |
|
195 void paintWithContext(WebCore::GraphicsContext&, const WebRect&); |
|
196 void createFrameView(); |
|
197 |
|
198 static WebFrameImpl* fromFrame(WebCore::Frame* frame); |
|
199 static WebFrameImpl* fromFrameOwnerElement(WebCore::Element* element); |
|
200 |
|
201 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl |
|
202 // that hosts the plugin. |
|
203 static WebPluginContainerImpl* pluginContainerFromFrame(WebCore::Frame*); |
|
204 |
|
205 WebViewImpl* viewImpl() const; |
|
206 |
|
207 WebCore::Frame* frame() const { return m_frame; } |
|
208 WebCore::FrameView* frameView() const { return m_frame ? m_frame->view() : 0; } |
|
209 |
|
210 // Getters for the impls corresponding to Get(Provisional)DataSource. They |
|
211 // may return 0 if there is no corresponding data source. |
|
212 WebDataSourceImpl* dataSourceImpl() const; |
|
213 WebDataSourceImpl* provisionalDataSourceImpl() const; |
|
214 |
|
215 // Returns which frame has an active match. This function should only be |
|
216 // called on the main frame, as it is the only frame keeping track. Returned |
|
217 // value can be 0 if no frame has an active match. |
|
218 const WebFrameImpl* activeMatchFrame() const { return m_activeMatchFrame; } |
|
219 |
|
220 // When a Find operation ends, we want to set the selection to what was active |
|
221 // and set focus to the first focusable node we find (starting with the first |
|
222 // node in the matched range and going up the inheritance chain). If we find |
|
223 // nothing to focus we focus the first focusable node in the range. This |
|
224 // allows us to set focus to a link (when we find text inside a link), which |
|
225 // allows us to navigate by pressing Enter after closing the Find box. |
|
226 void setFindEndstateFocusAndSelection(); |
|
227 |
|
228 void didFail(const WebCore::ResourceError&, bool wasProvisional); |
|
229 |
|
230 // Sets whether the WebFrameImpl allows its document to be scrolled. |
|
231 // If the parameter is true, allow the document to be scrolled. |
|
232 // Otherwise, disallow scrolling. |
|
233 void setCanHaveScrollbars(bool); |
|
234 |
|
235 // Returns the password autocomplete listener associated with the passed |
|
236 // user name input element, or 0 if none available. |
|
237 // Note that the returned listener is owner by the WebFrameImpl and should not |
|
238 // be kept around as it is deleted when the page goes away. |
|
239 WebPasswordAutocompleteListener* getPasswordListener(const WebCore::HTMLInputElement*); |
|
240 |
|
241 WebFrameClient* client() const { return m_client; } |
|
242 void setClient(WebFrameClient* client) { m_client = client; } |
|
243 |
|
244 static void selectWordAroundPosition(WebCore::Frame*, WebCore::VisiblePosition); |
|
245 |
|
246 private: |
|
247 class DeferredScopeStringMatches; |
|
248 friend class DeferredScopeStringMatches; |
|
249 friend class FrameLoaderClientImpl; |
|
250 |
|
251 // A bit mask specifying area of the frame to invalidate. |
|
252 enum AreaToInvalidate { |
|
253 InvalidateNothing, |
|
254 InvalidateContentArea, |
|
255 InvalidateScrollbar, // Vertical scrollbar only. |
|
256 InvalidateAll // Both content area and the scrollbar. |
|
257 }; |
|
258 |
|
259 WebFrameImpl(WebFrameClient*); |
|
260 |
|
261 // Informs the WebFrame that the Frame is being closed, called by the |
|
262 // WebFrameLoaderClient |
|
263 void closing(); |
|
264 |
|
265 // Notifies the delegate about a new selection rect. |
|
266 void reportFindInPageSelection( |
|
267 const WebRect& selectionRect, int activeMatchOrdinal, int identifier); |
|
268 |
|
269 // Invalidates a certain area within the frame. |
|
270 void invalidateArea(AreaToInvalidate); |
|
271 |
|
272 // Add a WebKit TextMatch-highlight marker to nodes in a range. |
|
273 void addMarker(WebCore::Range*, bool activeMatch); |
|
274 |
|
275 // Sets the markers within a range as active or inactive. |
|
276 void setMarkerActive(WebCore::Range*, bool active); |
|
277 |
|
278 // Returns the ordinal of the first match in the frame specified. This |
|
279 // function enumerates the frames, starting with the main frame and up to (but |
|
280 // not including) the frame passed in as a parameter and counts how many |
|
281 // matches have been found. |
|
282 int ordinalOfFirstMatchForFrame(WebFrameImpl*) const; |
|
283 |
|
284 // Determines whether the scoping effort is required for a particular frame. |
|
285 // It is not necessary if the frame is invisible, for example, or if this |
|
286 // is a repeat search that already returned nothing last time the same prefix |
|
287 // was searched. |
|
288 bool shouldScopeMatches(const WebCore::String& searchText); |
|
289 |
|
290 // Queue up a deferred call to scopeStringMatches. |
|
291 void scopeStringMatchesSoon( |
|
292 int identifier, const WebString& searchText, const WebFindOptions&, |
|
293 bool reset); |
|
294 |
|
295 // Called by a DeferredScopeStringMatches instance. |
|
296 void callScopeStringMatches( |
|
297 DeferredScopeStringMatches*, int identifier, const WebString& searchText, |
|
298 const WebFindOptions&, bool reset); |
|
299 |
|
300 // Determines whether to invalidate the content area and scrollbar. |
|
301 void invalidateIfNecessary(); |
|
302 |
|
303 // Clears the map of password listeners. |
|
304 void clearPasswordListeners(); |
|
305 |
|
306 void loadJavaScriptURL(const WebCore::KURL&); |
|
307 |
|
308 FrameLoaderClientImpl m_frameLoaderClient; |
|
309 |
|
310 WebFrameClient* m_client; |
|
311 |
|
312 // This is a weak pointer to our corresponding WebCore frame. A reference to |
|
313 // ourselves is held while frame_ is valid. See our Closing method. |
|
314 WebCore::Frame* m_frame; |
|
315 |
|
316 // A way for the main frame to keep track of which frame has an active |
|
317 // match. Should be 0 for all other frames. |
|
318 WebFrameImpl* m_activeMatchFrame; |
|
319 |
|
320 // The range of the active match for the current frame. |
|
321 RefPtr<WebCore::Range> m_activeMatch; |
|
322 |
|
323 // The index of the active match. |
|
324 int m_activeMatchIndex; |
|
325 |
|
326 // This flag is used by the scoping effort to determine if we need to figure |
|
327 // out which rectangle is the active match. Once we find the active |
|
328 // rectangle we clear this flag. |
|
329 bool m_locatingActiveRect; |
|
330 |
|
331 // The scoping effort can time out and we need to keep track of where we |
|
332 // ended our last search so we can continue from where we left of. |
|
333 RefPtr<WebCore::Range> m_resumeScopingFromRange; |
|
334 |
|
335 // Keeps track of the last string this frame searched for. This is used for |
|
336 // short-circuiting searches in the following scenarios: When a frame has |
|
337 // been searched and returned 0 results, we don't need to search that frame |
|
338 // again if the user is just adding to the search (making it more specific). |
|
339 WebCore::String m_lastSearchString; |
|
340 |
|
341 // Keeps track of how many matches this frame has found so far, so that we |
|
342 // don't loose count between scoping efforts, and is also used (in conjunction |
|
343 // with m_lastSearchString and m_scopingComplete) to figure out if we need to |
|
344 // search the frame again. |
|
345 int m_lastMatchCount; |
|
346 |
|
347 // This variable keeps a cumulative total of matches found so far for ALL the |
|
348 // frames on the page, and is only incremented by calling IncreaseMatchCount |
|
349 // (on the main frame only). It should be -1 for all other frames. |
|
350 size_t m_totalMatchCount; |
|
351 |
|
352 // This variable keeps a cumulative total of how many frames are currently |
|
353 // scoping, and is incremented/decremented on the main frame only. |
|
354 // It should be -1 for all other frames. |
|
355 int m_framesScopingCount; |
|
356 |
|
357 // Keeps track of whether the scoping effort was completed (the user may |
|
358 // interrupt it before it completes by submitting a new search). |
|
359 bool m_scopingComplete; |
|
360 |
|
361 // Keeps track of when the scoping effort should next invalidate the scrollbar |
|
362 // and the frame area. |
|
363 int m_nextInvalidateAfter; |
|
364 |
|
365 // A list of all of the pending calls to scopeStringMatches. |
|
366 Vector<DeferredScopeStringMatches*> m_deferredScopingWork; |
|
367 |
|
368 // Valid between calls to BeginPrint() and EndPrint(). Containts the print |
|
369 // information. Is used by PrintPage(). |
|
370 OwnPtr<ChromePrintContext> m_printContext; |
|
371 |
|
372 // The input fields that are interested in edit events and their associated |
|
373 // listeners. |
|
374 typedef HashMap<RefPtr<WebCore::HTMLInputElement>, |
|
375 WebPasswordAutocompleteListener*> PasswordListenerMap; |
|
376 PasswordListenerMap m_passwordListeners; |
|
377 |
|
378 // Keeps a reference to the frame's WebAnimationController. |
|
379 WebAnimationControllerImpl m_animationController; |
|
380 }; |
|
381 |
|
382 } // namespace WebKit |
|
383 |
|
384 #endif |