1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
5#ifndef WebRemoteFrameImpl_h
6#define WebRemoteFrameImpl_h
8#include "platform/heap/Handle.h"
9#include "public/web/WebRemoteFrame.h"
10#include "public/web/WebRemoteFrameClient.h"
11#include "web/RemoteFrameClient.h"
12#include "wtf/HashMap.h"
13#include "wtf/OwnPtr.h"
14#include "wtf/RefCounted.h"
16namespace blink {
18class FrameHost;
19class FrameOwner;
20class RemoteFrame;
21class WebViewImpl;
23class WebRemoteFrameImpl FINAL : public RefCountedWillBeGarbageCollectedFinalized<WebRemoteFrameImpl>, public WebRemoteFrame {
25    explicit WebRemoteFrameImpl(WebRemoteFrameClient*);
26    virtual ~WebRemoteFrameImpl();
28    // WebRemoteFrame methods.
29    virtual bool isWebLocalFrame() const OVERRIDE;
30    virtual WebLocalFrame* toWebLocalFrame() OVERRIDE;
31    virtual bool isWebRemoteFrame() const OVERRIDE;
32    virtual WebRemoteFrame* toWebRemoteFrame() OVERRIDE;
33    virtual void close() OVERRIDE;
34    virtual WebString uniqueName() const OVERRIDE;
35    virtual WebString assignedName() const OVERRIDE;
36    virtual void setName(const WebString&) OVERRIDE;
37    virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const OVERRIDE;
38    virtual void setIsRemote(bool) OVERRIDE;
39    virtual void setRemoteWebLayer(WebLayer*) OVERRIDE;
40    virtual void setPermissionClient(WebPermissionClient*) OVERRIDE;
41    virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) OVERRIDE;
42    virtual void setCanHaveScrollbars(bool) OVERRIDE;
43    virtual WebSize scrollOffset() const OVERRIDE;
44    virtual void setScrollOffset(const WebSize&) OVERRIDE;
45    virtual WebSize minimumScrollOffset() const OVERRIDE;
46    virtual WebSize maximumScrollOffset() const OVERRIDE;
47    virtual WebSize contentsSize() const OVERRIDE;
48    virtual bool hasVisibleContent() const OVERRIDE;
49    virtual WebRect visibleContentRect() const OVERRIDE;
50    virtual bool hasHorizontalScrollbar() const OVERRIDE;
51    virtual bool hasVerticalScrollbar() const OVERRIDE;
52    virtual WebView* view() const OVERRIDE;
53    virtual void removeChild(WebFrame*) OVERRIDE;
54    virtual WebDocument document() const OVERRIDE;
55    virtual WebPerformance performance() const OVERRIDE;
56    virtual bool dispatchBeforeUnloadEvent() OVERRIDE;
57    virtual void dispatchUnloadEvent() OVERRIDE;
58    virtual NPObject* windowObject() const OVERRIDE;
59    virtual void bindToWindowObject(const WebString& name, NPObject*) OVERRIDE;
60    virtual void bindToWindowObject(const WebString& name, NPObject*, void*) OVERRIDE;
61    virtual void executeScript(const WebScriptSource&) OVERRIDE;
62    virtual void executeScriptInIsolatedWorld(
63        int worldID, const WebScriptSource* sources, unsigned numSources,
64        int extensionGroup) OVERRIDE;
65    virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) OVERRIDE;
66    virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) OVERRIDE;
67    virtual void addMessageToConsole(const WebConsoleMessage&) OVERRIDE;
68    virtual void collectGarbage() OVERRIDE;
69    virtual bool checkIfRunInsecureContent(const WebURL&) const OVERRIDE;
70    virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
71        const WebScriptSource&) OVERRIDE;
72    virtual void executeScriptInIsolatedWorld(
73        int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
74        int extensionGroup, WebVector<v8::Local<v8::Value> >* results) OVERRIDE;
75    virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
76        v8::Handle<v8::Function>,
77        v8::Handle<v8::Value>,
78        int argc,
79        v8::Handle<v8::Value> argv[]) OVERRIDE;
80    virtual v8::Local<v8::Context> mainWorldScriptContext() const OVERRIDE;
81    virtual void reload(bool ignoreCache) OVERRIDE;
82    virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) OVERRIDE;
83    virtual void loadRequest(const WebURLRequest&) OVERRIDE;
84    virtual void loadHistoryItem(const WebHistoryItem&, WebHistoryLoadType, WebURLRequest::CachePolicy) OVERRIDE;
85    virtual void loadData(
86        const WebData&, const WebString& mimeType, const WebString& textEncoding,
87        const WebURL& baseURL, const WebURL& unreachableURL, bool replace) OVERRIDE;
88    virtual void loadHTMLString(
89        const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
90        bool replace) OVERRIDE;
91    virtual void stopLoading() OVERRIDE;
92    virtual WebDataSource* provisionalDataSource() const OVERRIDE;
93    virtual WebDataSource* dataSource() const OVERRIDE;
94    virtual void enableViewSourceMode(bool enable) OVERRIDE;
95    virtual bool isViewSourceModeEnabled() const OVERRIDE;
96    virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) OVERRIDE;
97    virtual void dispatchWillSendRequest(WebURLRequest&) OVERRIDE;
98    virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) OVERRIDE;
99    virtual unsigned unloadListenerCount() const OVERRIDE;
100    virtual void replaceSelection(const WebString&) OVERRIDE;
101    virtual void insertText(const WebString&) OVERRIDE;
102    virtual void setMarkedText(const WebString&, unsigned location, unsigned length) OVERRIDE;
103    virtual void unmarkText() OVERRIDE;
104    virtual bool hasMarkedText() const OVERRIDE;
105    virtual WebRange markedRange() const OVERRIDE;
106    virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const OVERRIDE;
107    virtual size_t characterIndexForPoint(const WebPoint&) const OVERRIDE;
108    virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) OVERRIDE;
109    virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) OVERRIDE;
110    virtual bool isCommandEnabled(const WebString&) const OVERRIDE;
111    virtual void enableContinuousSpellChecking(bool) OVERRIDE;
112    virtual bool isContinuousSpellCheckingEnabled() const OVERRIDE;
113    virtual void requestTextChecking(const WebElement&) OVERRIDE;
114    virtual void replaceMisspelledRange(const WebString&) OVERRIDE;
115    virtual void removeSpellingMarkers() OVERRIDE;
116    virtual bool hasSelection() const OVERRIDE;
117    virtual WebRange selectionRange() const OVERRIDE;
118    virtual WebString selectionAsText() const OVERRIDE;
119    virtual WebString selectionAsMarkup() const OVERRIDE;
120    virtual bool selectWordAroundCaret() OVERRIDE;
121    virtual void selectRange(const WebPoint& base, const WebPoint& extent) OVERRIDE;
122    virtual void selectRange(const WebRange&) OVERRIDE;
123    virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) OVERRIDE;
124    virtual void moveCaretSelection(const WebPoint&) OVERRIDE;
125    virtual bool setEditableSelectionOffsets(int start, int end) OVERRIDE;
126    virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) OVERRIDE;
127    virtual void extendSelectionAndDelete(int before, int after) OVERRIDE;
128    virtual void setCaretVisible(bool) OVERRIDE;
129    virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode) OVERRIDE;
130    virtual float printPage(int pageToPrint, WebCanvas*) OVERRIDE;
131    virtual float getPrintPageShrink(int page) OVERRIDE;
132    virtual void printEnd() OVERRIDE;
133    virtual bool isPrintScalingDisabledForPlugin(const WebNode&) OVERRIDE;
134    virtual int getPrintCopiesForPlugin(const WebNode&) OVERRIDE;
135    virtual bool hasCustomPageSizeStyle(int pageIndex) OVERRIDE;
136    virtual bool isPageBoxVisible(int pageIndex) OVERRIDE;
137    virtual void pageSizeAndMarginsInPixels(
138        int pageIndex,
139        WebSize& pageSize,
140        int& marginTop,
141        int& marginRight,
142        int& marginBottom,
143        int& marginLeft) OVERRIDE;
144    virtual WebString pageProperty(const WebString& propertyName, int pageIndex) OVERRIDE;
145    virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) OVERRIDE;
146    virtual bool find(
147        int identifier, const WebString& searchText, const WebFindOptions&,
148        bool wrapWithinFrame, WebRect* selectionRect) OVERRIDE;
149    virtual void stopFinding(bool clearSelection) OVERRIDE;
150    virtual void scopeStringMatches(
151        int identifier, const WebString& searchText, const WebFindOptions&,
152        bool reset) OVERRIDE;
153    virtual void cancelPendingScopingEffort() OVERRIDE;
154    virtual void increaseMatchCount(int count, int identifier) OVERRIDE;
155    virtual void resetMatchCount() OVERRIDE;
156    virtual int findMatchMarkersVersion() const OVERRIDE;
157    virtual WebFloatRect activeFindMatchRect() OVERRIDE;
158    virtual void findMatchRects(WebVector<WebFloatRect>&) OVERRIDE;
159    virtual int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect) OVERRIDE;
160    virtual void setTickmarks(const WebVector<WebRect>&) OVERRIDE;
161    virtual void dispatchMessageEventWithOriginCheck(
162        const WebSecurityOrigin& intendedTargetOrigin,
163        const WebDOMEvent&) OVERRIDE;
165    virtual WebString contentAsText(size_t maxChars) const OVERRIDE;
166    virtual WebString contentAsMarkup() const OVERRIDE;
167    virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const OVERRIDE;
168    virtual WebString markerTextForListItem(const WebElement&) const OVERRIDE;
169    virtual WebRect selectionBoundsRect() const OVERRIDE;
171    virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const OVERRIDE;
172    virtual WebString layerTreeAsText(bool showDebugInfo = false) const OVERRIDE;
174    virtual WebLocalFrame* createLocalChild(const WebString& name, WebFrameClient*) OVERRIDE;
175    virtual WebRemoteFrame* createRemoteChild(const WebString& name, WebRemoteFrameClient*) OVERRIDE;
177    void initializeCoreFrame(FrameHost*, FrameOwner*, const AtomicString& name);
179    void setCoreFrame(PassRefPtrWillBeRawPtr<RemoteFrame>);
180    RemoteFrame* frame() const { return m_frame.get(); }
182    WebRemoteFrameClient* client() const { return m_client; }
184    static WebRemoteFrameImpl* fromFrame(RemoteFrame&);
186    virtual void initializeFromFrame(WebLocalFrame*) const OVERRIDE;
188    virtual void trace(Visitor*);
191    RemoteFrameClient m_frameClient;
192    RefPtrWillBeMember<RemoteFrame> m_frame;
193    WebRemoteFrameClient* m_client;
195    WebViewImpl* viewImpl() const;
197    WillBeHeapHashMap<WebFrame*, OwnPtrWillBeMember<FrameOwner> > m_ownersForChildren;
200    // Oilpan: to provide the guarantee of having the frame live until
201    // close() is called, an instance keep a self-persistent. It is
202    // cleared upon calling close(). This avoids having to assume that
203    // an embedder's WebFrame references are all discovered via thread
204    // state (stack, registers) should an Oilpan GC strike while we're
205    // in the process of detaching.
206    GC_PLUGIN_IGNORE("340522")
207    Persistent<WebRemoteFrameImpl> m_selfKeepAlive;
211DEFINE_TYPE_CASTS(WebRemoteFrameImpl, WebFrame, frame, frame->isWebRemoteFrame(), frame.isWebRemoteFrame());
213} // namespace blink
215#endif // WebRemoteFrameImpl_h