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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/importer/firefox_importer_utils.h" 5 #include "chrome/browser/importer/firefox_importer_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/search_engines/template_url.h" 19 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_service.h" 20 #include "chrome/browser/search_engines/template_url_service.h"
21 #include "chrome/browser/search_engines/template_url_parser.h" 21 #include "chrome/browser/search_engines/template_url_parser.h"
22 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 22 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h"
24 26
25 namespace { 27 namespace {
26 28
27 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from 29 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from
28 // the search URL when importing search engines. 30 // the search URL when importing search engines.
29 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { 31 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter {
30 public: 32 public:
31 FirefoxURLParameterFilter() {} 33 FirefoxURLParameterFilter() {}
32 virtual ~FirefoxURLParameterFilter() {} 34 virtual ~FirefoxURLParameterFilter() {}
33 35
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 412 }
411 413
412 // String values have double quotes we don't need to return to the caller. 414 // String values have double quotes we don't need to return to the caller.
413 if (content[start] == '\"' && content[stop - 1] == '\"') { 415 if (content[start] == '\"' && content[stop - 1] == '\"') {
414 ++start; 416 ++start;
415 --stop; 417 --stop;
416 } 418 }
417 419
418 return content.substr(start, stop - start); 420 return content.substr(start, stop - start);
419 } 421 }
422
423 // The branding name is obtained from the application.ini file from the Firefox
424 // application directory. A sample application.ini file is the following:
425 // [App]
426 // Vendor=Mozilla
427 // Name=Iceweasel
428 // Profile=mozilla/firefox
429 // Version=3.5.16
430 // BuildID=20120421070307
431 // Copyright=Copyright (c) 1998 - 2010 mozilla.org
432 // ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
433 // .........................................
434 // In this example the function returns "Iceweasel" (or a localized equivalent).
435 string16 GetFirefoxImporterName(const FilePath& app_path) {
436 const FilePath app_ini_file = app_path.AppendASCII("application.ini");
437 std::string branding_name;
438 if (file_util::PathExists(app_ini_file)) {
439 std::string content;
440 file_util::ReadFileToString(app_ini_file, &content);
441 std::vector<std::string> lines;
442 base::SplitString(content, '\n', &lines);
443 const std::string name_attr("Name=");
444 bool in_app_section = false;
445 for (size_t i = 0; i < lines.size(); ++i) {
446 TrimWhitespace(lines[i], TRIM_ALL, &lines[i]);
447 if (lines[i] == "[App]") {
448 in_app_section = true;
449 } else if (in_app_section) {
450 if (lines[i].find(name_attr) == 0) {
451 branding_name = lines[i].substr(name_attr.size());
452 break;
453 } else if (lines[i].length() > 0 && lines[i][0] == '[') {
454 // No longer in the [App] section.
455 break;
456 }
457 }
458 }
459 }
460
461 StringToLowerASCII(&branding_name);
462 if (branding_name.find("iceweasel") != std::string::npos)
463 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_ICEWEASEL);
464 return l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX);
465 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.h ('k') | chrome/browser/importer/firefox_importer_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698