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/editing/VisiblePosition.h"
35 #include "core/frame/LocalFrame.h"
36 #include "platform/geometry/FloatRect.h"
37 #include "public/platform/WebFileSystemType.h"
38 #include "public/web/WebLocalFrame.h"
39 #include "web/FrameLoaderClientImpl.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 SharedWorkerRepositoryClientImpl
;
55 class WebAutofillClient
;
56 class WebDataSourceImpl
;
57 class WebDevToolsAgentImpl
;
58 class WebDevToolsFrontendImpl
;
64 class WebPluginContainerImpl
;
65 class WebScriptExecutionCallback
;
66 class WebSuspendableTask
;
69 struct FrameLoadRequest
;
70 struct WebPrintParams
;
72 template <typename T
> class WebVector
;
74 // Implementation of WebFrame, note that this is a reference counted object.
75 class WebLocalFrameImpl final
: public RefCountedWillBeGarbageCollectedFinalized
<WebLocalFrameImpl
>, public WebLocalFrame
{
78 bool isWebLocalFrame() const override
;
79 WebLocalFrame
* toWebLocalFrame() override
;
80 bool isWebRemoteFrame() const override
;
81 WebRemoteFrame
* toWebRemoteFrame() override
;
82 void close() override
;
83 WebString
uniqueName() const override
;
84 WebString
assignedName() const override
;
85 void setName(const WebString
&) override
;
86 WebVector
<WebIconURL
> iconURLs(int iconTypesMask
) const override
;
87 void setRemoteWebLayer(WebLayer
*) override
;
88 void setContentSettingsClient(WebContentSettingsClient
*) override
;
89 void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient
*) override
;
90 WebSize
scrollOffset() const override
;
91 void setScrollOffset(const WebSize
&) override
;
92 WebSize
contentsSize() const override
;
93 bool hasVisibleContent() const override
;
94 WebRect
visibleContentRect() const override
;
95 bool hasHorizontalScrollbar() const override
;
96 bool hasVerticalScrollbar() const override
;
97 WebView
* view() const override
;
98 void setOpener(WebFrame
*) override
;
99 WebDocument
document() const override
;
100 WebPerformance
performance() const override
;
101 bool dispatchBeforeUnloadEvent() override
;
102 void dispatchUnloadEvent() override
;
103 NPObject
* windowObject() const override
;
104 void bindToWindowObject(const WebString
& name
, NPObject
*) override
;
105 void bindToWindowObject(const WebString
& name
, NPObject
*, void*) override
;
106 void executeScript(const WebScriptSource
&) override
;
107 void executeScriptInIsolatedWorld(
108 int worldID
, const WebScriptSource
* sources
, unsigned numSources
,
109 int extensionGroup
) override
;
110 void setIsolatedWorldSecurityOrigin(int worldID
, const WebSecurityOrigin
&) override
;
111 void setIsolatedWorldContentSecurityPolicy(int worldID
, const WebString
&) override
;
112 void setIsolatedWorldHumanReadableName(int worldID
, const WebString
&) override
;
113 void addMessageToConsole(const WebConsoleMessage
&) override
;
114 void collectGarbage() override
;
115 bool checkIfRunInsecureContent(const WebURL
&) const override
;
116 v8::Local
<v8::Value
> executeScriptAndReturnValue(
117 const WebScriptSource
&) override
;
118 void requestExecuteScriptAndReturnValue(
119 const WebScriptSource
&, bool userGesture
, WebScriptExecutionCallback
*) override
;
120 void executeScriptInIsolatedWorld(
121 int worldID
, const WebScriptSource
* sourcesIn
, unsigned numSources
,
122 int extensionGroup
, WebVector
<v8::Local
<v8::Value
>>* results
) override
;
123 void requestExecuteScriptInIsolatedWorld(
124 int worldID
, const WebScriptSource
* sourceIn
, unsigned numSources
,
125 int extensionGroup
, bool userGesture
, WebScriptExecutionCallback
*) override
;
126 v8::Local
<v8::Value
> callFunctionEvenIfScriptDisabled(
127 v8::Local
<v8::Function
>,
128 v8::Local
<v8::Value
>,
130 v8::Local
<v8::Value
> argv
[]) override
;
131 v8::Local
<v8::Context
> mainWorldScriptContext() const override
;
132 void reload(bool ignoreCache
) override
;
133 void reloadWithOverrideURL(const WebURL
& overrideUrl
, bool ignoreCache
) override
;
134 void reloadImage(const WebNode
&) override
;
135 void loadRequest(const WebURLRequest
&) override
;
136 void loadHistoryItem(const WebHistoryItem
&, WebHistoryLoadType
, WebURLRequest::CachePolicy
) override
;
138 const WebData
&, const WebString
& mimeType
, const WebString
& textEncoding
,
139 const WebURL
& baseURL
, const WebURL
& unreachableURL
, bool replace
) override
;
141 const WebData
& html
, const WebURL
& baseURL
, const WebURL
& unreachableURL
,
142 bool replace
) override
;
143 void stopLoading() override
;
144 WebDataSource
* provisionalDataSource() const override
;
145 WebDataSource
* dataSource() const override
;
146 void enableViewSourceMode(bool enable
) override
;
147 bool isViewSourceModeEnabled() const override
;
148 void setReferrerForRequest(WebURLRequest
&, const WebURL
& referrer
) override
;
149 void dispatchWillSendRequest(WebURLRequest
&) override
;
150 WebURLLoader
* createAssociatedURLLoader(const WebURLLoaderOptions
&) override
;
151 unsigned unloadListenerCount() const override
;
152 void replaceSelection(const WebString
&) override
;
153 void insertText(const WebString
&) override
;
154 void setMarkedText(const WebString
&, unsigned location
, unsigned length
) override
;
155 void unmarkText() override
;
156 bool hasMarkedText() const override
;
157 WebRange
markedRange() const override
;
158 bool firstRectForCharacterRange(unsigned location
, unsigned length
, WebRect
&) const override
;
159 size_t characterIndexForPoint(const WebPoint
&) const override
;
160 bool executeCommand(const WebString
&, const WebNode
& = WebNode()) override
;
161 bool executeCommand(const WebString
&, const WebString
& value
, const WebNode
& = WebNode()) override
;
162 bool isCommandEnabled(const WebString
&) const override
;
163 void enableContinuousSpellChecking(bool) override
;
164 bool isContinuousSpellCheckingEnabled() const override
;
165 void requestTextChecking(const WebElement
&) override
;
166 void replaceMisspelledRange(const WebString
&) override
;
167 void removeSpellingMarkers() override
;
168 bool hasSelection() const override
;
169 WebRange
selectionRange() const override
;
170 WebString
selectionAsText() const override
;
171 WebString
selectionAsMarkup() const override
;
172 bool selectWordAroundCaret() override
;
173 void selectRange(const WebPoint
& base
, const WebPoint
& extent
) override
;
174 void selectRange(const WebRange
&) override
;
175 void moveRangeSelectionExtent(const WebPoint
&) override
;
176 void moveRangeSelection(const WebPoint
& base
, const WebPoint
& extent
, WebFrame::TextGranularity
= CharacterGranularity
) override
;
177 void moveCaretSelection(const WebPoint
&) override
;
178 bool setEditableSelectionOffsets(int start
, int end
) override
;
179 bool setCompositionFromExistingText(int compositionStart
, int compositionEnd
, const WebVector
<WebCompositionUnderline
>& underlines
) override
;
180 void extendSelectionAndDelete(int before
, int after
) override
;
181 void setCaretVisible(bool) override
;
182 int printBegin(const WebPrintParams
&, const WebNode
& constrainToNode
) override
;
183 float printPage(int pageToPrint
, WebCanvas
*) override
;
184 float getPrintPageShrink(int page
) override
;
185 void printEnd() override
;
186 bool isPrintScalingDisabledForPlugin(const WebNode
&) override
;
187 bool getPrintPresetOptionsForPlugin(const WebNode
&, WebPrintPresetOptions
*) override
;
188 bool hasCustomPageSizeStyle(int pageIndex
) override
;
189 bool isPageBoxVisible(int pageIndex
) override
;
190 void pageSizeAndMarginsInPixels(
196 int& marginLeft
) override
;
197 WebString
pageProperty(const WebString
& propertyName
, int pageIndex
) override
;
198 void printPagesWithBoundaries(WebCanvas
*, const WebSize
&) override
;
200 int identifier
, const WebString
& searchText
, const WebFindOptions
&,
201 bool wrapWithinFrame
, WebRect
* selectionRect
) override
;
202 void stopFinding(bool clearSelection
) override
;
203 void scopeStringMatches(
204 int identifier
, const WebString
& searchText
, const WebFindOptions
&,
205 bool reset
) override
;
206 void cancelPendingScopingEffort() override
;
207 void increaseMatchCount(int count
, int identifier
) override
;
208 void resetMatchCount() override
;
209 int findMatchMarkersVersion() const override
;
210 WebFloatRect
activeFindMatchRect() override
;
211 void findMatchRects(WebVector
<WebFloatRect
>&) override
;
212 int selectNearestFindMatch(const WebFloatPoint
&, WebRect
* selectionRect
) override
;
213 void setTickmarks(const WebVector
<WebRect
>&) override
;
215 void dispatchMessageEventWithOriginCheck(
216 const WebSecurityOrigin
& intendedTargetOrigin
,
217 const WebDOMEvent
&) override
;
219 WebString
contentAsText(size_t maxChars
) const override
;
220 WebString
contentAsMarkup() const override
;
221 WebString
layoutTreeAsText(LayoutAsTextControls toShow
= LayoutAsTextNormal
) const override
;
223 WebString
markerTextForListItem(const WebElement
&) const override
;
224 WebRect
selectionBoundsRect() const override
;
226 bool selectionStartHasSpellingMarkerFor(int from
, int length
) const override
;
227 WebString
layerTreeAsText(bool showDebugInfo
= false) const override
;
229 void registerTestInterface(const WebString
& name
, WebTestInterfaceFactory
*) override
;
231 // Creates a test interface by name if available, returns an empty handle
232 // for unknown names.
233 v8::Local
<v8::Value
> createTestInterface(const AtomicString
& name
);
235 // WebLocalFrame methods:
236 void initializeToReplaceRemoteFrame(WebRemoteFrame
*, const WebString
& name
, WebSandboxFlags
) override
;
237 void setAutofillClient(WebAutofillClient
*) override
;
238 WebAutofillClient
* autofillClient() override
;
239 void setDevToolsAgentClient(WebDevToolsAgentClient
*) override
;
240 WebDevToolsAgent
* devToolsAgent() override
;
241 void sendPings(const WebNode
& contextNode
, const WebURL
& destinationURL
) override
;
242 WebURLRequest
requestFromHistoryItem(const WebHistoryItem
&, WebURLRequest::CachePolicy
)
244 WebURLRequest
requestForReload(WebFrameLoadType
, const WebURL
&) const override
;
245 void load(const WebURLRequest
&, WebFrameLoadType
, const WebHistoryItem
&,
246 WebHistoryLoadType
) override
;
247 bool isLoading() const override
;
248 bool isResourceLoadInProgress() const override
;
249 bool isNavigationScheduled() const override
;
250 void setCommittedFirstRealLoad() override
;
251 void sendOrientationChangeEvent() override
;
252 void willShowInstallBannerPrompt(int requestId
, const WebVector
<WebString
>& platforms
, WebAppBannerPromptReply
*) override
;
253 WebSandboxFlags
effectiveSandboxFlags() const override
;
254 void requestRunTask(WebSuspendableTask
*) const override
;
256 void willBeDetached();
257 void willDetachParent();
259 static WebLocalFrameImpl
* create(WebTreeScopeType
, WebFrameClient
*);
260 ~WebLocalFrameImpl() override
;
262 PassRefPtrWillBeRawPtr
<LocalFrame
> initializeCoreFrame(FrameHost
*, FrameOwner
*, const AtomicString
& name
, const AtomicString
& fallbackName
);
264 PassRefPtrWillBeRawPtr
<LocalFrame
> createChildFrame(const FrameLoadRequest
&, const AtomicString
& name
, HTMLFrameOwnerElement
*);
266 void didChangeContentsSize(const IntSize
&);
268 void createFrameView();
270 static WebLocalFrameImpl
* fromFrame(LocalFrame
*);
271 static WebLocalFrameImpl
* fromFrame(LocalFrame
&);
272 static WebLocalFrameImpl
* fromFrameOwnerElement(Element
*);
274 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
275 // that hosts the plugin.
276 static WebPluginContainerImpl
* pluginContainerFromFrame(LocalFrame
*);
278 // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
279 // that hosts the plugin. If the provided node is a plugin, then it runs its
280 // WebPluginContainerImpl.
281 static WebPluginContainerImpl
* pluginContainerFromNode(LocalFrame
*, const WebNode
&);
283 WebViewImpl
* viewImpl() const;
285 FrameView
* frameView() const { return frame() ? frame()->view() : 0; }
287 WebDevToolsAgentImpl
* devToolsAgentImpl() const { return m_devToolsAgent
.get(); }
289 // Getters for the impls corresponding to Get(Provisional)DataSource. They
290 // may return 0 if there is no corresponding data source.
291 WebDataSourceImpl
* dataSourceImpl() const;
292 WebDataSourceImpl
* provisionalDataSourceImpl() const;
294 // Returns which frame has an active match. This function should only be
295 // called on the main frame, as it is the only frame keeping track. Returned
296 // value can be 0 if no frame has an active match.
297 WebLocalFrameImpl
* activeMatchFrame() const;
299 // Returns the active match in the current frame. Could be a null range if
300 // the local frame has no active match.
301 Range
* activeMatch() const;
303 // When a Find operation ends, we want to set the selection to what was active
304 // and set focus to the first focusable node we find (starting with the first
305 // node in the matched range and going up the inheritance chain). If we find
306 // nothing to focus we focus the first focusable node in the range. This
307 // allows us to set focus to a link (when we find text inside a link), which
308 // allows us to navigate by pressing Enter after closing the Find box.
309 void setFindEndstateFocusAndSelection();
311 void didFail(const ResourceError
&, bool wasProvisional
, HistoryCommitType
);
313 // Sets whether the WebLocalFrameImpl allows its document to be scrolled.
314 // If the parameter is true, allow the document to be scrolled.
315 // Otherwise, disallow scrolling.
316 void setCanHaveScrollbars(bool) override
;
318 LocalFrame
* frame() const { return m_frame
.get(); }
319 WebFrameClient
* client() const { return m_client
; }
320 void setClient(WebFrameClient
* client
) { m_client
= client
; }
322 WebContentSettingsClient
* contentSettingsClient() { return m_contentSettingsClient
; }
323 SharedWorkerRepositoryClientImpl
* sharedWorkerRepositoryClient() const { return m_sharedWorkerRepositoryClient
.get(); }
325 void setInputEventsTransformForEmulation(const IntSize
&, float);
327 static void selectWordAroundPosition(LocalFrame
*, VisiblePosition
);
329 // Returns the text finder object if it already exists.
330 // Otherwise creates it and then returns.
331 TextFinder
& ensureTextFinder();
333 // Returns a hit-tested VisiblePosition for the given point
334 VisiblePosition
visiblePositionForViewportPoint(const WebPoint
&);
336 void setFrameWidget(WebFrameWidget
*);
337 WebFrameWidget
* frameWidget() const;
339 // DevTools front-end bindings.
340 void setDevToolsFrontend(WebDevToolsFrontendImpl
* frontend
) { m_webDevToolsFrontend
= frontend
; }
341 WebDevToolsFrontendImpl
* devToolsFrontend() { return m_webDevToolsFrontend
; }
348 friend class FrameLoaderClientImpl
;
350 WebLocalFrameImpl(WebTreeScopeType
, WebFrameClient
*);
352 // Sets the local core frame and registers destruction observers.
353 void setCoreFrame(PassRefPtrWillBeRawPtr
<LocalFrame
>);
355 void loadJavaScriptURL(const KURL
&);
357 WebPlugin
* focusedPluginIfInputMethodSupported();
358 ScrollableArea
* layoutViewportScrollableArea() const;
360 OwnPtrWillBeMember
<FrameLoaderClientImpl
> m_frameLoaderClientImpl
;
362 // The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This
363 // reference is released when the frame is removed from the DOM or the entire page is closed.
364 // FIXME: These will need to change to WebFrame when we introduce WebFrameProxy.
365 RefPtrWillBeMember
<LocalFrame
> m_frame
;
367 OwnPtrWillBeMember
<WebDevToolsAgentImpl
> m_devToolsAgent
;
369 // This is set if the frame is the root of a local frame tree, and requires a widget for layout.
370 WebFrameWidget
* m_frameWidget
;
372 WebFrameClient
* m_client
;
373 WebAutofillClient
* m_autofillClient
;
374 WebContentSettingsClient
* m_contentSettingsClient
;
375 OwnPtr
<SharedWorkerRepositoryClientImpl
> m_sharedWorkerRepositoryClient
;
377 // Will be initialized after first call to find() or scopeStringMatches().
378 OwnPtrWillBeMember
<TextFinder
> m_textFinder
;
380 // Valid between calls to BeginPrint() and EndPrint(). Containts the print
381 // information. Is used by PrintPage().
382 OwnPtrWillBeMember
<ChromePrintContext
> m_printContext
;
384 // Stores the additional input events offset and scale when device metrics emulation is enabled.
385 IntSize m_inputEventsOffsetForEmulation
;
386 float m_inputEventsScaleFactorForEmulation
;
388 UserMediaClientImpl m_userMediaClientImpl
;
390 OwnPtrWillBeMember
<GeolocationClientProxy
> m_geolocationClientProxy
;
392 WebDevToolsFrontendImpl
* m_webDevToolsFrontend
;
394 HashMap
<AtomicString
, OwnPtr
<WebTestInterfaceFactory
>> m_testInterfaces
;
397 // Oilpan: WebLocalFrameImpl must remain alive until close() is called.
398 // Accomplish that by keeping a self-referential Persistent<>. It is
399 // cleared upon close().
400 SelfKeepAlive
<WebLocalFrameImpl
> m_selfKeepAlive
;
404 DEFINE_TYPE_CASTS(WebLocalFrameImpl
, WebFrame
, frame
, frame
->isWebLocalFrame(), frame
.isWebLocalFrame());