1/*
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "WebPlatformStrategies.h"
28
29#include "FrameLoader.h"
30#include "WebFrameNetworkingContext.h"
31#include <WebCore/Page.h>
32#include <WebCore/PageGroup.h>
33#include <WebCore/PlatformCookieJar.h>
34#include <WebCore/PluginDatabase.h>
35#if USE(CFNETWORK)
36#include <WebKitSystemInterface/WebKitSystemInterface.h>
37#endif
38
39using namespace WebCore;
40
41void WebPlatformStrategies::initialize()
42{
43    DEPRECATED_DEFINE_STATIC_LOCAL(WebPlatformStrategies, platformStrategies, ());
44}
45
46WebPlatformStrategies::WebPlatformStrategies()
47{
48    setPlatformStrategies(this);
49}
50
51CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
52{
53    return this;
54}
55
56DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy()
57{
58    return this;
59}
60
61LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
62{
63    return this;
64}
65
66PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
67{
68    return 0;
69}
70
71PluginStrategy* WebPlatformStrategies::createPluginStrategy()
72{
73    return this;
74}
75
76SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy()
77{
78    return this;
79}
80
81StorageStrategy* WebPlatformStrategies::createStorageStrategy()
82{
83    return this;
84}
85
86String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url)
87{
88    return WebCore::cookiesForDOM(session, firstParty, url);
89}
90
91void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url, const String& cookieString)
92{
93    WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
94}
95
96bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const URL& firstParty, const URL& url)
97{
98    return WebCore::cookiesEnabled(session, firstParty, url);
99}
100
101String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const URL& url)
102{
103    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
104}
105
106bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const URL& url, Vector<Cookie>& rawCookies)
107{
108    return WebCore::getRawCookies(session, firstParty, url, rawCookies);
109}
110
111void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
112{
113    WebCore::deleteCookie(session, url, cookieName);
114}
115
116void WebPlatformStrategies::refreshPlugins()
117{
118    PluginDatabase::installedPlugins()->refresh();
119}
120
121void WebPlatformStrategies::getPluginInfo(const WebCore::Page*, Vector<WebCore::PluginInfo>& outPlugins)
122{
123    const Vector<PluginPackage*>& plugins = PluginDatabase::installedPlugins()->plugins();
124
125    outPlugins.resize(plugins.size());
126
127    for (size_t i = 0; i < plugins.size(); ++i) {
128        PluginPackage* package = plugins[i];
129
130        PluginInfo info;
131        info.name = package->name();
132        info.file = package->fileName();
133        info.desc = package->description();
134
135        const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
136
137        info.mimes.reserveCapacity(mimeToDescriptions.size());
138
139        MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
140        for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
141            MimeClassInfo mime;
142
143            mime.type = it->key;
144            mime.desc = it->value;
145            mime.extensions = package->mimeToExtensions().get(mime.type);
146
147            info.mimes.append(mime);
148        }
149
150        outPlugins[i] = info;
151    }
152}
153