2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #import "PluginInfoStore.h"
29 #import "NetscapePluginModule.h"
30 #import "WebKitSystemInterface.h"
31 #import <WebCore/WebCoreNSStringExtras.h>
32 #import <wtf/HashSet.h>
33 #import <wtf/RetainPtr.h>
35 using namespace WebCore;
39 Vector<String> PluginInfoStore::pluginsDirectories()
41 Vector<String> pluginsDirectories;
43 pluginsDirectories.append([NSHomeDirectory() stringByAppendingPathComponent:@"Library/Internet Plug-Ins"]);
44 pluginsDirectories.append("/Library/Internet Plug-Ins");
46 return pluginsDirectories;
49 // FIXME: Once the UI process knows the difference between the main thread and the web thread we can drop this and just use
50 // String::createCFString.
51 static CFStringRef safeCreateCFString(const String& string)
53 return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(string.characters()), string.length());
56 Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory)
58 Vector<String> pluginPaths;
60 RetainPtr<CFStringRef> directoryCFString(AdoptCF, safeCreateCFString(directory));
62 NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:(NSString *)directoryCFString.get() error:nil];
63 for (NSString *filename in filenames)
64 pluginPaths.append([(NSString *)directoryCFString.get() stringByAppendingPathComponent:filename]);
69 Vector<String> PluginInfoStore::individualPluginPaths()
71 return Vector<String>();
74 bool PluginInfoStore::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin)
76 return NetscapePluginModule::getPluginInfo(pluginPath, plugin);
79 bool PluginInfoStore::shouldUsePlugin(Vector<PluginModuleInfo>& alreadyLoadedPlugins, const PluginModuleInfo& plugin)
81 for (size_t i = 0; i < alreadyLoadedPlugins.size(); ++i) {
82 const PluginModuleInfo& loadedPlugin = alreadyLoadedPlugins[i];
84 // If a plug-in with the same bundle identifier already exists, we don't want to load it.
85 if (loadedPlugin.bundleIdentifier == plugin.bundleIdentifier)
92 String PluginInfoStore::getMIMETypeForExtension(const String& extension)
94 // FIXME: This should just call MIMETypeRegistry::getMIMETypeForExtension and be
95 // strength reduced into the callsite once we can safely convert String
96 // to CFStringRef off the main thread.
98 RetainPtr<CFStringRef> extensionCFString(AdoptCF, safeCreateCFString(extension));
99 return WKGetMIMETypeForExtension((NSString *)extensionCFString.get());
102 } // namespace WebKit