~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/UIProcess/efl/PagePolicyClientEfl.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "PagePolicyClientEfl.h"
 
28
 
 
29
#include "EwkViewImpl.h"
 
30
#include "WKFrame.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>
 
37
 
 
38
using namespace EwkViewCallbacks;
 
39
 
 
40
namespace WebKit {
 
41
 
 
42
static inline PagePolicyClientEfl* toPagePolicyClientEfl(const void* clientInfo)
 
43
{
 
44
    return static_cast<PagePolicyClientEfl*>(const_cast<void*>(clientInfo));
 
45
}
 
46
 
 
47
void PagePolicyClientEfl::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* clientInfo)
 
48
{
 
49
    PagePolicyClientEfl* policyClient = toPagePolicyClientEfl(clientInfo);
 
50
 
 
51
    RefPtr<EwkNavigationPolicyDecision> decision = EwkNavigationPolicyDecision::create(navigationType, mouseButton, modifiers, request, 0, listener);
 
52
    policyClient->m_viewImpl->smartCallback<NavigationPolicyDecision>().call(decision.get());
 
53
}
 
54
 
 
55
void PagePolicyClientEfl::decidePolicyForNewWindowAction(WKPageRef, WKFrameRef, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* clientInfo)
 
56
{
 
57
    PagePolicyClientEfl* policyClient = toPagePolicyClientEfl(clientInfo);
 
58
 
 
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());
 
61
}
 
62
 
 
63
void PagePolicyClientEfl::decidePolicyForResponseCallback(WKPageRef, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef /*userData*/, const void* /*clientInfo*/)
 
64
{
 
65
    using namespace WebCore;
 
66
 
 
67
    const ResourceResponse resourceResponse = toImpl(response)->resourceResponse();
 
68
 
 
69
    // Ignore responses with an HTTP status code of 204 (No Content)
 
70
    if (resourceResponse.httpStatusCode() == HTTPNoContent) {
 
71
        WKFramePolicyListenerIgnore(listener);
 
72
        return;
 
73
    }
 
74
 
 
75
    // If the URL Response has "Content-Disposition: attachment;" header, then
 
76
    // we should download it.
 
77
    if (resourceResponse.isAttachment()) {
 
78
        WKFramePolicyListenerDownload(listener);
 
79
        return;
 
80
    }
 
81
 
 
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);
 
87
            return;
 
88
        }
 
89
 
 
90
        // If we can't use (show) it then we should download it.
 
91
        WKFramePolicyListenerDownload(listener);
 
92
        return;
 
93
    }
 
94
 
 
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);
 
99
        return;
 
100
    }
 
101
 
 
102
    WKFramePolicyListenerUse(listener);
 
103
}
 
104
 
 
105
PagePolicyClientEfl::PagePolicyClientEfl(EwkViewImpl* viewImpl)
 
106
    : m_viewImpl(viewImpl)
 
107
{
 
108
    WKPageRef pageRef = m_viewImpl->wkPage();
 
109
    ASSERT(pageRef);
 
110
 
 
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;
 
118
 
 
119
    WKPageSetPagePolicyClient(pageRef, &policyClient);
 
120
}
 
121
 
 
122
} // namespace WebKit