8389640d7ee563e814cf14c1fe1c38428e48273b
[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::commitPageTransitionViewport()
64 {
65     if (!isValid())
66         return;
67
68     process()->send(Messages::WebPage::CommitPageTransitionViewport(), m_pageID);
69 }
70
71 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
72 {
73     // FIXME: We need to find out how to proper handle the crashes case.
74     if (!isValid())
75         return;
76
77     process()->send(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), m_pageID);
78 }
79
80 void WebPageProxy::confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength)
81 {
82     if (!isValid())
83         return;
84
85     process()->send(Messages::WebPage::ConfirmComposition(compositionString, selectionStart, selectionLength), m_pageID);
86 }
87
88 void WebPageProxy::cancelComposition()
89 {
90     if (!isValid())
91         return;
92
93     process()->send(Messages::WebPage::CancelComposition(), m_pageID);
94 }
95
96 void WebPageProxy::didRenderFrame(const WebCore::IntSize& contentsSize)
97 {
98     m_pageClient->didRenderFrame(contentsSize);
99 }
100
101 void WebPageProxy::registerApplicationScheme(const String& scheme)
102 {
103     process()->send(Messages::WebPage::RegisterApplicationScheme(scheme), m_pageID);
104 }
105
106 void WebPageProxy::resolveApplicationSchemeRequest(QtNetworkRequestData request)
107 {
108 #if HAVE(QTQUICK)
109     RefPtr<QtRefCountedNetworkRequestData> requestData = adoptRef(new QtRefCountedNetworkRequestData(request));
110     m_applicationSchemeRequests.add(requestData);
111     static_cast<QtPageClient*>(m_pageClient)->handleApplicationSchemeRequest(requestData);
112 #endif
113 }
114
115 void WebPageProxy::sendApplicationSchemeReply(const QQuickNetworkReply* reply)
116 {
117 #if HAVE(QTQUICK)
118     RefPtr<QtRefCountedNetworkRequestData> requestData = reply->networkRequestData();
119     if (m_applicationSchemeRequests.contains(requestData)) {
120         RefPtr<QtRefCountedNetworkReplyData> replyData = reply->networkReplyData();
121         process()->send(Messages::WebPage::ApplicationSchemeReply(replyData->data()), pageID());
122         m_applicationSchemeRequests.remove(requestData);
123     }
124 #endif
125 }
126
127 void WebPageProxy::setUserScripts(const Vector<String>& scripts)
128 {
129     process()->send(Messages::WebPage::SetUserScripts(scripts), m_pageID);
130 }
131
132 void WebPageProxy::pageTransitionViewportReady()
133 {
134     m_pageClient->pageTransitionViewportReady();
135 }
136
137 #if PLUGIN_ARCHITECTURE(X11)
138 void WebPageProxy::createPluginContainer(uint64_t& windowID)
139 {
140     notImplemented();
141 }
142
143 void WebPageProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
144 {
145     notImplemented();
146 }
147 #endif
148
149 void WebPageProxy::changeSelectedIndex(int32_t selectedIndex)
150 {
151     process()->send(Messages::WebPage::SelectedIndex(selectedIndex), m_pageID);
152 }
153
154 void WebPageProxy::closePopupMenu()
155 {
156     process()->send(Messages::WebPage::HidePopupMenu(), m_pageID);
157 }
158
159 } // namespace WebKit