summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 04:29:26 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 04:29:26 +0000
commitdf2013932664ec3718248ed7c6f41445bb939a10 (patch)
tree49c2eb838e9a7cff2e47ea3afef0c3c9d8dee406 /chrome
parent5a43a8d52d5c369beb16b52a8a32315a228f804b (diff)
downloadchromium_src-df2013932664ec3718248ed7c6f41445bb939a10.zip
chromium_src-df2013932664ec3718248ed7c6f41445bb939a10.tar.gz
chromium_src-df2013932664ec3718248ed7c6f41445bb939a10.tar.bz2
Re-land r10564 with a fix for unit tests. Fixed a typo in an ifdef.
Make firefox_importer_utils.cc compile on Posix. TBR=evan Review URL: http://codereview.chromium.org/29006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.scons1
-rw-r--r--chrome/browser/importer/firefox_importer_utils.cc110
-rw-r--r--chrome/browser/importer/firefox_importer_utils.h11
-rw-r--r--chrome/browser/importer/importer.cc9
-rw-r--r--chrome/chrome.gyp1
-rw-r--r--chrome/chrome.xcodeproj/project.pbxproj4
6 files changed, 95 insertions, 41 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 81221a3..28d0ddf 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -691,7 +691,6 @@ 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 c546727..e8b3efa 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.
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index e09bdea..25ad4ab 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1168,7 +1168,6 @@
'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 e1121d5..0d2f911 100644
--- a/chrome/chrome.xcodeproj/project.pbxproj
+++ b/chrome/chrome.xcodeproj/project.pbxproj
@@ -270,6 +270,7 @@
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 */; };
@@ -2947,6 +2948,7 @@
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>"; };
@@ -3358,6 +3360,7 @@
12F137DA942221A44BFA0967 /* bookmark_drop_info.cc */,
90BF0D1189BB7158BD7F1600 /* bookmark_context_menu.cc */,
D224399513442348FF231FCB /* importer.cc */,
+ E7A3400C283C5FA030AD4BF2 /* firefox_importer_utils.cc */,
);
sourceTree = "<group>";
};
@@ -5775,6 +5778,7 @@
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 */,