a3b0b319e455e41d5832275100e80f6690c54aad
[WebKit-https.git] / Source / WebKit / win / WebCoreSupport / WebPlatformStrategies.cpp
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 <WebCore/ResourceHandle.h>
37 #include <WebKitSystemInterface/WebKitSystemInterface.h>
38 #endif
39
40 using namespace WebCore;
41
42 void WebPlatformStrategies::initialize()
43 {
44     DEFINE_STATIC_LOCAL(WebPlatformStrategies, platformStrategies, ());
45 }
46
47 WebPlatformStrategies::WebPlatformStrategies()
48 {
49     setPlatformStrategies(this);
50 }
51
52 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
53 {
54     return this;
55 }
56
57 DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy()
58 {
59     return this;
60 }
61
62 LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
63 {
64     return this;
65 }
66
67 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
68 {
69     return 0;
70 }
71
72 PluginStrategy* WebPlatformStrategies::createPluginStrategy()
73 {
74     return this;
75 }
76
77 SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy()
78 {
79     return this;
80 }
81
82 StorageStrategy* WebPlatformStrategies::createStorageStrategy()
83 {
84     return this;
85 }
86
87 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
88 {
89     return this;
90 }
91
92 String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
93 {
94     return WebCore::cookiesForDOM(session, firstParty, url);
95 }
96
97 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
98 {
99     WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
100 }
101
102 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
103 {
104     return WebCore::cookiesEnabled(session, firstParty, url);
105 }
106
107 String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
108 {
109     return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
110 }
111
112 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
113 {
114     return WebCore::getRawCookies(session, firstParty, url, rawCookies);
115 }
116
117 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
118 {
119     WebCore::deleteCookie(session, url, cookieName);
120 }
121
122 void WebPlatformStrategies::refreshPlugins()
123 {
124     PluginDatabase::installedPlugins()->refresh();
125 }
126
127 void WebPlatformStrategies::getPluginInfo(const WebCore::Page*, Vector<WebCore::PluginInfo>& outPlugins)
128 {
129     const Vector<PluginPackage*>& plugins = PluginDatabase::installedPlugins()->plugins();
130
131     outPlugins.resize(plugins.size());
132
133     for (size_t i = 0; i < plugins.size(); ++i) {
134         PluginPackage* package = plugins[i];
135
136         PluginInfo info;
137         info.name = package->name();
138         info.file = package->fileName();
139         info.desc = package->description();
140
141         const MIMEToDescriptionsMap& mimeToDescriptions = package->mimeToDescriptions();
142
143         info.mimes.reserveCapacity(mimeToDescriptions.size());
144
145         MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
146         for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
147             MimeClassInfo mime;
148
149             mime.type = it->key;
150             mime.desc = it->value;
151             mime.extensions = package->mimeToExtensions().get(mime.type);
152
153             info.mimes.append(mime);
154         }
155
156         outPlugins[i] = info;
157     }
158 }
159
160 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
161 {
162     return page->group().isLinkVisited(hash);
163 }
164
165 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
166 {
167     page->group().addVisitedLinkHash(hash);
168 }