Changeset 74061 in webkit
- Timestamp:
- Dec 14, 2010 2:40:05 PM (13 years ago)
- Location:
- trunk/WebKit2
- Files:
-
- 1 added
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r74060 r74061 1 2010-12-14 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Adam Roben. 4 5 Move PluginInfoStore::getPluginInfo to NetscapePluginModule 6 https://bugs.webkit.org/show_bug.cgi?id=51058 7 8 * Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm: 9 Move implementation of PluginInfoStore::getPluginInfo and related 10 helper functions here. 11 12 * UIProcess/Plugins/mac/PluginInfoStoreMac.mm: 13 (WebKit::PluginInfoStore::getPluginInfo): 14 Just call NetscapePluginModule::getPluginInfo here for now. 15 16 * WebKit2.xcodeproj/project.pbxproj: 17 Add NetscapePluginModuleMac.mm. 18 1 19 2010-12-14 Anders Carlsson <andersca@apple.com> 2 20 -
trunk/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h
r74058 r74061 32 32 #include <wtf/text/WTFString.h> 33 33 34 // FIXME: We should not include PluginInfoStore.h here. Instead, 35 // PluginInfoStore::Plugin should be moved out into its own header which we can 36 // put in Shared/Plugins. 37 #include "PluginInfoStore.h" 38 34 39 namespace WebKit { 35 40 … … 43 48 void pluginCreated(); 44 49 void pluginDestroyed(); 50 51 static bool getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin&); 45 52 46 53 private: -
trunk/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm
r74060 r74061 24 24 */ 25 25 26 #include "PluginInfoStore.h" 27 28 #include "WebKitSystemInterface.h" 26 #include "NetscapePluginModule.h" 27 29 28 #include <WebCore/WebCoreNSStringExtras.h> 30 29 #include <wtf/HashSet.h> 31 #include <wtf/RetainPtr.h>32 30 33 31 using namespace WebCore; 34 32 35 33 namespace WebKit { 36 37 Vector<String> PluginInfoStore::pluginsDirectories()38 {39 Vector<String> pluginsDirectories;40 41 pluginsDirectories.append([NSHomeDirectory() stringByAppendingPathComponent:@"Library/Internet Plug-Ins"]);42 pluginsDirectories.append("/Library/Internet Plug-Ins");43 44 return pluginsDirectories;45 }46 47 // FIXME: Once the UI process knows the difference between the main thread and the web thread we can drop this and just use48 // String::createCFString.49 static CFStringRef safeCreateCFString(const String& string)50 {51 return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(string.characters()), string.length());52 }53 54 Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory)55 {56 Vector<String> pluginPaths;57 58 RetainPtr<CFStringRef> directoryCFString(AdoptCF, safeCreateCFString(directory));59 60 NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:(NSString *)directoryCFString.get() error:nil];61 for (NSString *filename in filenames)62 pluginPaths.append([(NSString *)directoryCFString.get() stringByAppendingPathComponent:filename]);63 64 return pluginPaths;65 }66 67 Vector<String> PluginInfoStore::individualPluginPaths()68 {69 return Vector<String>();70 }71 34 72 35 static bool getPluginArchitecture(CFBundleRef bundle, cpu_type_t& pluginArchitecture) … … 319 282 } 320 283 321 bool PluginInfoStore::getPluginInfo(const String& pluginPath,Plugin& plugin)284 bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin& plugin) 322 285 { 323 RetainPtr<CFStringRef> bundlePath(AdoptCF, safeCreateCFString(pluginPath));286 RetainPtr<CFStringRef> bundlePath(AdoptCF, pluginPath.createCFString()); 324 287 RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath.get(), kCFURLPOSIXPathStyle, false)); 325 288 326 289 // Try to initialize the bundle. 327 290 RetainPtr<CFBundleRef> bundle(AdoptCF, CFBundleCreate(kCFAllocatorDefault, bundleURL.get())); 328 291 if (!bundle) 329 292 return false; 330 293 331 294 // Check if this bundle is an NPAPI plug-in. 332 295 UInt32 packageType = 0; … … 339 302 if (!getPluginArchitecture(bundle.get(), pluginArchitecture)) 340 303 return false; 341 304 342 305 // Check that there's valid info for this plug-in. 343 306 if (!getPluginInfoFromPropertyLists(bundle.get(), plugin.info) && 344 307 !getPluginInfoFromCarbonResources(bundle.get(), plugin.info)) 345 308 return false; 346 309 347 310 plugin.path = pluginPath; 348 311 plugin.pluginArchitecture = pluginArchitecture; 349 312 plugin.bundleIdentifier = CFBundleGetIdentifier(bundle.get()); 350 313 plugin.versionNumber = CFBundleGetVersionNumber(bundle.get()); 351 314 352 315 RetainPtr<CFStringRef> filename(AdoptCF, CFURLCopyLastPathComponent(bundleURL.get())); 353 316 plugin.info.file = filename.get(); … … 361 324 } 362 325 363 bool PluginInfoStore::shouldUsePlugin(const Plugin& plugin)364 {365 for (size_t i = 0; i < m_plugins.size(); ++i) {366 const Plugin& loadedPlugin = m_plugins[i];367 368 // If a plug-in with the same bundle identifier already exists, we don't want to load it.369 if (loadedPlugin.bundleIdentifier == plugin.bundleIdentifier)370 return false;371 }372 373 return true;374 }375 376 String PluginInfoStore::getMIMETypeForExtension(const String& extension)377 {378 // FIXME: This should just call MIMETypeRegistry::getMIMETypeForExtension and be379 // strength reduced into the callsite once we can safely convert String380 // to CFStringRef off the main thread.381 382 RetainPtr<CFStringRef> extensionCFString(AdoptCF, safeCreateCFString(extension));383 return WKGetMIMETypeForExtension((NSString *)extensionCFString.get());384 }385 386 326 } // namespace WebKit -
trunk/WebKit2/UIProcess/Plugins/mac/PluginInfoStoreMac.mm
r74060 r74061 26 26 #include "PluginInfoStore.h" 27 27 28 #include "NetscapePluginModule.h" 28 29 #include "WebKitSystemInterface.h" 29 30 #include <WebCore/WebCoreNSStringExtras.h> … … 70 71 } 71 72 72 static bool getPluginArchitecture(CFBundleRef bundle, cpu_type_t& pluginArchitecture)73 {74 RetainPtr<CFArrayRef> pluginArchitecturesArray(AdoptCF, CFBundleCopyExecutableArchitectures(bundle));75 if (!pluginArchitecturesArray)76 return false;77 78 // Turn the array into a set.79 HashSet<unsigned> architectures;80 for (CFIndex i = 0, numPluginArchitectures = CFArrayGetCount(pluginArchitecturesArray.get()); i < numPluginArchitectures; ++i) {81 CFNumberRef number = static_cast<CFNumberRef>(CFArrayGetValueAtIndex(pluginArchitecturesArray.get(), i));82 83 SInt32 architecture;84 if (!CFNumberGetValue(number, kCFNumberSInt32Type, &architecture))85 continue;86 architectures.add(architecture);87 }88 89 #ifdef __x86_64__90 // We only support 64-bit Intel plug-ins on 64-bit Intel.91 if (architectures.contains(kCFBundleExecutableArchitectureX86_64)) {92 pluginArchitecture = CPU_TYPE_X86_64;93 return true;94 }95 96 // We also support 32-bit Intel plug-ins on 64-bit Intel.97 if (architectures.contains(kCFBundleExecutableArchitectureI386)) {98 pluginArchitecture = CPU_TYPE_X86;99 return true;100 }101 #elif defined(__i386__)102 // We only support 32-bit Intel plug-ins on 32-bit Intel.103 if (architectures.contains(kCFBundleExecutableArchitectureI386)) {104 pluginArchitecture = CPU_TYPE_X86;105 return true;106 }107 #elif defined(__ppc64__)108 // We only support 64-bit PPC plug-ins on 64-bit PPC.109 if (architectures.contains(kCFBundleExecutableArchitecturePPC64)) {110 pluginArchitecture = CPU_TYPE_POWERPC64;111 return true;112 }113 #elif defined(__ppc__)114 // We only support 32-bit PPC plug-ins on 32-bit PPC.115 if (architectures.contains(kCFBundleExecutableArchitecturePPC)) {116 pluginArchitecture = CPU_TYPE_POWERPC;117 return true;118 }119 #else120 #error "Unhandled architecture"121 #endif122 123 return false;124 }125 126 static bool getPluginInfoFromPropertyLists(CFBundleRef bundle, PluginInfo& pluginInfo)127 {128 // FIXME: Handle WebPluginMIMETypesFilenameKey.129 130 CFDictionaryRef mimeTypes = static_cast<CFDictionaryRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypes")));131 if (!mimeTypes || CFGetTypeID(mimeTypes) != CFDictionaryGetTypeID())132 return false;133 134 // Get the plug-in name.135 CFStringRef pluginName = static_cast<CFStringRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginName")));136 if (pluginName && CFGetTypeID(pluginName) == CFStringGetTypeID())137 pluginInfo.name = pluginName;138 139 // Get the plug-in description.140 CFStringRef pluginDescription = static_cast<CFStringRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginDescription")));141 if (pluginDescription && CFGetTypeID(pluginDescription) == CFStringGetTypeID())142 pluginInfo.desc = pluginDescription;143 144 // Get the MIME type mapping dictionary.145 CFIndex numMimeTypes = CFDictionaryGetCount(mimeTypes);146 Vector<CFStringRef> mimeTypesVector(numMimeTypes);147 Vector<CFDictionaryRef> mimeTypeInfoVector(numMimeTypes);148 CFDictionaryGetKeysAndValues(mimeTypes, reinterpret_cast<const void**>(mimeTypesVector.data()), reinterpret_cast<const void**>(mimeTypeInfoVector.data()));149 150 for (CFIndex i = 0; i < numMimeTypes; ++i) {151 MimeClassInfo mimeClassInfo;152 153 // If this MIME type is invalid, ignore it.154 CFStringRef mimeType = mimeTypesVector[i];155 if (!mimeType || CFGetTypeID(mimeType) != CFStringGetTypeID() || CFStringGetLength(mimeType) == 0)156 continue;157 158 // If this MIME type doesn't have a valid info dictionary, ignore it.159 CFDictionaryRef mimeTypeInfo = mimeTypeInfoVector[i];160 if (!mimeTypeInfo || CFGetTypeID(mimeTypeInfo) != CFDictionaryGetTypeID())161 continue;162 163 // Get the MIME type description.164 CFStringRef mimeTypeDescription = static_cast<CFStringRef>(CFDictionaryGetValue(mimeTypeInfo, CFSTR("WebPluginTypeDescription")));165 if (mimeTypeDescription && CFGetTypeID(mimeTypeDescription) != CFStringGetTypeID())166 mimeTypeDescription = 0;167 168 mimeClassInfo.type = String(mimeType).lower();169 mimeClassInfo.desc = mimeTypeDescription;170 171 // Now get the extensions for this MIME type.172 CFIndex numExtensions = 0;173 CFArrayRef extensionsArray = static_cast<CFArrayRef>(CFDictionaryGetValue(mimeTypeInfo, CFSTR("WebPluginExtensions")));174 if (extensionsArray && CFGetTypeID(extensionsArray) == CFArrayGetTypeID())175 numExtensions = CFArrayGetCount(extensionsArray);176 177 for (CFIndex i = 0; i < numExtensions; ++i) {178 CFStringRef extension = static_cast<CFStringRef>(CFArrayGetValueAtIndex(extensionsArray, i));179 if (!extension || CFGetTypeID(extension) != CFStringGetTypeID())180 continue;181 182 mimeClassInfo.extensions.append(String(extension).lower());183 }184 185 // Add this MIME type.186 pluginInfo.mimes.append(mimeClassInfo);187 }188 189 return true;190 }191 192 class ResourceMap {193 public:194 explicit ResourceMap(CFBundleRef bundle)195 : m_bundle(bundle)196 , m_currentResourceFile(CurResFile())197 , m_bundleResourceMap(CFBundleOpenBundleResourceMap(m_bundle))198 {199 UseResFile(m_bundleResourceMap);200 }201 202 ~ResourceMap()203 {204 // Close the resource map.205 CFBundleCloseBundleResourceMap(m_bundle, m_bundleResourceMap);206 207 // And restore the old resource.208 UseResFile(m_currentResourceFile);209 }210 211 bool isValid() const { return m_bundleResourceMap != -1; }212 213 private:214 CFBundleRef m_bundle;215 ResFileRefNum m_currentResourceFile;216 ResFileRefNum m_bundleResourceMap;217 };218 219 static bool getStringListResource(ResID resourceID, Vector<String>& stringList) {220 Handle stringListHandle = Get1Resource('STR#', resourceID);221 if (!stringListHandle || !*stringListHandle)222 return false;223 224 // Get the string list size.225 Size stringListSize = GetHandleSize(stringListHandle);226 if (stringListSize < static_cast<Size>(sizeof(UInt16)))227 return false;228 229 CFStringEncoding stringEncoding = stringEncodingForResource(stringListHandle);230 231 unsigned char* ptr = reinterpret_cast<unsigned char*>(*stringListHandle);232 unsigned char* end = ptr + stringListSize;233 234 // Get the number of strings in the string list.235 UInt16 numStrings = *reinterpret_cast<UInt16*>(ptr);236 ptr += sizeof(UInt16);237 238 for (UInt16 i = 0; i < numStrings; ++i) {239 // We're past the end of the string, bail.240 if (ptr >= end)241 return false;242 243 // Get the string length.244 unsigned char stringLength = *ptr++;245 246 RetainPtr<CFStringRef> cfString(AdoptCF, CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, stringLength, stringEncoding, false, kCFAllocatorNull));247 if (!cfString.get())248 return false;249 250 stringList.append(cfString.get());251 ptr += stringLength;252 }253 254 if (ptr != end)255 return false;256 257 return true;258 }259 260 static const ResID PluginNameOrDescriptionStringNumber = 126;261 static const ResID MIMEDescriptionStringNumber = 127;262 static const ResID MIMEListStringStringNumber = 128;263 264 static bool getPluginInfoFromCarbonResources(CFBundleRef bundle, PluginInfo& pluginInfo)265 {266 ResourceMap resourceMap(bundle);267 if (!resourceMap.isValid())268 return false;269 270 // Get the description and name string list.271 Vector<String> descriptionAndName;272 if (!getStringListResource(PluginNameOrDescriptionStringNumber, descriptionAndName))273 return false;274 275 // Get the MIME types and extensions string list. This list needs to be a multiple of two.276 Vector<String> mimeTypesAndExtensions;277 if (!getStringListResource(MIMEListStringStringNumber, mimeTypesAndExtensions))278 return false;279 280 if (mimeTypesAndExtensions.size() % 2)281 return false;282 283 size_t numMimeTypes = mimeTypesAndExtensions.size() / 2;284 285 // Now get the MIME type descriptions string list. This string list needs to be the same length as the number of MIME types.286 Vector<String> mimeTypeDescriptions;287 if (!getStringListResource(MIMEDescriptionStringNumber, mimeTypeDescriptions))288 return false;289 290 if (mimeTypeDescriptions.size() != numMimeTypes)291 return false;292 293 // Add all MIME types.294 for (size_t i = 0; i < mimeTypesAndExtensions.size() / 2; ++i) {295 MimeClassInfo mimeClassInfo;296 297 const String& mimeType = mimeTypesAndExtensions[i * 2];298 const String& description = mimeTypeDescriptions[i];299 300 mimeClassInfo.type = mimeType.lower();301 mimeClassInfo.desc = description;302 303 Vector<String> extensions;304 mimeTypesAndExtensions[i * 2 + 1].split(',', extensions);305 306 for (size_t i = 0; i < extensions.size(); ++i)307 mimeClassInfo.extensions.append(extensions[i].lower());308 309 pluginInfo.mimes.append(mimeClassInfo);310 }311 312 // Set the description and name if they exist.313 if (descriptionAndName.size() > 0)314 pluginInfo.desc = descriptionAndName[0];315 if (descriptionAndName.size() > 1)316 pluginInfo.name = descriptionAndName[1];317 318 return true;319 }320 321 73 bool PluginInfoStore::getPluginInfo(const String& pluginPath, Plugin& plugin) 322 74 { 323 RetainPtr<CFStringRef> bundlePath(AdoptCF, safeCreateCFString(pluginPath)); 324 RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath.get(), kCFURLPOSIXPathStyle, false)); 325 326 // Try to initialize the bundle. 327 RetainPtr<CFBundleRef> bundle(AdoptCF, CFBundleCreate(kCFAllocatorDefault, bundleURL.get())); 328 if (!bundle) 329 return false; 330 331 // Check if this bundle is an NPAPI plug-in. 332 UInt32 packageType = 0; 333 CFBundleGetPackageInfo(bundle.get(), &packageType, 0); 334 if (packageType != FOUR_CHAR_CODE('BRPL')) 335 return false; 336 337 // Check that the architecture is valid. 338 cpu_type_t pluginArchitecture = 0; 339 if (!getPluginArchitecture(bundle.get(), pluginArchitecture)) 340 return false; 341 342 // Check that there's valid info for this plug-in. 343 if (!getPluginInfoFromPropertyLists(bundle.get(), plugin.info) && 344 !getPluginInfoFromCarbonResources(bundle.get(), plugin.info)) 345 return false; 346 347 plugin.path = pluginPath; 348 plugin.pluginArchitecture = pluginArchitecture; 349 plugin.bundleIdentifier = CFBundleGetIdentifier(bundle.get()); 350 plugin.versionNumber = CFBundleGetVersionNumber(bundle.get()); 351 352 RetainPtr<CFStringRef> filename(AdoptCF, CFURLCopyLastPathComponent(bundleURL.get())); 353 plugin.info.file = filename.get(); 354 355 if (plugin.info.name.isNull()) 356 plugin.info.name = plugin.info.file; 357 if (plugin.info.desc.isNull()) 358 plugin.info.desc = plugin.info.file; 359 360 return true; 75 return NetscapePluginModule::getPluginInfo(pluginPath, plugin); 361 76 } 362 77 -
trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj
r74058 r74061 113 113 1A4A9C5512B816CF008FE984 /* NetscapePluginModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */; }; 114 114 1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */; }; 115 1A4A9C9A12B821CD008FE984 /* NetscapePluginModuleMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A9C9912B821CD008FE984 /* NetscapePluginModuleMac.mm */; }; 115 116 1A50DB66110A3D57000D3FE5 /* WebProcess.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A50DB1E110A3BDC000D3FE5 /* WebProcess.app */; }; 116 117 1A594ABA112A1FB6009DE7C7 /* WebUIClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A594AB8112A1FB6009DE7C7 /* WebUIClient.cpp */; }; … … 745 746 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePluginModule.cpp; sourceTree = "<group>"; }; 746 747 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetscapePluginModule.h; sourceTree = "<group>"; }; 748 1A4A9C9912B821CD008FE984 /* NetscapePluginModuleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginModuleMac.mm; sourceTree = "<group>"; }; 747 749 1A4F976A100E7B6600637A18 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; }; 748 750 1A4F976B100E7B6600637A18 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; }; … … 1412 1414 isa = PBXGroup; 1413 1415 children = ( 1416 1A4A9C9812B821C0008FE984 /* mac */, 1414 1417 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */, 1415 1418 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */, 1416 1419 ); 1417 1420 path = Netscape; 1421 sourceTree = "<group>"; 1422 }; 1423 1A4A9C9812B821C0008FE984 /* mac */ = { 1424 isa = PBXGroup; 1425 children = ( 1426 1A4A9C9912B821CD008FE984 /* NetscapePluginModuleMac.mm */, 1427 ); 1428 path = mac; 1418 1429 sourceTree = "<group>"; 1419 1430 }; … … 3123 3134 1A4A9AA912B7E796008FE984 /* WKTextInputWindowController.mm in Sources */, 3124 3135 1A4A9C5512B816CF008FE984 /* NetscapePluginModule.cpp in Sources */, 3136 1A4A9C9A12B821CD008FE984 /* NetscapePluginModuleMac.mm in Sources */, 3125 3137 ); 3126 3138 runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset
for help on using the changeset viewer.