[Release] Webkit2-efl-123997_0.11.86
[framework/web/webkit-efl.git] / Source / WebKit / qt / WebCoreSupport / PlatformStrategiesQt.cpp
1 /*
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
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
16  *
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.
28  */
29
30 #include "config.h"
31 #include "PlatformStrategiesQt.h"
32
33 #include "Chrome.h"
34 #include "ChromeClientQt.h"
35 #include <IntSize.h>
36 #include "NotImplemented.h"
37 #include <Page.h>
38 #include <PageGroup.h>
39 #include <PluginDatabase.h>
40 #include <QCoreApplication>
41 #include <QLocale>
42 #include <qwebhistoryinterface.h>
43 #include <qwebpage.h>
44 #include <qwebpluginfactory.h>
45 #include <wtf/MathExtras.h>
46
47 using namespace WebCore;
48
49 void PlatformStrategiesQt::initialize()
50 {
51     DEFINE_STATIC_LOCAL(PlatformStrategiesQt, platformStrategies, ());
52     Q_UNUSED(platformStrategies);
53 }
54
55 PlatformStrategiesQt::PlatformStrategiesQt()
56 {
57     setPlatformStrategies(this);
58 }
59
60
61 CookiesStrategy* PlatformStrategiesQt::createCookiesStrategy()
62 {
63     return this;
64 }
65
66 PluginStrategy* PlatformStrategiesQt::createPluginStrategy()
67 {
68     return this;
69 }
70
71 VisitedLinkStrategy* PlatformStrategiesQt::createVisitedLinkStrategy()
72 {
73     return this;
74 }
75
76 PasteboardStrategy* PlatformStrategiesQt::createPasteboardStrategy()
77 {
78     return 0;
79 }
80
81 void PlatformStrategiesQt::notifyCookiesChanged()
82 {
83 }
84
85 void PlatformStrategiesQt::refreshPlugins()
86 {
87     PluginDatabase::installedPlugins()->refresh();
88 }
89
90 void PlatformStrategiesQt::getPluginInfo(const WebCore::Page* page, Vector<WebCore::PluginInfo>& outPlugins)
91 {
92     QWebPage* qPage = static_cast<ChromeClientQt*>(page->chrome()->client())->m_webPage;
93     QWebPluginFactory* factory;
94     if (qPage && (factory = qPage->pluginFactory())) {
95
96         QList<QWebPluginFactory::Plugin> qplugins = factory->plugins();
97         for (int i = 0; i < qplugins.count(); ++i) {
98             const QWebPluginFactory::Plugin& qplugin = qplugins.at(i);
99             PluginInfo info;
100             info.name = qplugin.name;
101             info.desc = qplugin.description;
102
103             for (int j = 0; j < qplugin.mimeTypes.count(); ++j) {
104                 const QWebPluginFactory::MimeType& mimeType = qplugin.mimeTypes.at(j);
105
106                 MimeClassInfo mimeInfo;
107                 mimeInfo.type = mimeType.name;
108                 mimeInfo.desc = mimeType.description;
109                 for (int k = 0; k < mimeType.fileExtensions.count(); ++k)
110                   mimeInfo.extensions.append(mimeType.fileExtensions.at(k));
111
112                 info.mimes.append(mimeInfo);
113             }
114             outPlugins.append(info);
115         }
116     }
117
118     PluginDatabase* db = PluginDatabase::installedPlugins();
119     const Vector<PluginPackage*> &plugins = db->plugins();
120
121     outPlugins.resize(plugins.size());
122
123     for (unsigned int i = 0; i < plugins.size(); ++i) {
124         PluginInfo info;
125         PluginPackage* package = plugins[i];
126
127         info.name = package->name();
128         info.file = package->fileName();
129         info.desc = package->description();
130
131         const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
132         MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
133         for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
134             MimeClassInfo mime;
135
136             mime.type = it->first;
137             mime.desc = it->second;
138             mime.extensions = package->mimeToExtensions().get(mime.type);
139
140             info.mimes.append(mime);
141         }
142
143         outPlugins.append(info);
144     }
145
146 }
147
148 // VisitedLinkStrategy
149
150 bool PlatformStrategiesQt::isLinkVisited(Page* page, LinkHash hash, const KURL& baseURL, const AtomicString& attributeURL)
151 {
152     ASSERT(hash);
153
154     Vector<UChar, 512> url;
155     visitedURL(baseURL, attributeURL, url);
156
157     // If the Qt4.4 interface for the history is used, we will have to fallback
158     // to the old global history.
159     QWebHistoryInterface* iface = QWebHistoryInterface::defaultInterface();
160     if (iface)
161         return iface->historyContains(QString(reinterpret_cast<QChar*>(url.data()), url.size()));
162
163     return page->group().isLinkVisited(hash);
164 }
165
166 void PlatformStrategiesQt::addVisitedLink(Page* page, LinkHash hash)
167 {
168     page->group().addVisitedLinkHash(hash);
169 }