Upstream version 7.36.149.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 SharedWorkerRepositoryClientImpl;
62 class TextFinder;
63 class WebDataSourceImpl;
64 class WebInputElement;
65 class WebFrameClient;
66 class WebPerformance;
67 class WebPlugin;
68 class WebPluginContainerImpl;
69 class WebView;
70 class WebViewImpl;
71 struct WebPrintParams;
72
73 template <typename T> class WebVector;
74
75 // Implementation of WebFrame, note that this is a reference counted object.
76 class WebLocalFrameImpl FINAL
77     : public WebLocalFrame
78     , public RefCounted<WebLocalFrameImpl> {
79 public:
80     // WebFrame methods:
81     virtual bool isWebLocalFrame() const OVERRIDE;
82     virtual WebLocalFrame* toWebLocalFrame() OVERRIDE;
83     virtual bool isWebRemoteFrame() const OVERRIDE;
84     virtual WebRemoteFrame* toWebRemoteFrame() OVERRIDE;
85     virtual void close() OVERRIDE;
86     virtual WebString uniqueName() const OVERRIDE;
87     virtual WebString assignedName() const OVERRIDE;
88     virtual void setName(const WebString&) OVERRIDE;
89     virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const OVERRIDE;
90     virtual void setIsRemote(bool) OVERRIDE;
91     virtual void setRemoteWebLayer(WebLayer*) OVERRIDE;
92     virtual void setPermissionClient(WebPermissionClient*) OVERRIDE;
93     virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) OVERRIDE;
94     virtual WebSize scrollOffset() const OVERRIDE;
95     virtual void setScrollOffset(const WebSize&) OVERRIDE;
96     virtual WebSize minimumScrollOffset() const OVERRIDE;
97     virtual WebSize maximumScrollOffset() const OVERRIDE;
98     virtual WebSize contentsSize() const OVERRIDE;
99     virtual bool hasVisibleContent() const OVERRIDE;
100     virtual WebRect visibleContentRect() const OVERRIDE;
101     virtual bool hasHorizontalScrollbar() const OVERRIDE;
102     virtual bool hasVerticalScrollbar() const OVERRIDE;
103     virtual WebView* view() const OVERRIDE;
104     virtual void setOpener(WebFrame*) OVERRIDE;
105     virtual void appendChild(WebFrame*) OVERRIDE;
106     virtual void removeChild(WebFrame*) OVERRIDE;
107     virtual WebFrame* traversePrevious(bool wrap) const OVERRIDE;
108     virtual WebFrame* traverseNext(bool wrap) const OVERRIDE;
109     virtual WebFrame* findChildByName(const WebString&) const OVERRIDE;
110     virtual WebDocument document() const OVERRIDE;
111     virtual WebPerformance performance() const OVERRIDE;
112     virtual bool dispatchBeforeUnloadEvent() OVERRIDE;
113     virtual void dispatchUnloadEvent() OVERRIDE;
114     virtual NPObject* windowObject() const OVERRIDE;
115     virtual void bindToWindowObject(const WebString& name, NPObject*) OVERRIDE;
116     virtual void bindToWindowObject(const WebString& name, NPObject*, void*) OVERRIDE;
117     virtual void executeScript(const WebScriptSource&) OVERRIDE;
118     virtual void executeScriptInIsolatedWorld(
119         int worldID, const WebScriptSource* sources, unsigned numSources,
120         int extensionGroup) OVERRIDE;
121     virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) OVERRIDE;
122     virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) OVERRIDE;
123     virtual void addMessageToConsole(const WebConsoleMessage&) OVERRIDE;
124     virtual void collectGarbage() OVERRIDE;
125     virtual bool checkIfRunInsecureContent(const WebURL&) const OVERRIDE;
126     virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
127         const WebScriptSource&) OVERRIDE;
128     virtual void executeScriptInIsolatedWorld(
129         int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
130         int extensionGroup, WebVector<v8::Local<v8::Value> >* results) OVERRIDE;
131     virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
132         v8::Handle<v8::Function>,
133         v8::Handle<v8::Value>,
134         int argc,
135         v8::Handle<v8::Value> argv[]) OVERRIDE;
136     virtual v8::Local<v8::Context> mainWorldScriptContext() const OVERRIDE;
137     virtual void reload(bool ignoreCache) OVERRIDE;
138     virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) OVERRIDE;
139     virtual void loadRequest(const WebURLRequest&) OVERRIDE;
140     virtual void loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy) OVERRIDE;
141     virtual void loadData(
142         const WebData&, const WebString& mimeType, const WebString& textEncoding,
143         const WebURL& baseURL, const WebURL& unreachableURL, bool replace) OVERRIDE;
144     virtual void loadHTMLString(
145         const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
146         bool replace) OVERRIDE;
147     virtual bool isLoading() const OVERRIDE;
148     virtual void stopLoading() OVERRIDE;
149     virtual WebDataSource* provisionalDataSource() const OVERRIDE;
150     virtual WebDataSource* dataSource() const OVERRIDE;
151     virtual void enableViewSourceMode(bool enable) OVERRIDE;
152     virtual bool isViewSourceModeEnabled() const OVERRIDE;
153     virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) OVERRIDE;
154     virtual void dispatchWillSendRequest(WebURLRequest&) OVERRIDE;
155     virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) OVERRIDE;
156     virtual unsigned unloadListenerCount() const OVERRIDE;
157     virtual void replaceSelection(const WebString&) OVERRIDE;
158     virtual void insertText(const WebString&) OVERRIDE;
159     virtual void setMarkedText(const WebString&, unsigned location, unsigned length) OVERRIDE;
160     virtual void unmarkText() OVERRIDE;
161     virtual bool hasMarkedText() const OVERRIDE;
162     virtual WebRange markedRange() const OVERRIDE;
163     virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const OVERRIDE;
164     virtual size_t characterIndexForPoint(const WebPoint&) const OVERRIDE;
165     virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) OVERRIDE;
166     virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) OVERRIDE;
167     virtual bool isCommandEnabled(const WebString&) const OVERRIDE;
168     virtual void enableContinuousSpellChecking(bool) OVERRIDE;
169     virtual bool isContinuousSpellCheckingEnabled() const OVERRIDE;
170     virtual void requestTextChecking(const WebElement&) OVERRIDE;
171     virtual void replaceMisspelledRange(const WebString&) OVERRIDE;
172     virtual void removeSpellingMarkers() OVERRIDE;
173     virtual bool hasSelection() const OVERRIDE;
174     virtual WebRange selectionRange() const OVERRIDE;
175     virtual WebString selectionAsText() const OVERRIDE;
176     virtual WebString selectionAsMarkup() const OVERRIDE;
177     virtual bool selectWordAroundCaret() OVERRIDE;
178     virtual void selectRange(const WebPoint& base, const WebPoint& extent) OVERRIDE;
179     virtual void selectRange(const WebRange&) OVERRIDE;
180     virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) OVERRIDE;
181     virtual void moveCaretSelection(const WebPoint&) OVERRIDE;
182     virtual bool setEditableSelectionOffsets(int start, int end) OVERRIDE;
183     virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) OVERRIDE;
184     virtual void extendSelectionAndDelete(int before, int after) OVERRIDE;
185     virtual void setCaretVisible(bool) OVERRIDE;
186     virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode) OVERRIDE;
187     virtual float printPage(int pageToPrint, WebCanvas*) OVERRIDE;
188     virtual float getPrintPageShrink(int page) OVERRIDE;
189     virtual void printEnd() OVERRIDE;
190     virtual bool isPrintScalingDisabledForPlugin(const WebNode&) OVERRIDE;
191     virtual bool hasCustomPageSizeStyle(int pageIndex) OVERRIDE;
192     virtual bool isPageBoxVisible(int pageIndex) OVERRIDE;
193     virtual void pageSizeAndMarginsInPixels(
194         int pageIndex,
195         WebSize& pageSize,
196         int& marginTop,
197         int& marginRight,
198         int& marginBottom,
199         int& marginLeft) OVERRIDE;
200     virtual WebString pageProperty(const WebString& propertyName, int pageIndex) OVERRIDE;
201     virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) OVERRIDE;
202     virtual bool find(
203         int identifier, const WebString& searchText, const WebFindOptions&,
204         bool wrapWithinFrame, WebRect* selectionRect) OVERRIDE;
205     virtual void stopFinding(bool clearSelection) OVERRIDE;
206     virtual void scopeStringMatches(
207         int identifier, const WebString& searchText, const WebFindOptions&,
208         bool reset) OVERRIDE;
209     virtual void cancelPendingScopingEffort() OVERRIDE;
210     virtual void increaseMatchCount(int count, int identifier) OVERRIDE;
211     virtual void resetMatchCount() OVERRIDE;
212     virtual int findMatchMarkersVersion() const OVERRIDE;
213     virtual WebFloatRect activeFindMatchRect() OVERRIDE;
214     virtual void findMatchRects(WebVector<WebFloatRect>&) OVERRIDE;
215     virtual int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect) OVERRIDE;
216     virtual void setTickmarks(const WebVector<WebRect>&) OVERRIDE;
217
218     virtual void sendOrientationChangeEvent() OVERRIDE;
219
220     virtual void dispatchMessageEventWithOriginCheck(
221         const WebSecurityOrigin& intendedTargetOrigin,
222         const WebDOMEvent&) OVERRIDE;
223
224     virtual WebString contentAsText(size_t maxChars) const OVERRIDE;
225     virtual WebString contentAsMarkup() const OVERRIDE;
226     virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const OVERRIDE;
227     virtual WebString markerTextForListItem(const WebElement&) const OVERRIDE;
228     virtual WebRect selectionBoundsRect() const OVERRIDE;
229
230     virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const OVERRIDE;
231     virtual WebString layerTreeAsText(bool showDebugInfo = false) const OVERRIDE;
232
233     void willDetachParent();
234
235     static WebLocalFrameImpl* create(WebFrameClient*);
236     virtual ~WebLocalFrameImpl();
237
238     // Called by the WebViewImpl to initialize the main frame for the page.
239     void initializeAsMainFrame(WebCore::Page*);
240
241     PassRefPtr<WebCore::LocalFrame> createChildFrame(
242         const WebCore::FrameLoadRequest&, WebCore::HTMLFrameOwnerElement*);
243
244     void didChangeContentsSize(const WebCore::IntSize&);
245
246     void createFrameView();
247
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 private:
315     friend class FrameLoaderClientImpl;
316
317     explicit WebLocalFrameImpl(WebFrameClient*);
318
319     // Sets the local WebCore frame and registers destruction observers.
320     void setWebCoreFrame(PassRefPtr<WebCore::LocalFrame>);
321
322     void loadJavaScriptURL(const WebCore::KURL&);
323
324     // Returns a hit-tested VisiblePosition for the given point
325     WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
326
327     WebPlugin* focusedPluginIfInputMethodSupported();
328
329     FrameLoaderClientImpl m_frameLoaderClientImpl;
330
331     // The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This
332     // reference is released when the frame is removed from the DOM or the entire page is closed.
333     // FIXME: These will need to change to WebFrame when we introduce WebFrameProxy.
334     RefPtr<WebCore::LocalFrame> m_frame;
335
336     // Indicate whether the current LocalFrame is local or remote. Remote frames are
337     // rendered in a different process from their parent frames.
338     bool m_isRemote;
339
340     WebFrameClient* m_client;
341     WebPermissionClient* m_permissionClient;
342     OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient;
343
344     // Will be initialized after first call to find() or scopeStringMatches().
345     OwnPtr<TextFinder> m_textFinder;
346
347     // Valid between calls to BeginPrint() and EndPrint(). Containts the print
348     // information. Is used by PrintPage().
349     OwnPtr<ChromePrintContext> m_printContext;
350
351     // Stores the additional input events offset and scale when device metrics emulation is enabled.
352     WebCore::IntSize m_inputEventsOffsetForEmulation;
353     float m_inputEventsScaleFactorForEmulation;
354
355     UserMediaClientImpl m_userMediaClientImpl;
356 };
357
358 DEFINE_TYPE_CASTS(WebLocalFrameImpl, WebFrame, frame, frame->isWebLocalFrame(), frame.isWebLocalFrame());
359
360 } // namespace blink
361
362 #endif