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 "chrome/browser/importer/firefox_importer_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 |
| 9 #if defined(OS_WIN) |
8 #include <shlobj.h> | 10 #include <shlobj.h> |
| 11 #endif |
9 | 12 |
10 #include "base/file_util.h" | 13 #include "base/file_util.h" |
11 #include "base/logging.h" | 14 #include "base/logging.h" |
12 #include "base/registry.h" | |
13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
14 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
15 #include "base/time.h" | 17 #include "base/time.h" |
16 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/search_engines/template_url_model.h" | 19 #include "chrome/browser/search_engines/template_url_model.h" |
18 #include "chrome/browser/search_engines/template_url_parser.h" | 20 #include "chrome/browser/search_engines/template_url_parser.h" |
19 #include "chrome/common/win_util.h" | |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "net/base/base64.h" | 22 #include "net/base/base64.h" |
22 | 23 |
| 24 #if defined(OS_WIN) |
| 25 #include "base/registry.h" |
| 26 #include "chrome/common/win_util.h" |
| 27 #endif |
| 28 |
23 namespace { | 29 namespace { |
24 | 30 |
| 31 #if defined(OS_WIN) |
25 // NOTE: Keep these in order since we need test all those paths according | 32 // NOTE: Keep these in order since we need test all those paths according |
26 // to priority. For example. One machine has multiple users. One non-admin | 33 // to priority. For example. One machine has multiple users. One non-admin |
27 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. | 34 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. |
28 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry | 35 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry |
29 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 | 36 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 |
30 // related data instead of Firefox 3. | 37 // related data instead of Firefox 3. |
31 static const HKEY kFireFoxRegistryPaths[] = { | 38 static const HKEY kFireFoxRegistryPaths[] = { |
32 HKEY_CURRENT_USER, | 39 HKEY_CURRENT_USER, |
33 HKEY_LOCAL_MACHINE | 40 HKEY_LOCAL_MACHINE |
34 }; | 41 }; |
| 42 #endif |
35 | 43 |
36 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from | 44 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from |
37 // the search URL when importing search engines. | 45 // the search URL when importing search engines. |
38 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { | 46 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { |
39 public: | 47 public: |
40 FirefoxURLParameterFilter() { } | 48 FirefoxURLParameterFilter() { } |
41 ~FirefoxURLParameterFilter() { } | 49 ~FirefoxURLParameterFilter() { } |
42 | 50 |
43 // TemplateURLParser::ParameterFilter method. | 51 // TemplateURLParser::ParameterFilter method. |
44 virtual bool KeepParameter(const std::string& key, | 52 virtual bool KeepParameter(const std::string& key, |
45 const std::string& value) { | 53 const std::string& value) { |
46 std::string low_value = StringToLowerASCII(value); | 54 std::string low_value = StringToLowerASCII(value); |
47 if (low_value.find("mozilla") != -1 || low_value.find("firefox") != -1 || | 55 if (low_value.find("mozilla") != std::string::npos || |
48 low_value.find("moz:") != -1 ) | 56 low_value.find("firefox") != std::string::npos || |
| 57 low_value.find("moz:") != std::string::npos ) |
49 return false; | 58 return false; |
50 return true; | 59 return true; |
51 } | 60 } |
52 | 61 |
53 private: | 62 private: |
54 DISALLOW_EVIL_CONSTRUCTORS(FirefoxURLParameterFilter); | 63 DISALLOW_EVIL_CONSTRUCTORS(FirefoxURLParameterFilter); |
55 }; | 64 }; |
56 | 65 |
| 66 #if defined(OS_WIN) |
57 typedef BOOL (WINAPI* SetDllDirectoryFunc)(LPCTSTR lpPathName); | 67 typedef BOOL (WINAPI* SetDllDirectoryFunc)(LPCTSTR lpPathName); |
58 | 68 |
59 // A helper class whose destructor calls SetDllDirectory(NULL) to undo the | 69 // A helper class whose destructor calls SetDllDirectory(NULL) to undo the |
60 // effects of a previous SetDllDirectory call. | 70 // effects of a previous SetDllDirectory call. |
61 class SetDllDirectoryCaller { | 71 class SetDllDirectoryCaller { |
62 public: | 72 public: |
63 explicit SetDllDirectoryCaller() : func_(NULL) { } | 73 explicit SetDllDirectoryCaller() : func_(NULL) { } |
64 | 74 |
65 ~SetDllDirectoryCaller() { | 75 ~SetDllDirectoryCaller() { |
66 if (func_) | 76 if (func_) |
67 func_(NULL); | 77 func_(NULL); |
68 } | 78 } |
69 | 79 |
70 // Sets the SetDllDirectory function pointer to activates this object. | 80 // Sets the SetDllDirectory function pointer to activates this object. |
71 void set_func(SetDllDirectoryFunc func) { func_ = func; } | 81 void set_func(SetDllDirectoryFunc func) { func_ = func; } |
72 | 82 |
73 private: | 83 private: |
74 SetDllDirectoryFunc func_; | 84 SetDllDirectoryFunc func_; |
75 }; | 85 }; |
| 86 #endif |
76 | 87 |
77 } // namespace | 88 } // namespace |
78 | 89 |
79 int GetCurrentFirefoxMajorVersion() { | 90 int GetCurrentFirefoxMajorVersion() { |
| 91 #if defined(OS_WIN) |
80 TCHAR ver_buffer[128]; | 92 TCHAR ver_buffer[128]; |
81 DWORD ver_buffer_length = sizeof(ver_buffer); | 93 DWORD ver_buffer_length = sizeof(ver_buffer); |
82 int highest_version = 0; | 94 int highest_version = 0; |
83 // When installing Firefox with admin account, the product keys will be | 95 // When installing Firefox with admin account, the product keys will be |
84 // written under HKLM\Mozilla. Otherwise it the keys will be written under | 96 // written under HKLM\Mozilla. Otherwise it the keys will be written under |
85 // HKCU\Mozilla. | 97 // HKCU\Mozilla. |
86 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { | 98 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { |
87 bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], | 99 bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], |
88 L"Software\\Mozilla\\Mozilla Firefox", | 100 L"Software\\Mozilla\\Mozilla Firefox", |
89 L"CurrentVersion", ver_buffer, &ver_buffer_length); | 101 L"CurrentVersion", ver_buffer, &ver_buffer_length); |
90 if (!result) | 102 if (!result) |
91 continue; | 103 continue; |
92 highest_version = std::max(highest_version, _wtoi(ver_buffer)); | 104 highest_version = std::max(highest_version, _wtoi(ver_buffer)); |
93 } | 105 } |
94 return highest_version; | 106 return highest_version; |
| 107 #else |
| 108 // TODO(port): Read in firefox configuration. |
| 109 NOTIMPLEMENTED(); |
| 110 return 0; |
| 111 #endif |
95 } | 112 } |
96 | 113 |
| 114 #if defined(OS_WIN) |
97 std::wstring GetProfilesINI() { | 115 std::wstring GetProfilesINI() { |
98 // The default location of the profile folder containing user data is | 116 // The default location of the profile folder containing user data is |
99 // under the "Application Data" folder in Windows XP. | 117 // under the "Application Data" folder in Windows XP. |
100 std::wstring ini_file; | 118 std::wstring ini_file; |
101 wchar_t buffer[MAX_PATH] = {0}; | 119 wchar_t buffer[MAX_PATH] = {0}; |
102 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, | 120 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
103 SHGFP_TYPE_CURRENT, buffer))) { | 121 SHGFP_TYPE_CURRENT, buffer))) { |
104 ini_file = buffer; | 122 ini_file = buffer; |
105 file_util::AppendToPath(&ini_file, L"Mozilla\\Firefox\\profiles.ini"); | 123 file_util::AppendToPath(&ini_file, L"Mozilla\\Firefox\\profiles.ini"); |
106 } | 124 } |
107 if (!file_util::PathExists(ini_file)) | 125 if (!file_util::PathExists(ini_file)) |
108 ini_file.clear(); | 126 ini_file.clear(); |
109 | 127 |
110 return ini_file; | 128 return ini_file; |
111 } | 129 } |
112 | 130 |
113 std::wstring GetFirefoxInstallPath() { | |
114 // Detects the path that Firefox is installed in. | |
115 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; | |
116 TCHAR buffer[MAX_PATH]; | |
117 DWORD buffer_length = sizeof(buffer); | |
118 bool result; | |
119 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), | |
120 L"CurrentVersion", buffer, &buffer_length); | |
121 if (!result) | |
122 return std::wstring(); | |
123 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; | |
124 buffer_length = sizeof(buffer); | |
125 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), | |
126 L"Install Directory", buffer, &buffer_length); | |
127 if (!result) | |
128 return std::wstring(); | |
129 return buffer; | |
130 } | |
131 | |
132 void ParseProfileINI(std::wstring file, DictionaryValue* root) { | 131 void ParseProfileINI(std::wstring file, DictionaryValue* root) { |
133 // Reads the whole INI file. | 132 // Reads the whole INI file. |
134 std::string content; | 133 std::string content; |
135 file_util::ReadFileToString(file, &content); | 134 file_util::ReadFileToString(file, &content); |
136 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); | 135 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); |
137 std::vector<std::string> lines; | 136 std::vector<std::string> lines; |
138 SplitString(content, '\n', &lines); | 137 SplitString(content, '\n', &lines); |
139 | 138 |
140 // Parses the file. | 139 // Parses the file. |
141 root->Clear(); | 140 root->Clear(); |
(...skipping 23 matching lines...) Expand all Loading... |
165 // Checks whether the section and key contain a '.' character. | 164 // Checks whether the section and key contain a '.' character. |
166 // Those sections and keys break DictionaryValue's path format, | 165 // Those sections and keys break DictionaryValue's path format, |
167 // so we discard them. | 166 // so we discard them. |
168 if (current_section.find(L'.') == std::wstring::npos && | 167 if (current_section.find(L'.') == std::wstring::npos && |
169 key.find(L'.') == std::wstring::npos) | 168 key.find(L'.') == std::wstring::npos) |
170 root->SetString(current_section + L"." + key, value); | 169 root->SetString(current_section + L"." + key, value); |
171 } | 170 } |
172 } | 171 } |
173 } | 172 } |
174 } | 173 } |
| 174 #endif |
| 175 |
| 176 std::wstring GetFirefoxInstallPath() { |
| 177 #if defined(OS_WIN) |
| 178 // Detects the path that Firefox is installed in. |
| 179 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; |
| 180 TCHAR buffer[MAX_PATH]; |
| 181 DWORD buffer_length = sizeof(buffer); |
| 182 bool result; |
| 183 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
| 184 L"CurrentVersion", buffer, &buffer_length); |
| 185 if (!result) |
| 186 return std::wstring(); |
| 187 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; |
| 188 buffer_length = sizeof(buffer); |
| 189 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
| 190 L"Install Directory", buffer, &buffer_length); |
| 191 if (!result) |
| 192 return std::wstring(); |
| 193 return buffer; |
| 194 #else |
| 195 // TODO(port): Load firefox configuration. |
| 196 NOTIMPLEMENTED(); |
| 197 return std::wstring(); |
| 198 #endif |
| 199 } |
175 | 200 |
176 bool CanImportURL(const GURL& url) { | 201 bool CanImportURL(const GURL& url) { |
177 const char* kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"}; | 202 const char* kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"}; |
178 | 203 |
179 // The URL is not valid. | 204 // The URL is not valid. |
180 if (!url.is_valid()) | 205 if (!url.is_valid()) |
181 return false; | 206 return false; |
182 | 207 |
183 // Filter out the URLs with unsupported schemes. | 208 // Filter out the URLs with unsupported schemes. |
184 for (int i = 0; i < arraysize(kInvalidSchemes); ++i) { | 209 for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) { |
185 if (url.SchemeIs(kInvalidSchemes[i])) | 210 if (url.SchemeIs(kInvalidSchemes[i])) |
186 return false; | 211 return false; |
187 } | 212 } |
188 | 213 |
189 return true; | 214 return true; |
190 } | 215 } |
191 | 216 |
192 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, | 217 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, |
193 std::vector<TemplateURL*>* search_engines) { | 218 std::vector<TemplateURL*>* search_engines) { |
194 DCHECK(search_engines); | 219 DCHECK(search_engines); |
(...skipping 17 matching lines...) Expand all Loading... |
212 search_engine_for_url.find(url); | 237 search_engine_for_url.find(url); |
213 if (iter != search_engine_for_url.end()) { | 238 if (iter != search_engine_for_url.end()) { |
214 // We have already found a search engine with the same URL. We give | 239 // We have already found a search engine with the same URL. We give |
215 // priority to the latest one found, as GetSearchEnginesXMLFiles() | 240 // priority to the latest one found, as GetSearchEnginesXMLFiles() |
216 // returns a vector with first Firefox default search engines and then | 241 // returns a vector with first Firefox default search engines and then |
217 // the user's ones. We want to give priority to the user ones. | 242 // the user's ones. We want to give priority to the user ones. |
218 delete iter->second; | 243 delete iter->second; |
219 search_engine_for_url.erase(iter); | 244 search_engine_for_url.erase(iter); |
220 } | 245 } |
221 // Give this a keyword to facilitate tab-to-search, if possible. | 246 // Give this a keyword to facilitate tab-to-search, if possible. |
222 template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), | 247 template_url->set_keyword( |
223 false)); | 248 TemplateURLModel::GenerateKeyword(GURL(WideToUTF8(url)), false)); |
224 template_url->set_show_in_default_list(true); | 249 template_url->set_show_in_default_list(true); |
225 search_engine_for_url[url] = template_url; | 250 search_engine_for_url[url] = template_url; |
226 if (!default_turl) | 251 if (!default_turl) |
227 default_turl = template_url; | 252 default_turl = template_url; |
228 } else { | 253 } else { |
229 delete template_url; | 254 delete template_url; |
230 } | 255 } |
231 content.clear(); | 256 content.clear(); |
232 } | 257 } |
233 | 258 |
(...skipping 29 matching lines...) Expand all Loading... |
263 } | 288 } |
264 | 289 |
265 std::string ReadBrowserConfigProp(const std::wstring& app_path, | 290 std::string ReadBrowserConfigProp(const std::wstring& app_path, |
266 const std::string& pref_key) { | 291 const std::string& pref_key) { |
267 std::string content; | 292 std::string content; |
268 if (!ReadPrefFile(app_path, L"browserconfig.properties", &content)) | 293 if (!ReadPrefFile(app_path, L"browserconfig.properties", &content)) |
269 return ""; | 294 return ""; |
270 | 295 |
271 // This file has the syntax: key=value. | 296 // This file has the syntax: key=value. |
272 size_t prop_index = content.find(pref_key + "="); | 297 size_t prop_index = content.find(pref_key + "="); |
273 if (prop_index == -1) | 298 if (prop_index == std::string::npos) |
274 return ""; | 299 return ""; |
275 | 300 |
276 size_t start = prop_index + pref_key.length(); | 301 size_t start = prop_index + pref_key.length(); |
277 size_t stop = -1; | 302 size_t stop = std::string::npos; |
278 if (start != -1) | 303 if (start != std::string::npos) |
279 stop = content.find("\n", start + 1); | 304 stop = content.find("\n", start + 1); |
280 | 305 |
281 if (start == -1 || stop == -1 || (start == stop)) { | 306 if (start == std::string::npos || |
| 307 stop == std::string::npos || (start == stop)) { |
282 NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; | 308 NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; |
283 return ""; | 309 return ""; |
284 } | 310 } |
285 | 311 |
286 return content.substr(start + 1, stop - start - 1); | 312 return content.substr(start + 1, stop - start - 1); |
287 } | 313 } |
288 | 314 |
289 std::string ReadPrefsJsValue(const std::wstring& profile_path, | 315 std::string ReadPrefsJsValue(const std::wstring& profile_path, |
290 const std::string& pref_key) { | 316 const std::string& pref_key) { |
291 std::string content; | 317 std::string content; |
292 if (!ReadPrefFile(profile_path, L"prefs.js", &content)) | 318 if (!ReadPrefFile(profile_path, L"prefs.js", &content)) |
293 return ""; | 319 return ""; |
294 | 320 |
295 // This file has the syntax: user_pref("key", value); | 321 // This file has the syntax: user_pref("key", value); |
296 std::string search_for = std::string("user_pref(\"") + pref_key + | 322 std::string search_for = std::string("user_pref(\"") + pref_key + |
297 std::string("\", "); | 323 std::string("\", "); |
298 size_t prop_index = content.find(search_for); | 324 size_t prop_index = content.find(search_for); |
299 if (prop_index == -1) | 325 if (prop_index == std::string::npos) |
300 return ""; | 326 return ""; |
301 | 327 |
302 size_t start = prop_index + search_for.length(); | 328 size_t start = prop_index + search_for.length(); |
303 size_t stop = -1; | 329 size_t stop = std::string::npos; |
304 if (start != -1) | 330 if (start != std::string::npos) |
305 stop = content.find(")", start + 1); | 331 stop = content.find(")", start + 1); |
306 | 332 |
307 if (start == -1 || stop == -1) { | 333 if (start == std::string::npos || stop == std::string::npos) { |
308 NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; | 334 NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; |
309 return ""; | 335 return ""; |
310 } | 336 } |
311 | 337 |
312 // String values have double quotes we don't need to return to the caller. | 338 // String values have double quotes we don't need to return to the caller. |
313 if (content[start] == '\"' && content[stop - 1] == '\"') { | 339 if (content[start] == '\"' && content[stop - 1] == '\"') { |
314 ++start; | 340 ++start; |
315 --stop; | 341 --stop; |
316 } | 342 } |
317 | 343 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 const wchar_t NSSDecryptor::kNSS3Library[] = L"nss3.dll"; | 421 const wchar_t NSSDecryptor::kNSS3Library[] = L"nss3.dll"; |
396 const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll"; | 422 const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll"; |
397 const wchar_t NSSDecryptor::kPLDS4Library[] = L"plds4.dll"; | 423 const wchar_t NSSDecryptor::kPLDS4Library[] = L"plds4.dll"; |
398 const wchar_t NSSDecryptor::kNSPR4Library[] = L"nspr4.dll"; | 424 const wchar_t NSSDecryptor::kNSPR4Library[] = L"nspr4.dll"; |
399 | 425 |
400 NSSDecryptor::NSSDecryptor() | 426 NSSDecryptor::NSSDecryptor() |
401 : NSS_Init(NULL), NSS_Shutdown(NULL), PK11_GetInternalKeySlot(NULL), | 427 : NSS_Init(NULL), NSS_Shutdown(NULL), PK11_GetInternalKeySlot(NULL), |
402 PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL), | 428 PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL), |
403 PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL), | 429 PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL), |
404 PL_ArenaFinish(NULL), PR_Cleanup(NULL), | 430 PL_ArenaFinish(NULL), PR_Cleanup(NULL), |
| 431 #if defined(OS_WIN) |
405 nss3_dll_(NULL), softokn3_dll_(NULL), | 432 nss3_dll_(NULL), softokn3_dll_(NULL), |
| 433 #endif |
406 is_nss_initialized_(false) { | 434 is_nss_initialized_(false) { |
407 } | 435 } |
408 | 436 |
409 NSSDecryptor::~NSSDecryptor() { | 437 NSSDecryptor::~NSSDecryptor() { |
410 Free(); | 438 Free(); |
411 } | 439 } |
412 | 440 |
413 bool NSSDecryptor::Init(const std::wstring& dll_path, | 441 bool NSSDecryptor::Init(const std::wstring& dll_path, |
414 const std::wstring& db_path) { | 442 const std::wstring& db_path) { |
| 443 #if defined(OS_WIN) |
415 // We call SetDllDirectory to work around a Purify bug (GetModuleHandle | 444 // We call SetDllDirectory to work around a Purify bug (GetModuleHandle |
416 // fails inside Purify under certain conditions). SetDllDirectory only | 445 // fails inside Purify under certain conditions). SetDllDirectory only |
417 // exists on Windows XP SP1 or later, so we look up its address at run time. | 446 // exists on Windows XP SP1 or later, so we look up its address at run time. |
418 HMODULE kernel32_dll = GetModuleHandle(L"kernel32.dll"); | 447 HMODULE kernel32_dll = GetModuleHandle(L"kernel32.dll"); |
419 if (kernel32_dll == NULL) | 448 if (kernel32_dll == NULL) |
420 return false; | 449 return false; |
421 SetDllDirectoryFunc set_dll_directory = | 450 SetDllDirectoryFunc set_dll_directory = |
422 (SetDllDirectoryFunc)GetProcAddress(kernel32_dll, "SetDllDirectoryW"); | 451 (SetDllDirectoryFunc)GetProcAddress(kernel32_dll, "SetDllDirectoryW"); |
423 SetDllDirectoryCaller caller; | 452 SetDllDirectoryCaller caller; |
424 | 453 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 523 } |
495 | 524 |
496 SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); | 525 SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); |
497 if (result != SECSuccess) { | 526 if (result != SECSuccess) { |
498 Free(); | 527 Free(); |
499 return false; | 528 return false; |
500 } | 529 } |
501 | 530 |
502 is_nss_initialized_ = true; | 531 is_nss_initialized_ = true; |
503 return true; | 532 return true; |
| 533 #else |
| 534 // TODO(port): Load NSS. |
| 535 NOTIMPLEMENTED(); |
| 536 return false; |
| 537 #endif |
504 } | 538 } |
505 | 539 |
506 void NSSDecryptor::Free() { | 540 void NSSDecryptor::Free() { |
507 if (is_nss_initialized_) { | 541 if (is_nss_initialized_) { |
508 NSS_Shutdown(); | 542 NSS_Shutdown(); |
509 PL_ArenaFinish(); | 543 PL_ArenaFinish(); |
510 PR_Cleanup(); | 544 PR_Cleanup(); |
511 is_nss_initialized_ = false; | 545 is_nss_initialized_ = false; |
512 } | 546 } |
| 547 #if defined(OS_WIN) |
513 if (softokn3_dll_ != NULL) | 548 if (softokn3_dll_ != NULL) |
514 FreeLibrary(softokn3_dll_); | 549 FreeLibrary(softokn3_dll_); |
515 softokn3_dll_ = NULL; | 550 softokn3_dll_ = NULL; |
516 if (nss3_dll_ != NULL) | 551 if (nss3_dll_ != NULL) |
517 FreeLibrary(nss3_dll_); | 552 FreeLibrary(nss3_dll_); |
518 nss3_dll_ = NULL; | 553 nss3_dll_ = NULL; |
| 554 #endif |
519 NSS_Init = NULL; | 555 NSS_Init = NULL; |
520 NSS_Shutdown = NULL; | 556 NSS_Shutdown = NULL; |
521 PK11_GetInternalKeySlot = NULL; | 557 PK11_GetInternalKeySlot = NULL; |
522 PK11_FreeSlot = NULL; | 558 PK11_FreeSlot = NULL; |
523 PK11_Authenticate = NULL; | 559 PK11_Authenticate = NULL; |
524 PK11SDR_Decrypt = NULL; | 560 PK11SDR_Decrypt = NULL; |
525 SECITEM_FreeItem = NULL; | 561 SECITEM_FreeItem = NULL; |
526 PL_ArenaFinish = NULL; | 562 PL_ArenaFinish = NULL; |
527 PR_Cleanup = NULL; | 563 PR_Cleanup = NULL; |
528 } | 564 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 * under the terms of either the GPL or the LGPL, and not to allow others to | 597 * under the terms of either the GPL or the LGPL, and not to allow others to |
562 * use your version of this file under the terms of the MPL, indicate your | 598 * use your version of this file under the terms of the MPL, indicate your |
563 * decision by deleting the provisions above and replace them with the notice | 599 * decision by deleting the provisions above and replace them with the notice |
564 * and other provisions required by the GPL or the LGPL. If you do not delete | 600 * and other provisions required by the GPL or the LGPL. If you do not delete |
565 * the provisions above, a recipient may use your version of this file under | 601 * the provisions above, a recipient may use your version of this file under |
566 * the terms of any one of the MPL, the GPL or the LGPL. | 602 * the terms of any one of the MPL, the GPL or the LGPL. |
567 * | 603 * |
568 * ***** END LICENSE BLOCK ***** */ | 604 * ***** END LICENSE BLOCK ***** */ |
569 | 605 |
570 std::wstring NSSDecryptor::Decrypt(const std::string& crypt) const { | 606 std::wstring NSSDecryptor::Decrypt(const std::string& crypt) const { |
| 607 #if defined(OS_WIN_) |
571 // Do nothing if NSS is not loaded. | 608 // Do nothing if NSS is not loaded. |
572 if (!nss3_dll_) | 609 if (!nss3_dll_) |
573 return std::wstring(); | 610 return std::wstring(); |
| 611 #else |
| 612 // TODO(port): Load nss3. |
| 613 NOTIMPLEMENTED(); |
| 614 return std::wstring(); |
| 615 #endif |
574 | 616 |
575 std::string plain; | 617 std::string plain; |
576 | 618 |
577 // The old style password is encoded in base64. They are identified | 619 // The old style password is encoded in base64. They are identified |
578 // by a leading '~'. Otherwise, we should decrypt the text. | 620 // by a leading '~'. Otherwise, we should decrypt the text. |
579 if (crypt[0] != '~') { | 621 if (crypt[0] != '~') { |
580 std::string decoded_data; | 622 std::string decoded_data; |
581 net::Base64Decode(crypt, &decoded_data); | 623 net::Base64Decode(crypt, &decoded_data); |
582 PK11SlotInfo* slot = NULL; | 624 PK11SlotInfo* slot = NULL; |
583 slot = PK11_GetInternalKeySlot(); | 625 slot = PK11_GetInternalKeySlot(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // Version 3 has an extra line for further use. | 770 // Version 3 has an extra line for further use. |
729 if (version == 3) { | 771 if (version == 3) { |
730 ++begin; | 772 ++begin; |
731 } | 773 } |
732 | 774 |
733 forms->push_back(form); | 775 forms->push_back(form); |
734 } | 776 } |
735 } | 777 } |
736 } | 778 } |
737 | 779 |
OLD | NEW |