diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 01:59:09 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 01:59:09 +0000 |
commit | 4a8af424ef5110aaab4fcbda42d8280417e91b2f (patch) | |
tree | 4910d133e671cea0812b03e71c1248a12ce9e0a3 /chrome/browser/importer | |
parent | e28244138561a28a6ff77013dbcddc45d85f3a30 (diff) | |
download | chromium_src-4a8af424ef5110aaab4fcbda42d8280417e91b2f.zip chromium_src-4a8af424ef5110aaab4fcbda42d8280417e91b2f.tar.gz chromium_src-4a8af424ef5110aaab4fcbda42d8280417e91b2f.tar.bz2 |
Make firefox_importer_utils.cc compile on Posix.
Review URL: http://codereview.chromium.org/27249
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10564 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils.cc | 110 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils.h | 11 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 9 |
3 files changed, 91 insertions, 39 deletions
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index c546727..82e5110 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -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 @@ 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. @@ -44,8 +52,9 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { 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 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { 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 @@ class SetDllDirectoryCaller { 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 @@ int GetCurrentFirefoxMajorVersion() { 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 @@ std::wstring GetProfilesINI() { 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,6 +171,32 @@ void ParseProfileINI(std::wstring file, DictionaryValue* root) { } } } +#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 @@ bool CanImportURL(const GURL& url) { 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 @@ void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, 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 @@ std::string ReadBrowserConfigProp(const std::wstring& app_path, // 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 ReadPrefsJsValue(const std::wstring& profile_path, 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 @@ 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) { } @@ -412,6 +440,7 @@ NSSDecryptor::~NSSDecryptor() { 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 @@ 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() { @@ -510,12 +544,14 @@ void NSSDecryptor::Free() { 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 @@ 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 + // TODO(port): Load nss3. + NOTIMPLEMENTED(); + return std::wstring(); +#endif std::string plain; diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h index 4bf287c..0c43bd3 100644 --- a/chrome/browser/importer/firefox_importer_utils.h +++ b/chrome/browser/importer/firefox_importer_utils.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ +#include "base/basictypes.h" #include "base/values.h" #include "build/build_config.h" #include "webkit/glue/password_form.h" @@ -18,15 +19,12 @@ class TemplateURL; // biased to return the biggest version. int GetCurrentFirefoxMajorVersion(); +#if defined(OS_WIN) // Gets the full path of the profiles.ini file. This file records // the profiles that can be used by Firefox. Returns an empty // string if failed. std::wstring GetProfilesINI(); -// Detects where Firefox lives. Returns a empty string if Firefox -// is not installed. -std::wstring GetFirefoxInstallPath(); - // Parses the profile.ini file, and stores its information in |root|. // This file is a plain-text file. Key/value pairs are stored one per // line, and they are separeated in different sections. For example: @@ -40,6 +38,11 @@ std::wstring GetFirefoxInstallPath(); // We set "[value]" in path "<Section>.<Key>". For example, the path // "Genenral.StartWithLastProfile" has the value "1". void ParseProfileINI(std::wstring file, DictionaryValue* root); +#endif + +// Detects where Firefox lives. Returns a empty string if Firefox +// is not installed. +std::wstring GetFirefoxInstallPath(); // Returns true if we want to add the URL to the history. We filter // out the URL with a unsupported scheme. diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 6a2e59f..9c98362 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -647,9 +647,14 @@ void ImporterHost::DetectFirefoxProfiles() { return; } - std::wstring ini_file = GetProfilesINI(); DictionaryValue root; +#if defined(OS_WIN) + std::wstring ini_file = GetProfilesINI(); ParseProfileINI(ini_file, &root); +#else + // TODO(port): Do we need to concern ourselves with profiles on posix? + NOTIMPLEMENTED(); +#endif std::wstring source_path; for (int i = 0; ; ++i) { @@ -664,6 +669,7 @@ void ImporterHost::DetectFirefoxProfiles() { root.GetString(current_profile + L".Path", &path)) { ReplaceSubstringsAfterOffset(&path, 0, L"/", L"\\"); +#if defined(OS_WIN) // IsRelative=1 means the folder path would be relative to the // path of profiles.ini. IsRelative=0 refers to a custom profile // location. @@ -673,6 +679,7 @@ void ImporterHost::DetectFirefoxProfiles() { } else { profile_path = path; } +#endif // We only import the default profile when multiple profiles exist, // since the other profiles are used mostly by developers for testing. |