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
37using namespace WebKit;
38
39WKTypeID WKFrameGetTypeID()
40{
41 return toAPI(WebFrameProxy::APIType);
42}
43
44bool WKFrameIsMainFrame(WKFrameRef frameRef)
45{
46 return toImpl(frameRef)->isMainFrame();
47}
48
49WKFrameLoadState 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
65WKURLRef WKFrameCopyProvisionalURL(WKFrameRef frameRef)
66{
67 return toCopiedURLAPI(toImpl(frameRef)->provisionalURL());
68}
69
70WKURLRef WKFrameCopyURL(WKFrameRef frameRef)
71{
72 return toCopiedURLAPI(toImpl(frameRef)->url());
73}
74
75WKURLRef WKFrameCopyUnreachableURL(WKFrameRef frameRef)
76{
77 return toCopiedURLAPI(toImpl(frameRef)->unreachableURL());
78}
79
80void WKFrameStopLoading(WKFrameRef frameRef)
81{
82 toImpl(frameRef)->stopLoading();
83}
84
85WKStringRef WKFrameCopyMIMEType(WKFrameRef frameRef)
86{
87 return toCopiedAPI(toImpl(frameRef)->mimeType());
88}
89
90WKStringRef WKFrameCopyTitle(WKFrameRef frameRef)
91{
92 return toCopiedAPI(toImpl(frameRef)->title());
93}
94
95WKPageRef WKFrameGetPage(WKFrameRef frameRef)
96{
97 return toAPI(toImpl(frameRef)->page());
98}
99
100WKCertificateInfoRef WKFrameGetCertificateInfo(WKFrameRef frameRef)
101{
102 return toAPI(toImpl(frameRef)->certificateInfo());
103}
104
105bool WKFrameCanProvideSource(WKFrameRef frameRef)
106{
107 return toImpl(frameRef)->canProvideSource();
108}
109
110bool WKFrameCanShowMIMEType(WKFrameRef frameRef, WKStringRef mimeTypeRef)
111{
112 return toImpl(frameRef)->canShowMIMEType(toWTFString(mimeTypeRef));
113}
114
115bool WKFrameIsDisplayingStandaloneImageDocument(WKFrameRef frameRef)
116{
117 return toImpl(frameRef)->isDisplayingStandaloneImageDocument();
118}
119
120bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frameRef)
121{
122 return toImpl(frameRef)->isDisplayingMarkupDocument();
123}
124
125bool WKFrameIsFrameSet(WKFrameRef frameRef)
126{
127 return toImpl(frameRef)->isFrameSet();
128}
129
130WKFrameHandleRef WKFrameCreateFrameHandle(WKFrameRef frameRef)
131{
132 return toAPI(&API::FrameHandle::create(toImpl(frameRef)->frameID()).leakRef());
133}
134
135WKFrameInfoRef WKFrameCreateFrameInfo(WKFrameRef frameRef)
136{
137 return toAPI(&API::FrameInfo::create(*toImpl(frameRef), WebCore::SecurityOrigin::createFromString(toImpl(frameRef)->url())).leakRef());
138}
139
140void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context)
141{
142 toImpl(frameRef)->getMainResourceData(toGenericCallbackFunction(context, callback));
143}
144
145void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context)
146{
147 toImpl(frameRef)->getResourceData(toImpl(resourceURL), toGenericCallbackFunction(context, callback));
148}
149
150void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context)
151{
152 toImpl(frameRef)->getWebArchive(toGenericCallbackFunction(context, callback));
153}
154