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"
31 #include "WebFrameLoaderClient.h"
32 #include <JavaScriptCore/JSBase.h>
33 #include <WebCore/FrameLoaderClient.h>
34 #include <WebCore/FrameLoaderTypes.h>
35 #include <WebCore/PolicyChecker.h>
36 #include <wtf/Forward.h>
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefPtr.h>
42 class HTMLFrameOwnerElement;
48 class InjectedBundleNodeHandle;
49 class InjectedBundleRangeHandle;
50 class InjectedBundleScriptWorld;
53 class WebFrame : public APIObject {
55 static const Type APIType = TypeBundleFrame;
57 static PassRefPtr<WebFrame> createMainFrame(WebPage*);
58 static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
61 // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down.
64 WebPage* page() const;
65 WebCore::Frame* coreFrame() const { return m_coreFrame; }
67 uint64_t frameID() const { return m_frameID; }
69 uint64_t setUpPolicyListener(WebCore::FramePolicyFunction);
70 void invalidatePolicyListener();
71 void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t downloadID);
73 void startDownload(const WebCore::ResourceRequest&);
74 void convertHandleToDownload(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest& initialRequest, const WebCore::ResourceResponse&);
76 String source() const;
77 String contentsAsString() const;
78 String selectionAsString() const;
80 WebCore::IntSize size() const;
82 // WKBundleFrame API and SPI functions
83 bool isMainFrame() const;
86 String innerText() const;
87 bool isFrameSet() const;
88 PassRefPtr<ImmutableArray> childFrames();
89 JSValueRef computedStyleIncludingVisitedInfo(JSObjectRef element);
90 JSGlobalContextRef jsContext();
91 JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*);
92 WebCore::IntRect contentBounds() const;
93 WebCore::IntRect visibleContentBounds() const;
94 WebCore::IntRect visibleContentBoundsExcludingScrollbars() const;
95 WebCore::IntSize scrollOffset() const;
96 bool hasHorizontalScrollbar() const;
97 bool hasVerticalScrollbar() const;
98 bool getDocumentBackgroundColor(double* red, double* green, double* blue, double* alpha);
99 bool containsAnyFormElements() const;
101 static WebFrame* frameForContext(JSContextRef);
103 JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
104 JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
106 static String counterValue(JSObjectRef element);
107 static String markerText(JSObjectRef element);
109 unsigned numberOfActiveAnimations() const;
110 bool pauseAnimationOnElementWithId(const String& animationName, const String& elementID, double time);
111 bool pauseTransitionOnElementWithId(const String& propertyName, const String& elementID, double time);
112 void suspendAnimations();
113 void resumeAnimations();
114 String layerTreeAsText() const;
116 unsigned pendingUnloadCount() const;
118 bool allowsFollowingLink(const WebCore::KURL&) const;
120 String provisionalURL() const;
121 String suggestedFilenameForResourceWithURL(const WebCore::KURL&) const;
122 String mimeTypeForResourceWithURL(const WebCore::KURL&) const;
124 void setTextDirection(const String&);
126 // Simple listener class used by plug-ins to know when frames finish or fail loading.
129 virtual ~LoadListener() { }
131 virtual void didFinishLoad(WebFrame*) = 0;
132 virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
134 void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
135 LoadListener* loadListener() const { return m_loadListener; }
137 #if PLATFORM(MAC) || PLATFORM(WIN)
138 RetainPtr<CFDataRef> webArchiveData() const;
142 static PassRefPtr<WebFrame> create();
145 void init(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
147 virtual Type type() const { return APIType; }
149 WebCore::Frame* m_coreFrame;
151 uint64_t m_policyListenerID;
152 WebCore::FramePolicyFunction m_policyFunction;
153 uint64_t m_policyDownloadID;
155 WebFrameLoaderClient m_frameLoaderClient;
156 LoadListener* m_loadListener;
161 } // namespace WebKit