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