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 "ImmutableArray.h"
32 #include "WebFrameLoaderClient.h"
33 #include <JavaScriptCore/JSBase.h>
34 #include <WebCore/FrameLoaderClient.h>
35 #include <WebCore/FrameLoaderTypes.h>
36 #include <WebCore/PolicyChecker.h>
37 #include <wtf/Forward.h>
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/RefPtr.h>
40 #include <wtf/RetainPtr.h>
44 class HTMLFrameOwnerElement;
50 class InjectedBundleNodeHandle;
51 class InjectedBundleRangeHandle;
52 class InjectedBundleScriptWorld;
55 #if ENABLE(WEB_INTENTS)
59 class WebFrame : public APIObject {
61 static const Type APIType = TypeBundleFrame;
63 static PassRefPtr<WebFrame> createMainFrame(WebPage*);
64 static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
67 // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down.
70 WebPage* page() const;
71 WebCore::Frame* coreFrame() const { return m_coreFrame; }
73 uint64_t frameID() const { return m_frameID; }
75 uint64_t setUpPolicyListener(WebCore::FramePolicyFunction);
76 void invalidatePolicyListener();
77 void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t downloadID);
78 #if ENABLE(TIZEN_DOWNLOAD_ATTRIBUTE)
79 void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String());
81 void startDownload(const WebCore::ResourceRequest&);
83 void convertHandleToDownload(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
85 #if ENABLE(WEB_INTENTS)
86 void deliverIntent(const IntentData&);
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 String innerText() const;
100 bool isFrameSet() const;
101 WebFrame* parentFrame() const;
102 PassRefPtr<ImmutableArray> childFrames();
103 JSValueRef computedStyleIncludingVisitedInfo(JSObjectRef element);
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 bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha);
113 bool containsAnyFormElements() const;
115 static WebFrame* frameForContext(JSContextRef);
117 JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
118 JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
120 static String counterValue(JSObjectRef element);
121 static String markerText(JSObjectRef element);
123 unsigned numberOfActiveAnimations() const;
124 bool pauseAnimationOnElementWithId(const String& animationName, const String& elementID, double time);
125 bool pauseTransitionOnElementWithId(const String& propertyName, const String& elementID, double time);
126 void suspendAnimations();
127 void resumeAnimations();
128 String layerTreeAsText() const;
130 unsigned pendingUnloadCount() const;
132 bool allowsFollowingLink(const WebCore::KURL&) const;
134 String provisionalURL() const;
135 String suggestedFilenameForResourceWithURL(const WebCore::KURL&) const;
136 String mimeTypeForResourceWithURL(const WebCore::KURL&) const;
138 void setTextDirection(const String&);
140 // Simple listener class used by plug-ins to know when frames finish or fail loading.
143 virtual ~LoadListener() { }
145 virtual void didFinishLoad(WebFrame*) = 0;
146 virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
148 void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
149 LoadListener* loadListener() const { return m_loadListener; }
151 #if PLATFORM(MAC) || PLATFORM(WIN)
152 typedef bool (*FrameFilterFunction)(WKBundleFrameRef, WKBundleFrameRef subframe, void* context);
153 RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context);
157 static PassRefPtr<WebFrame> create();
160 void init(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
162 virtual Type type() const { return APIType; }
164 WebCore::Frame* m_coreFrame;
166 uint64_t m_policyListenerID;
167 WebCore::FramePolicyFunction m_policyFunction;
168 uint64_t m_policyDownloadID;
170 WebFrameLoaderClient m_frameLoaderClient;
171 LoadListener* m_loadListener;
176 } // namespace WebKit