WebKit2: Need API to stop loading a WKFrame
[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 void WKFrameStopLoading(WKFrameRef frameRef)
79 {
80     toImpl(frameRef)->stopLoading();
81 }
82
83 WKStringRef WKFrameCopyMIMEType(WKFrameRef frameRef)
84 {
85     return toCopiedAPI(toImpl(frameRef)->mimeType());
86 }
87
88 WKStringRef WKFrameCopyTitle(WKFrameRef frameRef)
89 {
90     return toCopiedAPI(toImpl(frameRef)->title());
91 }
92
93 WKPageRef WKFrameGetPage(WKFrameRef frameRef)
94 {
95     return toAPI(toImpl(frameRef)->page());
96 }
97
98 WKArrayRef WKFrameCopyChildFrames(WKFrameRef frameRef)
99 {
100     return toAPI(toImpl(frameRef)->childFrames().releaseRef());
101 }
102
103 WKFrameRef WKFrameGetParentFrame(WKFrameRef frameRef)
104 {
105     return toAPI(toImpl(frameRef)->parentFrame());
106 }
107
108 WKCertificateInfoRef WKFrameGetCertificateInfo(WKFrameRef frameRef)
109 {
110     return toAPI(toImpl(frameRef)->certificateInfo());
111 }
112
113 bool WKFrameCanProvideSource(WKFrameRef frameRef)
114 {
115     return toImpl(frameRef)->canProvideSource();
116 }
117
118 bool WKFrameCanShowMIMEType(WKFrameRef frameRef, WKStringRef mimeTypeRef)
119 {
120     return toImpl(frameRef)->canShowMIMEType(toWTFString(mimeTypeRef));
121 }
122
123 bool WKFrameIsDisplayingStandaloneImageDocument(WKFrameRef frameRef)
124 {
125     return toImpl(frameRef)->isDisplayingStandaloneImageDocument();
126 }
127
128 bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frameRef)
129 {
130     return toImpl(frameRef)->isDisplayingMarkupDocument();
131 }
132
133 bool WKFrameIsFrameSet(WKFrameRef frameRef)
134 {
135     return toImpl(frameRef)->isFrameSet();
136 }
137
138 void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context)
139 {
140     toImpl(frameRef)->getMainResourceData(DataCallback::create(context, callback));
141 }
142
143 void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context)
144 {
145     toImpl(frameRef)->getResourceData(toImpl(resourceURL), DataCallback::create(context, callback));
146 }
147
148 #ifdef __BLOCKS__
149 static void callGetResourceDataBlockAndDispose(WKDataRef data, WKErrorRef error, void* context)
150 {
151     WKFrameGetResourceDataBlock block = (WKFrameGetResourceDataBlock)context;
152     block(data, error);
153     Block_release(block);
154 }
155
156 void WKFrameGetMainResourceData_b(WKFrameRef frameRef, WKFrameGetResourceDataBlock block)
157 {
158     WKFrameGetMainResourceData(frameRef, callGetResourceDataBlockAndDispose, Block_copy(block));
159 }
160
161 void WKFrameGetResourceData_b(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataBlock block)
162 {
163     WKFrameGetResourceData(frameRef, resourceURL, callGetResourceDataBlockAndDispose, Block_copy(block));
164 }
165 #endif
166
167 void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context)
168 {
169     toImpl(frameRef)->getWebArchive(DataCallback::create(context, callback));
170 }
171
172 #ifdef __BLOCKS__
173 static void callGetWebArchiveBlockAndDispose(WKDataRef archiveData, WKErrorRef error, void* context)
174 {
175     WKFrameGetWebArchiveBlock block = (WKFrameGetWebArchiveBlock)context;
176     block(archiveData, error);
177     Block_release(block);
178 }
179
180 void WKFrameGetWebArchive_b(WKFrameRef frameRef, WKFrameGetWebArchiveBlock block)
181 {
182     WKFrameGetWebArchive(frameRef, callGetWebArchiveBlockAndDispose, Block_copy(block));
183 }
184 #endif