46429461f1bb5931c21690eac2d532ab63bf3886
[WebKit-https.git] / Source / WebKit2 / UIProcess / qt / WebPageProxyQt.cpp
1 /*
2  * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2010 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "WebPageProxy.h"
29
30 #include "PageClient.h"
31 #include "UserAgentQt.h"
32 #include "WebKitVersion.h"
33 #include "WebPageMessages.h"
34 #include "WebProcessProxy.h"
35 #include <WebCore/Editor.h>
36 #include <WebCore/NotImplemented.h>
37
38 #if HAVE(QTQUICK)
39 #include "QtNetworkReplyData.h"
40 #include "QtPageClient.h"
41 #include "qquicknetworkreply_p.h"
42 #endif
43
44 using namespace WebCore;
45
46 namespace WebKit {
47
48 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
49 {
50     return UserAgentQt::standardUserAgent(applicationNameForUserAgent, WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION);
51 }
52
53 void WebPageProxy::saveRecentSearches(const String&, const Vector<String>&)
54 {
55     notImplemented();
56 }
57
58 void WebPageProxy::loadRecentSearches(const String&, Vector<String>&)
59 {
60     notImplemented();
61 }
62
63 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
64 {
65     // FIXME: We need to find out how to proper handle the crashes case.
66     if (!isValid())
67         return;
68
69     process()->send(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), m_pageID);
70 }
71
72 void WebPageProxy::confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength)
73 {
74     if (!isValid())
75         return;
76
77     process()->send(Messages::WebPage::ConfirmComposition(compositionString, selectionStart, selectionLength), m_pageID);
78 }
79
80 void WebPageProxy::cancelComposition()
81 {
82     if (!isValid())
83         return;
84
85     process()->send(Messages::WebPage::CancelComposition(), m_pageID);
86 }
87
88 void WebPageProxy::registerApplicationScheme(const String& scheme)
89 {
90     process()->send(Messages::WebPage::RegisterApplicationScheme(scheme), m_pageID);
91 }
92
93 void WebPageProxy::resolveApplicationSchemeRequest(QtNetworkRequestData request)
94 {
95 #if HAVE(QTQUICK)
96     RefPtr<QtRefCountedNetworkRequestData> requestData = adoptRef(new QtRefCountedNetworkRequestData(request));
97     m_applicationSchemeRequests.add(requestData);
98     static_cast<QtPageClient*>(m_pageClient)->handleApplicationSchemeRequest(requestData);
99 #endif
100 }
101
102 void WebPageProxy::sendApplicationSchemeReply(const QQuickNetworkReply* reply)
103 {
104 #if HAVE(QTQUICK)
105     RefPtr<QtRefCountedNetworkRequestData> requestData = reply->networkRequestData();
106     if (m_applicationSchemeRequests.contains(requestData)) {
107         RefPtr<QtRefCountedNetworkReplyData> replyData = reply->networkReplyData();
108         process()->send(Messages::WebPage::ApplicationSchemeReply(replyData->data()), pageID());
109         m_applicationSchemeRequests.remove(requestData);
110     }
111 #endif
112 }
113
114 void WebPageProxy::setUserScripts(const Vector<String>& scripts)
115 {
116     process()->send(Messages::WebPage::SetUserScripts(scripts), m_pageID);
117 }
118
119 void WebPageProxy::didFindZoomableArea(const IntPoint& target, const IntRect& area)
120 {
121     m_pageClient->didFindZoomableArea(target, area);
122 }
123
124 void WebPageProxy::findZoomableAreaForPoint(const IntPoint& point, const IntSize& area)
125 {
126     if (!isValid())
127         return;
128
129     m_process->send(Messages::WebPage::FindZoomableAreaForPoint(point, area), m_pageID);
130 }
131
132 void WebPageProxy::didReceiveMessageFromNavigatorQtObject(const String& contents)
133 {
134     m_pageClient->didReceiveMessageFromNavigatorQtObject(contents);
135 }
136
137 void WebPageProxy::authenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
138 {
139     m_pageClient->handleAuthenticationRequiredRequest(hostname, realm, prefilledUsername, username, password);
140 }
141
142 void WebPageProxy::proxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password)
143 {
144     m_pageClient->handleProxyAuthenticationRequiredRequest(hostname, port, prefilledUsername, username, password);
145 }
146
147 void WebPageProxy::certificateVerificationRequest(const String& hostname, bool& ignoreErrors)
148 {
149     m_pageClient->handleCertificateVerificationRequest(hostname, ignoreErrors);
150 }
151
152 #if PLUGIN_ARCHITECTURE(X11)
153 void WebPageProxy::createPluginContainer(uint64_t& windowID)
154 {
155     notImplemented();
156 }
157
158 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
159 {
160     notImplemented();
161 }
162 #endif
163
164 void WebPageProxy::changeSelectedIndex(int32_t selectedIndex)
165 {
166     process()->send(Messages::WebPage::SelectedIndex(selectedIndex), m_pageID);
167 }
168
169 void WebPageProxy::closePopupMenu()
170 {
171     process()->send(Messages::WebPage::HidePopupMenu(), m_pageID);
172 }
173
174 } // namespace WebKit