summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/installer/util/google_chrome_distribution_unittest.cc25
-rw-r--r--chrome/installer/util/master_preferences.cc35
-rw-r--r--chrome/installer/util/master_preferences.h22
3 files changed, 76 insertions, 6 deletions
diff --git a/chrome/installer/util/google_chrome_distribution_unittest.cc b/chrome/installer/util/google_chrome_distribution_unittest.cc
index 9339f0c..5e3a71e 100644
--- a/chrome/installer/util/google_chrome_distribution_unittest.cc
+++ b/chrome/installer/util/google_chrome_distribution_unittest.cc
@@ -300,3 +300,28 @@ TEST(MasterPreferences, ParseDistroParams) {
EXPECT_TRUE(result & installer_util::MASTER_PROFILE_ALT_SHORTCUT_TXT);
EXPECT_TRUE(file_util::Delete(prefs, false));
}
+
+TEST(MasterPreferences, FirstRunTabs) {
+ std::wstring prefs;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"something here\": true\n"
+ " },\n"
+ " \"first_run_tabs\": [\n"
+ " \"http://google.com/f1\",\n"
+ " \"https://google.com/f2\",\n"
+ " \"new_tab_page\"\n"
+ " ]\n"
+ "} \n";
+
+ EXPECT_TRUE(file_util::WriteFile(prefs, text, sizeof(text)));
+ typedef std::vector<std::wstring> TabsVector;
+ TabsVector tabs = installer_util::ParseFirstRunTabs(prefs);
+ ASSERT_EQ(3, tabs.size());
+ EXPECT_EQ(L"http://google.com/f1", tabs[0]);
+ EXPECT_EQ(L"https://google.com/f2", tabs[1]);
+ EXPECT_EQ(L"new_tab_page", tabs[2]);
+ EXPECT_TRUE(file_util::Delete(prefs, false));
+}
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index 22dbf08..d376456 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -21,6 +21,13 @@ DictionaryValue* ReadJSONPrefs(const std::string& data) {
return static_cast<DictionaryValue*>(root.release());
}
+DictionaryValue* GetPrefsFromFile(const std::wstring& master_prefs_path) {
+ std::string json_data;
+ if (!file_util::ReadFileToString(master_prefs_path, &json_data))
+ return NULL;
+ return ReadJSONPrefs(json_data);
+}
+
bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) {
bool value = false;
prefs->GetBoolean(name, &value);
@@ -67,18 +74,13 @@ const wchar_t kAltShortcutText[] = L"alternate_shortcut_text";
int ParseDistributionPreferences(const std::wstring& master_prefs_path) {
if (!file_util::PathExists(master_prefs_path))
return MASTER_PROFILE_NOT_FOUND;
-
LOG(INFO) << "master profile found";
- std::string json_data;
- if (!file_util::ReadFileToString(master_prefs_path, &json_data))
- return MASTER_PROFILE_ERROR;
- scoped_ptr<DictionaryValue> json_root(ReadJSONPrefs(json_data));
+ scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path));
if (!json_root.get())
return MASTER_PROFILE_ERROR;
int parse_result = 0;
-
DictionaryValue* distro = NULL;
if (json_root->GetDictionary(L"distribution", &distro)) {
if (GetBooleanPref(distro, kDistroSkipFirstRunPref))
@@ -111,4 +113,25 @@ int ParseDistributionPreferences(const std::wstring& master_prefs_path) {
return parse_result;
}
+std::vector<std::wstring> ParseFirstRunTabs(
+ const std::wstring& master_prefs_path) {
+ std::vector<std::wstring> launch_tabs;
+ scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path));
+ if (!json_root.get())
+ return launch_tabs;
+ ListValue* tabs_list = NULL;
+ if (!json_root->GetList(L"first_run_tabs", &tabs_list))
+ return launch_tabs;
+ for (size_t i = 0; i < tabs_list->GetSize(); ++i) {
+ Value* entry;
+ std::wstring tab_entry;
+ if (!tabs_list->Get(i, &entry) || !entry->GetAsString(&tab_entry)) {
+ NOTREACHED();
+ break;
+ }
+ launch_tabs.push_back(tab_entry);
+ }
+ return launch_tabs;
+}
+
} // installer_util
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index 13bee22..14426f1 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -9,6 +9,7 @@
#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__
#include <string>
+#include <vector>
namespace installer_util {
@@ -83,6 +84,10 @@ enum MasterPrefResult {
// "bookmark_bar": {
// "show_on_all_tabs": true
// },
+// "first_run_tabs": [
+// "http://gmail.com",
+// "https://igoogle.com"
+// ],
// "homepage": "http://example.org",
// "homepage_is_newtabpage": false
// }
@@ -93,6 +98,23 @@ enum MasterPrefResult {
// of MasterPrefResult.
int ParseDistributionPreferences(const std::wstring& master_prefs_path);
+// As part of the master preferences an optional section indicates the tabs
+// to open during first run. An example is the following:
+//
+// {
+// "first_run_tabs": [
+// "http://google.com/f1",
+// "https://google.com/f2"
+// ]
+// }
+//
+// Note that the entries are usually urls but they don't have to.
+//
+// This function retuns the list as a vector of strings. If the master
+// preferences file does not contain such list the vector is empty.
+std::vector<std::wstring> ParseFirstRunTabs(
+ const std::wstring& master_prefs_path);
+
}
#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__