| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006 Apple Computer, 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 | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef WEBKIT_GLUE_WEBFRAME_IMPL_H_ | |
| 27 #define WEBKIT_GLUE_WEBFRAME_IMPL_H_ | |
| 28 | |
| 29 #include "Frame.h" | |
| 30 #include "PlatformString.h" | |
| 31 #include <wtf/OwnPtr.h> | |
| 32 #include <wtf/RefCounted.h> | |
| 33 | |
| 34 #include "webkit/api/public/WebFrame.h" | |
| 35 #include "webkit/glue/webframeloaderclient_impl.h" | |
| 36 | |
| 37 class ChromePrintContext; | |
| 38 class WebViewImpl; | |
| 39 | |
| 40 namespace gfx { | |
| 41 class BitmapPlatformDevice; | |
| 42 } | |
| 43 | |
| 44 namespace WebCore { | |
| 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 PasswordAutocompleteListener; | |
| 55 class WebDataSourceImpl; | |
| 56 class WebFrameClient; | |
| 57 class WebView; | |
| 58 } | |
| 59 | |
| 60 // Implementation of WebFrame, note that this is a reference counted object. | |
| 61 class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { | |
| 62 public: | |
| 63 // WebFrame methods: | |
| 64 virtual WebKit::WebString name() const; | |
| 65 virtual WebKit::WebURL url() const; | |
| 66 virtual WebKit::WebURL favIconURL() const; | |
| 67 virtual WebKit::WebURL openSearchDescriptionURL() const; | |
| 68 virtual WebKit::WebSize scrollOffset() const; | |
| 69 virtual WebKit::WebSize contentsSize() const; | |
| 70 virtual int contentsPreferredWidth() const; | |
| 71 virtual bool hasVisibleContent() const; | |
| 72 virtual WebKit::WebView* view() const; | |
| 73 virtual WebKit::WebFrame* opener() const; | |
| 74 virtual WebKit::WebFrame* parent() const; | |
| 75 virtual WebKit::WebFrame* top() const; | |
| 76 virtual WebKit::WebFrame* firstChild() const; | |
| 77 virtual WebKit::WebFrame* lastChild() const; | |
| 78 virtual WebKit::WebFrame* nextSibling() const; | |
| 79 virtual WebKit::WebFrame* previousSibling() const; | |
| 80 virtual WebKit::WebFrame* traverseNext(bool wrap) const; | |
| 81 virtual WebKit::WebFrame* traversePrevious(bool wrap) const; | |
| 82 virtual WebKit::WebFrame* findChildByName(const WebKit::WebString& name) const
; | |
| 83 virtual WebKit::WebFrame* findChildByExpression( | |
| 84 const WebKit::WebString& xpath) const; | |
| 85 virtual void forms(WebKit::WebVector<WebKit::WebForm>&) const; | |
| 86 virtual WebKit::WebSecurityOrigin securityOrigin() const; | |
| 87 virtual void grantUniversalAccess(); | |
| 88 virtual NPObject* windowObject() const; | |
| 89 virtual void bindToWindowObject( | |
| 90 const WebKit::WebString& name, NPObject* object); | |
| 91 virtual void executeScript(const WebKit::WebScriptSource&); | |
| 92 virtual void executeScriptInNewContext( | |
| 93 const WebKit::WebScriptSource* sources, unsigned num_sources, | |
| 94 int extension_group); | |
| 95 virtual void executeScriptInIsolatedWorld( | |
| 96 int world_id, const WebKit::WebScriptSource* sources, | |
| 97 unsigned num_sources, int extension_group); | |
| 98 virtual void addMessageToConsole(const WebKit::WebConsoleMessage&); | |
| 99 virtual void collectGarbage(); | |
| 100 #if WEBKIT_USING_V8 | |
| 101 virtual v8::Local<v8::Context> mainWorldScriptContext() const; | |
| 102 #endif | |
| 103 virtual bool insertStyleText( | |
| 104 const WebKit::WebString& css, const WebKit::WebString& id); | |
| 105 virtual void reload(); | |
| 106 virtual void loadRequest(const WebKit::WebURLRequest& request); | |
| 107 virtual void loadHistoryItem(const WebKit::WebHistoryItem& history_item); | |
| 108 virtual void loadData( | |
| 109 const WebKit::WebData& data, const WebKit::WebString& mime_type, | |
| 110 const WebKit::WebString& text_encoding, const WebKit::WebURL& base_url, | |
| 111 const WebKit::WebURL& unreachable_url, bool replace); | |
| 112 virtual void loadHTMLString( | |
| 113 const WebKit::WebData& html, const WebKit::WebURL& base_url, | |
| 114 const WebKit::WebURL& unreachable_url, bool replace); | |
| 115 virtual bool isLoading() const; | |
| 116 virtual void stopLoading(); | |
| 117 virtual WebKit::WebDataSource* provisionalDataSource() const; | |
| 118 virtual WebKit::WebDataSource* dataSource() const; | |
| 119 virtual WebKit::WebHistoryItem previousHistoryItem() const; | |
| 120 virtual WebKit::WebHistoryItem currentHistoryItem() const; | |
| 121 virtual void enableViewSourceMode(bool enable); | |
| 122 virtual bool isViewSourceModeEnabled() const; | |
| 123 virtual void setReferrerForRequest( | |
| 124 WebKit::WebURLRequest& request, const WebKit::WebURL& referrer); | |
| 125 virtual void dispatchWillSendRequest(WebKit::WebURLRequest& request); | |
| 126 virtual void commitDocumentData(const char* data, size_t length); | |
| 127 virtual unsigned unloadListenerCount() const; | |
| 128 virtual bool isProcessingUserGesture() const; | |
| 129 virtual bool willSuppressOpenerInNewFrame() const; | |
| 130 virtual void replaceSelection(const WebKit::WebString& text); | |
| 131 virtual void insertText(const WebKit::WebString& text); | |
| 132 virtual void setMarkedText( | |
| 133 const WebKit::WebString& text, unsigned location, unsigned length); | |
| 134 virtual void unmarkText(); | |
| 135 virtual bool hasMarkedText() const; | |
| 136 virtual WebKit::WebRange markedRange() const; | |
| 137 virtual bool executeCommand(const WebKit::WebString& command); | |
| 138 virtual bool executeCommand( | |
| 139 const WebKit::WebString& command, const WebKit::WebString& value); | |
| 140 virtual bool isCommandEnabled(const WebKit::WebString& command) const; | |
| 141 virtual void enableContinuousSpellChecking(bool enable); | |
| 142 virtual bool isContinuousSpellCheckingEnabled() const; | |
| 143 virtual bool hasSelection() const; | |
| 144 virtual WebKit::WebRange selectionRange() const; | |
| 145 virtual WebKit::WebString selectionAsText() const; | |
| 146 virtual WebKit::WebString selectionAsMarkup() const; | |
| 147 virtual int printBegin(const WebKit::WebSize& page_size); | |
| 148 virtual float printPage(int page_to_print, WebKit::WebCanvas* canvas); | |
| 149 virtual float getPrintPageShrink(int page); | |
| 150 virtual void printEnd(); | |
| 151 virtual bool find( | |
| 152 int identifier, const WebKit::WebString& search_text, | |
| 153 const WebKit::WebFindOptions& options, bool wrap_within_frame, | |
| 154 WebKit::WebRect* selection_rect); | |
| 155 virtual void stopFinding(bool clear_selection); | |
| 156 virtual void scopeStringMatches( | |
| 157 int identifier, const WebKit::WebString& search_text, | |
| 158 const WebKit::WebFindOptions& options, bool reset); | |
| 159 virtual void cancelPendingScopingEffort(); | |
| 160 virtual void increaseMatchCount(int count, int identifier); | |
| 161 virtual void resetMatchCount(); | |
| 162 virtual WebKit::WebURL completeURL(const WebKit::WebString& url) const; | |
| 163 virtual WebKit::WebString contentAsText(size_t max_chars) const; | |
| 164 virtual WebKit::WebString contentAsMarkup() const; | |
| 165 | |
| 166 static PassRefPtr<WebFrameImpl> create(WebKit::WebFrameClient* client); | |
| 167 ~WebFrameImpl(); | |
| 168 | |
| 169 static int live_object_count() { | |
| 170 return live_object_count_; | |
| 171 } | |
| 172 | |
| 173 // Called by the WebViewImpl to initialize its main frame: | |
| 174 void InitMainFrame(WebViewImpl* webview_impl); | |
| 175 | |
| 176 PassRefPtr<WebCore::Frame> CreateChildFrame( | |
| 177 const WebCore::FrameLoadRequest&, | |
| 178 WebCore::HTMLFrameOwnerElement* owner_element); | |
| 179 | |
| 180 void Layout(); | |
| 181 void Paint(WebKit::WebCanvas* canvas, const WebKit::WebRect& rect); | |
| 182 | |
| 183 void CreateFrameView(); | |
| 184 | |
| 185 WebCore::Frame* frame() const { | |
| 186 return frame_; | |
| 187 } | |
| 188 | |
| 189 static WebFrameImpl* FromFrame(WebCore::Frame* frame); | |
| 190 | |
| 191 WebViewImpl* GetWebViewImpl() const; | |
| 192 | |
| 193 WebCore::FrameView* frameview() const { | |
| 194 return frame_ ? frame_->view() : NULL; | |
| 195 } | |
| 196 | |
| 197 // Getters for the impls corresponding to Get(Provisional)DataSource. They | |
| 198 // may return NULL if there is no corresponding data source. | |
| 199 WebKit::WebDataSourceImpl* GetDataSourceImpl() const; | |
| 200 WebKit::WebDataSourceImpl* GetProvisionalDataSourceImpl() const; | |
| 201 | |
| 202 // Returns which frame has an active match. This function should only be | |
| 203 // called on the main frame, as it is the only frame keeping track. Returned | |
| 204 // value can be NULL if no frame has an active match. | |
| 205 const WebFrameImpl* active_match_frame() const { | |
| 206 return active_match_frame_; | |
| 207 } | |
| 208 | |
| 209 // When a Find operation ends, we want to set the selection to what was active | |
| 210 // and set focus to the first focusable node we find (starting with the first | |
| 211 // node in the matched range and going up the inheritance chain). If we find | |
| 212 // nothing to focus we focus the first focusable node in the range. This | |
| 213 // allows us to set focus to a link (when we find text inside a link), which | |
| 214 // allows us to navigate by pressing Enter after closing the Find box. | |
| 215 void SetFindEndstateFocusAndSelection(); | |
| 216 | |
| 217 void DidFail(const WebCore::ResourceError& error, bool was_provisional); | |
| 218 | |
| 219 // Sets whether the WebFrameImpl allows its document to be scrolled. | |
| 220 // If the parameter is true, allow the document to be scrolled. | |
| 221 // Otherwise, disallow scrolling. | |
| 222 void SetAllowsScrolling(bool flag); | |
| 223 | |
| 224 // Registers a listener for the specified user name input element. The | |
| 225 // listener will receive notifications for blur and when autocomplete should | |
| 226 // be triggered. | |
| 227 // The WebFrameImpl becomes the owner of the passed listener. | |
| 228 void RegisterPasswordListener( | |
| 229 PassRefPtr<WebCore::HTMLInputElement> user_name_input_element, | |
| 230 WebKit::PasswordAutocompleteListener* listener); | |
| 231 | |
| 232 // Returns the password autocomplete listener associated with the passed | |
| 233 // user name input element, or NULL if none available. | |
| 234 // Note that the returned listener is owner by the WebFrameImpl and should not | |
| 235 // be kept around as it is deleted when the page goes away. | |
| 236 WebKit::PasswordAutocompleteListener* GetPasswordListener( | |
| 237 WebCore::HTMLInputElement* user_name_input_element); | |
| 238 | |
| 239 WebKit::WebFrameClient* client() const { return client_handle_->client(); } | |
| 240 void drop_client() { client_handle_->drop_client(); } | |
| 241 | |
| 242 protected: | |
| 243 friend class WebFrameLoaderClient; | |
| 244 | |
| 245 // A weak reference to the WebFrameClient. Each WebFrame in the hierarchy | |
| 246 // owns a reference to a ClientHandle. When the main frame is destroyed, it | |
| 247 // clears the WebFrameClient. | |
| 248 class ClientHandle : public RefCounted<ClientHandle> { | |
| 249 public: | |
| 250 static PassRefPtr<ClientHandle> create(WebKit::WebFrameClient* client) { | |
| 251 return adoptRef(new ClientHandle(client)); | |
| 252 } | |
| 253 WebKit::WebFrameClient* client() { return client_; } | |
| 254 void drop_client() { client_ = NULL; } | |
| 255 private: | |
| 256 ClientHandle(WebKit::WebFrameClient* client) : client_(client) {} | |
| 257 WebKit::WebFrameClient* client_; | |
| 258 }; | |
| 259 | |
| 260 WebFrameImpl(PassRefPtr<ClientHandle> client_handle); | |
| 261 | |
| 262 // Informs the WebFrame that the Frame is being closed, called by the | |
| 263 // WebFrameLoaderClient | |
| 264 void Closing(); | |
| 265 | |
| 266 // Used to check for leaks of this object. | |
| 267 static int live_object_count_; | |
| 268 | |
| 269 WebFrameLoaderClient frame_loader_client_; | |
| 270 | |
| 271 RefPtr<ClientHandle> client_handle_; | |
| 272 | |
| 273 // This is a weak pointer to our corresponding WebCore frame. A reference to | |
| 274 // ourselves is held while frame_ is valid. See our Closing method. | |
| 275 WebCore::Frame* frame_; | |
| 276 | |
| 277 // A way for the main frame to keep track of which frame has an active | |
| 278 // match. Should be NULL for all other frames. | |
| 279 WebFrameImpl* active_match_frame_; | |
| 280 | |
| 281 // The range of the active match for the current frame. | |
| 282 RefPtr<WebCore::Range> active_match_; | |
| 283 | |
| 284 // The index of the active match. | |
| 285 int active_match_index_; | |
| 286 | |
| 287 // This flag is used by the scoping effort to determine if we need to figure | |
| 288 // out which rectangle is the active match. Once we find the active | |
| 289 // rectangle we clear this flag. | |
| 290 bool locating_active_rect_; | |
| 291 | |
| 292 // The scoping effort can time out and we need to keep track of where we | |
| 293 // ended our last search so we can continue from where we left of. | |
| 294 RefPtr<WebCore::Range> resume_scoping_from_range_; | |
| 295 | |
| 296 // Keeps track of the last string this frame searched for. This is used for | |
| 297 // short-circuiting searches in the following scenarios: When a frame has | |
| 298 // been searched and returned 0 results, we don't need to search that frame | |
| 299 // again if the user is just adding to the search (making it more specific). | |
| 300 string16 last_search_string_; | |
| 301 | |
| 302 // Keeps track of how many matches this frame has found so far, so that we | |
| 303 // don't loose count between scoping efforts, and is also used (in conjunction | |
| 304 // with last_search_string_ and scoping_complete_) to figure out if we need to | |
| 305 // search the frame again. | |
| 306 int last_match_count_; | |
| 307 | |
| 308 // This variable keeps a cumulative total of matches found so far for ALL the | |
| 309 // frames on the page, and is only incremented by calling IncreaseMatchCount | |
| 310 // (on the main frame only). It should be -1 for all other frames. | |
| 311 size_t total_matchcount_; | |
| 312 | |
| 313 // This variable keeps a cumulative total of how many frames are currently | |
| 314 // scoping, and is incremented/decremented on the main frame only. | |
| 315 // It should be -1 for all other frames. | |
| 316 int frames_scoping_count_; | |
| 317 | |
| 318 // Keeps track of whether the scoping effort was completed (the user may | |
| 319 // interrupt it before it completes by submitting a new search). | |
| 320 bool scoping_complete_; | |
| 321 | |
| 322 // Keeps track of when the scoping effort should next invalidate the scrollbar | |
| 323 // and the frame area. | |
| 324 int next_invalidate_after_; | |
| 325 | |
| 326 private: | |
| 327 class DeferredScopeStringMatches; | |
| 328 friend class DeferredScopeStringMatches; | |
| 329 | |
| 330 // A bit mask specifying area of the frame to invalidate. | |
| 331 enum AreaToInvalidate { | |
| 332 INVALIDATE_NOTHING = 0, | |
| 333 INVALIDATE_CONTENT_AREA = 1, | |
| 334 INVALIDATE_SCROLLBAR = 2, // vertical scrollbar only. | |
| 335 INVALIDATE_ALL = 3 // both content area and the scrollbar. | |
| 336 }; | |
| 337 | |
| 338 // Notifies the delegate about a new selection rect. | |
| 339 void ReportFindInPageSelection( | |
| 340 const WebKit::WebRect& selection_rect, int active_match_ordinal, | |
| 341 int identifier); | |
| 342 | |
| 343 // Invalidates a certain area within the frame. | |
| 344 void InvalidateArea(AreaToInvalidate area); | |
| 345 | |
| 346 // Add a WebKit TextMatch-highlight marker to nodes in a range. | |
| 347 void AddMarker(WebCore::Range* range, bool active_match); | |
| 348 | |
| 349 // Sets the markers within a range as active or inactive. | |
| 350 void SetMarkerActive(WebCore::Range* range, bool active); | |
| 351 | |
| 352 // Returns the ordinal of the first match in the frame specified. This | |
| 353 // function enumerates the frames, starting with the main frame and up to (but | |
| 354 // not including) the frame passed in as a parameter and counts how many | |
| 355 // matches have been found. | |
| 356 int OrdinalOfFirstMatchForFrame(WebFrameImpl* frame) const; | |
| 357 | |
| 358 // Determines whether the scoping effort is required for a particular frame. | |
| 359 // It is not necessary if the frame is invisible, for example, or if this | |
| 360 // is a repeat search that already returned nothing last time the same prefix | |
| 361 // was searched. | |
| 362 bool ShouldScopeMatches(const string16& search_text); | |
| 363 | |
| 364 // Queue up a deferred call to scopeStringMatches. | |
| 365 void ScopeStringMatchesSoon( | |
| 366 int identifier, const WebKit::WebString& search_text, | |
| 367 const WebKit::WebFindOptions& options, bool reset); | |
| 368 | |
| 369 // Called by a DeferredScopeStringMatches instance. | |
| 370 void CallScopeStringMatches( | |
| 371 DeferredScopeStringMatches* deferred, | |
| 372 int identifier, const WebKit::WebString& search_text, | |
| 373 const WebKit::WebFindOptions& options, bool reset); | |
| 374 | |
| 375 // Determines whether to invalidate the content area and scrollbar. | |
| 376 void InvalidateIfNecessary(); | |
| 377 | |
| 378 // Clears the map of password listeners. | |
| 379 void ClearPasswordListeners(); | |
| 380 | |
| 381 void LoadJavaScriptURL(const WebCore::KURL& url); | |
| 382 | |
| 383 // A list of all of the pending calls to scopeStringMatches. | |
| 384 Vector<DeferredScopeStringMatches*> deferred_scoping_work_; | |
| 385 | |
| 386 // Valid between calls to BeginPrint() and EndPrint(). Containts the print | |
| 387 // information. Is used by PrintPage(). | |
| 388 OwnPtr<ChromePrintContext> print_context_; | |
| 389 | |
| 390 // The input fields that are interested in edit events and their associated | |
| 391 // listeners. | |
| 392 typedef HashMap<RefPtr<WebCore::HTMLInputElement>, | |
| 393 WebKit::PasswordAutocompleteListener*> PasswordListenerMap; | |
| 394 PasswordListenerMap password_listeners_; | |
| 395 }; | |
| 396 | |
| 397 #endif // WEBKIT_GLUE_WEBFRAME_IMPL_H_ | |
| OLD | NEW |