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 "WebLoaderClient.h"
28 
29 #include "ImmutableArray.h"
30 #include "WebBackForwardListItem.h"
31 #include "WKAPICast.h"
32 #include <string.h>
33 
34 using namespace WebCore;
35 
36 namespace WebKit {
37 
didStartProvisionalLoadForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)38 void WebLoaderClient::didStartProvisionalLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
39 {
40     if (!m_client.didStartProvisionalLoadForFrame)
41         return;
42 
43     m_client.didStartProvisionalLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
44 }
45 
didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)46 void WebLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
47 {
48     if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
49         return;
50 
51     m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
52 }
53 
didFailProvisionalLoadWithErrorForFrame(WebPageProxy * page,WebFrameProxy * frame,const ResourceError & error,APIObject * userData)54 void WebLoaderClient::didFailProvisionalLoadWithErrorForFrame(WebPageProxy* page, WebFrameProxy* frame, const ResourceError& error, APIObject* userData)
55 {
56     if (!m_client.didFailProvisionalLoadWithErrorForFrame)
57         return;
58 
59     m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), toAPI(userData), m_client.clientInfo);
60 }
61 
didCommitLoadForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)62 void WebLoaderClient::didCommitLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
63 {
64     if (!m_client.didCommitLoadForFrame)
65         return;
66 
67     m_client.didCommitLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
68 }
69 
didFinishDocumentLoadForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)70 void WebLoaderClient::didFinishDocumentLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
71 {
72     if (!m_client.didFinishDocumentLoadForFrame)
73         return;
74 
75     m_client.didFinishDocumentLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
76 }
77 
didFinishLoadForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)78 void WebLoaderClient::didFinishLoadForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
79 {
80     if (!m_client.didFinishLoadForFrame)
81         return;
82 
83     m_client.didFinishLoadForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
84 }
85 
didFailLoadWithErrorForFrame(WebPageProxy * page,WebFrameProxy * frame,const ResourceError & error,APIObject * userData)86 void WebLoaderClient::didFailLoadWithErrorForFrame(WebPageProxy* page, WebFrameProxy* frame, const ResourceError& error, APIObject* userData)
87 {
88     if (!m_client.didFailLoadWithErrorForFrame)
89         return;
90 
91     m_client.didFailLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), toAPI(userData), m_client.clientInfo);
92 }
93 
didSameDocumentNavigationForFrame(WebPageProxy * page,WebFrameProxy * frame,SameDocumentNavigationType type,APIObject * userData)94 void WebLoaderClient::didSameDocumentNavigationForFrame(WebPageProxy* page, WebFrameProxy* frame, SameDocumentNavigationType type, APIObject* userData)
95 {
96     if (!m_client.didSameDocumentNavigationForFrame)
97         return;
98 
99     m_client.didSameDocumentNavigationForFrame(toAPI(page), toAPI(frame), toAPI(type), toAPI(userData), m_client.clientInfo);
100 }
101 
didReceiveTitleForFrame(WebPageProxy * page,const String & title,WebFrameProxy * frame,APIObject * userData)102 void WebLoaderClient::didReceiveTitleForFrame(WebPageProxy* page, const String& title, WebFrameProxy* frame, APIObject* userData)
103 {
104     if (!m_client.didReceiveTitleForFrame)
105         return;
106 
107     m_client.didReceiveTitleForFrame(toAPI(page), toAPI(title.impl()), toAPI(frame), toAPI(userData), m_client.clientInfo);
108 }
109 
didFirstLayoutForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)110 void WebLoaderClient::didFirstLayoutForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
111 {
112     if (!m_client.didFirstLayoutForFrame)
113         return;
114 
115     m_client.didFirstLayoutForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
116 }
117 
didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)118 void WebLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
119 {
120     if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
121         return;
122 
123     m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
124 }
125 
didRemoveFrameFromHierarchy(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)126 void WebLoaderClient::didRemoveFrameFromHierarchy(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
127 {
128     if (!m_client.didRemoveFrameFromHierarchy)
129         return;
130 
131     m_client.didRemoveFrameFromHierarchy(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
132 }
133 
didDisplayInsecureContentForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)134 void WebLoaderClient::didDisplayInsecureContentForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
135 {
136     if (!m_client.didDisplayInsecureContentForFrame)
137         return;
138 
139     m_client.didDisplayInsecureContentForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
140 }
141 
didRunInsecureContentForFrame(WebPageProxy * page,WebFrameProxy * frame,APIObject * userData)142 void WebLoaderClient::didRunInsecureContentForFrame(WebPageProxy* page, WebFrameProxy* frame, APIObject* userData)
143 {
144     if (!m_client.didRunInsecureContentForFrame)
145         return;
146 
147     m_client.didRunInsecureContentForFrame(toAPI(page), toAPI(frame), toAPI(userData), m_client.clientInfo);
148 }
149 
canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy * page,WebFrameProxy * frame,WebProtectionSpace * protectionSpace)150 bool WebLoaderClient::canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy* page, WebFrameProxy* frame, WebProtectionSpace* protectionSpace)
151 {
152     if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
153         return false;
154 
155     return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(page), toAPI(frame), toAPI(protectionSpace), m_client.clientInfo);
156 }
157 
didReceiveAuthenticationChallengeInFrame(WebPageProxy * page,WebFrameProxy * frame,AuthenticationChallengeProxy * authenticationChallenge)158 void WebLoaderClient::didReceiveAuthenticationChallengeInFrame(WebPageProxy* page, WebFrameProxy* frame, AuthenticationChallengeProxy* authenticationChallenge)
159 {
160     if (!m_client.didReceiveAuthenticationChallengeInFrame)
161         return;
162 
163     m_client.didReceiveAuthenticationChallengeInFrame(toAPI(page), toAPI(frame), toAPI(authenticationChallenge), m_client.clientInfo);
164 }
165 
didStartProgress(WebPageProxy * page)166 void WebLoaderClient::didStartProgress(WebPageProxy* page)
167 {
168     if (!m_client.didStartProgress)
169         return;
170 
171     m_client.didStartProgress(toAPI(page), m_client.clientInfo);
172 }
173 
didChangeProgress(WebPageProxy * page)174 void WebLoaderClient::didChangeProgress(WebPageProxy* page)
175 {
176     if (!m_client.didChangeProgress)
177         return;
178 
179     m_client.didChangeProgress(toAPI(page), m_client.clientInfo);
180 }
181 
didFinishProgress(WebPageProxy * page)182 void WebLoaderClient::didFinishProgress(WebPageProxy* page)
183 {
184     if (!m_client.didFinishProgress)
185         return;
186 
187     m_client.didFinishProgress(toAPI(page), m_client.clientInfo);
188 }
189 
processDidBecomeUnresponsive(WebPageProxy * page)190 void WebLoaderClient::processDidBecomeUnresponsive(WebPageProxy* page)
191 {
192     if (!m_client.processDidBecomeUnresponsive)
193         return;
194 
195     m_client.processDidBecomeUnresponsive(toAPI(page), m_client.clientInfo);
196 }
197 
processDidBecomeResponsive(WebPageProxy * page)198 void WebLoaderClient::processDidBecomeResponsive(WebPageProxy* page)
199 {
200     if (!m_client.processDidBecomeResponsive)
201         return;
202 
203     m_client.processDidBecomeResponsive(toAPI(page), m_client.clientInfo);
204 }
205 
processDidCrash(WebPageProxy * page)206 void WebLoaderClient::processDidCrash(WebPageProxy* page)
207 {
208     if (!m_client.processDidCrash)
209         return;
210 
211     m_client.processDidCrash(toAPI(page), m_client.clientInfo);
212 }
213 
didChangeBackForwardList(WebPageProxy * page,WebBackForwardListItem * addedItem,Vector<RefPtr<APIObject>> * removedItems)214 void WebLoaderClient::didChangeBackForwardList(WebPageProxy* page, WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems)
215 {
216     if (!m_client.didChangeBackForwardList)
217         return;
218 
219     RefPtr<ImmutableArray> removedItemsArray;
220     if (removedItems && !removedItems->isEmpty())
221         removedItemsArray = ImmutableArray::adopt(*removedItems);
222 
223     m_client.didChangeBackForwardList(toAPI(page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.clientInfo);
224 }
225 
shouldGoToBackForwardListItem(WebPageProxy * page,WebBackForwardListItem * item)226 bool WebLoaderClient::shouldGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item)
227 {
228     if (!m_client.shouldGoToBackForwardListItem)
229         return true;
230 
231     return m_client.shouldGoToBackForwardListItem(toAPI(page), toAPI(item), m_client.clientInfo);
232 }
233 
didFailToInitializePlugin(WebPageProxy * page,const String & mimeType)234 void WebLoaderClient::didFailToInitializePlugin(WebPageProxy* page, const String& mimeType)
235 {
236     if (!m_client.didFailToInitializePlugin)
237         return;
238 
239     m_client.didFailToInitializePlugin(toAPI(page), toAPI(mimeType.impl()), m_client.clientInfo);
240 }
241 
242 } // namespace WebKit
243