summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 23:45:25 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 23:45:25 +0000
commit1bdf29eb27c00bd1be0a6f3eb65d33ecddde274f (patch)
tree35abd9143abed93d47d2bd4bf63f922e4d5c99dc /chrome/browser/importer
parent0c557f15b825d1036a1e48a148ff10d9cd51ab0f (diff)
downloadchromium_src-1bdf29eb27c00bd1be0a6f3eb65d33ecddde274f.zip
chromium_src-1bdf29eb27c00bd1be0a6f3eb65d33ecddde274f.tar.gz
chromium_src-1bdf29eb27c00bd1be0a6f3eb65d33ecddde274f.tar.bz2
Add import settings dialog on linux.
BUG=11191 TEST=Open Import Settings dialog from Chrome wrench menu on Linux and make sure it imports Firefox data as selected. Review URL: http://codereview.chromium.org/115133 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r--chrome/browser/importer/firefox_importer_utils.cc55
-rw-r--r--chrome/browser/importer/firefox_importer_utils.h12
-rw-r--r--chrome/browser/importer/firefox_profile_lock.cc8
-rw-r--r--chrome/browser/importer/importer.cc44
4 files changed, 87 insertions, 32 deletions
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
index 1003b90..66e30b0 100644
--- a/chrome/browser/importer/firefox_importer_utils.cc
+++ b/chrome/browser/importer/firefox_importer_utils.cc
@@ -12,7 +12,6 @@
#include "app/win_util.h"
#include "base/registry.h"
#endif
-#include "base/file_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -108,21 +107,61 @@ int GetCurrentFirefoxMajorVersion() {
#endif
}
+#if defined(OS_WIN) || defined(OS_LINUX)
+bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path,
+ int* version,
+ std::wstring* app_path) {
+ bool ret = false;
+ std::wstring compatibility_file(profile_path);
+ file_util::AppendToPath(&compatibility_file, L"compatibility.ini");
+ std::string content;
+ file_util::ReadFileToString(compatibility_file, &content);
+ ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
+ std::vector<std::string> lines;
+ SplitString(content, '\n', &lines);
+
+ for (size_t i = 0; i < lines.size(); ++i) {
+ const std::string& line = lines[i];
+ if (line.empty() || line[0] == '#' || line[0] == ';')
+ continue;
+ size_t equal = line.find('=');
+ if (equal != std::string::npos) {
+ std::string key = line.substr(0, equal);
+ if (key == "LastVersion") {
+ *version = line.substr(equal + 1)[0] - '0';
+ ret = true;
+ } else if (key == "LastAppDir") {
+ *app_path = UTF8ToWide(line.substr(equal + 1));
+ }
+ }
+ }
+ return ret;
+}
+
+
+FilePath GetProfilesINI() {
+ FilePath ini_file;
#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.
- std::wstring ini_file;
wchar_t buffer[MAX_PATH] = {0};
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, buffer))) {
- ini_file = buffer;
- file_util::AppendToPath(&ini_file, L"Mozilla\\Firefox\\profiles.ini");
+ ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini");
}
- if (!file_util::PathExists(ini_file))
- ini_file.clear();
- return ini_file;
+#else
+ // The default location of the profile folder containing user data is
+ // under user HOME directory in .mozilla/firefox folder on Linux.
+ const char *home = getenv("HOME");
+ if (home && home[0]) {
+ ini_file = FilePath(home).Append(".mozilla/firefox/profiles.ini");
+ }
+#endif
+ if (file_util::PathExists(ini_file))
+ return ini_file;
+
+ return FilePath();
}
void ParseProfileINI(std::wstring file, DictionaryValue* root) {
diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h
index 0f2461e..06b6063 100644
--- a/chrome/browser/importer/firefox_importer_utils.h
+++ b/chrome/browser/importer/firefox_importer_utils.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_
#include "base/basictypes.h"
+#include "base/file_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "webkit/glue/password_form.h"
@@ -13,17 +14,22 @@
class GURL;
class TemplateURL;
-// Detects which version of Firefox is installed. Returns its
+// Detects which version of Firefox is installed from registry. Returns its
// major version, and drops the minor version. Returns 0 if
// failed. If there are indicators of both FF2 and FF3 it is
// biased to return the biggest version.
int GetCurrentFirefoxMajorVersion();
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
+// Detects version of Firefox and installation path from given Firefox profile
+bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path,
+ int* version,
+ std::wstring* app_path);
+
// 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();
+FilePath GetProfilesINI();
// 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
diff --git a/chrome/browser/importer/firefox_profile_lock.cc b/chrome/browser/importer/firefox_profile_lock.cc
index d033002..f51a9f9 100644
--- a/chrome/browser/importer/firefox_profile_lock.cc
+++ b/chrome/browser/importer/firefox_profile_lock.cc
@@ -52,8 +52,16 @@
* ***** END LICENSE BLOCK ***** */
// static
+#if defined(OS_LINUX)
+// TODO(rahulk): Even though this is called OLD_LOCK_FILE_NAME in Firefox code
+// http://www.google.com/codesearch/p?hl=en#e_ObwTAVPyo/profile/dirserviceprovider/src/nsProfileLock.cpp&l=433
+// this seems to work with Firefox 3.0.
+const FilePath::CharType* FirefoxProfileLock::kLockFileName =
+ FILE_PATH_LITERAL("lock");
+#else
const FilePath::CharType* FirefoxProfileLock::kLockFileName =
FILE_PATH_LITERAL("parent.lock");
+#endif
FirefoxProfileLock::FirefoxProfileLock(const std::wstring& path) {
Init();
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 66aa8ed..2bfb9f6 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -515,7 +515,7 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info,
}
}
- #if defined(OS_WIN)
+#if defined(OS_WIN)
// For google toolbar import, we need the user to log in and store their GAIA
// credentials.
if (profile_info.browser_type == GOOGLE_TOOLBAR5) {
@@ -677,26 +677,12 @@ void ImporterHost::DetectIEProfiles() {
#endif
void ImporterHost::DetectFirefoxProfiles() {
- // Detects which version of Firefox is installed.
- int version = GetCurrentFirefoxMajorVersion();
- ProfileType firefox_type;
- if (version == 2) {
- firefox_type = FIREFOX2;
- } else if (version == 3) {
- firefox_type = FIREFOX3;
- } else {
- // Ignores other versions of firefox.
- return;
- }
-
+#if defined(OS_MACOSX)
+ NOTIMPLEMENTED();
+#else
DictionaryValue root;
-#if defined(OS_WIN)
- std::wstring ini_file = GetProfilesINI();
+ std::wstring ini_file = GetProfilesINI().ToWStringHack();
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) {
@@ -714,7 +700,6 @@ void ImporterHost::DetectFirefoxProfiles() {
&path16, 0, ASCIIToUTF16("/"), ASCIIToUTF16("\\"));
path.assign(UTF16ToWideHack(path16));
-#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.
@@ -724,7 +709,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.
@@ -740,16 +724,34 @@ void ImporterHost::DetectFirefoxProfiles() {
}
}
+ // Detects which version of Firefox is installed.
+ ProfileType firefox_type;
+ std::wstring app_path;
+ int version = GetCurrentFirefoxMajorVersion();
+ if (version != 2 && version != 3)
+ GetFirefoxVersionAndPathFromProfile(source_path, &version, &app_path);
+ if (version == 2) {
+ firefox_type = FIREFOX2;
+ } else if (version == 3) {
+ firefox_type = FIREFOX3;
+ } else {
+ // Ignores other versions of firefox.
+ return;
+ }
+
if (!source_path.empty()) {
ProfileInfo* firefox = new ProfileInfo();
firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX);
firefox->browser_type = firefox_type;
firefox->source_path = source_path;
firefox->app_path = GetFirefoxInstallPath();
+ if (firefox->app_path.empty())
+ firefox->app_path = app_path;
firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS |
SEARCH_ENGINES;
source_profiles_.push_back(firefox);
}
+#endif
}
void ImporterHost::DetectGoogleToolbarProfiles() {