2 * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net>
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008 Collabora Ltd. All rights reserved.
5 * Copyright (C) 2010 Apple Inc. All rights reserved.
6 * Copyright (C) 2010 INdT - Instituto Nokia de Tecnologia
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGE.
31 #include "PlatformStrategiesQt.h"
34 #include "ChromeClientQt.h"
35 #include "QWebPageAdapter.h"
36 #include "qwebhistoryinterface.h"
37 #include "qwebpluginfactory.h"
40 #include <NotImplemented.h>
42 #include <PageGroup.h>
43 #include <PlatformCookieJar.h>
44 #include <PluginDatabase.h>
45 #include <QCoreApplication>
47 #include <wtf/MathExtras.h>
49 using namespace WebCore;
51 void PlatformStrategiesQt::initialize()
53 DEFINE_STATIC_LOCAL(PlatformStrategiesQt, platformStrategies, ());
54 Q_UNUSED(platformStrategies);
57 PlatformStrategiesQt::PlatformStrategiesQt()
59 setPlatformStrategies(this);
63 CookiesStrategy* PlatformStrategiesQt::createCookiesStrategy()
68 DatabaseStrategy* PlatformStrategiesQt::createDatabaseStrategy()
73 LoaderStrategy* PlatformStrategiesQt::createLoaderStrategy()
78 PasteboardStrategy* PlatformStrategiesQt::createPasteboardStrategy()
83 PluginStrategy* PlatformStrategiesQt::createPluginStrategy()
88 SharedWorkerStrategy* PlatformStrategiesQt::createSharedWorkerStrategy()
93 VisitedLinkStrategy* PlatformStrategiesQt::createVisitedLinkStrategy()
98 void PlatformStrategiesQt::notifyCookiesChanged()
102 String PlatformStrategiesQt::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
104 return WebCore::cookiesForDOM(session, firstParty, url);
107 void PlatformStrategiesQt::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
109 WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
112 bool PlatformStrategiesQt::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
114 return WebCore::cookiesEnabled(session, firstParty, url);
117 String PlatformStrategiesQt::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
119 return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
122 bool PlatformStrategiesQt::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
124 return WebCore::getRawCookies(session, firstParty, url, rawCookies);
127 void PlatformStrategiesQt::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
129 WebCore::deleteCookie(session, url, cookieName);
132 void PlatformStrategiesQt::refreshPlugins()
134 PluginDatabase::installedPlugins()->refresh();
137 void PlatformStrategiesQt::getPluginInfo(const WebCore::Page* page, Vector<WebCore::PluginInfo>& outPlugins)
139 QWebPageAdapter* qPage = static_cast<ChromeClientQt*>(page->chrome()->client())->m_webPage;
140 QWebPluginFactory* factory;
141 if (qPage && (factory = qPage->pluginFactory)) {
143 QList<QWebPluginFactory::Plugin> qplugins = factory->plugins();
144 for (int i = 0; i < qplugins.count(); ++i) {
145 const QWebPluginFactory::Plugin& qplugin = qplugins.at(i);
147 info.name = qplugin.name;
148 info.desc = qplugin.description;
150 for (int j = 0; j < qplugin.mimeTypes.count(); ++j) {
151 const QWebPluginFactory::MimeType& mimeType = qplugin.mimeTypes.at(j);
153 MimeClassInfo mimeInfo;
154 mimeInfo.type = mimeType.name;
155 mimeInfo.desc = mimeType.description;
156 for (int k = 0; k < mimeType.fileExtensions.count(); ++k)
157 mimeInfo.extensions.append(mimeType.fileExtensions.at(k));
159 info.mimes.append(mimeInfo);
161 outPlugins.append(info);
165 PluginDatabase* db = PluginDatabase::installedPlugins();
166 const Vector<PluginPackage*> &plugins = db->plugins();
168 outPlugins.resize(plugins.size());
170 for (int i = 0; i < plugins.size(); ++i) {
172 PluginPackage* package = plugins[i];
174 info.name = package->name();
175 info.file = package->fileName();
176 info.desc = package->description();
178 const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
179 MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
180 for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
184 mime.desc = it->value;
185 mime.extensions = package->mimeToExtensions().get(mime.type);
187 info.mimes.append(mime);
190 outPlugins.append(info);
195 // VisitedLinkStrategy
197 bool PlatformStrategiesQt::isLinkVisited(Page* page, LinkHash hash, const KURL& baseURL, const AtomicString& attributeURL)
201 Vector<UChar, 512> url;
202 visitedURL(baseURL, attributeURL, url);
204 // If the Qt4.4 interface for the history is used, we will have to fallback
205 // to the old global history.
206 QWebHistoryInterface* iface = QWebHistoryInterface::defaultInterface();
208 return iface->historyContains(QString(reinterpret_cast<QChar*>(url.data()), url.size()));
210 return page->group().isLinkVisited(hash);
213 void PlatformStrategiesQt::addVisitedLink(Page* page, LinkHash hash)
215 page->group().addVisitedLinkHash(hash);