1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ 6#define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ 7#pragma once 8 9#include <string> 10#include <vector> 11 12#include "base/basictypes.h" 13#include "build/build_config.h" 14 15class DictionaryValue; 16class FilePath; 17class GURL; 18class TemplateURL; 19 20#if defined(OS_WIN) 21// Detects which version of Firefox is installed from registry. Returns its 22// major version, and drops the minor version. Returns 0 if failed. If there are 23// indicators of both Firefox 2 and Firefox 3 it is biased to return the biggest 24// version. 25int GetCurrentFirefoxMajorVersionFromRegistry(); 26 27// Detects where Firefox lives. Returns an empty path if Firefox is not 28// installed. 29FilePath GetFirefoxInstallPathFromRegistry(); 30#endif // OS_WIN 31 32#if defined(OS_MACOSX) 33// Get the directory in which the Firefox .dylibs live, we need to load these 34// in order to decoded FF profile passwords. 35// The Path is usuall FF App Bundle/Contents/Mac OS/ 36// Returns empty path on failure. 37FilePath GetFirefoxDylibPath(); 38#endif // OS_MACOSX 39 40// Returns the path to the Firefox profile. 41FilePath GetFirefoxProfilePath(); 42 43// Detects version of Firefox and installation path for the given Firefox 44// profile. 45bool GetFirefoxVersionAndPathFromProfile(const FilePath& profile_path, 46 int* version, 47 FilePath* app_path); 48 49// Gets the full path of the profiles.ini file. This file records the profiles 50// that can be used by Firefox. Returns an empty path if failed. 51FilePath GetProfilesINI(); 52 53// Parses the profile.ini file, and stores its information in |root|. 54// This file is a plain-text file. Key/value pairs are stored one per line, and 55// they are separated in different sections. For example: 56// [General] 57// StartWithLastProfile=1 58// 59// [Profile0] 60// Name=default 61// IsRelative=1 62// Path=Profiles/abcdefeg.default 63// We set "[value]" in path "<Section>.<Key>". For example, the path 64// "Genenral.StartWithLastProfile" has the value "1". 65void ParseProfileINI(const FilePath& file, DictionaryValue* root); 66 67// Returns true if we want to add the URL to the history. We filter out the URL 68// with a unsupported scheme. 69bool CanImportURL(const GURL& url); 70 71// Parses the OpenSearch XML files in |xml_files| and populates |search_engines| 72// with the resulting TemplateURLs. 73void ParseSearchEnginesFromXMLFiles(const std::vector<FilePath>& xml_files, 74 std::vector<TemplateURL*>* search_engines); 75 76// Returns the index of the default search engine in the |search_engines| list. 77// If none is found, -1 is returned. 78int GetFirefoxDefaultSearchEngineIndex( 79 const std::vector<TemplateURL*>& search_engines, 80 const FilePath& profile_path); 81 82// Returns the home page set in Firefox in a particular profile. 83GURL GetHomepage(const FilePath& profile_path); 84 85// Checks to see if this home page is a default home page, as specified by 86// the resource file browserconfig.properties in the Firefox application 87// directory. 88bool IsDefaultHomepage(const GURL& homepage, const FilePath& app_path); 89 90// Parses the prefs found in the file |pref_file| and puts the key/value pairs 91// in |prefs|. Keys are strings, and values can be strings, booleans or 92// integers. Returns true if it succeeded, false otherwise (in which case 93// |prefs| is not filled). 94// Note: for strings, only valid UTF-8 string values are supported. If a 95// key/pair is not valid UTF-8, it is ignored and will not appear in |prefs|. 96bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs); 97 98// Parses the value of a particular firefox preference from a string that is the 99// contents of the prefs file. 100std::string GetPrefsJsValue(const std::string& prefs, 101 const std::string& pref_key); 102 103#endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ 104