| Index: chrome/browser/importer/firefox_importer_utils.cc
|
| diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
|
| index afe484e84c0edb9988e5bb9e063406070b0abdb3..838029075bcfbddaa6e58182bb65b829ba6fce13 100644
|
| --- a/chrome/browser/importer/firefox_importer_utils.cc
|
| +++ b/chrome/browser/importer/firefox_importer_utils.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -24,19 +24,6 @@
|
|
|
| namespace {
|
|
|
| -#if defined(OS_WIN)
|
| -// NOTE: Keep these in order since we need test all those paths according
|
| -// to priority. For example. One machine has multiple users. One non-admin
|
| -// user installs Firefox 2, which causes there is a Firefox2 entry under HKCU.
|
| -// One admin user installs Firefox 3, which causes there is a Firefox 3 entry
|
| -// under HKLM. So when the non-admin user log in, we should deal with Firefox 2
|
| -// related data instead of Firefox 3.
|
| -static const HKEY kFireFoxRegistryPaths[] = {
|
| - HKEY_CURRENT_USER,
|
| - HKEY_LOCAL_MACHINE
|
| -};
|
| -#endif
|
| -
|
| // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from
|
| // the search URL when importing search engines.
|
| class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter {
|
| @@ -84,6 +71,17 @@ class SetDllDirectoryCaller {
|
| } // namespace
|
|
|
| #if defined(OS_WIN)
|
| +// NOTE: Keep these in order since we need test all those paths according
|
| +// to priority. For example. One machine has multiple users. One non-admin
|
| +// user installs Firefox 2, which causes there is a Firefox2 entry under HKCU.
|
| +// One admin user installs Firefox 3, which causes there is a Firefox 3 entry
|
| +// under HKLM. So when the non-admin user log in, we should deal with Firefox 2
|
| +// related data instead of Firefox 3.
|
| +static const HKEY kFireFoxRegistryPaths[] = {
|
| + HKEY_CURRENT_USER,
|
| + HKEY_LOCAL_MACHINE
|
| +};
|
| +
|
| int GetCurrentFirefoxMajorVersionFromRegistry() {
|
| TCHAR ver_buffer[128];
|
| DWORD ver_buffer_length = sizeof(ver_buffer);
|
| @@ -454,9 +452,7 @@ NSSDecryptor::NSSDecryptor()
|
| PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL),
|
| PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL),
|
| PL_ArenaFinish(NULL), PR_Cleanup(NULL),
|
| -#if defined(OS_WIN)
|
| nss3_dll_(NULL), softokn3_dll_(NULL),
|
| -#endif
|
| is_nss_initialized_(false) {
|
| }
|
|
|
| @@ -514,30 +510,49 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,
|
| return false;
|
| }
|
| }
|
| -
|
| - // NSPR DLLs are already loaded now.
|
| HMODULE plds4_dll = GetModuleHandle(kPLDS4Library);
|
| HMODULE nspr4_dll = GetModuleHandle(kNSPR4Library);
|
| +#elif defined(OS_LINUX)
|
| + nss3_dll_ = base::LoadNativeLibrary(FilePath("libnss3.so"));
|
| + if (nss3_dll_ == NULL)
|
| + return false;
|
| + base::NativeLibrary plds4_dll = base::LoadNativeLibrary(
|
| + FilePath("libplds4.so"));
|
| + base::NativeLibrary nspr4_dll = base::LoadNativeLibrary(
|
| + FilePath("libnspr4.so"));
|
| +#else
|
| + // TODO(port): Check on MAC
|
| + base::NativeLibrary plds4_dll, nspr4_dll;
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +#endif
|
| +
|
| + // NSPR DLLs are already loaded now.
|
| if (plds4_dll == NULL || nspr4_dll == NULL) {
|
| Free();
|
| return false;
|
| }
|
|
|
| // Gets the function address.
|
| - NSS_Init = (NSSInitFunc)GetProcAddress(nss3_dll_, "NSS_Init");
|
| - NSS_Shutdown = (NSSShutdownFunc)GetProcAddress(nss3_dll_, "NSS_Shutdown");
|
| + NSS_Init = (NSSInitFunc)
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Init");
|
| + NSS_Shutdown = (NSSShutdownFunc)
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Shutdown");
|
| PK11_GetInternalKeySlot = (PK11GetInternalKeySlotFunc)
|
| - GetProcAddress(nss3_dll_, "PK11_GetInternalKeySlot");
|
| - PK11_FreeSlot = (PK11FreeSlotFunc)GetProcAddress(nss3_dll_, "PK11_FreeSlot");
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_,
|
| + "PK11_GetInternalKeySlot");
|
| + PK11_FreeSlot = (PK11FreeSlotFunc)
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_FreeSlot");
|
| PK11_Authenticate = (PK11AuthenticateFunc)
|
| - GetProcAddress(nss3_dll_, "PK11_Authenticate");
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_Authenticate");
|
| PK11SDR_Decrypt = (PK11SDRDecryptFunc)
|
| - GetProcAddress(nss3_dll_, "PK11SDR_Decrypt");
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11SDR_Decrypt");
|
| SECITEM_FreeItem = (SECITEMFreeItemFunc)
|
| - GetProcAddress(nss3_dll_, "SECITEM_FreeItem");
|
| + base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "SECITEM_FreeItem");
|
| PL_ArenaFinish = (PLArenaFinishFunc)
|
| - GetProcAddress(plds4_dll, "PL_ArenaFinish");
|
| - PR_Cleanup = (PRCleanupFunc)GetProcAddress(nspr4_dll, "PR_Cleanup");
|
| + base::GetFunctionPointerFromNativeLibrary(plds4_dll, "PL_ArenaFinish");
|
| + PR_Cleanup = (PRCleanupFunc)
|
| + base::GetFunctionPointerFromNativeLibrary(nspr4_dll, "PR_Cleanup");
|
|
|
| if (NSS_Init == NULL || NSS_Shutdown == NULL ||
|
| PK11_GetInternalKeySlot == NULL || PK11_FreeSlot == NULL ||
|
| @@ -556,11 +571,6 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,
|
|
|
| is_nss_initialized_ = true;
|
| return true;
|
| -#else
|
| - // TODO(port): Load NSS.
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| -#endif
|
| }
|
|
|
| void NSSDecryptor::Free() {
|
| @@ -570,13 +580,11 @@ void NSSDecryptor::Free() {
|
| PR_Cleanup();
|
| is_nss_initialized_ = false;
|
| }
|
| -#if defined(OS_WIN)
|
| +#if defined(OS_WIN) || defined(OS_LINUX)
|
| if (softokn3_dll_ != NULL)
|
| - FreeLibrary(softokn3_dll_);
|
| - softokn3_dll_ = NULL;
|
| + base::UnloadNativeLibrary(softokn3_dll_);
|
| if (nss3_dll_ != NULL)
|
| - FreeLibrary(nss3_dll_);
|
| - nss3_dll_ = NULL;
|
| + base::UnloadNativeLibrary(nss3_dll_);
|
| #endif
|
| NSS_Init = NULL;
|
| NSS_Shutdown = NULL;
|
| @@ -587,6 +595,8 @@ void NSSDecryptor::Free() {
|
| SECITEM_FreeItem = NULL;
|
| PL_ArenaFinish = NULL;
|
| PR_Cleanup = NULL;
|
| + nss3_dll_ = NULL;
|
| + softokn3_dll_ = NULL;
|
| }
|
|
|
| // This method is based on some Firefox code in
|
| @@ -630,20 +640,19 @@ void NSSDecryptor::Free() {
|
| * ***** END LICENSE BLOCK ***** */
|
|
|
| std::wstring NSSDecryptor::Decrypt(const std::string& crypt) const {
|
| -#if defined(OS_WIN)
|
| - // Do nothing if NSS is not loaded.
|
| - if (!nss3_dll_)
|
| - return std::wstring();
|
| -#else
|
| +#if !defined(OS_WIN) && !defined(OS_LINUX)
|
| // TODO(port): Load nss3.
|
| NOTIMPLEMENTED();
|
| return std::wstring();
|
| #endif
|
|
|
| - std::string plain;
|
| + // Do nothing if NSS is not loaded.
|
| + if (!nss3_dll_)
|
| + return std::wstring();
|
|
|
| // The old style password is encoded in base64. They are identified
|
| // by a leading '~'. Otherwise, we should decrypt the text.
|
| + std::string plain;
|
| if (crypt[0] != '~') {
|
| std::string decoded_data;
|
| net::Base64Decode(crypt, &decoded_data);
|
|
|