| Index: chrome/browser/importer/firefox_importer_utils.cc
|
| ===================================================================
|
| --- chrome/browser/importer/firefox_importer_utils.cc (revision 10540)
|
| +++ chrome/browser/importer/firefox_importer_utils.cc (working copy)
|
| @@ -5,23 +5,30 @@
|
| #include "chrome/browser/importer/firefox_importer_utils.h"
|
|
|
| #include <algorithm>
|
| +
|
| +#if defined(OS_WIN)
|
| #include <shlobj.h>
|
| +#endif
|
|
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| -#include "base/registry.h"
|
| #include "base/string_util.h"
|
| #include "base/sys_string_conversions.h"
|
| #include "base/time.h"
|
| #include "chrome/browser/search_engines/template_url.h"
|
| #include "chrome/browser/search_engines/template_url_model.h"
|
| #include "chrome/browser/search_engines/template_url_parser.h"
|
| -#include "chrome/common/win_util.h"
|
| #include "googleurl/src/gurl.h"
|
| #include "net/base/base64.h"
|
|
|
| +#if defined(OS_WIN)
|
| +#include "base/registry.h"
|
| +#include "chrome/common/win_util.h"
|
| +#endif
|
| +
|
| 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.
|
| @@ -32,6 +39,7 @@
|
| HKEY_CURRENT_USER,
|
| HKEY_LOCAL_MACHINE
|
| };
|
| +#endif
|
|
|
| // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from
|
| // the search URL when importing search engines.
|
| @@ -44,8 +52,9 @@
|
| virtual bool KeepParameter(const std::string& key,
|
| const std::string& value) {
|
| std::string low_value = StringToLowerASCII(value);
|
| - if (low_value.find("mozilla") != -1 || low_value.find("firefox") != -1 ||
|
| - low_value.find("moz:") != -1 )
|
| + if (low_value.find("mozilla") != std::string::npos ||
|
| + low_value.find("firefox") != std::string::npos ||
|
| + low_value.find("moz:") != std::string::npos )
|
| return false;
|
| return true;
|
| }
|
| @@ -54,6 +63,7 @@
|
| DISALLOW_EVIL_CONSTRUCTORS(FirefoxURLParameterFilter);
|
| };
|
|
|
| +#if defined(OS_WIN)
|
| typedef BOOL (WINAPI* SetDllDirectoryFunc)(LPCTSTR lpPathName);
|
|
|
| // A helper class whose destructor calls SetDllDirectory(NULL) to undo the
|
| @@ -73,10 +83,12 @@
|
| private:
|
| SetDllDirectoryFunc func_;
|
| };
|
| +#endif
|
|
|
| } // namespace
|
|
|
| int GetCurrentFirefoxMajorVersion() {
|
| +#if defined(OS_WIN)
|
| TCHAR ver_buffer[128];
|
| DWORD ver_buffer_length = sizeof(ver_buffer);
|
| int highest_version = 0;
|
| @@ -92,8 +104,14 @@
|
| highest_version = std::max(highest_version, _wtoi(ver_buffer));
|
| }
|
| return highest_version;
|
| +#else
|
| + // TODO(port): Read in firefox configuration.
|
| + NOTIMPLEMENTED();
|
| + return 0;
|
| +#endif
|
| }
|
|
|
| +#if defined(OS_WIN)
|
| std::wstring GetProfilesINI() {
|
| // The default location of the profile folder containing user data is
|
| // under the "Application Data" folder in Windows XP.
|
| @@ -110,25 +128,6 @@
|
| return ini_file;
|
| }
|
|
|
| -std::wstring GetFirefoxInstallPath() {
|
| - // Detects the path that Firefox is installed in.
|
| - std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox";
|
| - TCHAR buffer[MAX_PATH];
|
| - DWORD buffer_length = sizeof(buffer);
|
| - bool result;
|
| - result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(),
|
| - L"CurrentVersion", buffer, &buffer_length);
|
| - if (!result)
|
| - return std::wstring();
|
| - registry_path += L"\\" + std::wstring(buffer) + L"\\Main";
|
| - buffer_length = sizeof(buffer);
|
| - result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(),
|
| - L"Install Directory", buffer, &buffer_length);
|
| - if (!result)
|
| - return std::wstring();
|
| - return buffer;
|
| -}
|
| -
|
| void ParseProfileINI(std::wstring file, DictionaryValue* root) {
|
| // Reads the whole INI file.
|
| std::string content;
|
| @@ -172,7 +171,33 @@
|
| }
|
| }
|
| }
|
| +#endif
|
|
|
| +std::wstring GetFirefoxInstallPath() {
|
| +#if defined(OS_WIN)
|
| + // Detects the path that Firefox is installed in.
|
| + std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox";
|
| + TCHAR buffer[MAX_PATH];
|
| + DWORD buffer_length = sizeof(buffer);
|
| + bool result;
|
| + result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(),
|
| + L"CurrentVersion", buffer, &buffer_length);
|
| + if (!result)
|
| + return std::wstring();
|
| + registry_path += L"\\" + std::wstring(buffer) + L"\\Main";
|
| + buffer_length = sizeof(buffer);
|
| + result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(),
|
| + L"Install Directory", buffer, &buffer_length);
|
| + if (!result)
|
| + return std::wstring();
|
| + return buffer;
|
| +#else
|
| + // TODO(port): Load firefox configuration.
|
| + NOTIMPLEMENTED();
|
| + return std::wstring();
|
| +#endif
|
| +}
|
| +
|
| bool CanImportURL(const GURL& url) {
|
| const char* kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"};
|
|
|
| @@ -181,7 +206,7 @@
|
| return false;
|
|
|
| // Filter out the URLs with unsupported schemes.
|
| - for (int i = 0; i < arraysize(kInvalidSchemes); ++i) {
|
| + for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) {
|
| if (url.SchemeIs(kInvalidSchemes[i]))
|
| return false;
|
| }
|
| @@ -219,8 +244,8 @@
|
| search_engine_for_url.erase(iter);
|
| }
|
| // Give this a keyword to facilitate tab-to-search, if possible.
|
| - template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url),
|
| - false));
|
| + template_url->set_keyword(
|
| + TemplateURLModel::GenerateKeyword(GURL(WideToUTF8(url)), false));
|
| template_url->set_show_in_default_list(true);
|
| search_engine_for_url[url] = template_url;
|
| if (!default_turl)
|
| @@ -270,15 +295,16 @@
|
|
|
| // This file has the syntax: key=value.
|
| size_t prop_index = content.find(pref_key + "=");
|
| - if (prop_index == -1)
|
| + if (prop_index == std::string::npos)
|
| return "";
|
|
|
| size_t start = prop_index + pref_key.length();
|
| - size_t stop = -1;
|
| - if (start != -1)
|
| + size_t stop = std::string::npos;
|
| + if (start != std::string::npos)
|
| stop = content.find("\n", start + 1);
|
|
|
| - if (start == -1 || stop == -1 || (start == stop)) {
|
| + if (start == std::string::npos ||
|
| + stop == std::string::npos || (start == stop)) {
|
| NOTREACHED() << "Firefox property " << pref_key << " could not be parsed.";
|
| return "";
|
| }
|
| @@ -296,15 +322,15 @@
|
| std::string search_for = std::string("user_pref(\"") + pref_key +
|
| std::string("\", ");
|
| size_t prop_index = content.find(search_for);
|
| - if (prop_index == -1)
|
| + if (prop_index == std::string::npos)
|
| return "";
|
|
|
| size_t start = prop_index + search_for.length();
|
| - size_t stop = -1;
|
| - if (start != -1)
|
| + size_t stop = std::string::npos;
|
| + if (start != std::string::npos)
|
| stop = content.find(")", start + 1);
|
|
|
| - if (start == -1 || stop == -1) {
|
| + if (start == std::string::npos || stop == std::string::npos) {
|
| NOTREACHED() << "Firefox property " << pref_key << " could not be parsed.";
|
| return "";
|
| }
|
| @@ -402,7 +428,9 @@
|
| 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) {
|
| }
|
|
|
| @@ -412,6 +440,7 @@
|
|
|
| bool NSSDecryptor::Init(const std::wstring& dll_path,
|
| const std::wstring& db_path) {
|
| +#if defined(OS_WIN)
|
| // We call SetDllDirectory to work around a Purify bug (GetModuleHandle
|
| // fails inside Purify under certain conditions). SetDllDirectory only
|
| // exists on Windows XP SP1 or later, so we look up its address at run time.
|
| @@ -501,6 +530,11 @@
|
|
|
| is_nss_initialized_ = true;
|
| return true;
|
| +#else
|
| + // TODO(port): Load NSS.
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +#endif
|
| }
|
|
|
| void NSSDecryptor::Free() {
|
| @@ -510,12 +544,14 @@
|
| PR_Cleanup();
|
| is_nss_initialized_ = false;
|
| }
|
| +#if defined(OS_WIN)
|
| if (softokn3_dll_ != NULL)
|
| FreeLibrary(softokn3_dll_);
|
| softokn3_dll_ = NULL;
|
| if (nss3_dll_ != NULL)
|
| FreeLibrary(nss3_dll_);
|
| nss3_dll_ = NULL;
|
| +#endif
|
| NSS_Init = NULL;
|
| NSS_Shutdown = NULL;
|
| PK11_GetInternalKeySlot = NULL;
|
| @@ -568,9 +604,15 @@
|
| * ***** 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
|
| + // TODO(port): Load nss3.
|
| + NOTIMPLEMENTED();
|
| + return std::wstring();
|
| +#endif
|
|
|
| std::string plain;
|
|
|
|
|