WebKitLoaderClient.cpp [plain text]
#include "config.h"
#include "WebKitLoaderClient.h"
#include "WebKitBackForwardListPrivate.h"
#include "WebKitPrivate.h"
#include "WebKitURIResponsePrivate.h"
#include "WebKitWebViewBasePrivate.h"
#include "WebKitWebViewPrivate.h"
#include <wtf/gobject/GUniquePtr.h>
#include <wtf/text/CString.h>
using namespace WebKit;
using namespace WebCore;
static void didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef , const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_STARTED);
}
static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef , const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_REDIRECTED);
}
static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef , const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
const ResourceError& resourceError = toImpl(error)->platformError();
GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()),
toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data()));
if (resourceError.tlsErrors()) {
webkitWebViewLoadFailedWithTLSErrors(WEBKIT_WEB_VIEW(clientInfo), resourceError.failingURL().utf8().data(), webError.get(),
static_cast<GTlsCertificateFlags>(resourceError.tlsErrors()), resourceError.certificate());
} else
webkitWebViewLoadFailed(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_STARTED, resourceError.failingURL().utf8().data(), webError.get());
}
static void didCommitLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef , const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_COMMITTED);
}
static void didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef , const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
webkitWebViewLoadChanged(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_FINISHED);
}
static void didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
const ResourceError& resourceError = toImpl(error)->platformError();
GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()),
toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data()));
webkitWebViewLoadFailed(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_LOAD_COMMITTED,
resourceError.failingURL().utf8().data(), webError.get());
}
static void didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef frame, WKSameDocumentNavigationType, WKTypeRef, const void* clientInfo)
{
if (!WKFrameIsMainFrame(frame))
return;
webkitWebViewUpdateURI(WEBKIT_WEB_VIEW(clientInfo));
}
static void didReceiveTitleForFrame(WKPageRef, WKStringRef titleRef, WKFrameRef frameRef, WKTypeRef, const void* clientInfo)
{
if (!WKFrameIsMainFrame(frameRef))
return;
webkitWebViewSetTitle(WEBKIT_WEB_VIEW(clientInfo), toImpl(titleRef)->string().utf8());
}
static void didDisplayInsecureContentForFrame(WKPageRef, WKFrameRef, WKTypeRef , const void *clientInfo)
{
webkitWebViewInsecureContentDetected(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_INSECURE_CONTENT_DISPLAYED);
}
static void didRunInsecureContentForFrame(WKPageRef, WKFrameRef, WKTypeRef , const void *clientInfo)
{
webkitWebViewInsecureContentDetected(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_INSECURE_CONTENT_RUN);
}
static void didChangeProgress(WKPageRef page, const void* clientInfo)
{
webkitWebViewSetEstimatedLoadProgress(WEBKIT_WEB_VIEW(clientInfo), WKPageGetEstimatedProgress(page));
}
static void didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void* clientInfo)
{
webkitBackForwardListChanged(webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(clientInfo)), toImpl(addedItem), toImpl(removedItems));
}
static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo)
{
webkitWebViewHandleAuthenticationChallenge(WEBKIT_WEB_VIEW(clientInfo), toImpl(authenticationChallenge));
}
static void processDidCrash(WKPageRef, const void* clientInfo)
{
webkitWebViewWebProcessCrashed(WEBKIT_WEB_VIEW(clientInfo));
}
void attachLoaderClientToView(WebKitWebView* webView)
{
WKPageLoaderClientV3 wkLoaderClient = {
{
3, webView, },
didStartProvisionalLoadForFrame,
didReceiveServerRedirectForProvisionalLoadForFrame,
didFailProvisionalLoadWithErrorForFrame,
didCommitLoadForFrame,
0, didFinishLoadForFrame,
didFailLoadWithErrorForFrame,
didSameDocumentNavigationForFrame,
didReceiveTitleForFrame,
0, 0, 0, didDisplayInsecureContentForFrame,
didRunInsecureContentForFrame,
0, didReceiveAuthenticationChallengeInFrame,
didChangeProgress, didChangeProgress,
didChangeProgress, 0, 0, processDidCrash,
didChangeBackForwardList,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)));
WKPageSetPageLoaderClient(wkPage, &wkLoaderClient.base);
}