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.
27
#include "PagePolicyClientEfl.h"
29
#include "EwkViewImpl.h"
31
#include "WKFramePolicyListener.h"
32
#include "WebFrameProxy.h"
33
#include "ewk_navigation_policy_decision.h"
34
#include "ewk_navigation_policy_decision_private.h"
35
#include <WebCore/HTTPStatusCodes.h>
36
#include <wtf/text/CString.h>
38
using namespace EwkViewCallbacks;
42
static inline PagePolicyClientEfl* toPagePolicyClientEfl(const void* clientInfo)
44
return static_cast<PagePolicyClientEfl*>(const_cast<void*>(clientInfo));
47
void PagePolicyClientEfl::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* clientInfo)
49
PagePolicyClientEfl* policyClient = toPagePolicyClientEfl(clientInfo);
51
RefPtr<EwkNavigationPolicyDecision> decision = EwkNavigationPolicyDecision::create(navigationType, mouseButton, modifiers, request, 0, listener);
52
policyClient->m_viewImpl->smartCallback<NavigationPolicyDecision>().call(decision.get());
55
void PagePolicyClientEfl::decidePolicyForNewWindowAction(WKPageRef, WKFrameRef, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* clientInfo)
57
PagePolicyClientEfl* policyClient = toPagePolicyClientEfl(clientInfo);
59
RefPtr<EwkNavigationPolicyDecision> decision = EwkNavigationPolicyDecision::create(navigationType, mouseButton, modifiers, request, toImpl(frameName)->string().utf8().data(), listener);
60
policyClient->m_viewImpl->smartCallback<NewWindowPolicyDecision>().call(decision.get());
63
void PagePolicyClientEfl::decidePolicyForResponseCallback(WKPageRef, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* /*clientInfo*/)
65
using namespace WebCore;
67
const ResourceResponse resourceResponse = toImpl(response)->resourceResponse();
69
// Ignore responses with an HTTP status code of 204 (No Content)
70
if (resourceResponse.httpStatusCode() == HTTPNoContent) {
71
WKFramePolicyListenerIgnore(listener);
75
// If the URL Response has "Content-Disposition: attachment;" header, then
76
// we should download it.
77
if (resourceResponse.isAttachment()) {
78
WKFramePolicyListenerDownload(listener);
82
String mimeType = toImpl(response)->resourceResponse().mimeType().lower();
83
bool canShowMIMEType = toImpl(frame)->canShowMIMEType(mimeType);
84
if (WKFrameIsMainFrame(frame)) {
85
if (canShowMIMEType) {
86
WKFramePolicyListenerUse(listener);
90
// If we can't use (show) it then we should download it.
91
WKFramePolicyListenerDownload(listener);
95
// We should ignore downloadable top-level content for subframes, with an exception for text/xml and application/xml so we can still support Acid3 test.
96
// It makes the browser intentionally behave differently when it comes to text(application)/xml content in subframes vs. mainframe.
97
if (!canShowMIMEType && !(mimeType == "text/xml" || mimeType == "application/xml")) {
98
WKFramePolicyListenerIgnore(listener);
102
WKFramePolicyListenerUse(listener);
105
PagePolicyClientEfl::PagePolicyClientEfl(EwkViewImpl* viewImpl)
106
: m_viewImpl(viewImpl)
108
WKPageRef pageRef = m_viewImpl->wkPage();
111
WKPagePolicyClient policyClient;
112
memset(&policyClient, 0, sizeof(WKPagePolicyClient));
113
policyClient.version = kWKPagePolicyClientCurrentVersion;
114
policyClient.clientInfo = this;
115
policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
116
policyClient.decidePolicyForNewWindowAction = decidePolicyForNewWindowAction;
117
policyClient.decidePolicyForResponse = decidePolicyForResponseCallback;
119
WKPageSetPagePolicyClient(pageRef, &policyClient);
122
} // namespace WebKit