Home | History | Annotate | Download | only in c
      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 "WKBundleFrame.h"
     28 #include "WKBundleFramePrivate.h"
     29 
     30 #include "WKAPICast.h"
     31 #include "WKBundleAPICast.h"
     32 #include "WebFrame.h"
     33 #include <WebCore/Frame.h>
     34 #include <WebCore/FrameView.h>
     35 
     36 using namespace WebCore;
     37 using namespace WebKit;
     38 
     39 WKTypeID WKBundleFrameGetTypeID()
     40 {
     41     return toAPI(WebFrame::APIType);
     42 }
     43 
     44 bool WKBundleFrameIsMainFrame(WKBundleFrameRef frameRef)
     45 {
     46     return toImpl(frameRef)->isMainFrame();
     47 }
     48 
     49 WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frameRef)
     50 {
     51     return toCopiedURLAPI(toImpl(frameRef)->url());
     52 }
     53 
     54 WKURLRef WKBundleFrameCopyProvisionalURL(WKBundleFrameRef frameRef)
     55 {
     56     return toCopiedURLAPI(toImpl(frameRef)->provisionalURL());
     57 }
     58 
     59 WKFrameLoadState WKBundleFrameGetFrameLoadState(WKBundleFrameRef frameRef)
     60 {
     61     Frame* coreFrame = toImpl(frameRef)->coreFrame();
     62     if (!coreFrame)
     63         return kWKFrameLoadStateFinished;
     64 
     65     FrameLoader* loader = coreFrame->loader();
     66     if (!loader)
     67         return kWKFrameLoadStateFinished;
     68 
     69     switch (loader->state()) {
     70     case FrameStateProvisional:
     71         return kWKFrameLoadStateProvisional;
     72     case FrameStateCommittedPage:
     73         return kWKFrameLoadStateCommitted;
     74     case FrameStateComplete:
     75         return kWKFrameLoadStateFinished;
     76     }
     77 
     78     ASSERT_NOT_REACHED();
     79     return kWKFrameLoadStateFinished;
     80 }
     81 
     82 WKArrayRef WKBundleFrameCopyChildFrames(WKBundleFrameRef frameRef)
     83 {
     84     return toAPI(toImpl(frameRef)->childFrames().releaseRef());
     85 }
     86 
     87 unsigned WKBundleFrameGetNumberOfActiveAnimations(WKBundleFrameRef frameRef)
     88 {
     89     return toImpl(frameRef)->numberOfActiveAnimations();
     90 }
     91 
     92 bool WKBundleFramePauseAnimationOnElementWithId(WKBundleFrameRef frameRef, WKStringRef name, WKStringRef elementID, double time)
     93 {
     94     return toImpl(frameRef)->pauseAnimationOnElementWithId(toImpl(name)->string(), toImpl(elementID)->string(), time);
     95 }
     96 
     97 void WKBundleFrameSuspendAnimations(WKBundleFrameRef frameRef)
     98 {
     99     toImpl(frameRef)->suspendAnimations();
    100 }
    101 
    102 void WKBundleFrameResumeAnimations(WKBundleFrameRef frameRef)
    103 {
    104     toImpl(frameRef)->resumeAnimations();
    105 }
    106 
    107 JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frameRef)
    108 {
    109     return toImpl(frameRef)->jsContext();
    110 }
    111 
    112 WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context)
    113 {
    114     return toAPI(WebFrame::frameForContext(context));
    115 }
    116 
    117 JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frameRef, WKBundleScriptWorldRef worldRef)
    118 {
    119     return toImpl(frameRef)->jsContextForWorld(toImpl(worldRef));
    120 }
    121 
    122 JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frameRef, WKBundleNodeHandleRef nodeHandleRef, WKBundleScriptWorldRef worldRef)
    123 {
    124     return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef));
    125 }
    126 
    127 JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef)
    128 {
    129     return toImpl(frameRef)->jsWrapperForWorld(toImpl(rangeHandleRef), toImpl(worldRef));
    130 }
    131 
    132 WKStringRef WKBundleFrameCopyName(WKBundleFrameRef frameRef)
    133 {
    134     return toCopiedAPI(toImpl(frameRef)->name());
    135 }
    136 
    137 JSValueRef WKBundleFrameGetComputedStyleIncludingVisitedInfo(WKBundleFrameRef frameRef, JSObjectRef element)
    138 {
    139     return toImpl(frameRef)->computedStyleIncludingVisitedInfo(element);
    140 }
    141 
    142 WKStringRef WKBundleFrameCopyCounterValue(WKBundleFrameRef frameRef, JSObjectRef element)
    143 {
    144     return toCopiedAPI(toImpl(frameRef)->counterValue(element));
    145 }
    146 
    147 WKStringRef WKBundleFrameCopyMarkerText(WKBundleFrameRef frameRef, JSObjectRef element)
    148 {
    149     return toCopiedAPI(toImpl(frameRef)->markerText(element));
    150 }
    151 
    152 WKStringRef WKBundleFrameCopyInnerText(WKBundleFrameRef frameRef)
    153 {
    154     return toCopiedAPI(toImpl(frameRef)->innerText());
    155 }
    156 
    157 unsigned WKBundleFrameGetPendingUnloadCount(WKBundleFrameRef frameRef)
    158 {
    159     return toImpl(frameRef)->pendingUnloadCount();
    160 }
    161 
    162 WKBundlePageRef WKBundleFrameGetPage(WKBundleFrameRef frameRef)
    163 {
    164     return toAPI(toImpl(frameRef)->page());
    165 }
    166 
    167 void WKBundleFrameClearOpener(WKBundleFrameRef frameRef)
    168 {
    169     Frame* coreFrame = toImpl(frameRef)->coreFrame();
    170     if (coreFrame)
    171         coreFrame->loader()->setOpener(0);
    172 }
    173 
    174 WKStringRef WKBundleFrameCopyLayerTreeAsText(WKBundleFrameRef frameRef)
    175 {
    176     return toCopiedAPI(toImpl(frameRef)->layerTreeAsText());
    177 }
    178 
    179 bool WKBundleFrameAllowsFollowingLink(WKBundleFrameRef frameRef, WKURLRef urlRef)
    180 {
    181     return toImpl(frameRef)->allowsFollowingLink(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()));
    182 }
    183 
    184 WKRect WKBundleFrameGetContentBounds(WKBundleFrameRef frameRef)
    185 {
    186     return toAPI(toImpl(frameRef)->contentBounds());
    187 }
    188 
    189 WKRect WKBundleFrameGetVisibleContentBounds(WKBundleFrameRef frameRef)
    190 {
    191     return toAPI(toImpl(frameRef)->visibleContentBounds());
    192 }
    193 
    194 WKRect WKBundleFrameGetVisibleContentBoundsExcludingScrollbars(WKBundleFrameRef frameRef)
    195 {
    196     return toAPI(toImpl(frameRef)->visibleContentBoundsExcludingScrollbars());
    197 }
    198 
    199 WKSize WKBundleFrameGetScrollOffset(WKBundleFrameRef frameRef)
    200 {
    201     return toAPI(toImpl(frameRef)->scrollOffset());
    202 }
    203 
    204 bool WKBundleFrameHasHorizontalScrollbar(WKBundleFrameRef frameRef)
    205 {
    206     return toImpl(frameRef)->hasHorizontalScrollbar();
    207 }
    208 
    209 bool WKBundleFrameHasVerticalScrollbar(WKBundleFrameRef frameRef)
    210 {
    211     return toImpl(frameRef)->hasVerticalScrollbar();
    212 }
    213 
    214 bool WKBundleFrameGetDocumentBackgroundColor(WKBundleFrameRef frameRef, double* red, double* green, double* blue, double* alpha)
    215 {
    216     return toImpl(frameRef)->getDocumentBackgroundColor(red, green, blue, alpha);
    217 }
    218 
    219 WKStringRef WKBundleFrameCopySuggestedFilenameForResourceWithURL(WKBundleFrameRef frameRef, WKURLRef urlRef)
    220 {
    221     return toCopiedAPI(toImpl(frameRef)->suggestedFilenameForResourceWithURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string())));
    222 }
    223 
    224 WKStringRef WKBundleFrameCopyMIMETypeForResourceWithURL(WKBundleFrameRef frameRef, WKURLRef urlRef)
    225 {
    226     return toCopiedAPI(toImpl(frameRef)->mimeTypeForResourceWithURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string())));
    227 }
    228