[EFL][WK2] Use C API inside ewk_auth_request
[WebKit-https.git] / Source / WebKit2 / UIProcess / efl / PageLoadClientEfl.cpp
1 /*
2  * Copyright (C) 2012 Intel Corporation. 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 "PageLoadClientEfl.h"
28
29 #include "EwkView.h"
30 #include "PageClientBase.h"
31 #include "WKAPICast.h"
32 #include "WKFrame.h"
33 #include "WKPage.h"
34 #include "ewk_auth_request_private.h"
35 #include "ewk_back_forward_list_private.h"
36 #include "ewk_error_private.h"
37 #include "ewk_view.h"
38
39 using namespace EwkViewCallbacks;
40
41 namespace WebKit {
42
43 static inline PageLoadClientEfl* toPageLoadClientEfl(const void* clientInfo)
44 {
45     return static_cast<PageLoadClientEfl*>(const_cast<void*>(clientInfo));
46 }
47
48 void PageLoadClientEfl::didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef frame, WKTypeRef, const void* clientInfo)
49 {
50     if (!WKFrameIsMainFrame(frame))
51         return;
52
53     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
54     view->smartCallback<TitleChange>().call(toImpl(title)->string());
55 }
56
57 void PageLoadClientEfl::didChangeProgress(WKPageRef page, const void* clientInfo)
58 {
59     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
60     double progress = WKPageGetEstimatedProgress(page);
61     view->smartCallback<LoadProgress>().call(&progress);
62 }
63
64 void PageLoadClientEfl::didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef /*userData*/, const void* clientInfo)
65 {
66     if (!WKFrameIsMainFrame(frame))
67         return;
68
69     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
70     view->smartCallback<LoadFinished>().call();
71 }
72
73 void PageLoadClientEfl::didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo)
74 {
75     if (!WKFrameIsMainFrame(frame))
76         return;
77
78     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
79     OwnPtr<EwkError> ewkError = EwkError::create(error);
80     view->smartCallback<LoadError>().call(ewkError.get());
81     view->smartCallback<LoadFinished>().call();
82 }
83
84 void PageLoadClientEfl::didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef /*userData*/, const void* clientInfo)
85 {
86     if (!WKFrameIsMainFrame(frame))
87         return;
88
89     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
90     view->informURLChange();
91     view->smartCallback<ProvisionalLoadStarted>().call();
92 }
93
94 void PageLoadClientEfl::didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef /*userData*/, const void* clientInfo)
95 {
96     if (!WKFrameIsMainFrame(frame))
97         return;
98
99     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
100     view->informURLChange();
101     view->smartCallback<ProvisionalLoadRedirect>().call();
102 }
103
104 void PageLoadClientEfl::didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo)
105 {
106     if (!WKFrameIsMainFrame(frame))
107         return;
108
109     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
110     OwnPtr<EwkError> ewkError = EwkError::create(error);
111     view->smartCallback<ProvisionalLoadFailed>().call(ewkError.get());
112 }
113
114 #if USE(TILED_BACKING_STORE)
115 void PageLoadClientEfl::didCommitLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void* clientInfo)
116 {
117     if (!WKFrameIsMainFrame(frame))
118         return;
119
120     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
121     view->pageClient()->didCommitLoad();
122 }
123 #endif
124
125 void PageLoadClientEfl::didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void* clientInfo)
126 {
127     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
128     ASSERT(view);
129
130     Ewk_Back_Forward_List* list = ewk_view_back_forward_list_get(view->view());
131     ASSERT(list);
132     list->update(addedItem, removedItems);
133
134     view->smartCallback<BackForwardListChange>().call();
135 }
136
137 void PageLoadClientEfl::didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef frame, WKSameDocumentNavigationType, WKTypeRef, const void* clientInfo)
138 {
139     if (!WKFrameIsMainFrame(frame))
140         return;
141
142     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
143     view->informURLChange();
144 }
145
146 void PageLoadClientEfl::didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef authenticationChallenge, const void* clientInfo)
147 {
148     EwkView* view = toPageLoadClientEfl(clientInfo)->view();
149
150     RefPtr<EwkAuthRequest> authenticationRequest = EwkAuthRequest::create(authenticationChallenge);
151     view->smartCallback<AuthenticationRequest>().call(authenticationRequest.get());
152 }
153
154 PageLoadClientEfl::PageLoadClientEfl(EwkView* view)
155     : m_view(view)
156 {
157     WKPageRef pageRef = m_view->wkPage();
158     ASSERT(pageRef);
159
160     WKPageLoaderClient loadClient;
161     memset(&loadClient, 0, sizeof(WKPageLoaderClient));
162     loadClient.version = kWKPageLoaderClientCurrentVersion;
163     loadClient.clientInfo = this;
164     loadClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
165     loadClient.didStartProgress = didChangeProgress;
166     loadClient.didChangeProgress = didChangeProgress;
167     loadClient.didFinishProgress = didChangeProgress;
168     loadClient.didFinishLoadForFrame = didFinishLoadForFrame;
169     loadClient.didFailLoadWithErrorForFrame = didFailLoadWithErrorForFrame;
170     loadClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
171     loadClient.didReceiveServerRedirectForProvisionalLoadForFrame = didReceiveServerRedirectForProvisionalLoadForFrame;
172     loadClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame;
173 #if USE(TILED_BACKING_STORE)
174     loadClient.didCommitLoadForFrame = didCommitLoadForFrame;
175 #endif
176     loadClient.didChangeBackForwardList = didChangeBackForwardList;
177     loadClient.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame;
178     loadClient.didReceiveAuthenticationChallengeInFrame = didReceiveAuthenticationChallengeInFrame;
179     WKPageSetPageLoaderClient(pageRef, &loadClient);
180 }
181
182 } // namespace WebKit