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 WebLocalFrameImpl_h
32 #define WebLocalFrameImpl_h
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"
48 class ChromePrintContext;
49 class GeolocationClientProxy;
53 class ScriptSourceCode;
54 class SharedWorkerRepositoryClientImpl;
56 class WebDataSourceImpl;
60 class WebPluginContainerImpl;
61 class WebScriptExecutionCallback;
64 struct FrameLoadRequest;
65 struct WebPrintParams;
67 template <typename T> class WebVector;
69 // Implementation of WebFrame, note that this is a reference counted object.
70 class WebLocalFrameImpl final : public RefCountedWillBeGarbageCollectedFinalized<WebLocalFrameImpl>, public WebLocalFrame {
73 virtual bool isWebLocalFrame() const override;
74 virtual WebLocalFrame* toWebLocalFrame() override;
75 virtual bool isWebRemoteFrame() const override;
76 virtual WebRemoteFrame* toWebRemoteFrame() override;
77 virtual void close() override;
78 virtual WebString uniqueName() const override;
79 virtual WebString assignedName() const override;
80 virtual void setName(const WebString&) override;
81 virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const override;
82 virtual void setRemoteWebLayer(WebLayer*) override;
83 virtual void setPermissionClient(WebPermissionClient*) override;
84 virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) override;
85 virtual WebSize scrollOffset() const override;
86 virtual void setScrollOffset(const WebSize&) override;
87 virtual WebSize minimumScrollOffset() const override;
88 virtual WebSize maximumScrollOffset() const override;
89 virtual WebSize contentsSize() const override;
90 virtual bool hasVisibleContent() const override;
91 virtual WebRect visibleContentRect() const override;
92 virtual bool hasHorizontalScrollbar() const override;
93 virtual bool hasVerticalScrollbar() const override;
94 virtual WebView* view() const override;
95 virtual void setOpener(WebFrame*) override;
96 virtual WebDocument document() const override;
97 virtual WebPerformance performance() const override;
98 virtual bool dispatchBeforeUnloadEvent() override;
99 virtual void dispatchUnloadEvent() override;
100 virtual NPObject* windowObject() const override;
101 virtual void bindToWindowObject(const WebString& name, NPObject*) override;
102 virtual void bindToWindowObject(const WebString& name, NPObject*, void*) override;
103 virtual void executeScript(const WebScriptSource&) override;
104 virtual void executeScriptInIsolatedWorld(
105 int worldID, const WebScriptSource* sources, unsigned numSources,
106 int extensionGroup) override;
107 virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) override;
108 virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) override;
109 virtual void setIsolatedWorldHumanReadableName(int worldID, const WebString&) override;
110 virtual void addMessageToConsole(const WebConsoleMessage&) override;
111 virtual void collectGarbage() override;
112 virtual bool checkIfRunInsecureContent(const WebURL&) const override;
113 virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
114 const WebScriptSource&) override;
115 virtual void requestExecuteScriptAndReturnValue(
116 const WebScriptSource&, bool userGesture, WebScriptExecutionCallback*) override;
117 virtual void executeScriptInIsolatedWorld(
118 int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
119 int extensionGroup, WebVector<v8::Local<v8::Value> >* results) override;
120 virtual void requestExecuteScriptInIsolatedWorld(
121 int worldID, const WebScriptSource* sourceIn, unsigned numSources,
122 int extensionGroup, bool userGesture, WebScriptExecutionCallback*) override;
123 virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
124 v8::Handle<v8::Function>,
125 v8::Handle<v8::Value>,
127 v8::Handle<v8::Value> argv[]) override;
128 virtual v8::Local<v8::Context> mainWorldScriptContext() const override;
129 virtual void reload(bool ignoreCache) override;
130 virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) override;
131 virtual void loadRequest(const WebURLRequest&) override;
132 virtual void loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy) override;
133 virtual void loadData(
134 const WebData&, const WebString& mimeType, const WebString& textEncoding,
135 const WebURL& baseURL, const WebURL& unreachableURL, bool replace) override;
136 virtual void loadHTMLString(
137 const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
138 bool replace) override;
139 virtual void stopLoading() override;
140 virtual WebDataSource* provisionalDataSource() const override;
141 virtual WebDataSource* dataSource() const override;
142 virtual void enableViewSourceMode(bool enable) override;
143 virtual bool isViewSourceModeEnabled() const override;
144 virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) override;
145 virtual void dispatchWillSendRequest(WebURLRequest&) override;
146 virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) override;
147 virtual unsigned unloadListenerCount() const override;
148 virtual void replaceSelection(const WebString&) override;
149 virtual void insertText(const WebString&) override;
150 virtual void setMarkedText(const WebString&, unsigned location, unsigned length) override;
151 virtual void unmarkText() override;
152 virtual bool hasMarkedText() const override;
153 virtual WebRange markedRange() const override;
154 virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const override;
155 virtual size_t characterIndexForPoint(const WebPoint&) const override;
156 virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) override;
157 virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) override;
158 virtual bool isCommandEnabled(const WebString&) const override;
159 virtual void enableContinuousSpellChecking(bool) override;
160 virtual bool isContinuousSpellCheckingEnabled() const override;
161 virtual void requestTextChecking(const WebElement&) override;
162 virtual void replaceMisspelledRange(const WebString&) override;
163 virtual void removeSpellingMarkers() override;
164 virtual bool hasSelection() const override;
165 virtual WebRange selectionRange() const override;
166 virtual WebString selectionAsText() const override;
167 virtual WebString selectionAsMarkup() const override;
168 virtual bool selectWordAroundCaret() override;
169 virtual void selectRange(const WebPoint& base, const WebPoint& extent) override;
170 virtual void selectRange(const WebRange&) override;
171 virtual void moveRangeSelectionExtent(const WebPoint&) 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(
192 int& marginLeft) override;
193 virtual WebString pageProperty(const WebString& propertyName, int pageIndex) override;
194 virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) override;
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;
211 virtual void dispatchMessageEventWithOriginCheck(
212 const WebSecurityOrigin& intendedTargetOrigin,
213 const WebDOMEvent&) override;
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;
221 virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const override;
222 virtual WebString layerTreeAsText(bool showDebugInfo = false) const override;
224 // WebLocalFrame methods:
225 virtual void initializeToReplaceRemoteFrame(WebRemoteFrame*) override;
226 virtual void sendPings(const WebNode& linkNode, const WebURL& destinationURL) override;
227 virtual bool isLoading() const override;
228 virtual bool isResourceLoadInProgress() const override;
229 virtual void addStyleSheetByURL(const WebString& url) override;
230 virtual void navigateToSandboxedMarkup(const WebData& markup) override;
231 virtual void sendOrientationChangeEvent() override;
232 virtual v8::Handle<v8::Value> executeScriptAndReturnValueForTests(
233 const WebScriptSource&) override;
235 void willDetachParent();
237 static WebLocalFrameImpl* create(WebFrameClient*);
238 virtual ~WebLocalFrameImpl();
240 PassRefPtrWillBeRawPtr<LocalFrame> initializeCoreFrame(FrameHost*, FrameOwner*, const AtomicString& name, const AtomicString& fallbackName);
242 PassRefPtrWillBeRawPtr<LocalFrame> createChildFrame(const FrameLoadRequest&, HTMLFrameOwnerElement*);
244 void didChangeContentsSize(const IntSize&);
246 void createFrameView();
248 static WebLocalFrameImpl* fromFrame(LocalFrame*);
249 static WebLocalFrameImpl* fromFrame(LocalFrame&);
250 static WebLocalFrameImpl* fromFrameOwnerElement(Element*);
252 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
253 // that hosts the plugin.
254 static WebPluginContainerImpl* pluginContainerFromFrame(LocalFrame*);
256 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
257 // that hosts the plugin. If the provided node is a plugin, then it runs its
258 // WebPluginContainerImpl.
259 static WebPluginContainerImpl* pluginContainerFromNode(LocalFrame*, const WebNode&);
261 WebViewImpl* viewImpl() const;
263 FrameView* frameView() const { return frame() ? frame()->view() : 0; }
265 // Getters for the impls corresponding to Get(Provisional)DataSource. They
266 // may return 0 if there is no corresponding data source.
267 WebDataSourceImpl* dataSourceImpl() const;
268 WebDataSourceImpl* provisionalDataSourceImpl() const;
270 // Returns which frame has an active match. This function should only be
271 // called on the main frame, as it is the only frame keeping track. Returned
272 // value can be 0 if no frame has an active match.
273 WebLocalFrameImpl* activeMatchFrame() const;
275 // Returns the active match in the current frame. Could be a null range if
276 // the local frame has no active match.
277 Range* activeMatch() const;
279 // When a Find operation ends, we want to set the selection to what was active
280 // and set focus to the first focusable node we find (starting with the first
281 // node in the matched range and going up the inheritance chain). If we find
282 // nothing to focus we focus the first focusable node in the range. This
283 // allows us to set focus to a link (when we find text inside a link), which
284 // allows us to navigate by pressing Enter after closing the Find box.
285 void setFindEndstateFocusAndSelection();
287 void didFail(const ResourceError&, bool wasProvisional);
289 // Sets whether the WebLocalFrameImpl allows its document to be scrolled.
290 // If the parameter is true, allow the document to be scrolled.
291 // Otherwise, disallow scrolling.
292 virtual void setCanHaveScrollbars(bool) override;
294 LocalFrame* frame() const { return m_frame.get(); }
295 WebFrameClient* client() const { return m_client; }
296 void setClient(WebFrameClient* client) { m_client = client; }
298 WebPermissionClient* permissionClient() { return m_permissionClient; }
299 SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { return m_sharedWorkerRepositoryClient.get(); }
301 void setInputEventsTransformForEmulation(const IntSize&, float);
303 static void selectWordAroundPosition(LocalFrame*, VisiblePosition);
305 // Returns the text finder object if it already exists.
306 // Otherwise creates it and then returns.
307 TextFinder& ensureTextFinder();
309 // Invalidates vertical scrollbar only.
310 void invalidateScrollbar() const;
312 // Invalidates both content area and the scrollbar.
313 void invalidateAll() const;
315 // Returns a hit-tested VisiblePosition for the given point
316 VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
319 void trace(Visitor*);
323 friend class FrameLoaderClientImpl;
325 explicit WebLocalFrameImpl(WebFrameClient*);
327 // Sets the local core frame and registers destruction observers.
328 void setCoreFrame(PassRefPtrWillBeRawPtr<LocalFrame>);
330 void loadJavaScriptURL(const KURL&);
332 WebPlugin* focusedPluginIfInputMethodSupported();
334 FrameLoaderClientImpl m_frameLoaderClientImpl;
336 // The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This
337 // reference is released when the frame is removed from the DOM or the entire page is closed.
338 // FIXME: These will need to change to WebFrame when we introduce WebFrameProxy.
339 RefPtrWillBeMember<LocalFrame> m_frame;
341 WebFrameClient* m_client;
342 WebPermissionClient* m_permissionClient;
343 OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient;
345 // Will be initialized after first call to find() or scopeStringMatches().
346 OwnPtrWillBeMember<TextFinder> m_textFinder;
348 // Valid between calls to BeginPrint() and EndPrint(). Containts the print
349 // information. Is used by PrintPage().
350 OwnPtrWillBeMember<ChromePrintContext> m_printContext;
352 // Stores the additional input events offset and scale when device metrics emulation is enabled.
353 IntSize m_inputEventsOffsetForEmulation;
354 float m_inputEventsScaleFactorForEmulation;
356 UserMediaClientImpl m_userMediaClientImpl;
358 OwnPtrWillBeMember<GeolocationClientProxy> m_geolocationClientProxy;
361 // Oilpan: to provide the guarantee of having the frame live until
362 // close() is called, an instance keep a self-persistent. It is
363 // cleared upon calling close(). This avoids having to assume that
364 // an embedder's WebFrame references are all discovered via thread
365 // state (stack, registers) should an Oilpan GC strike while we're
366 // in the process of detaching.
367 GC_PLUGIN_IGNORE("340522")
368 Persistent<WebLocalFrameImpl> m_selfKeepAlive;
372 DEFINE_TYPE_CASTS(WebLocalFrameImpl, WebFrame, frame, frame->isWebLocalFrame(), frame.isWebLocalFrame());