| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file contains functions processing master preference file used by | 5 // This file contains functions processing master preference file used by |
| 6 // setup and first run. | 6 // setup and first run. |
| 7 | 7 |
| 8 #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 8 #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
| 9 #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 9 #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include "base/file_path.h" |
| 12 #include <vector> | 12 #include "base/values.h" |
| 13 | |
| 14 #include "base/file_util.h" | |
| 15 | 13 |
| 16 namespace installer_util { | 14 namespace installer_util { |
| 17 | 15 |
| 16 namespace master_preferences { |
| 17 // All the preferences below are expected to be inside the JSON "distribution" |
| 18 // block. Some of them also have equivalent command line option. If same option |
| 19 // is specified in master preference as well as command line, the commnd line |
| 20 // value takes precedence. |
| 21 |
| 22 // Boolean. Use alternate text for the shortcut. Cmd line override present. |
| 23 extern const wchar_t kAltShortcutText[]; |
| 24 // Boolean. Use alternate smaller first run info bubble. |
| 25 extern const wchar_t kAltFirstRunBubble[]; |
| 26 // Boolean. Create Desktop and QuickLaunch shortcuts. Cmd line override present. |
| 27 extern const wchar_t kCreateAllShortcuts[]; |
| 28 // Boolean pref that triggers silent import of the default browser bookmarks. |
| 29 extern const wchar_t kDistroImportBookmarksPref[]; |
| 30 // Boolean pref that triggers silent import of the default browser history. |
| 31 extern const wchar_t kDistroImportHistoryPref[]; |
| 32 // Boolean pref that triggers silent import of the default browser homepage. |
| 33 extern const wchar_t kDistroImportHomePagePref[]; |
| 34 // Boolean pref that triggers silent import of the default search engine. |
| 35 extern const wchar_t kDistroImportSearchPref[]; |
| 36 // Integer. RLZ ping delay in seconds. |
| 37 extern const wchar_t kDistroPingDelay[]; |
| 38 // Boolean pref that triggers loading the welcome page. |
| 39 extern const wchar_t kDistroShowWelcomePage[]; |
| 40 // Boolean pref that triggers skipping the first run dialogs. |
| 41 extern const wchar_t kDistroSkipFirstRunPref[]; |
| 42 // Boolean. Do not launch Chrome after first install. Cmd line override present. |
| 43 extern const wchar_t kDoNotLaunchChrome[]; |
| 44 // Boolean. Register Chrome as default browser. Cmd line override present. |
| 45 extern const wchar_t kMakeChromeDefault[]; |
| 46 // Boolean. Register Chrome as default browser for the current user. |
| 47 extern const wchar_t kMakeChromeDefaultForUser[]; |
| 48 // Boolean. Show EULA dialog before install. |
| 49 extern const wchar_t kRequireEula[]; |
| 50 // Boolean. Install Chrome to system wise location. Cmd line override present. |
| 51 extern const wchar_t kSystemLevel[]; |
| 52 // Boolean. Run installer in verbose mode. Cmd line override present. |
| 53 extern const wchar_t kVerboseLogging[]; |
| 54 } |
| 55 |
| 18 // This is the default name for the master preferences file used to pre-set | 56 // This is the default name for the master preferences file used to pre-set |
| 19 // values in the user profile at first run. | 57 // values in the user profile at first run. |
| 20 const wchar_t kDefaultMasterPrefs[] = L"master_preferences"; | 58 const wchar_t kDefaultMasterPrefs[] = L"master_preferences"; |
| 21 | 59 |
| 22 // These are the possible results of calling ParseDistributionPreferences. | 60 // Gets the value of given boolean preference |name| from |prefs| dictionary |
| 23 // Some of the results can be combined, so they are bit flags. | 61 // which is assumed to contain a dictionary named "distribution". |
| 24 enum MasterPrefResult { | 62 bool GetDistroBooleanPreference(const DictionaryValue* prefs, |
| 25 MASTER_PROFILE_NOT_FOUND = 0x1, | 63 const std::wstring& name); |
| 26 // A critical error processing the master profile. | |
| 27 MASTER_PROFILE_ERROR = 0x1 << 1, | |
| 28 // Skip first run dialogs. | |
| 29 MASTER_PROFILE_NO_FIRST_RUN_UI = 0x1 << 2, | |
| 30 // Show welcome page. | |
| 31 MASTER_PROFILE_SHOW_WELCOME = 0x1 << 3, | |
| 32 // Import search engine setting from the default browser. | |
| 33 MASTER_PROFILE_IMPORT_SEARCH_ENGINE = 0x1 << 4, | |
| 34 // Import history from the default browser. | |
| 35 MASTER_PROFILE_IMPORT_HISTORY = 0x1 << 5, | |
| 36 // Import bookmarks from the default browser. | |
| 37 MASTER_PROFILE_IMPORT_BOOKMARKS = 0x1 << 6, | |
| 38 // Register Chrome as default browser for the current user. This option is | |
| 39 // different than MAKE_CHROME_DEFAULT as installer ignores this option and | |
| 40 // Chrome on first run makes itself default. | |
| 41 MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER = 0x1 << 7, | |
| 42 // The following boolean prefs have the same semantics as the corresponding | |
| 43 // setup command line switches. See chrome/installer/util/util_constants.cc | |
| 44 // for more info. | |
| 45 // Create Desktop and QuickLaunch shortcuts. | |
| 46 MASTER_PROFILE_CREATE_ALL_SHORTCUTS = 0x1 << 8, | |
| 47 // Prevent installer from launching Chrome after a successful first install. | |
| 48 MASTER_PROFILE_DO_NOT_LAUNCH_CHROME = 0x1 << 9, | |
| 49 // Register Chrome as default browser on the system. | |
| 50 MASTER_PROFILE_MAKE_CHROME_DEFAULT = 0x1 << 10, | |
| 51 // Install Chrome to system wise location. | |
| 52 MASTER_PROFILE_SYSTEM_LEVEL = 0x1 << 11, | |
| 53 // Run installer in verbose mode. | |
| 54 MASTER_PROFILE_VERBOSE_LOGGING = 0x1 << 12, | |
| 55 // Show the EULA and do not install if not accepted. | |
| 56 MASTER_PROFILE_REQUIRE_EULA = 0x1 << 13, | |
| 57 // Use an alternate description text for some shortcuts. | |
| 58 MASTER_PROFILE_ALT_SHORTCUT_TXT = 0x1 << 14, | |
| 59 // Use a smaller OEM info bubble on first run. | |
| 60 MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE = 0x1 << 15, | |
| 61 // Import home page from the default browser. | |
| 62 MASTER_PROFILE_IMPORT_HOME_PAGE = 0x1 << 16 | |
| 63 }; | |
| 64 | 64 |
| 65 // This function gets ping delay (ping_delay in the sample above) from master | 65 // This function gets ping delay (ping_delay in the sample above) from master |
| 66 // preferences. | 66 // preferences. |
| 67 bool GetDistributionPingDelay(const FilePath& master_prefs_path, | 67 bool GetDistributionPingDelay(const DictionaryValue* prefs, |
| 68 int& delay); | 68 int* ping_delay); |
| 69 | 69 |
| 70 // The master preferences is a JSON file with the same entries as the | 70 // The master preferences is a JSON file with the same entries as the |
| 71 // 'Default\Preferences' file. This function parses the distribution | 71 // 'Default\Preferences' file. This function parses the distribution |
| 72 // section of the preferences file. | 72 // section of the preferences file. |
| 73 // | 73 // |
| 74 // A prototypical 'master_preferences' file looks like this: | 74 // A prototypical 'master_preferences' file looks like this: |
| 75 // | 75 // |
| 76 // { | 76 // { |
| 77 // "distribution": { | 77 // "distribution": { |
| 78 // "alternate_shortcut_text": false, |
| 79 // "oem_bubble": false, |
| 80 // "create_all_shortcuts": true, |
| 81 // "import_bookmarks": false, |
| 82 // "import_history": false, |
| 83 // "import_home_page": false, |
| 84 // "import_search_engine": true, |
| 85 // "ping_delay": 40, |
| 86 // "show_welcome_page": true, |
| 78 // "skip_first_run_ui": true, | 87 // "skip_first_run_ui": true, |
| 79 // "show_welcome_page": true, | |
| 80 // "import_search_engine": true, | |
| 81 // "import_history": false, | |
| 82 // "import_bookmarks": false, | |
| 83 // "import_home_page": false, | |
| 84 // "create_all_shortcuts": true, | |
| 85 // "do_not_launch_chrome": false, | 88 // "do_not_launch_chrome": false, |
| 86 // "make_chrome_default": false, | 89 // "make_chrome_default": false, |
| 87 // "make_chrome_default_for_user": true, | 90 // "make_chrome_default_for_user": true, |
| 91 // "require_eula": true, |
| 88 // "system_level": false, | 92 // "system_level": false, |
| 89 // "verbose_logging": true, | 93 // "verbose_logging": true |
| 90 // "require_eula": true, | |
| 91 // "alternate_shortcut_text": false, | |
| 92 // "ping_delay": 40 | |
| 93 // }, | 94 // }, |
| 94 // "browser": { | 95 // "browser": { |
| 95 // "show_home_button": true | 96 // "show_home_button": true |
| 96 // }, | 97 // }, |
| 97 // "bookmark_bar": { | 98 // "bookmark_bar": { |
| 98 // "show_on_all_tabs": true | 99 // "show_on_all_tabs": true |
| 99 // }, | 100 // }, |
| 100 // "first_run_tabs": [ | 101 // "first_run_tabs": [ |
| 101 // "http://gmail.com", | 102 // "http://gmail.com", |
| 102 // "https://igoogle.com" | 103 // "https://igoogle.com" |
| 103 // ], | 104 // ], |
| 104 // "homepage": "http://example.org", | 105 // "homepage": "http://example.org", |
| 105 // "homepage_is_newtabpage": false | 106 // "homepage_is_newtabpage": false |
| 106 // } | 107 // } |
| 107 // | 108 // |
| 108 // A reserved "distribution" entry in the file is used to group related | 109 // A reserved "distribution" entry in the file is used to group related |
| 109 // installation properties. This entry will be ignored at other times. | 110 // installation properties. This entry will be ignored at other times. |
| 110 // This function parses the 'distribution' entry and returns a combination | 111 // This function parses the 'distribution' entry and returns a combination |
| 111 // of MasterPrefResult. | 112 // of MasterPrefResult. |
| 112 int ParseDistributionPreferences(const std::wstring& master_prefs_path); | 113 DictionaryValue* ParseDistributionPreferences( |
| 114 const FilePath& master_prefs_path); |
| 113 | 115 |
| 114 // As part of the master preferences an optional section indicates the tabs | 116 // As part of the master preferences an optional section indicates the tabs |
| 115 // to open during first run. An example is the following: | 117 // to open during first run. An example is the following: |
| 116 // | 118 // |
| 117 // { | 119 // { |
| 118 // "first_run_tabs": [ | 120 // "first_run_tabs": [ |
| 119 // "http://google.com/f1", | 121 // "http://google.com/f1", |
| 120 // "https://google.com/f2" | 122 // "https://google.com/f2" |
| 121 // ] | 123 // ] |
| 122 // } | 124 // } |
| 123 // | 125 // |
| 124 // Note that the entries are usually urls but they don't have to. | 126 // Note that the entries are usually urls but they don't have to. |
| 125 // | 127 // |
| 126 // This function retuns the list as a vector of strings. If the master | 128 // This function retuns the list as a vector of strings. If the master |
| 127 // preferences file does not contain such list the vector is empty. | 129 // preferences file does not contain such list the vector is empty. |
| 128 std::vector<std::wstring> ParseFirstRunTabs( | 130 std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs); |
| 129 const std::wstring& master_prefs_path); | 131 |
| 132 // Sets the value of given boolean preference |name| in "distribution" |
| 133 // dictionary inside |prefs| dictionary. |
| 134 bool SetDistroBooleanPreference(DictionaryValue* prefs, |
| 135 const std::wstring& name, |
| 136 bool value); |
| 130 } | 137 } |
| 131 | 138 |
| 132 #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 139 #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
| OLD | NEW |