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