2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #include "WKAPICast.h"
31 #include "WKRetainPtr.h"
33 #include "WKURLRequest.h"
34 #include "WKURLResponse.h"
35 #include "ewk_url_request.h"
36 #include "ewk_url_request_private.h"
37 #include "ewk_url_response.h"
38 #include "ewk_url_response_private.h"
39 #include "ewk_view_private.h"
40 #include "ewk_view_resource_load_client_private.h"
41 #include "ewk_web_error.h"
42 #include "ewk_web_error_private.h"
43 #include "ewk_web_resource.h"
44 #include "ewk_web_resource_private.h"
45 #include <wtf/text/CString.h>
47 using namespace WebCore;
48 using namespace WebKit;
50 static inline Evas_Object* toEwkView(const void* clientInfo)
52 return static_cast<Evas_Object*>(const_cast<void*>(clientInfo));
55 static void didInitiateLoadForResource(WKPageRef, WKFrameRef wkFrame, uint64_t resourceIdentifier, WKURLRequestRef wkRequest, bool pageIsProvisionallyLoading, const void* clientInfo)
57 bool isMainResource = (WKFrameIsMainFrame(wkFrame) && pageIsProvisionallyLoading);
58 WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKURLRequestCopyURL(wkRequest));
59 #if ENABLE(TIZEN_ON_REDIRECTION_REQUESTED)
63 Ewk_Web_Resource* resource = ewk_web_resource_new(toImpl(wkUrl.get())->string().utf8().data(), isMainResource);
64 Ewk_Url_Request* request = ewk_url_request_new(wkRequest);
65 ewk_view_resource_load_initiated(toEwkView(clientInfo), resourceIdentifier, resource, request);
66 ewk_web_resource_unref(resource);
67 ewk_url_request_unref(request);
70 static void didSendRequestForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo)
72 Ewk_Url_Request* request = ewk_url_request_new(wkRequest);
73 Ewk_Url_Response* redirectResponse = wkRedirectResponse ? ewk_url_response_new(toImpl(wkRedirectResponse)->resourceResponse()) : 0;
74 ewk_view_resource_request_sent(toEwkView(clientInfo), resourceIdentifier, request, redirectResponse);
75 ewk_url_request_unref(request);
77 ewk_url_response_unref(redirectResponse);
80 static void didReceiveResponseForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKURLResponseRef wkResponse, const void* clientInfo)
82 Ewk_Url_Response* response = ewk_url_response_new(toImpl(wkResponse)->resourceResponse());
83 ewk_view_resource_load_response(toEwkView(clientInfo), resourceIdentifier, response);
84 ewk_url_response_unref(response);
87 static void didFinishLoadForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, const void* clientInfo)
89 ewk_view_resource_load_finished(toEwkView(clientInfo), resourceIdentifier);
92 static void didFailLoadForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKErrorRef wkError, const void* clientInfo)
94 Ewk_Web_Error* ewkError = ewk_web_error_new(wkError);
95 ewk_view_resource_load_failed(toEwkView(clientInfo), resourceIdentifier, ewkError);
96 ewk_view_resource_load_finished(toEwkView(clientInfo), resourceIdentifier);
97 ewk_web_error_free(ewkError);
100 void ewk_view_resource_load_client_attach(WKPageRef pageRef, Evas_Object* ewkView)
102 WKPageResourceLoadClient wkResourceLoadClient;
103 memset(&wkResourceLoadClient, 0, sizeof(WKPageResourceLoadClient));
104 wkResourceLoadClient.version = kWKPageResourceLoadClientCurrentVersion;
105 wkResourceLoadClient.clientInfo = ewkView;
106 wkResourceLoadClient.didInitiateLoadForResource = didInitiateLoadForResource;
107 wkResourceLoadClient.didSendRequestForResource = didSendRequestForResource;
108 wkResourceLoadClient.didReceiveResponseForResource = didReceiveResponseForResource;
109 wkResourceLoadClient.didFinishLoadForResource = didFinishLoadForResource;
110 wkResourceLoadClient.didFailLoadForResource = didFailLoadForResource;
112 WKPageSetPageResourceLoadClient(pageRef, &wkResourceLoadClient);