Home | History | Annotate | Download | only in InjectedBundle
      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 "InjectedBundlePageLoaderClient.h"
     28 
     29 #include "InjectedBundleScriptWorld.h"
     30 #include "WKAPICast.h"
     31 #include "WKBundleAPICast.h"
     32 #include "WebError.h"
     33 #include <wtf/text/WTFString.h>
     34 
     35 using namespace WebCore;
     36 
     37 namespace WebKit {
     38 
     39 void InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
     40 {
     41     if (!m_client.didStartProvisionalLoadForFrame)
     42         return;
     43 
     44     WKTypeRef userDataToPass = 0;
     45     m_client.didStartProvisionalLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
     46     userData = adoptRef(toImpl(userDataToPass));
     47 }
     48 
     49 void InjectedBundlePageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
     50 {
     51     if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
     52         return;
     53 
     54     WKTypeRef userDataToPass = 0;
     55     m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
     56     userData = adoptRef(toImpl(userDataToPass));
     57 }
     58 
     59 void InjectedBundlePageLoaderClient::didFailProvisionalLoadWithErrorForFrame(WebPage* page, WebFrame* frame, const ResourceError& error, RefPtr<APIObject>& userData)
     60 {
     61     if (!m_client.didFailProvisionalLoadWithErrorForFrame)
     62         return;
     63 
     64     WKTypeRef userDataToPass = 0;
     65     m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), &userDataToPass, m_client.clientInfo);
     66     userData = adoptRef(toImpl(userDataToPass));
     67 }
     68 
     69 void InjectedBundlePageLoaderClient::didCommitLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
     70 {
     71     if (!m_client.didCommitLoadForFrame)
     72         return;
     73 
     74     WKTypeRef userDataToPass = 0;
     75     m_client.didCommitLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
     76     userData = adoptRef(toImpl(userDataToPass));
     77 }
     78 
     79 void InjectedBundlePageLoaderClient::didFinishDocumentLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
     80 {
     81     if (!m_client.didFinishDocumentLoadForFrame)
     82         return;
     83 
     84     WKTypeRef userDataToPass = 0;
     85     m_client.didFinishDocumentLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
     86     userData = adoptRef(toImpl(userDataToPass));
     87 }
     88 
     89 void InjectedBundlePageLoaderClient::didFinishLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
     90 {
     91     if (!m_client.didFinishLoadForFrame)
     92         return;
     93 
     94     WKTypeRef userDataToPass = 0;
     95     m_client.didFinishLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
     96     userData = adoptRef(toImpl(userDataToPass));
     97 }
     98 
     99 void InjectedBundlePageLoaderClient::didFailLoadWithErrorForFrame(WebPage* page, WebFrame* frame, const ResourceError& error, RefPtr<APIObject>& userData)
    100 {
    101     if (!m_client.didFailLoadWithErrorForFrame)
    102         return;
    103 
    104     WKTypeRef userDataToPass = 0;
    105     m_client.didFailLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), &userDataToPass, m_client.clientInfo);
    106     userData = adoptRef(toImpl(userDataToPass));
    107 }
    108 
    109 void InjectedBundlePageLoaderClient::didSameDocumentNavigationForFrame(WebPage* page, WebFrame* frame, SameDocumentNavigationType type, RefPtr<APIObject>& userData)
    110 {
    111     if (!m_client.didSameDocumentNavigationForFrame)
    112         return;
    113 
    114     WKTypeRef userDataToPass = 0;
    115     m_client.didSameDocumentNavigationForFrame(toAPI(page), toAPI(frame), toAPI(type), &userDataToPass, m_client.clientInfo);
    116     userData = adoptRef(toImpl(userDataToPass));
    117 }
    118 
    119 void InjectedBundlePageLoaderClient::didReceiveTitleForFrame(WebPage* page, const String& title, WebFrame* frame, RefPtr<APIObject>& userData)
    120 {
    121     if (!m_client.didReceiveTitleForFrame)
    122         return;
    123 
    124     WKTypeRef userDataToPass = 0;
    125     m_client.didReceiveTitleForFrame(toAPI(page), toAPI(title.impl()), toAPI(frame), &userDataToPass, m_client.clientInfo);
    126     userData = adoptRef(toImpl(userDataToPass));
    127 }
    128 
    129 void InjectedBundlePageLoaderClient::didFirstLayoutForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
    130 {
    131     if (!m_client.didFirstLayoutForFrame)
    132         return;
    133 
    134     WKTypeRef userDataToPass = 0;
    135     m_client.didFirstLayoutForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
    136     userData = adoptRef(toImpl(userDataToPass));
    137 }
    138 
    139 void InjectedBundlePageLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
    140 {
    141     if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
    142         return;
    143 
    144     WKTypeRef userDataToPass = 0;
    145     m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
    146     userData = adoptRef(toImpl(userDataToPass));
    147 }
    148 
    149 void InjectedBundlePageLoaderClient::didRemoveFrameFromHierarchy(WebPage* page , WebFrame* frame, RefPtr<APIObject>& userData)
    150 {
    151     if (!m_client.didRemoveFrameFromHierarchy)
    152         return;
    153 
    154     WKTypeRef userDataToPass = 0;
    155     m_client.didRemoveFrameFromHierarchy(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
    156     userData = adoptRef(toImpl(userDataToPass));
    157 }
    158 
    159 void InjectedBundlePageLoaderClient::didDisplayInsecureContentForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
    160 {
    161     if (!m_client.didDisplayInsecureContentForFrame)
    162         return;
    163 
    164     WKTypeRef userDataToPass = 0;
    165     m_client.didDisplayInsecureContentForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
    166     userData = adoptRef(toImpl(userDataToPass));
    167 }
    168 
    169 void InjectedBundlePageLoaderClient::didRunInsecureContentForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
    170 {
    171     if (!m_client.didRunInsecureContentForFrame)
    172         return;
    173 
    174     WKTypeRef userDataToPass = 0;
    175     m_client.didRunInsecureContentForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo);
    176     userData = adoptRef(toImpl(userDataToPass));
    177 }
    178 
    179 void InjectedBundlePageLoaderClient::didClearWindowObjectForFrame(WebPage* page, WebFrame* frame, DOMWrapperWorld* world)
    180 {
    181     if (!m_client.didClearWindowObjectForFrame)
    182         return;
    183 
    184     m_client.didClearWindowObjectForFrame(toAPI(page), toAPI(frame), toAPI(InjectedBundleScriptWorld::getOrCreate(world).get()), m_client.clientInfo);
    185 }
    186 
    187 void InjectedBundlePageLoaderClient::didCancelClientRedirectForFrame(WebPage* page, WebFrame* frame)
    188 {
    189     if (!m_client.didCancelClientRedirectForFrame)
    190         return;
    191 
    192     m_client.didCancelClientRedirectForFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
    193 }
    194 
    195 void InjectedBundlePageLoaderClient::willPerformClientRedirectForFrame(WebPage* page, WebFrame* frame, const String& url, double delay, double date)
    196 {
    197     if (!m_client.willPerformClientRedirectForFrame)
    198         return;
    199 
    200     m_client.willPerformClientRedirectForFrame(toAPI(page), toAPI(frame), toURLRef(url.impl()), delay, date, m_client.clientInfo);
    201 }
    202 
    203 void InjectedBundlePageLoaderClient::didHandleOnloadEventsForFrame(WebPage* page, WebFrame* frame)
    204 {
    205     if (!m_client.didHandleOnloadEventsForFrame)
    206         return;
    207 
    208     m_client.didHandleOnloadEventsForFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
    209 }
    210 
    211 } // namespace WebKit
    212