Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebLocalFrameImpl.h
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 WebCore {
47 class GraphicsContext;
48 class HTMLInputElement;
49 class HistoryItem;
50 class IntSize;
51 class KURL;
52 class Node;
53 class Range;
54 class SubstituteData;
55 struct FrameLoadRequest;
56 struct WindowFeatures;
57 }
58
59 namespace blink {
60 class ChromePrintContext;
61 class GeolocationClientProxy;
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 WebLocalFrameImpl FINAL
78     : public WebLocalFrame
79     , public RefCounted<WebLocalFrameImpl> {
80 public:
81     // WebFrame methods:
82     virtual bool isWebLocalFrame() const OVERRIDE;
83     virtual WebLocalFrame* toWebLocalFrame() OVERRIDE;
84     virtual bool isWebRemoteFrame() const OVERRIDE;
85     virtual WebRemoteFrame* toWebRemoteFrame() OVERRIDE;
86     virtual void close() OVERRIDE;
87     virtual WebString uniqueName() const OVERRIDE;
88     virtual WebString assignedName() const OVERRIDE;
89     virtual void setName(const WebString&) OVERRIDE;
90     virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const OVERRIDE;
91     virtual void setIsRemote(bool) OVERRIDE;
92     virtual void setRemoteWebLayer(WebLayer*) OVERRIDE;
93     virtual void setPermissionClient(WebPermissionClient*) OVERRIDE;
94     virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) OVERRIDE;
95     virtual WebSize scrollOffset() const OVERRIDE;
96     virtual void setScrollOffset(const WebSize&) OVERRIDE;
97     virtual WebSize minimumScrollOffset() const OVERRIDE;
98     virtual WebSize maximumScrollOffset() const OVERRIDE;
99     virtual WebSize contentsSize() const OVERRIDE;
100     virtual bool hasVisibleContent() const OVERRIDE;
101     virtual WebRect visibleContentRect() const OVERRIDE;
102     virtual bool hasHorizontalScrollbar() const OVERRIDE;
103     virtual bool hasVerticalScrollbar() const OVERRIDE;
104     virtual WebView* view() const OVERRIDE;
105     virtual void setOpener(WebFrame*) OVERRIDE;
106     virtual WebDocument document() const OVERRIDE;
107     virtual WebPerformance performance() const OVERRIDE;
108     virtual bool dispatchBeforeUnloadEvent() OVERRIDE;
109     virtual void dispatchUnloadEvent() OVERRIDE;
110     virtual NPObject* windowObject() const OVERRIDE;
111     virtual void bindToWindowObject(const WebString& name, NPObject*) OVERRIDE;
112     virtual void bindToWindowObject(const WebString& name, NPObject*, void*) OVERRIDE;
113     virtual void executeScript(const WebScriptSource&) OVERRIDE;
114     virtual void executeScriptInIsolatedWorld(
115         int worldID, const WebScriptSource* sources, unsigned numSources,
116         int extensionGroup) OVERRIDE;
117     virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) OVERRIDE;
118     virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) OVERRIDE;
119     virtual void addMessageToConsole(const WebConsoleMessage&) OVERRIDE;
120     virtual void collectGarbage() OVERRIDE;
121     virtual bool checkIfRunInsecureContent(const WebURL&) const OVERRIDE;
122     virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
123         const WebScriptSource&) OVERRIDE;
124     virtual void executeScriptInIsolatedWorld(
125         int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
126         int extensionGroup, WebVector<v8::Local<v8::Value> >* results) OVERRIDE;
127     virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
128         v8::Handle<v8::Function>,
129         v8::Handle<v8::Value>,
130         int argc,
131         v8::Handle<v8::Value> argv[]) OVERRIDE;
132     virtual v8::Local<v8::Context> mainWorldScriptContext() const OVERRIDE;
133     virtual void reload(bool ignoreCache) OVERRIDE;
134     virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) OVERRIDE;
135     virtual void loadRequest(const WebURLRequest&) OVERRIDE;
136     virtual void loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy) OVERRIDE;
137     virtual void loadData(
138         const WebData&, const WebString& mimeType, const WebString& textEncoding,
139         const WebURL& baseURL, const WebURL& unreachableURL, bool replace) OVERRIDE;
140     virtual void loadHTMLString(
141         const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
142         bool replace) OVERRIDE;
143     virtual bool isLoading() const OVERRIDE;
144     virtual void stopLoading() OVERRIDE;
145     virtual WebDataSource* provisionalDataSource() const OVERRIDE;
146     virtual WebDataSource* dataSource() const OVERRIDE;
147     virtual void enableViewSourceMode(bool enable) OVERRIDE;
148     virtual bool isViewSourceModeEnabled() const OVERRIDE;
149     virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) OVERRIDE;
150     virtual void dispatchWillSendRequest(WebURLRequest&) OVERRIDE;
151     virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) OVERRIDE;
152     virtual unsigned unloadListenerCount() const OVERRIDE;
153     virtual void replaceSelection(const WebString&) OVERRIDE;
154     virtual void insertText(const WebString&) OVERRIDE;
155     virtual void setMarkedText(const WebString&, unsigned location, unsigned length) OVERRIDE;
156     virtual void unmarkText() OVERRIDE;
157     virtual bool hasMarkedText() const OVERRIDE;
158     virtual WebRange markedRange() const OVERRIDE;
159     virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const OVERRIDE;
160     virtual size_t characterIndexForPoint(const WebPoint&) const OVERRIDE;
161     virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) OVERRIDE;
162     virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) OVERRIDE;
163     virtual bool isCommandEnabled(const WebString&) const OVERRIDE;
164     virtual void enableContinuousSpellChecking(bool) OVERRIDE;
165     virtual bool isContinuousSpellCheckingEnabled() const OVERRIDE;
166     virtual void requestTextChecking(const WebElement&) OVERRIDE;
167     virtual void replaceMisspelledRange(const WebString&) OVERRIDE;
168     virtual void removeSpellingMarkers() OVERRIDE;
169     virtual bool hasSelection() const OVERRIDE;
170     virtual WebRange selectionRange() const OVERRIDE;
171     virtual WebString selectionAsText() const OVERRIDE;
172     virtual WebString selectionAsMarkup() const OVERRIDE;
173     virtual bool selectWordAroundCaret() OVERRIDE;
174     virtual void selectRange(const WebPoint& base, const WebPoint& extent) OVERRIDE;
175     virtual void selectRange(const WebRange&) OVERRIDE;
176     virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) OVERRIDE;
177     virtual void moveCaretSelection(const WebPoint&) OVERRIDE;
178     virtual bool setEditableSelectionOffsets(int start, int end) OVERRIDE;
179     virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) OVERRIDE;
180     virtual void extendSelectionAndDelete(int before, int after) OVERRIDE;
181     virtual void setCaretVisible(bool) OVERRIDE;
182     virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode) OVERRIDE;
183     virtual float printPage(int pageToPrint, WebCanvas*) OVERRIDE;
184     virtual float getPrintPageShrink(int page) OVERRIDE;
185     virtual void printEnd() OVERRIDE;
186     virtual bool isPrintScalingDisabledForPlugin(const WebNode&) OVERRIDE;
187     virtual bool hasCustomPageSizeStyle(int pageIndex) OVERRIDE;
188     virtual bool isPageBoxVisible(int pageIndex) OVERRIDE;
189     virtual void pageSizeAndMarginsInPixels(
190         int pageIndex,
191         WebSize& pageSize,
192         int& marginTop,
193         int& marginRight,
194         int& marginBottom,
195         int& marginLeft) OVERRIDE;
196     virtual WebString pageProperty(const WebString& propertyName, int pageIndex) OVERRIDE;
197     virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) OVERRIDE;
198     virtual bool find(
199         int identifier, const WebString& searchText, const WebFindOptions&,
200         bool wrapWithinFrame, WebRect* selectionRect) OVERRIDE;
201     virtual void stopFinding(bool clearSelection) OVERRIDE;
202     virtual void scopeStringMatches(
203         int identifier, const WebString& searchText, const WebFindOptions&,
204         bool reset) OVERRIDE;
205     virtual void cancelPendingScopingEffort() OVERRIDE;
206     virtual void increaseMatchCount(int count, int identifier) OVERRIDE;
207     virtual void resetMatchCount() OVERRIDE;
208     virtual int findMatchMarkersVersion() const OVERRIDE;
209     virtual WebFloatRect activeFindMatchRect() OVERRIDE;
210     virtual void findMatchRects(WebVector<WebFloatRect>&) OVERRIDE;
211     virtual int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect) OVERRIDE;
212     virtual void setTickmarks(const WebVector<WebRect>&) OVERRIDE;
213
214     virtual void sendOrientationChangeEvent() OVERRIDE;
215
216     virtual void dispatchMessageEventWithOriginCheck(
217         const WebSecurityOrigin& intendedTargetOrigin,
218         const WebDOMEvent&) OVERRIDE;
219
220     virtual WebString contentAsText(size_t maxChars) const OVERRIDE;
221     virtual WebString contentAsMarkup() const OVERRIDE;
222     virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const OVERRIDE;
223     virtual WebString markerTextForListItem(const WebElement&) const OVERRIDE;
224     virtual WebRect selectionBoundsRect() const OVERRIDE;
225
226     virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const OVERRIDE;
227     virtual WebString layerTreeAsText(bool showDebugInfo = false) const OVERRIDE;
228
229     // WebLocalFrame methods:
230     virtual void addStyleSheetByURL(const WebString& url) OVERRIDE;
231
232     void willDetachParent();
233
234     static WebLocalFrameImpl* create(WebFrameClient*);
235     virtual ~WebLocalFrameImpl();
236
237     // Called by the WebViewImpl to initialize the main frame for the page.
238     void initializeAsMainFrame(WebCore::Page*);
239
240     PassRefPtr<WebCore::LocalFrame> createChildFrame(
241         const WebCore::FrameLoadRequest&, WebCore::HTMLFrameOwnerElement*);
242
243     void didChangeContentsSize(const WebCore::IntSize&);
244
245     void createFrameView();
246
247     static WebLocalFrameImpl* fromFrame(WebCore::LocalFrame*);
248     static WebLocalFrameImpl* fromFrame(WebCore::LocalFrame&);
249     static WebLocalFrameImpl* fromFrameOwnerElement(WebCore::Element*);
250
251     // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
252     // that hosts the plugin.
253     static WebPluginContainerImpl* pluginContainerFromFrame(WebCore::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(WebCore::LocalFrame*, const WebNode&);
259
260     WebViewImpl* viewImpl() const;
261
262     WebCore::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     WebCore::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 WebCore::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
293     WebCore::LocalFrame* frame() const { return m_frame.get(); }
294     WebFrameClient* client() const { return m_client; }
295     void setClient(WebFrameClient* client) { m_client = client; }
296
297     WebPermissionClient* permissionClient() { return m_permissionClient; }
298     SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { return m_sharedWorkerRepositoryClient.get(); }
299
300     void setInputEventsTransformForEmulation(const WebCore::IntSize&, float);
301
302     static void selectWordAroundPosition(WebCore::LocalFrame*, WebCore::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     PassRefPtr<WebCore::LocalFrame> initializeAsChildFrame(WebCore::FrameHost*, WebCore::FrameOwner*, const AtomicString& name, const AtomicString& fallbackName);
315
316     // Returns a hit-tested VisiblePosition for the given point
317     WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
318
319 private:
320     friend class FrameLoaderClientImpl;
321
322     explicit WebLocalFrameImpl(WebFrameClient*);
323
324     // Sets the local WebCore frame and registers destruction observers.
325     void setWebCoreFrame(PassRefPtr<WebCore::LocalFrame>);
326
327     void loadJavaScriptURL(const WebCore::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     RefPtr<WebCore::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     OwnPtr<ChromePrintContext> m_printContext;
352
353     // Stores the additional input events offset and scale when device metrics emulation is enabled.
354     WebCore::IntSize m_inputEventsOffsetForEmulation;
355     float m_inputEventsScaleFactorForEmulation;
356
357     UserMediaClientImpl m_userMediaClientImpl;
358
359     OwnPtr<GeolocationClientProxy> m_geolocationClientProxy;
360 };
361
362 DEFINE_TYPE_CASTS(WebLocalFrameImpl, WebFrame, frame, frame->isWebLocalFrame(), frame.isWebLocalFrame());
363
364 } // namespace blink
365
366 #endif