Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: chrome/browser/importer/firefox_importer_utils.cc

Issue 10830098: Get the Firefox branding name dynamically (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/firefox_importer_utils.cc
===================================================================
--- chrome/browser/importer/firefox_importer_utils.cc (revision 148898)
+++ chrome/browser/importer/firefox_importer_utils.cc (working copy)
@@ -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,44 @@
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.Append("application.ini");
+ std::string branding_name;
+ if (file_util::PathExists(app_ini_file)) {
+ std::string content;
+ file_util::ReadFileToString(app_ini_file, &content);
+ ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
Ilya Sherman 2012/08/07 21:52:21 nit: Is this necessary? It seems like the TrimWhi
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ 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 (in_app_section) {
+ if (lines[i].find(name_attr) == 0)
+ branding_name = lines[i].substr(name_attr.size());
Ilya Sherman 2012/08/07 21:52:21 nit: You probably want to break out of the for loo
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ else if (lines[i].length() > 0 && lines[i][0] == '[')
+ break;
Ilya Sherman 2012/08/07 21:52:21 nit: Please add a quick comment along the lines of
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ } else if (lines[i] == "[App]") {
+ in_app_section = true;
+ }
Ilya Sherman 2012/08/07 21:52:21 Optional nit: I would move this bit of logic to be
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ }
+ }
Ilya Sherman 2012/08/07 21:52:21 nit: Please add a blank line after this line
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ if (branding_name.find("Iceweasel") != std::string::npos ||
+ branding_name.find("iceweasel") != std::string::npos)
Ilya Sherman 2012/08/07 21:52:21 nit: Rather than searching for both strings, how a
cristian.patrasciuc 2012/08/08 15:20:52 Done.
+ return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL);
+ return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
+}

Powered by Google App Engine
This is Rietveld 408576698