2 * Copyright (C) 2010 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include "APIObject.h"
30 #include "DownloadID.h"
31 #include "ShareableBitmap.h"
33 #include "WebFrameLoaderClient.h"
34 #include <JavaScriptCore/JSBase.h>
35 #include <WebCore/FrameLoaderClient.h>
36 #include <WebCore/FrameLoaderTypes.h>
37 #include <WebCore/PolicyChecker.h>
38 #include <wtf/Forward.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/RetainPtr.h>
48 class CertificateInfo;
50 class HTMLFrameOwnerElement;
59 class InjectedBundleFileHandle;
60 class InjectedBundleHitTestResult;
61 class InjectedBundleNodeHandle;
62 class InjectedBundleRangeHandle;
63 class InjectedBundleScriptWorld;
66 class WebFrame : public API::ObjectImpl<API::Object::Type::BundleFrame> {
68 static PassRefPtr<WebFrame> createWithCoreMainFrame(WebPage*, WebCore::Frame*);
69 static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
72 // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down.
75 WebPage* page() const;
77 static WebFrame* fromCoreFrame(WebCore::Frame&);
78 WebCore::Frame* coreFrame() const { return m_coreFrame; }
80 uint64_t frameID() const { return m_frameID; }
82 uint64_t setUpPolicyListener(WebCore::FramePolicyFunction);
83 void invalidatePolicyListener();
84 void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t navigationID, DownloadID);
86 void startDownload(const WebCore::ResourceRequest&);
87 void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, WebCore::SessionID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
89 String source() const;
90 String contentsAsString() const;
91 String selectionAsString() const;
93 WebCore::IntSize size() const;
95 // WKBundleFrame API and SPI functions
96 bool isMainFrame() const;
99 WebCore::CertificateInfo certificateInfo() const;
100 String innerText() const;
101 bool isFrameSet() const;
102 WebFrame* parentFrame() const;
103 Ref<API::Array> childFrames();
104 JSGlobalContextRef jsContext();
105 JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*);
106 WebCore::IntRect contentBounds() const;
107 WebCore::IntRect visibleContentBounds() const;
108 WebCore::IntRect visibleContentBoundsExcludingScrollbars() const;
109 WebCore::IntSize scrollOffset() const;
110 bool hasHorizontalScrollbar() const;
111 bool hasVerticalScrollbar() const;
112 PassRefPtr<InjectedBundleHitTestResult> hitTest(const WebCore::IntPoint) const;
113 bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha);
114 bool containsAnyFormElements() const;
115 bool containsAnyFormControls() const;
117 bool handlesPageScaleGesture() const;
118 bool requiresUnifiedScaleFactor() const;
119 void setAccessibleName(const String&);
121 static WebFrame* frameForContext(JSContextRef);
123 JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
124 JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
125 JSValueRef jsWrapperForWorld(InjectedBundleFileHandle*, InjectedBundleScriptWorld*);
127 static String counterValue(JSObjectRef element);
129 String layerTreeAsText() const;
131 unsigned pendingUnloadCount() const;
133 bool allowsFollowingLink(const WebCore::URL&) const;
135 String provisionalURL() const;
136 String suggestedFilenameForResourceWithURL(const WebCore::URL&) const;
137 String mimeTypeForResourceWithURL(const WebCore::URL&) const;
139 void setTextDirection(const String&);
141 void documentLoaderDetached(uint64_t navigationID);
143 // Simple listener class used by plug-ins to know when frames finish or fail loading.
146 virtual ~LoadListener() { }
148 virtual void didFinishLoad(WebFrame*) = 0;
149 virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
151 void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
152 LoadListener* loadListener() const { return m_loadListener; }
155 typedef bool (*FrameFilterFunction)(WKBundleFrameRef, WKBundleFrameRef subframe, void* context);
156 RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context);
159 PassRefPtr<ShareableBitmap> createSelectionSnapshot() const;
162 uint64_t firstLayerTreeTransactionIDAfterDidCommitLoad() const { return m_firstLayerTreeTransactionIDAfterDidCommitLoad; }
163 void setFirstLayerTreeTransactionIDAfterDidCommitLoad(uint64_t transactionID) { m_firstLayerTreeTransactionIDAfterDidCommitLoad = transactionID; }
167 static PassRefPtr<WebFrame> create(std::unique_ptr<WebFrameLoaderClient>);
168 WebFrame(std::unique_ptr<WebFrameLoaderClient>);
170 WebCore::Frame* m_coreFrame;
172 uint64_t m_policyListenerID;
173 WebCore::FramePolicyFunction m_policyFunction;
174 DownloadID m_policyDownloadID;
176 std::unique_ptr<WebFrameLoaderClient> m_frameLoaderClient;
177 LoadListener* m_loadListener;
182 uint64_t m_firstLayerTreeTransactionIDAfterDidCommitLoad;
186 } // namespace WebKit