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