OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/importer/firefox_importer_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_utils.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/registry.h" | 10 #include "base/registry.h" |
11 | 11 |
12 namespace { | |
13 | |
14 typedef BOOL (WINAPI* SetDllDirectoryFunc)(LPCTSTR lpPathName); | |
15 | |
16 // A helper class whose destructor calls SetDllDirectory(NULL) to undo the | |
17 // effects of a previous SetDllDirectory call. | |
18 class SetDllDirectoryCaller { | |
19 public: | |
20 explicit SetDllDirectoryCaller() : func_(NULL) { } | |
21 | |
22 ~SetDllDirectoryCaller() { | |
23 if (func_) | |
24 func_(NULL); | |
25 } | |
26 | |
27 // Sets the SetDllDirectory function pointer to activates this object. | |
28 void set_func(SetDllDirectoryFunc func) { func_ = func; } | |
29 | |
30 private: | |
31 SetDllDirectoryFunc func_; | |
32 }; | |
33 | |
34 } // namespace | |
35 | |
36 // NOTE: Keep these in order since we need test all those paths according | 12 // NOTE: Keep these in order since we need test all those paths according |
37 // to priority. For example. One machine has multiple users. One non-admin | 13 // to priority. For example. One machine has multiple users. One non-admin |
38 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. | 14 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. |
39 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry | 15 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry |
40 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 | 16 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 |
41 // related data instead of Firefox 3. | 17 // related data instead of Firefox 3. |
42 static const HKEY kFireFoxRegistryPaths[] = { | 18 static const HKEY kFireFoxRegistryPaths[] = { |
43 HKEY_CURRENT_USER, | 19 HKEY_CURRENT_USER, |
44 HKEY_LOCAL_MACHINE | 20 HKEY_LOCAL_MACHINE |
45 }; | 21 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 wchar_t buffer[MAX_PATH] = {0}; | 64 wchar_t buffer[MAX_PATH] = {0}; |
89 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, | 65 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
90 SHGFP_TYPE_CURRENT, buffer))) { | 66 SHGFP_TYPE_CURRENT, buffer))) { |
91 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); | 67 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); |
92 } | 68 } |
93 if (file_util::PathExists(ini_file)) | 69 if (file_util::PathExists(ini_file)) |
94 return ini_file; | 70 return ini_file; |
95 | 71 |
96 return FilePath(); | 72 return FilePath(); |
97 } | 73 } |
98 | |
99 // static | |
100 const wchar_t NSSDecryptor::kNSS3Library[] = L"nss3.dll"; | |
101 const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll"; | |
102 const wchar_t NSSDecryptor::kPLDS4Library[] = L"plds4.dll"; | |
103 const wchar_t NSSDecryptor::kNSPR4Library[] = L"nspr4.dll"; | |
104 | |
105 bool NSSDecryptor::Init(const std::wstring& dll_path, | |
106 const std::wstring& db_path) { | |
107 // We call SetDllDirectory to work around a Purify bug (GetModuleHandle | |
108 // fails inside Purify under certain conditions). SetDllDirectory only | |
109 // exists on Windows XP SP1 or later, so we look up its address at run time. | |
110 HMODULE kernel32_dll = GetModuleHandle(L"kernel32.dll"); | |
111 if (kernel32_dll == NULL) | |
112 return false; | |
113 SetDllDirectoryFunc set_dll_directory = | |
114 (SetDllDirectoryFunc)GetProcAddress(kernel32_dll, "SetDllDirectoryW"); | |
115 SetDllDirectoryCaller caller; | |
116 | |
117 if (set_dll_directory != NULL) { | |
118 if (!set_dll_directory(dll_path.c_str())) | |
119 return false; | |
120 caller.set_func(set_dll_directory); | |
121 nss3_dll_ = LoadLibrary(kNSS3Library); | |
122 if (nss3_dll_ == NULL) | |
123 return false; | |
124 } else { | |
125 // Fall back on LoadLibraryEx if SetDllDirectory isn't available. We | |
126 // actually prefer this method because it doesn't change the DLL search | |
127 // path, which is a process-wide property. | |
128 std::wstring path = dll_path; | |
129 file_util::AppendToPath(&path, kNSS3Library); | |
130 nss3_dll_ = LoadLibraryEx(path.c_str(), NULL, | |
131 LOAD_WITH_ALTERED_SEARCH_PATH); | |
132 if (nss3_dll_ == NULL) | |
133 return false; | |
134 | |
135 // Firefox 2 uses NSS 3.11. Firefox 3 uses NSS 3.12. NSS 3.12 has two | |
136 // changes in its DLLs: | |
137 // 1. nss3.dll is not linked with softokn3.dll at build time, but rather | |
138 // loads softokn3.dll using LoadLibrary in NSS_Init. | |
139 // 2. softokn3.dll has a new dependency sqlite3.dll. | |
140 // NSS_Init's LoadLibrary call has trouble finding sqlite3.dll. To help | |
141 // it out, we preload softokn3.dll using LoadLibraryEx with the | |
142 // LOAD_WITH_ALTERED_SEARCH_PATH flag. This helps because LoadLibrary | |
143 // doesn't load a DLL again if it's already loaded. This workaround is | |
144 // harmless for NSS 3.11. | |
145 path = dll_path; | |
146 file_util::AppendToPath(&path, kSoftokn3Library); | |
147 softokn3_dll_ = LoadLibraryEx(path.c_str(), NULL, | |
148 LOAD_WITH_ALTERED_SEARCH_PATH); | |
149 if (softokn3_dll_ == NULL) { | |
150 Free(); | |
151 return false; | |
152 } | |
153 } | |
154 HMODULE plds4_dll = GetModuleHandle(kPLDS4Library); | |
155 HMODULE nspr4_dll = GetModuleHandle(kNSPR4Library); | |
156 | |
157 return InitNSS(db_path, plds4_dll, nspr4_dll); | |
158 } | |
OLD | NEW |