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 WebLocalFrameImpl_h 32 #define WebLocalFrameImpl_h 33 34 #include "core/frame/LocalFrame.h" 35 #include "platform/geometry/FloatRect.h" 36 #include "public/platform/WebFileSystemType.h" 37 #include "public/web/WebLocalFrame.h" 38 #include "web/FrameLoaderClientImpl.h" 39 #include "web/NotificationPresenterImpl.h" 40 #include "web/UserMediaClientImpl.h" 41 #include "wtf/Compiler.h" 42 #include "wtf/OwnPtr.h" 43 #include "wtf/RefCounted.h" 44 #include "wtf/text/WTFString.h" 45 46 namespace blink { 47 48 class ChromePrintContext; 49 class GeolocationClientProxy; 50 class GraphicsContext; 51 class HTMLInputElement; 52 class HistoryItem; 53 class IntSize; 54 class KURL; 55 class Node; 56 class Range; 57 class SharedWorkerRepositoryClientImpl; 58 class SubstituteData; 59 class TextFinder; 60 class WebDataSourceImpl; 61 class WebInputElement; 62 class WebFrameClient; 63 class WebPerformance; 64 class WebPlugin; 65 class WebPluginContainerImpl; 66 class WebView; 67 class WebViewImpl; 68 struct FrameLoadRequest; 69 struct WebPrintParams; 70 struct WindowFeatures; 71 72 template <typename T> class WebVector; 73 74 // Implementation of WebFrame, note that this is a reference counted object. 75 class WebLocalFrameImpl FINAL : public RefCountedWillBeGarbageCollectedFinalized<WebLocalFrameImpl>, public WebLocalFrame { 76 public: 77 // WebFrame methods: 78 virtual bool isWebLocalFrame() const OVERRIDE; 79 virtual WebLocalFrame* toWebLocalFrame() OVERRIDE; 80 virtual bool isWebRemoteFrame() const OVERRIDE; 81 virtual WebRemoteFrame* toWebRemoteFrame() OVERRIDE; 82 virtual void close() OVERRIDE; 83 virtual WebString uniqueName() const OVERRIDE; 84 virtual WebString assignedName() const OVERRIDE; 85 virtual void setName(const WebString&) OVERRIDE; 86 virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const OVERRIDE; 87 virtual void setIsRemote(bool) OVERRIDE; 88 virtual void setRemoteWebLayer(WebLayer*) OVERRIDE; 89 virtual void setPermissionClient(WebPermissionClient*) OVERRIDE; 90 virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) OVERRIDE; 91 virtual WebSize scrollOffset() const OVERRIDE; 92 virtual void setScrollOffset(const WebSize&) OVERRIDE; 93 virtual WebSize minimumScrollOffset() const OVERRIDE; 94 virtual WebSize maximumScrollOffset() const OVERRIDE; 95 virtual WebSize contentsSize() const OVERRIDE; 96 virtual bool hasVisibleContent() const OVERRIDE; 97 virtual WebRect visibleContentRect() const OVERRIDE; 98 virtual bool hasHorizontalScrollbar() const OVERRIDE; 99 virtual bool hasVerticalScrollbar() const OVERRIDE; 100 virtual WebView* view() const OVERRIDE; 101 virtual void setOpener(WebFrame*) OVERRIDE; 102 virtual WebDocument document() const OVERRIDE; 103 virtual WebPerformance performance() const OVERRIDE; 104 virtual bool dispatchBeforeUnloadEvent() OVERRIDE; 105 virtual void dispatchUnloadEvent() OVERRIDE; 106 virtual NPObject* windowObject() const OVERRIDE; 107 virtual void bindToWindowObject(const WebString& name, NPObject*) OVERRIDE; 108 virtual void bindToWindowObject(const WebString& name, NPObject*, void*) OVERRIDE; 109 virtual void executeScript(const WebScriptSource&) OVERRIDE; 110 virtual void executeScriptInIsolatedWorld( 111 int worldID, const WebScriptSource* sources, unsigned numSources, 112 int extensionGroup) OVERRIDE; 113 virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) OVERRIDE; 114 virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) OVERRIDE; 115 virtual void setIsolatedWorldHumanReadableName(int worldID, const WebString&) OVERRIDE; 116 virtual void addMessageToConsole(const WebConsoleMessage&) OVERRIDE; 117 virtual void collectGarbage() OVERRIDE; 118 virtual bool checkIfRunInsecureContent(const WebURL&) const OVERRIDE; 119 virtual v8::Handle<v8::Value> executeScriptAndReturnValue( 120 const WebScriptSource&) OVERRIDE; 121 virtual void executeScriptInIsolatedWorld( 122 int worldID, const WebScriptSource* sourcesIn, unsigned numSources, 123 int extensionGroup, WebVector<v8::Local<v8::Value> >* results) OVERRIDE; 124 virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled( 125 v8::Handle<v8::Function>, 126 v8::Handle<v8::Value>, 127 int argc, 128 v8::Handle<v8::Value> argv[]) OVERRIDE; 129 virtual v8::Local<v8::Context> mainWorldScriptContext() const OVERRIDE; 130 virtual void reload(bool ignoreCache) OVERRIDE; 131 virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) OVERRIDE; 132 virtual void loadRequest(const WebURLRequest&) OVERRIDE; 133 virtual void loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy) OVERRIDE; 134 virtual void loadData( 135 const WebData&, const WebString& mimeType, const WebString& textEncoding, 136 const WebURL& baseURL, const WebURL& unreachableURL, bool replace) OVERRIDE; 137 virtual void loadHTMLString( 138 const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL, 139 bool replace) OVERRIDE; 140 virtual void stopLoading() OVERRIDE; 141 virtual WebDataSource* provisionalDataSource() const OVERRIDE; 142 virtual WebDataSource* dataSource() const OVERRIDE; 143 virtual void enableViewSourceMode(bool enable) OVERRIDE; 144 virtual bool isViewSourceModeEnabled() const OVERRIDE; 145 virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) OVERRIDE; 146 virtual void dispatchWillSendRequest(WebURLRequest&) OVERRIDE; 147 virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) OVERRIDE; 148 virtual unsigned unloadListenerCount() const OVERRIDE; 149 virtual void replaceSelection(const WebString&) OVERRIDE; 150 virtual void insertText(const WebString&) OVERRIDE; 151 virtual void setMarkedText(const WebString&, unsigned location, unsigned length) OVERRIDE; 152 virtual void unmarkText() OVERRIDE; 153 virtual bool hasMarkedText() const OVERRIDE; 154 virtual WebRange markedRange() const OVERRIDE; 155 virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const OVERRIDE; 156 virtual size_t characterIndexForPoint(const WebPoint&) const OVERRIDE; 157 virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) OVERRIDE; 158 virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) OVERRIDE; 159 virtual bool isCommandEnabled(const WebString&) const OVERRIDE; 160 virtual void enableContinuousSpellChecking(bool) OVERRIDE; 161 virtual bool isContinuousSpellCheckingEnabled() const OVERRIDE; 162 virtual void requestTextChecking(const WebElement&) OVERRIDE; 163 virtual void replaceMisspelledRange(const WebString&) OVERRIDE; 164 virtual void removeSpellingMarkers() OVERRIDE; 165 virtual bool hasSelection() const OVERRIDE; 166 virtual WebRange selectionRange() const OVERRIDE; 167 virtual WebString selectionAsText() const OVERRIDE; 168 virtual WebString selectionAsMarkup() const OVERRIDE; 169 virtual bool selectWordAroundCaret() OVERRIDE; 170 virtual void selectRange(const WebPoint& base, const WebPoint& extent) OVERRIDE; 171 virtual void selectRange(const WebRange&) OVERRIDE; 172 virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) OVERRIDE; 173 virtual void moveCaretSelection(const WebPoint&) OVERRIDE; 174 virtual bool setEditableSelectionOffsets(int start, int end) OVERRIDE; 175 virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) OVERRIDE; 176 virtual void extendSelectionAndDelete(int before, int after) OVERRIDE; 177 virtual void setCaretVisible(bool) OVERRIDE; 178 virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode) OVERRIDE; 179 virtual float printPage(int pageToPrint, WebCanvas*) OVERRIDE; 180 virtual float getPrintPageShrink(int page) OVERRIDE; 181 virtual void printEnd() OVERRIDE; 182 virtual bool isPrintScalingDisabledForPlugin(const WebNode&) OVERRIDE; 183 virtual int getPrintCopiesForPlugin(const WebNode&) OVERRIDE; 184 virtual bool hasCustomPageSizeStyle(int pageIndex) OVERRIDE; 185 virtual bool isPageBoxVisible(int pageIndex) OVERRIDE; 186 virtual void pageSizeAndMarginsInPixels( 187 int pageIndex, 188 WebSize& pageSize, 189 int& marginTop, 190 int& marginRight, 191 int& marginBottom, 192 int& marginLeft) OVERRIDE; 193 virtual WebString pageProperty(const WebString& propertyName, int pageIndex) OVERRIDE; 194 virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) OVERRIDE; 195 virtual bool find( 196 int identifier, const WebString& searchText, const WebFindOptions&, 197 bool wrapWithinFrame, WebRect* selectionRect) OVERRIDE; 198 virtual void stopFinding(bool clearSelection) OVERRIDE; 199 virtual void scopeStringMatches( 200 int identifier, const WebString& searchText, const WebFindOptions&, 201 bool reset) OVERRIDE; 202 virtual void cancelPendingScopingEffort() OVERRIDE; 203 virtual void increaseMatchCount(int count, int identifier) OVERRIDE; 204 virtual void resetMatchCount() OVERRIDE; 205 virtual int findMatchMarkersVersion() const OVERRIDE; 206 virtual WebFloatRect activeFindMatchRect() OVERRIDE; 207 virtual void findMatchRects(WebVector<WebFloatRect>&) OVERRIDE; 208 virtual int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect) OVERRIDE; 209 virtual void setTickmarks(const WebVector<WebRect>&) OVERRIDE; 210 211 virtual void dispatchMessageEventWithOriginCheck( 212 const WebSecurityOrigin& intendedTargetOrigin, 213 const WebDOMEvent&) OVERRIDE; 214 215 virtual WebString contentAsText(size_t maxChars) const OVERRIDE; 216 virtual WebString contentAsMarkup() const OVERRIDE; 217 virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const OVERRIDE; 218 virtual WebString markerTextForListItem(const WebElement&) const OVERRIDE; 219 virtual WebRect selectionBoundsRect() const OVERRIDE; 220 221 virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const OVERRIDE; 222 virtual WebString layerTreeAsText(bool showDebugInfo = false) const OVERRIDE; 223 224 // WebLocalFrame methods: 225 virtual void sendPings(const WebNode& linkNode, const WebURL& destinationURL) OVERRIDE; 226 virtual bool isLoading() const OVERRIDE; 227 virtual bool isResourceLoadInProgress() const OVERRIDE; 228 virtual void addStyleSheetByURL(const WebString& url) OVERRIDE; 229 virtual void navigateToSandboxedMarkup(const WebData& markup) OVERRIDE; 230 virtual void sendOrientationChangeEvent() OVERRIDE; 231 virtual v8::Handle<v8::Value> executeScriptAndReturnValueForTests( 232 const WebScriptSource&) OVERRIDE; 233 234 void willDetachParent(); 235 236 static WebLocalFrameImpl* create(WebFrameClient*); 237 virtual ~WebLocalFrameImpl(); 238 239 PassRefPtrWillBeRawPtr<LocalFrame> initializeCoreFrame(FrameHost*, FrameOwner*, const AtomicString& name, const AtomicString& fallbackName); 240 241 PassRefPtrWillBeRawPtr<LocalFrame> createChildFrame(const FrameLoadRequest&, HTMLFrameOwnerElement*); 242 243 void didChangeContentsSize(const IntSize&); 244 245 void createFrameView(); 246 247 static WebLocalFrameImpl* fromFrame(LocalFrame*); 248 static WebLocalFrameImpl* fromFrame(LocalFrame&); 249 static WebLocalFrameImpl* fromFrameOwnerElement(Element*); 250 251 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl 252 // that hosts the plugin. 253 static WebPluginContainerImpl* pluginContainerFromFrame(LocalFrame*); 254 255 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl 256 // that hosts the plugin. If the provided node is a plugin, then it runs its 257 // WebPluginContainerImpl. 258 static WebPluginContainerImpl* pluginContainerFromNode(LocalFrame*, const WebNode&); 259 260 WebViewImpl* viewImpl() const; 261 frameView()262 FrameView* frameView() const { return frame() ? frame()->view() : 0; } 263 264 // Getters for the impls corresponding to Get(Provisional)DataSource. They 265 // may return 0 if there is no corresponding data source. 266 WebDataSourceImpl* dataSourceImpl() const; 267 WebDataSourceImpl* provisionalDataSourceImpl() const; 268 269 // Returns which frame has an active match. This function should only be 270 // called on the main frame, as it is the only frame keeping track. Returned 271 // value can be 0 if no frame has an active match. 272 WebLocalFrameImpl* activeMatchFrame() const; 273 274 // Returns the active match in the current frame. Could be a null range if 275 // the local frame has no active match. 276 Range* activeMatch() const; 277 278 // When a Find operation ends, we want to set the selection to what was active 279 // and set focus to the first focusable node we find (starting with the first 280 // node in the matched range and going up the inheritance chain). If we find 281 // nothing to focus we focus the first focusable node in the range. This 282 // allows us to set focus to a link (when we find text inside a link), which 283 // allows us to navigate by pressing Enter after closing the Find box. 284 void setFindEndstateFocusAndSelection(); 285 286 void didFail(const ResourceError&, bool wasProvisional); 287 288 // Sets whether the WebLocalFrameImpl allows its document to be scrolled. 289 // If the parameter is true, allow the document to be scrolled. 290 // Otherwise, disallow scrolling. 291 virtual void setCanHaveScrollbars(bool) OVERRIDE; 292 frame()293 LocalFrame* frame() const { return m_frame.get(); } client()294 WebFrameClient* client() const { return m_client; } setClient(WebFrameClient * client)295 void setClient(WebFrameClient* client) { m_client = client; } 296 permissionClient()297 WebPermissionClient* permissionClient() { return m_permissionClient; } sharedWorkerRepositoryClient()298 SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { return m_sharedWorkerRepositoryClient.get(); } 299 300 void setInputEventsTransformForEmulation(const IntSize&, float); 301 302 static void selectWordAroundPosition(LocalFrame*, VisiblePosition); 303 304 // Returns the text finder object if it already exists. 305 // Otherwise creates it and then returns. 306 TextFinder& ensureTextFinder(); 307 308 // Invalidates vertical scrollbar only. 309 void invalidateScrollbar() const; 310 311 // Invalidates both content area and the scrollbar. 312 void invalidateAll() const; 313 314 // Returns a hit-tested VisiblePosition for the given point 315 VisiblePosition visiblePositionForWindowPoint(const WebPoint&); 316 317 void trace(Visitor*); 318 319 private: 320 friend class FrameLoaderClientImpl; 321 322 explicit WebLocalFrameImpl(WebFrameClient*); 323 324 // Sets the local core frame and registers destruction observers. 325 void setCoreFrame(PassRefPtrWillBeRawPtr<LocalFrame>); 326 327 void loadJavaScriptURL(const KURL&); 328 329 WebPlugin* focusedPluginIfInputMethodSupported(); 330 331 FrameLoaderClientImpl m_frameLoaderClientImpl; 332 333 // The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This 334 // reference is released when the frame is removed from the DOM or the entire page is closed. 335 // FIXME: These will need to change to WebFrame when we introduce WebFrameProxy. 336 RefPtrWillBeMember<LocalFrame> m_frame; 337 338 // Indicate whether the current LocalFrame is local or remote. Remote frames are 339 // rendered in a different process from their parent frames. 340 bool m_isRemote; 341 342 WebFrameClient* m_client; 343 WebPermissionClient* m_permissionClient; 344 OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient; 345 346 // Will be initialized after first call to find() or scopeStringMatches(). 347 OwnPtr<TextFinder> m_textFinder; 348 349 // Valid between calls to BeginPrint() and EndPrint(). Containts the print 350 // information. Is used by PrintPage(). 351 OwnPtrWillBeMember<ChromePrintContext> m_printContext; 352 353 // Stores the additional input events offset and scale when device metrics emulation is enabled. 354 IntSize m_inputEventsOffsetForEmulation; 355 float m_inputEventsScaleFactorForEmulation; 356 357 UserMediaClientImpl m_userMediaClientImpl; 358 359 OwnPtrWillBeMember<GeolocationClientProxy> m_geolocationClientProxy; 360 361 #if ENABLE(OILPAN) 362 // Oilpan: to provide the guarantee of having the frame live until 363 // close() is called, an instance keep a self-persistent. It is 364 // cleared upon calling close(). This avoids having to assume that 365 // an embedder's WebFrame references are all discovered via thread 366 // state (stack, registers) should an Oilpan GC strike while we're 367 // in the process of detaching. 368 GC_PLUGIN_IGNORE("340522") 369 Persistent<WebLocalFrameImpl> m_selfKeepAlive; 370 #endif 371 }; 372 373 DEFINE_TYPE_CASTS(WebLocalFrameImpl, WebFrame, frame, frame->isWebLocalFrame(), frame.isWebLocalFrame()); 374 375 } // namespace blink 376 377 #endif 378