1/*
2 * Copyright (C) 2012 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#include "config.h"
20#include "PlatformStrategiesGtk.h"
21
22#include "NotImplemented.h"
23#include "Page.h"
24#include "PageGroup.h"
25#include "PlatformCookieJar.h"
26#include "PluginDatabase.h"
27#include "PluginPackage.h"
28
29using namespace WebCore;
30
31void PlatformStrategiesGtk::initialize()
32{
33    DEFINE_STATIC_LOCAL(PlatformStrategiesGtk, platformStrategies, ());
34    setPlatformStrategies(&platformStrategies);
35}
36
37PlatformStrategiesGtk::PlatformStrategiesGtk()
38{
39}
40
41CookiesStrategy* PlatformStrategiesGtk::createCookiesStrategy()
42{
43    return this;
44}
45
46DatabaseStrategy* PlatformStrategiesGtk::createDatabaseStrategy()
47{
48    return this;
49}
50
51LoaderStrategy* PlatformStrategiesGtk::createLoaderStrategy()
52{
53    return this;
54}
55
56PasteboardStrategy* PlatformStrategiesGtk::createPasteboardStrategy()
57{
58    // This is currently used only by Mac code.
59    notImplemented();
60    return 0;
61}
62
63PluginStrategy* PlatformStrategiesGtk::createPluginStrategy()
64{
65    return this;
66}
67
68SharedWorkerStrategy* PlatformStrategiesGtk::createSharedWorkerStrategy()
69{
70    return this;
71}
72
73StorageStrategy* PlatformStrategiesGtk::createStorageStrategy()
74{
75    return this;
76}
77
78VisitedLinkStrategy* PlatformStrategiesGtk::createVisitedLinkStrategy()
79{
80    return this;
81}
82
83// CookiesStrategy
84String PlatformStrategiesGtk::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
85{
86    return WebCore::cookiesForDOM(session, firstParty, url);
87}
88
89void PlatformStrategiesGtk::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
90{
91    WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
92}
93
94bool PlatformStrategiesGtk::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
95{
96    return WebCore::cookiesEnabled(session, firstParty, url);
97}
98
99String PlatformStrategiesGtk::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
100{
101    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
102}
103
104bool PlatformStrategiesGtk::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
105{
106    return WebCore::getRawCookies(session, firstParty, url, rawCookies);
107}
108
109void PlatformStrategiesGtk::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
110{
111    WebCore::deleteCookie(session, url, cookieName);
112}
113
114// PluginStrategy
115void PlatformStrategiesGtk::refreshPlugins()
116{
117    PluginDatabase::installedPlugins()->refresh();
118}
119
120void PlatformStrategiesGtk::getPluginInfo(const Page* page, Vector<PluginInfo>& outPlugins)
121{
122    PluginDatabase* database = PluginDatabase::installedPlugins();
123    const Vector<PluginPackage*> &plugins = database->plugins();
124
125    for (size_t i = 0; i < plugins.size(); ++i) {
126        PluginPackage* package = plugins[i];
127
128        PluginInfo pluginInfo;
129        pluginInfo.name = package->name();
130        pluginInfo.file = package->fileName();
131        pluginInfo.desc = package->description();
132
133        const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
134        MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
135        for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
136            MimeClassInfo mime;
137            mime.type = it->key;
138            mime.desc = it->value;
139            mime.extensions = package->mimeToExtensions().get(mime.type);
140            pluginInfo.mimes.append(mime);
141        }
142
143        outPlugins.append(pluginInfo);
144    }
145}
146
147// VisitedLinkStrategy
148bool PlatformStrategiesGtk::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
149{
150    return page->group().isLinkVisited(hash);
151}
152
153void PlatformStrategiesGtk::addVisitedLink(Page* page, LinkHash hash)
154{
155    page->group().addVisitedLinkHash(hash);
156}
157