282e12409d34b9126869b8e2485866f1b6964196
[WebKit.git] / Source / WebKit2 / UIProcess / API / C / WKFrame.cpp
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 #include "WKFrame.h"
27
28 #include "WKAPICast.h"
29 #include "WebFrameProxy.h"
30
31 #ifdef __BLOCKS__
32 #include <Block.h>
33 #endif
34
35 using namespace WebKit;
36
37 WKTypeID WKFrameGetTypeID()
38 {
39     return toAPI(WebFrameProxy::APIType);
40 }
41
42 bool WKFrameIsMainFrame(WKFrameRef frameRef)
43 {
44     return toImpl(frameRef)->isMainFrame();
45 }
46
47 WKFrameLoadState WKFrameGetFrameLoadState(WKFrameRef frameRef)
48 {
49     WebFrameProxy* frame = toImpl(frameRef);
50     switch (frame->loadState()) {
51         case WebFrameProxy::LoadStateProvisional:
52             return kWKFrameLoadStateProvisional;
53         case WebFrameProxy::LoadStateCommitted:
54             return kWKFrameLoadStateCommitted;
55         case WebFrameProxy::LoadStateFinished:
56             return kWKFrameLoadStateFinished;
57     }
58     
59     ASSERT_NOT_REACHED();
60     return kWKFrameLoadStateFinished;
61 }
62
63 WKURLRef WKFrameCopyProvisionalURL(WKFrameRef frameRef)
64 {
65     return toCopiedURLAPI(toImpl(frameRef)->provisionalURL());
66 }
67
68 WKURLRef WKFrameCopyURL(WKFrameRef frameRef)
69 {
70     return toCopiedURLAPI(toImpl(frameRef)->url());
71 }
72
73 WKURLRef WKFrameCopyUnreachableURL(WKFrameRef frameRef)
74 {
75     return toCopiedURLAPI(toImpl(frameRef)->unreachableURL());
76 }
77
78 WKStringRef WKFrameCopyMIMEType(WKFrameRef frameRef)
79 {
80     return toCopiedAPI(toImpl(frameRef)->mimeType());
81 }
82
83 WKStringRef WKFrameCopyTitle(WKFrameRef frameRef)
84 {
85     return toCopiedAPI(toImpl(frameRef)->title());
86 }
87
88 WKPageRef WKFrameGetPage(WKFrameRef frameRef)
89 {
90     return toAPI(toImpl(frameRef)->page());
91 }
92
93 WKArrayRef WKFrameCopyChildFrames(WKFrameRef frameRef)
94 {
95     return toAPI(toImpl(frameRef)->childFrames().releaseRef());
96 }
97
98 WKFrameRef WKFrameGetParentFrame(WKFrameRef frameRef)
99 {
100     return toAPI(toImpl(frameRef)->parentFrame());
101 }
102
103 WKCertificateInfoRef WKFrameGetCertificateInfo(WKFrameRef frameRef)
104 {
105     return toAPI(toImpl(frameRef)->certificateInfo());
106 }
107
108 bool WKFrameCanProvideSource(WKFrameRef frameRef)
109 {
110     return toImpl(frameRef)->canProvideSource();
111 }
112
113 bool WKFrameCanShowMIMEType(WKFrameRef frameRef, WKStringRef mimeTypeRef)
114 {
115     return toImpl(frameRef)->canShowMIMEType(toWTFString(mimeTypeRef));
116 }
117
118 bool WKFrameIsDisplayingStandaloneImageDocument(WKFrameRef frameRef)
119 {
120     return toImpl(frameRef)->isDisplayingStandaloneImageDocument();
121 }
122
123 bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frameRef)
124 {
125     return toImpl(frameRef)->isDisplayingMarkupDocument();
126 }
127
128 bool WKFrameIsFrameSet(WKFrameRef frameRef)
129 {
130     return toImpl(frameRef)->isFrameSet();
131 }
132
133 void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context)
134 {
135     toImpl(frameRef)->getMainResourceData(DataCallback::create(context, callback));
136 }
137
138 void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context)
139 {
140     toImpl(frameRef)->getResourceData(toImpl(resourceURL), DataCallback::create(context, callback));
141 }
142
143 #ifdef __BLOCKS__
144 static void callGetResourceDataBlockAndDispose(WKDataRef data, WKErrorRef error, void* context)
145 {
146     WKFrameGetResourceDataBlock block = (WKFrameGetResourceDataBlock)context;
147     block(data, error);
148     Block_release(block);
149 }
150
151 void WKFrameGetMainResourceData_b(WKFrameRef frameRef, WKFrameGetResourceDataBlock block)
152 {
153     WKFrameGetMainResourceData(frameRef, callGetResourceDataBlockAndDispose, Block_copy(block));
154 }
155
156 void WKFrameGetResourceData_b(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataBlock block)
157 {
158     WKFrameGetResourceData(frameRef, resourceURL, callGetResourceDataBlockAndDispose, Block_copy(block));
159 }
160 #endif
161
162 void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context)
163 {
164     toImpl(frameRef)->getWebArchive(DataCallback::create(context, callback));
165 }
166
167 #ifdef __BLOCKS__
168 static void callGetWebArchiveBlockAndDispose(WKDataRef archiveData, WKErrorRef error, void* context)
169 {
170     WKFrameGetWebArchiveBlock block = (WKFrameGetWebArchiveBlock)context;
171     block(archiveData, error);
172     Block_release(block);
173 }
174
175 void WKFrameGetWebArchive_b(WKFrameRef frameRef, WKFrameGetWebArchiveBlock block)
176 {
177     WKFrameGetWebArchive(frameRef, callGetWebArchiveBlockAndDispose, Block_copy(block));
178 }
179 #endif