summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer
diff options
context:
space:
mode:
authorcristian.patrasciuc@gmail.com <cristian.patrasciuc@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 14:27:47 +0000
committercristian.patrasciuc@gmail.com <cristian.patrasciuc@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 14:27:47 +0000
commit8a47e2e94a9782d4622f78f769e79fa113fcfdb3 (patch)
treeae8c02461fe492809f1b07b887f825f0f889137d /chrome/browser/importer
parent6015537e8186e5b2bee1485e8622806321ff4a80 (diff)
downloadchromium_src-8a47e2e94a9782d4622f78f769e79fa113fcfdb3.zip
chromium_src-8a47e2e94a9782d4622f78f769e79fa113fcfdb3.tar.gz
chromium_src-8a47e2e94a9782d4622f78f769e79fa113fcfdb3.tar.bz2
Get the Firefox branding name dynamically
from the application.ini file. This way we can display different names in the importer combobox, depending on the Firefox flavour that is installed on the machine. One such example is the Debian rebranding of Firefox, i.e. Iceweasel. BUG=119279 Review URL: https://chromiumcodereview.appspot.com/10830098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r--chrome/browser/importer/firefox_importer_utils.cc46
-rw-r--r--chrome/browser/importer/firefox_importer_utils.h7
-rw-r--r--chrome/browser/importer/firefox_importer_utils_unittest.cc75
-rw-r--r--chrome/browser/importer/importer_list.cc2
4 files changed, 128 insertions, 2 deletions
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
index 5cceeb2..3371bc1 100644
--- a/chrome/browser/importer/firefox_importer_utils.cc
+++ b/chrome/browser/importer/firefox_importer_utils.cc
@@ -21,6 +21,8 @@
#include "chrome/browser/search_engines/template_url_parser.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
namespace {
@@ -417,3 +419,47 @@ std::string GetPrefsJsValue(const std::string& content,
return content.substr(start, stop - start);
}
+
+// The branding name is obtained from the application.ini file from the Firefox
+// application directory. A sample application.ini file is the following:
+// [App]
+// Vendor=Mozilla
+// Name=Iceweasel
+// Profile=mozilla/firefox
+// Version=3.5.16
+// BuildID=20120421070307
+// Copyright=Copyright (c) 1998 - 2010 mozilla.org
+// ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+// .........................................
+// In this example the function returns "Iceweasel" (or a localized equivalent).
+string16 GetFirefoxImporterName(const FilePath& app_path) {
+ const FilePath app_ini_file = app_path.AppendASCII("application.ini");
+ std::string branding_name;
+ if (file_util::PathExists(app_ini_file)) {
+ std::string content;
+ file_util::ReadFileToString(app_ini_file, &content);
+ std::vector<std::string> lines;
+ base::SplitString(content, '\n', &lines);
+ const std::string name_attr("Name=");
+ bool in_app_section = false;
+ for (size_t i = 0; i < lines.size(); ++i) {
+ TrimWhitespace(lines[i], TRIM_ALL, &lines[i]);
+ if (lines[i] == "[App]") {
+ in_app_section = true;
+ } else if (in_app_section) {
+ if (lines[i].find(name_attr) == 0) {
+ branding_name = lines[i].substr(name_attr.size());
+ break;
+ } else if (lines[i].length() > 0 && lines[i][0] == '[') {
+ // No longer in the [App] section.
+ break;
+ }
+ }
+ }
+ }
+
+ StringToLowerASCII(&branding_name);
+ if (branding_name.find("iceweasel") != std::string::npos)
+ return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL);
+ return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
+}
diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h
index 76349ff..1ba9bfe 100644
--- a/chrome/browser/importer/firefox_importer_utils.h
+++ b/chrome/browser/importer/firefox_importer_utils.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/string16.h"
#include "build/build_config.h"
class FilePath;
@@ -96,4 +97,10 @@ bool ParsePrefFile(const FilePath& pref_file, base::DictionaryValue* prefs);
std::string GetPrefsJsValue(const std::string& prefs,
const std::string& pref_key);
+// Returns the localized Firefox branding name.
+// This is useful to differentiate between Firefox and Iceweasel.
+// If anything goes wrong while trying to obtain the branding name,
+// the function assumes it's Firefox.
+string16 GetFirefoxImporterName(const FilePath& app_path);
+
#endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_
diff --git a/chrome/browser/importer/firefox_importer_utils_unittest.cc b/chrome/browser/importer/firefox_importer_utils_unittest.cc
index 7e5fadc..8f79908 100644
--- a/chrome/browser/importer/firefox_importer_utils_unittest.cc
+++ b/chrome/browser/importer/firefox_importer_utils_unittest.cc
@@ -2,9 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/importer/firefox_importer_utils.h"
+#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
-#include "chrome/browser/importer/firefox_importer_utils.h"
+namespace {
struct GetPrefsJsValueCase {
std::string prefs_content;
@@ -32,6 +37,59 @@ struct GetPrefsJsValueCase {
{ "uesr_pref(\"foo.bar\", 1);", "foo.bar", "" },
};
+struct GetFirefoxImporterNameCase {
+ std::string app_ini_content;
+ int resource_id;
+} GetFirefoxImporterNameCases[] = {
+ // Basic case
+ { "[App]\n"
+ "Vendor=Mozilla\n"
+ "Name=iceweasel\n"
+ "Version=10.0.6\n"
+ "BuildID=20120717115048\n"
+ "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
+ IDS_IMPORT_FROM_ICEWEASEL },
+ // Whitespace
+ { " \t[App] \n"
+ "Vendor=Mozilla\n"
+ " Name=Firefox\t \r\n"
+ "Version=10.0.6\n",
+ IDS_IMPORT_FROM_FIREFOX },
+ // No Name setting
+ { "[App]\n"
+ "Vendor=Mozilla\n"
+ "Version=10.0.6\n"
+ "BuildID=20120717115048\n"
+ "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
+ IDS_IMPORT_FROM_FIREFOX },
+ // No [App] section
+ { "[Foo]\n"
+ "Vendor=Mozilla\n"
+ "Name=Foo\n",
+ IDS_IMPORT_FROM_FIREFOX },
+ // Multiple Name settings in different sections
+ { "[Foo]\n"
+ "Vendor=Mozilla\n"
+ "Name=Firefox\n"
+ "[App]\n"
+ "Profile=mozilla/firefox\n"
+ "Name=iceweasel\n"
+ "[Bar]\n"
+ "Name=Bar\n"
+ "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
+ IDS_IMPORT_FROM_ICEWEASEL },
+ // Case-insensitivity
+ { "[App]\n"
+ "Vendor=Mozilla\n"
+ "Name=IceWeasel\n"
+ "Version=10.0.6\n",
+ IDS_IMPORT_FROM_ICEWEASEL },
+ // Empty file
+ { "", IDS_IMPORT_FROM_FIREFOX }
+};
+
+} // anonymous namespace
+
TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) {
for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) {
EXPECT_EQ(
@@ -40,3 +98,18 @@ TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) {
GetPrefsJsValueCases[i].pref_name));
}
}
+
+TEST(FirefoxImporterUtilsTest, GetFirefoxImporterName) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ const FilePath app_ini_file(temp_dir.path().AppendASCII("application.ini"));
+ for (size_t i = 0; i < arraysize(GetFirefoxImporterNameCases); ++i) {
+ file_util::WriteFile(app_ini_file,
+ GetFirefoxImporterNameCases[i].app_ini_content.c_str(),
+ GetFirefoxImporterNameCases[i].app_ini_content.size());
+ EXPECT_EQ(GetFirefoxImporterName(temp_dir.path()),
+ l10n_util::GetStringUTF16(GetFirefoxImporterNameCases[i].resource_id));
+ }
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX),
+ GetFirefoxImporterName(FilePath(FILE_PATH_LITERAL("/invalid/path"))));
+}
diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc
index 7786897..1c3d0ab 100644
--- a/chrome/browser/importer/importer_list.cc
+++ b/chrome/browser/importer/importer_list.cc
@@ -80,7 +80,7 @@ void DetectFirefoxProfiles(std::vector<importer::SourceProfile*>* profiles) {
}
importer::SourceProfile* firefox = new importer::SourceProfile;
- firefox->importer_name = l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
+ firefox->importer_name = GetFirefoxImporterName(app_path);
firefox->importer_type = firefox_type;
firefox->source_path = profile_path;
#if defined(OS_WIN)