diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 02:28:16 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-27 02:28:16 +0000 |
commit | 344678b2b9e85692bf9ec24afd2593481c38dda1 (patch) | |
tree | ba3e2c1e6996abcab3b9d0e632a0a77bc4362a3c | |
parent | f911f74c395b825df8a1b92158e032a7e971b2a2 (diff) | |
download | chromium_src-344678b2b9e85692bf9ec24afd2593481c38dda1.zip chromium_src-344678b2b9e85692bf9ec24afd2593481c38dda1.tar.gz chromium_src-344678b2b9e85692bf9ec24afd2593481c38dda1.tar.bz2 |
Reverting 10564.
Review URL: http://codereview.chromium.org/28244
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10570 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.scons | 1 | ||||
-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 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 4 |
6 files changed, 41 insertions, 95 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 28d0ddf..81221a3 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -691,6 +691,7 @@ if not env.Bit('windows'): # Otherwise shared link builds won't work on Linux. 'importer/firefox2_importer.cc', 'importer/firefox3_importer.cc', + 'importer/firefox_importer_utils.cc', 'importer/ie_importer.cc', 'importer/toolbar_importer.cc', 'jankometer.cc', diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index 82e5110..c546727 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -5,30 +5,23 @@ #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. @@ -39,7 +32,6 @@ 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. @@ -52,9 +44,8 @@ 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") != std::string::npos || - low_value.find("firefox") != std::string::npos || - low_value.find("moz:") != std::string::npos ) + if (low_value.find("mozilla") != -1 || low_value.find("firefox") != -1 || + low_value.find("moz:") != -1 ) return false; return true; } @@ -63,7 +54,6 @@ 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 @@ -83,12 +73,10 @@ 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; @@ -104,14 +92,8 @@ 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. @@ -128,6 +110,25 @@ 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; @@ -171,32 +172,6 @@ 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"}; @@ -206,7 +181,7 @@ bool CanImportURL(const GURL& url) { return false; // Filter out the URLs with unsupported schemes. - for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) { + for (int i = 0; i < arraysize(kInvalidSchemes); ++i) { if (url.SchemeIs(kInvalidSchemes[i])) return false; } @@ -244,8 +219,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(WideToUTF8(url)), false)); + template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), + false)); template_url->set_show_in_default_list(true); search_engine_for_url[url] = template_url; if (!default_turl) @@ -295,16 +270,15 @@ 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 == std::string::npos) + if (prop_index == -1) return ""; size_t start = prop_index + pref_key.length(); - size_t stop = std::string::npos; - if (start != std::string::npos) + size_t stop = -1; + if (start != -1) stop = content.find("\n", start + 1); - if (start == std::string::npos || - stop == std::string::npos || (start == stop)) { + if (start == -1 || stop == -1 || (start == stop)) { NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; return ""; } @@ -322,15 +296,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 == std::string::npos) + if (prop_index == -1) return ""; size_t start = prop_index + search_for.length(); - size_t stop = std::string::npos; - if (start != std::string::npos) + size_t stop = -1; + if (start != -1) stop = content.find(")", start + 1); - if (start == std::string::npos || stop == std::string::npos) { + if (start == -1 || stop == -1) { NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; return ""; } @@ -428,9 +402,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) { } @@ -440,7 +412,6 @@ 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. @@ -530,11 +501,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() { @@ -544,14 +510,12 @@ 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; @@ -604,15 +568,9 @@ 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 0c43bd3..4bf287c 100644 --- a/chrome/browser/importer/firefox_importer_utils.h +++ b/chrome/browser/importer/firefox_importer_utils.h @@ -5,7 +5,6 @@ #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" @@ -19,12 +18,15 @@ 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: @@ -38,11 +40,6 @@ std::wstring GetProfilesINI(); // 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 9c98362..6a2e59f 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -647,14 +647,9 @@ void ImporterHost::DetectFirefoxProfiles() { return; } - DictionaryValue root; -#if defined(OS_WIN) std::wstring ini_file = GetProfilesINI(); + DictionaryValue root; 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) { @@ -669,7 +664,6 @@ 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. @@ -679,7 +673,6 @@ 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. diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 06dafc3..3757caa 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1168,6 +1168,7 @@ 'browser/debugger/debugger_window.cc', 'browser/importer/firefox2_importer.cc', 'browser/importer/firefox3_importer.cc', + 'browser/importer/firefox_importer_utils.cc', 'browser/importer/ie_importer.cc', 'browser/tab_contents/native_ui_contents.cc', 'browser/tab_contents/render_view_context_menu_controller.cc', diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 0d2f911..e1121d5 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -270,7 +270,6 @@ 71784BA931A610A94A7FEDC9 /* history_querying_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9F50E9D48F7009A6919 /* history_querying_unittest.cc */; }; 7442556F908264C52BEBFE4D /* starred_url_database_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFA090E9D48F7009A6919 /* starred_url_database_unittest.cc */; }; 7988AD180F4E5C710003C5CF /* child_process_info.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA9BC2620F44DCBE00588450 /* child_process_info.cc */; }; - 7A25BF747B2F2CC2115A2818 /* firefox_importer_utils.cc in Sources */ = {isa = PBXBuildFile; fileRef = E7A3400C283C5FA030AD4BF2 /* firefox_importer_utils.cc */; }; 7D296C6300A94C463E1E7BC7 /* interstitial_page.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6CCB9D10F1EC32700106F0D /* interstitial_page.cc */; }; 7D7BF08CA9978F8782A1E82D /* browser_shutdown.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF8460E9D4839009A6919 /* browser_shutdown.cc */; }; 7F84A3FF0F6102F46E0E5155 /* history_publisher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 269003C4E493789D82B6B0F9 /* history_publisher.cc */; }; @@ -2948,7 +2947,6 @@ E4F324420EE5CE94002533CE /* extension_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extension_unittest.cc; sourceTree = "<group>"; }; E4F324780EE5D17E002533CE /* referrer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = referrer.h; sourceTree = "<group>"; }; E4F324790EE5D17E002533CE /* referrer.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = referrer.cc; sourceTree = "<group>"; }; - E7A3400C283C5FA030AD4BF2 /* firefox_importer_utils.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = firefox_importer_utils.cc; path = browser/importer/firefox_importer_utils.cc; sourceTree = SOURCE_ROOT; }; E7FDE61828F151056D975855 /* bookmark_drag_data.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_drag_data.cc; path = browser/bookmarks/bookmark_drag_data.cc; sourceTree = SOURCE_ROOT; }; E81681ADC802675FE949BC63 /* child_thread.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = child_thread.cc; sourceTree = "<group>"; }; EA72C084DB3FC0FC595E525E /* template_url_model.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = template_url_model.cc; sourceTree = "<group>"; }; @@ -3360,7 +3358,6 @@ 12F137DA942221A44BFA0967 /* bookmark_drop_info.cc */, 90BF0D1189BB7158BD7F1600 /* bookmark_context_menu.cc */, D224399513442348FF231FCB /* importer.cc */, - E7A3400C283C5FA030AD4BF2 /* firefox_importer_utils.cc */, ); sourceTree = "<group>"; }; @@ -5778,7 +5775,6 @@ 9E85B39CA40439D93CE52E60 /* fav_icon_helper.cc in Sources */, E45075C10F1506F2003BE099 /* firefox2_importer.cc in Sources */, E45075C40F150701003BE099 /* firefox3_importer.cc in Sources */, - 7A25BF747B2F2CC2115A2818 /* firefox_importer_utils.cc in Sources */, E45075C60F15070D003BE099 /* firefox_profile_lock.cc in Sources */, 85C8A66BBC97243AF1C11166 /* gears_integration.cc in Sources */, 4D7BF9990E9D486B009A6919 /* google_url_tracker.cc in Sources */, |