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