| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/plugin_lib.h" | 7 #include "webkit/glue/plugins/plugin_lib.h" |
| 8 | 8 |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "webkit/glue/plugins/plugin_constants_win.h" | 11 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 12 #include "webkit/glue/plugins/plugin_list.h" | 12 #include "webkit/glue/plugins/plugin_list.h" |
| 13 | 13 |
| 14 namespace NPAPI | 14 namespace NPAPI |
| 15 { | 15 { |
| 16 | |
| 17 /* static */ | |
| 18 PluginLib::NativeLibrary PluginLib::LoadNativeLibrary( | |
| 19 const FilePath& library_path) { | |
| 20 // Switch the current directory to the plugin directory as the plugin | |
| 21 // may have dependencies on dlls in this directory. | |
| 22 bool restore_directory = false; | |
| 23 std::wstring current_directory; | |
| 24 if (PathService::Get(base::DIR_CURRENT, ¤t_directory)) { | |
| 25 FilePath plugin_path = library_path.DirName(); | |
| 26 if (!plugin_path.value().empty()) { | |
| 27 PathService::SetCurrentDirectory(plugin_path.value()); | |
| 28 restore_directory = true; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 HMODULE module = LoadLibrary(library_path.value().c_str()); | |
| 33 if (restore_directory) | |
| 34 PathService::SetCurrentDirectory(current_directory); | |
| 35 | |
| 36 return module; | |
| 37 } | |
| 38 | |
| 39 /* static */ | |
| 40 void PluginLib::UnloadNativeLibrary(NativeLibrary library) { | |
| 41 FreeLibrary(library); | |
| 42 } | |
| 43 | |
| 44 /* static */ | |
| 45 void* PluginLib::GetFunctionPointerFromNativeLibrary( | |
| 46 NativeLibrary library, | |
| 47 NativeLibraryFunctionNameType name) { | |
| 48 return GetProcAddress(library, name); | |
| 49 } | |
| 50 | |
| 51 bool PluginLib::ReadWebPluginInfo(const FilePath &filename, | 16 bool PluginLib::ReadWebPluginInfo(const FilePath &filename, |
| 52 WebPluginInfo* info) { | 17 WebPluginInfo* info) { |
| 53 // On windows, the way we get the mime types for the library is | 18 // On windows, the way we get the mime types for the library is |
| 54 // to check the version information in the DLL itself. This | 19 // to check the version information in the DLL itself. This |
| 55 // will be a string of the format: <type1>|<type2>|<type3>|... | 20 // will be a string of the format: <type1>|<type2>|<type3>|... |
| 56 // For example: | 21 // For example: |
| 57 // video/quicktime|audio/aiff|image/jpeg | 22 // video/quicktime|audio/aiff|image/jpeg |
| 58 scoped_ptr<FileVersionInfo> version_info( | 23 scoped_ptr<FileVersionInfo> version_info( |
| 59 FileVersionInfo::CreateFileVersionInfo(filename.value())); | 24 FileVersionInfo::CreateFileVersionInfo(filename.value())); |
| 60 if (!version_info.get()) | 25 if (!version_info.get()) |
| 61 return false; | 26 return false; |
| 62 | 27 |
| 63 PluginVersionInfo pvi; | 28 PluginVersionInfo pvi; |
| 64 pvi.mime_types = version_info->GetStringValue(L"MIMEType"); | 29 pvi.mime_types = version_info->GetStringValue(L"MIMEType"); |
| 65 pvi.file_extensions = version_info->GetStringValue(L"FileExtents"); | 30 pvi.file_extensions = version_info->GetStringValue(L"FileExtents"); |
| 66 pvi.type_descriptions = version_info->GetStringValue(L"FileOpenName"); | 31 pvi.type_descriptions = version_info->GetStringValue(L"FileOpenName"); |
| 67 pvi.product_name = version_info->product_name(); | 32 pvi.product_name = version_info->product_name(); |
| 68 pvi.file_description = version_info->file_description(); | 33 pvi.file_description = version_info->file_description(); |
| 69 pvi.file_version = version_info->file_version(); | 34 pvi.file_version = version_info->file_version(); |
| 70 pvi.path = filename; | 35 pvi.path = filename; |
| 71 | 36 |
| 72 return PluginList::CreateWebPluginInfo(pvi, info); | 37 return PluginList::CreateWebPluginInfo(pvi, info); |
| 73 } | 38 } |
| 74 | 39 |
| 75 } // namespace NPAPI | 40 } // namespace NPAPI |
| OLD | NEW |