Refactor ClipboardMac class to use PlatformStrategies.
[WebKit-https.git] / Source / WebKit / mac / WebCoreSupport / WebPlatformStrategies.mm
1 /*
2  * Copyright (C) 2010 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 #import "WebPlatformStrategies.h"
27
28 #import "WebPluginDatabase.h"
29 #import "WebPluginPackage.h"
30 #import <WebCore/BlockExceptions.h>
31 #import <WebCore/Page.h>
32 #import <WebCore/PageGroup.h>
33 #import <WebCore/PlatformPasteboard.h>
34
35 using namespace WebCore;
36
37 void WebPlatformStrategies::initialize()
38 {
39     DEFINE_STATIC_LOCAL(WebPlatformStrategies, platformStrategies, ());
40     setPlatformStrategies(&platformStrategies);
41 }
42
43 WebPlatformStrategies::WebPlatformStrategies()
44 {
45 }
46
47 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
48 {
49     return this;
50 }
51
52 PluginStrategy* WebPlatformStrategies::createPluginStrategy()
53 {
54     return this;
55 }
56
57 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
58 {
59     return this;
60 }
61
62 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
63 {
64     return this;
65 }
66
67 void WebPlatformStrategies::notifyCookiesChanged()
68 {
69 }
70
71 void WebPlatformStrategies::refreshPlugins()
72 {
73     [[WebPluginDatabase sharedDatabase] refresh];
74 }
75
76 void WebPlatformStrategies::getPluginInfo(const WebCore::Page*, Vector<WebCore::PluginInfo>& plugins)
77 {
78     BEGIN_BLOCK_OBJC_EXCEPTIONS;
79
80     NSArray* pluginsArray = [[WebPluginDatabase sharedDatabase] plugins];
81     for (unsigned int i = 0; i < [pluginsArray count]; ++i) {
82         WebPluginPackage *plugin = [pluginsArray objectAtIndex:i];
83
84         plugins.append([plugin pluginInfo]);
85     }
86     
87     END_BLOCK_OBJC_EXCEPTIONS;
88 }
89
90 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
91 {
92     return page->group().isLinkVisited(hash);
93 }
94
95 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
96 {
97     return page->group().addVisitedLinkHash(hash);
98 }
99
100 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
101 {
102     PlatformPasteboard pasteboard(pasteboardName);
103     pasteboard.getTypes(types);
104 }
105
106 PassRefPtr<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
107 {
108     PlatformPasteboard pasteboard(pasteboardName);
109     return pasteboard.bufferForType(pasteboardType);
110 }
111
112 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
113 {
114     PlatformPasteboard pasteboard(pasteboardName);
115     pasteboard.getPathnamesForType(pathnames, pasteboardType);
116 }
117
118 String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
119 {
120     PlatformPasteboard pasteboard(pasteboardName);
121     return pasteboard.stringForType(pasteboardType);
122 }
123
124 void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
125 {
126     PlatformPasteboard pasteboard(toPasteboard);
127     return pasteboard.copy(fromPasteboard);
128 }
129
130 int WebPlatformStrategies::changeCount(const String &pasteboardName)
131 {
132     PlatformPasteboard pasteboard(pasteboardName);
133     return pasteboard.changeCount();
134 }
135
136 String WebPlatformStrategies::uniqueName()
137 {
138     return PlatformPasteboard::uniqueName();
139 }
140
141 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
142 {
143     PlatformPasteboard pasteboard(pasteboardName);
144     return pasteboard.setTypes(pasteboardTypes);
145 }
146
147 void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
148 {
149     PlatformPasteboard pasteboard(pasteboardName);
150     return pasteboard.setBufferForType(buffer, pasteboardType);
151 }
152
153 void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
154 {
155     PlatformPasteboard pasteboard(pasteboardName);
156     pasteboard.setPathnamesForType(pathnames, pasteboardType);
157 }
158
159 void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
160 {
161     PlatformPasteboard pasteboard(pasteboardName);
162     return pasteboard.setStringForType(string, pasteboardType);    
163 }