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 "config.h" |
27 | #include "WKFrame.h" |
28 | |
29 | #include "APIData.h" |
30 | #include "APIFrameHandle.h" |
31 | #include "APIFrameInfo.h" |
32 | #include "WKAPICast.h" |
33 | #include "WebCertificateInfo.h" |
34 | #include "WebFrameProxy.h" |
35 | #include "WebPageProxy.h" |
36 | |
37 | using namespace WebKit; |
38 | |
39 | WKTypeID WKFrameGetTypeID() |
40 | { |
41 | return toAPI(WebFrameProxy::APIType); |
42 | } |
43 | |
44 | bool WKFrameIsMainFrame(WKFrameRef frameRef) |
45 | { |
46 | return toImpl(frameRef)->isMainFrame(); |
47 | } |
48 | |
49 | WKFrameLoadState WKFrameGetFrameLoadState(WKFrameRef frameRef) |
50 | { |
51 | WebFrameProxy* frame = toImpl(frameRef); |
52 | switch (frame->frameLoadState().state()) { |
53 | case FrameLoadState::State::Provisional: |
54 | return kWKFrameLoadStateProvisional; |
55 | case FrameLoadState::State::Committed: |
56 | return kWKFrameLoadStateCommitted; |
57 | case FrameLoadState::State::Finished: |
58 | return kWKFrameLoadStateFinished; |
59 | } |
60 | |
61 | ASSERT_NOT_REACHED(); |
62 | return kWKFrameLoadStateFinished; |
63 | } |
64 | |
65 | WKURLRef WKFrameCopyProvisionalURL(WKFrameRef frameRef) |
66 | { |
67 | return toCopiedURLAPI(toImpl(frameRef)->provisionalURL()); |
68 | } |
69 | |
70 | WKURLRef WKFrameCopyURL(WKFrameRef frameRef) |
71 | { |
72 | return toCopiedURLAPI(toImpl(frameRef)->url()); |
73 | } |
74 | |
75 | WKURLRef WKFrameCopyUnreachableURL(WKFrameRef frameRef) |
76 | { |
77 | return toCopiedURLAPI(toImpl(frameRef)->unreachableURL()); |
78 | } |
79 | |
80 | void WKFrameStopLoading(WKFrameRef frameRef) |
81 | { |
82 | toImpl(frameRef)->stopLoading(); |
83 | } |
84 | |
85 | WKStringRef WKFrameCopyMIMEType(WKFrameRef frameRef) |
86 | { |
87 | return toCopiedAPI(toImpl(frameRef)->mimeType()); |
88 | } |
89 | |
90 | WKStringRef WKFrameCopyTitle(WKFrameRef frameRef) |
91 | { |
92 | return toCopiedAPI(toImpl(frameRef)->title()); |
93 | } |
94 | |
95 | WKPageRef WKFrameGetPage(WKFrameRef frameRef) |
96 | { |
97 | return toAPI(toImpl(frameRef)->page()); |
98 | } |
99 | |
100 | WKCertificateInfoRef WKFrameGetCertificateInfo(WKFrameRef frameRef) |
101 | { |
102 | return toAPI(toImpl(frameRef)->certificateInfo()); |
103 | } |
104 | |
105 | bool WKFrameCanProvideSource(WKFrameRef frameRef) |
106 | { |
107 | return toImpl(frameRef)->canProvideSource(); |
108 | } |
109 | |
110 | bool WKFrameCanShowMIMEType(WKFrameRef frameRef, WKStringRef mimeTypeRef) |
111 | { |
112 | return toImpl(frameRef)->canShowMIMEType(toWTFString(mimeTypeRef)); |
113 | } |
114 | |
115 | bool WKFrameIsDisplayingStandaloneImageDocument(WKFrameRef frameRef) |
116 | { |
117 | return toImpl(frameRef)->isDisplayingStandaloneImageDocument(); |
118 | } |
119 | |
120 | bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frameRef) |
121 | { |
122 | return toImpl(frameRef)->isDisplayingMarkupDocument(); |
123 | } |
124 | |
125 | bool WKFrameIsFrameSet(WKFrameRef frameRef) |
126 | { |
127 | return toImpl(frameRef)->isFrameSet(); |
128 | } |
129 | |
130 | WKFrameHandleRef WKFrameCreateFrameHandle(WKFrameRef frameRef) |
131 | { |
132 | return toAPI(&API::FrameHandle::create(toImpl(frameRef)->frameID()).leakRef()); |
133 | } |
134 | |
135 | WKFrameInfoRef WKFrameCreateFrameInfo(WKFrameRef frameRef) |
136 | { |
137 | return toAPI(&API::FrameInfo::create(*toImpl(frameRef), WebCore::SecurityOrigin::createFromString(toImpl(frameRef)->url())).leakRef()); |
138 | } |
139 | |
140 | void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context) |
141 | { |
142 | toImpl(frameRef)->getMainResourceData(toGenericCallbackFunction(context, callback)); |
143 | } |
144 | |
145 | void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context) |
146 | { |
147 | toImpl(frameRef)->getResourceData(toImpl(resourceURL), toGenericCallbackFunction(context, callback)); |
148 | } |
149 | |
150 | void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context) |
151 | { |
152 | toImpl(frameRef)->getWebArchive(toGenericCallbackFunction(context, callback)); |
153 | } |
154 | |