initial import
[vuplus_webkit] / Source / WebKit2 / WebProcess / WebPage / WebFrame.h
1 /*
2  * Copyright (C) 2010 Apple 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
6  * are met:
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.
12  *
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.
24  */
25
26 #ifndef WebFrame_h
27 #define WebFrame_h
28
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>
39
40 namespace WebCore {
41     class Frame;
42     class HTMLFrameOwnerElement;
43     class KURL;
44 }
45
46 namespace WebKit {
47
48 class InjectedBundleNodeHandle;
49 class InjectedBundleRangeHandle;
50 class InjectedBundleScriptWorld;
51 class WebPage;
52
53 class WebFrame : public APIObject {
54 public:
55     static const Type APIType = TypeBundleFrame;
56
57     static PassRefPtr<WebFrame> createMainFrame(WebPage*);
58     static PassRefPtr<WebFrame> createSubframe(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
59     ~WebFrame();
60
61     // Called when the FrameLoaderClient (and therefore the WebCore::Frame) is being torn down.
62     void invalidate();
63
64     WebPage* page() const;
65     WebCore::Frame* coreFrame() const { return m_coreFrame; }
66
67     uint64_t frameID() const { return m_frameID; }
68
69     uint64_t setUpPolicyListener(WebCore::FramePolicyFunction);
70     void invalidatePolicyListener();
71     void didReceivePolicyDecision(uint64_t listenerID, WebCore::PolicyAction, uint64_t downloadID);
72
73     void startDownload(const WebCore::ResourceRequest&);
74     void convertHandleToDownload(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest& initialRequest, const WebCore::ResourceResponse&);
75
76     String source() const;
77     String contentsAsString() const;
78     String selectionAsString() const;
79
80     WebCore::IntSize size() const;
81
82     // WKBundleFrame API and SPI functions
83     bool isMainFrame() const;
84     String name() const;
85     String url() 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;
100
101     static WebFrame* frameForContext(JSContextRef);
102
103     JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
104     JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
105
106     static String counterValue(JSObjectRef element);
107     static String markerText(JSObjectRef element);
108
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;
115     
116     unsigned pendingUnloadCount() const;
117     
118     bool allowsFollowingLink(const WebCore::KURL&) const;
119
120     String provisionalURL() const;
121     String suggestedFilenameForResourceWithURL(const WebCore::KURL&) const;
122     String mimeTypeForResourceWithURL(const WebCore::KURL&) const;
123
124     void setTextDirection(const String&);
125
126     // Simple listener class used by plug-ins to know when frames finish or fail loading.
127     class LoadListener {
128     public:
129         virtual ~LoadListener() { }
130
131         virtual void didFinishLoad(WebFrame*) = 0;
132         virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
133     };
134     void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
135     LoadListener* loadListener() const { return m_loadListener; }
136     
137 #if PLATFORM(MAC) || PLATFORM(WIN)
138     RetainPtr<CFDataRef> webArchiveData() const;
139 #endif
140
141 private:
142     static PassRefPtr<WebFrame> create();
143     WebFrame();
144
145     void init(WebPage*, const String& frameName, WebCore::HTMLFrameOwnerElement*);
146
147     virtual Type type() const { return APIType; }
148
149     WebCore::Frame* m_coreFrame;
150
151     uint64_t m_policyListenerID;
152     WebCore::FramePolicyFunction m_policyFunction;
153     uint64_t m_policyDownloadID;
154
155     WebFrameLoaderClient m_frameLoaderClient;
156     LoadListener* m_loadListener;
157     
158     uint64_t m_frameID;
159 };
160
161 } // namespace WebKit
162
163 #endif // WebFrame_h