diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 28 | ||||
-rw-r--r-- | chrome/browser/first_run.cc | 19 | ||||
-rw-r--r-- | chrome/browser/first_run.h | 7 | ||||
-rw-r--r-- | chrome/browser/first_run_gtk.cc | 83 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 15 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 5 | ||||
-rw-r--r-- | chrome/chrome_exe.gypi | 2 | ||||
-rw-r--r-- | chrome/installer/installer.gyp | 3 | ||||
-rw-r--r-- | chrome/installer/installer_util.gypi | 22 | ||||
-rw-r--r-- | chrome/installer/setup/install.cc | 3 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 28 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 13 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/shell_util_unittest.cc | 3 |
16 files changed, 191 insertions, 58 deletions
@@ -68,3 +68,4 @@ James Choi <jchoi42@pha.jhu.edu> Paul Kehrer <paul.l.kehrer@gmail.com> Chamal De Silva <chamal.desilva@gmail.com> Jay Soffian <jaysoffian@gmail.com> +Brian G. Merrell <bgmerrell@gmail.com> diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 91c6cad..00f6755 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -302,34 +302,32 @@ void SetFileDescriptorLimit(unsigned int max_descriptors) { } #endif -#if defined(OS_WIN) +#if !defined(OS_MACOSX) void AddFirstRunNewTabs(BrowserInit* browser_init, - const std::vector<std::wstring>& new_tabs) { - for (std::vector<std::wstring>::const_iterator it = new_tabs.begin(); + const std::vector<GURL>& new_tabs) { + for (std::vector<GURL>::const_iterator it = new_tabs.begin(); it != new_tabs.end(); ++it) { - GURL url(*it); - if (url.is_valid()) - browser_init->AddFirstRunTab(url); + if (it->is_valid()) + browser_init->AddFirstRunTab(*it); } } void AddDefaultBookmarks(BrowserInit* browser_init, - const std::vector<std::wstring>& bookmarks) { - for (std::vector<std::wstring>::const_iterator it = bookmarks.begin(); + const std::vector<GURL>& bookmarks) { + for (std::vector<GURL>::const_iterator it = bookmarks.begin(); it != bookmarks.end(); ++it) { - GURL url(*it); - if (url.is_valid()) - browser_init->AddDefaultBookmark(url); + if (it->is_valid()) + browser_init->AddDefaultBookmark(*it); } } -#else +#else // OS_MACOSX // TODO(cpu): implement first run experience for other platforms. void AddFirstRunNewTabs(BrowserInit* browser_init, - const std::vector<std::wstring>& new_tabs) { + const std::vector<GURL>& new_tabs) { } void AddDefaultBookmarks(BrowserInit* browser_init, - const std::vector<std::wstring>& bookmarks) { + const std::vector<GURL>& bookmarks) { } #endif @@ -625,7 +623,6 @@ int BrowserMain(const MainFunctionParams& parameters) { FirstRun::MasterPrefs master_prefs = {0}; bool first_run_ui_bypass = false; if (is_first_run) { -#if defined(OS_WIN) // On first run, we need to process the master preferences before the // browser's profile_manager object is created, but after ResourceBundle // is initialized. @@ -638,7 +635,6 @@ int BrowserMain(const MainFunctionParams& parameters) { // The master prefs might specify a set of initial bookmarks. if (master_prefs.bookmarks.size()) AddDefaultBookmarks(&browser_init, master_prefs.bookmarks); -#endif // OS_WIN // If we are running in App mode, we do not want to show the importer // (first run) UI. diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc index d9ca211..dacf4f6 100644 --- a/chrome/browser/first_run.cc +++ b/chrome/browser/first_run.cc @@ -100,3 +100,22 @@ bool FirstRun::SetShowWelcomePagePref() { return true; } +bool FirstRun::SetOEMFirstRunBubblePref() { + PrefService* local_state = g_browser_process->local_state(); + if (!local_state) + return false; + if (!local_state->FindPreference(prefs::kShouldUseOEMFirstRunBubble)) { + local_state->RegisterBooleanPref(prefs::kShouldUseOEMFirstRunBubble, + false); + local_state->SetBoolean(prefs::kShouldUseOEMFirstRunBubble, true); + } + return true; +} + +#if defined(OS_MACOSX) +bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, + const FilePath& master_prefs_path, MasterPrefs* out_prefs) { + NOTIMPLEMENTED(); + return false; +} +#endif diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 08a101a4..7741e77 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -11,6 +11,7 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" #include "chrome/browser/browser_process_impl.h" +#include "googleurl/src/gurl.h" class CommandLine; class FilePath; @@ -34,8 +35,8 @@ class FirstRun { bool homepage_defined; int do_import_items; int dont_import_items; - std::vector<std::wstring> new_tabs; - std::vector<std::wstring> bookmarks; + std::vector<GURL> new_tabs; + std::vector<GURL> bookmarks; }; #if defined(OS_WIN) // Creates the desktop shortcut to chrome for the current user. Returns @@ -49,6 +50,7 @@ class FirstRun { // FirstRun::ImportSettings(). This function might or might not show // a visible UI depending on the cmdline parameters. static int ImportNow(Profile* profile, const CommandLine& cmdline); +#endif // OS_WIN // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function locates this file from @@ -68,7 +70,6 @@ class FirstRun { static bool ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, MasterPrefs* out_prefs); -#endif // OS_WIN // Returns true if this is the first time chrome is run for this user. static bool IsChromeFirstRun(); diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc index 3d4a091..59f3041 100644 --- a/chrome/browser/first_run_gtk.cc +++ b/chrome/browser/first_run_gtk.cc @@ -4,7 +4,20 @@ #include "chrome/browser/first_run.h" +#include "app/resource_bundle.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" #include "chrome/browser/gtk/first_run_dialog.h" +#include "chrome/browser/profile_manager.h" +#include "chrome/browser/shell_integration.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/result_codes.h" +#include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/master_preferences.h" +#include "chrome/installer/util/util_constants.h" +#include "googleurl/src/gurl.h" bool OpenFirstRunDialog(Profile* profile, bool homepage_defined, int import_items, @@ -12,3 +25,73 @@ bool OpenFirstRunDialog(Profile* profile, bool homepage_defined, ProcessSingleton* process_singleton) { return FirstRunDialog::Show(profile, process_singleton); } + +FilePath GetDefaultPrefFilePath(bool create_profile_dir, + const FilePath& user_data_dir) { + FilePath default_pref_dir = + ProfileManager::GetDefaultProfileDir(user_data_dir); + if (create_profile_dir) { + if (!file_util::PathExists(default_pref_dir)) { + if (!file_util::CreateDirectory(default_pref_dir)) + return FilePath(); + } + } + return ProfileManager::GetProfilePrefsPath(default_pref_dir); +} + +bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, + const FilePath& master_prefs_path, + MasterPrefs* out_prefs) { + DCHECK(!user_data_dir.empty()); + FilePath master_prefs = master_prefs_path; + if (master_prefs.empty()) { + // The default location of the master prefs is next to the chrome binary. + if (!PathService::Get(base::DIR_EXE, &master_prefs)) + return true; + master_prefs = + master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); + } + + scoped_ptr<DictionaryValue> prefs( + installer_util::ParseDistributionPreferences(master_prefs)); + if (!prefs.get()) + return true; + + out_prefs->new_tabs = installer_util::GetFirstRunTabs(prefs.get()); + + std::string not_used; + out_prefs->homepage_defined = prefs->GetString(prefs::kHomePage, ¬_used); + + bool value = false; + if (installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kAltFirstRunBubble, &value) && value) + FirstRun::SetOEMFirstRunBubblePref(); + + FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir); + if (user_prefs.empty()) + return true; + + // The master prefs are regular prefs so we can just copy the file + // to the default place and they just work. + if (!file_util::CopyFile(master_prefs, user_prefs)) + return true; + + // Note we are skipping all other master preferences if skip-first-run-ui + // is *not* specified. + if (!installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || + !value) + return true; + + // From here on we won't show first run so we need to do the work to set the + // required state given that FirstRunView is not going to be called. + FirstRun::SetShowFirstRunBubblePref(); + + if (installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroShowWelcomePage, &value) && + value) + FirstRun::SetShowWelcomePagePref(); + + return false; +} + diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index c57126c..2f3eda7 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -235,7 +235,8 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, // TODO(port): port installer_util and use this. if (!PathService::Get(base::DIR_EXE, &master_prefs)) return true; - master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs); + master_prefs = + master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); } scoped_ptr<DictionaryValue> prefs( @@ -705,18 +706,6 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { return observer.import_result(); } -bool FirstRun::SetOEMFirstRunBubblePref() { - PrefService* local_state = g_browser_process->local_state(); - if (!local_state) - return false; - if (!local_state->FindPreference(prefs::kShouldUseOEMFirstRunBubble)) { - local_state->RegisterBooleanPref(prefs::kShouldUseOEMFirstRunBubble, - false); - local_state->SetBoolean(prefs::kShouldUseOEMFirstRunBubble, true); - } - return true; -} - ////////////////////////////////////////////////////////////////////////// namespace { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 48e732d..ab32af3 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2501,6 +2501,10 @@ '<@(xib_files_to_scan)'], }, ], + }, { # OS != mac + 'dependencies': [ + 'installer/installer.gyp:installer_util', + ], }], ['OS=="win"', { 'defines': [ @@ -2515,7 +2519,6 @@ '../gears/gears.gyp:gears', '../google_update/google_update.gyp:google_update', '../views/views.gyp:views', - 'installer/installer.gyp:installer_util', '<(allocator_target)', ], 'export_dependent_settings': [ diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi index 0eac355..b42a673 100644 --- a/chrome/chrome_exe.gypi +++ b/chrome/chrome_exe.gypi @@ -182,6 +182,8 @@ # Needed for chrome_dll_main.cc #include of gtk/gtk.h '../build/linux/system.gyp:gtk', 'packed_resources', + # Needed to use the master_preferences functions + 'installer/installer.gyp:installer_util', ], 'sources': [ 'app/chrome_dll_main.cc', diff --git a/chrome/installer/installer.gyp b/chrome/installer/installer.gyp index 6d4a832..67e5c61 100644 --- a/chrome/installer/installer.gyp +++ b/chrome/installer/installer.gyp @@ -70,6 +70,7 @@ 'installer_util_strings', '../../base/base.gyp:base', '../../base/base.gyp:base_i18n', + '../../build/temp_gyp/googleurl.gyp:googleurl', '../../testing/gtest.gyp:gtest', ], 'include_dirs': [ @@ -175,6 +176,7 @@ 'dependencies': [ 'installer_util', 'installer_util_strings', + '../../build/temp_gyp/googleurl.gyp:googleurl', '../../build/util/build_util.gyp:lastchange', '../../build/util/support/support.gyp:*', '../../build/win/system.gyp:cygwin', @@ -295,6 +297,7 @@ 'installer_util', '../../base/base.gyp:base', '../../base/base.gyp:base_i18n', + '../../build/temp_gyp/googleurl.gyp:googleurl', '../../testing/gtest.gyp:gtest', ], 'include_dirs': [ diff --git a/chrome/installer/installer_util.gypi b/chrome/installer/installer_util.gypi index f613386..ba164a9 100644 --- a/chrome/installer/installer_util.gypi +++ b/chrome/installer/installer_util.gypi @@ -53,7 +53,7 @@ 'util/work_item_list.h', ], 'include_dirs': [ - '../..', + '<(DEPTH)', ], }], ], @@ -123,6 +123,26 @@ }, ], }], + ['OS=="linux"', { + 'targets': [ + { + 'target_name': 'installer_util', + 'type': '<(library)', + 'dependencies': [ + '../chrome.gyp:common_constants', + '../chrome.gyp:chrome_resources', + '../chrome.gyp:chrome_strings', + ], + 'sources': [ + 'util/master_preferences.cc', + 'util/master_preferences.h', + ], + 'include_dirs': [ + '<(DEPTH)', + ], + } + ], + }], ], } diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index eec0ed3..226437d 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -181,7 +181,8 @@ void CopyPreferenceFileForFirstRun(bool system_level, const std::wstring& prefs_source_path) { FilePath prefs_dest_path = FilePath::FromWStringHack( installer::GetChromeInstallPath(system_level)); - prefs_dest_path = prefs_dest_path.Append(installer_util::kDefaultMasterPrefs); + prefs_dest_path = prefs_dest_path.AppendASCII( + installer_util::kDefaultMasterPrefs); if (!file_util::CopyFile(FilePath::FromWStringHack(prefs_source_path), prefs_dest_path)) { LOG(INFO) << "Failed to copy master preferences."; diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 1e94257..ab7bf06 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -8,13 +8,24 @@ #include "base/logging.h" #include "base/path_service.h" #include "chrome/common/json_value_serializer.h" +#include "googleurl/src/gurl.h" namespace { const wchar_t* kDistroDict = L"distribution"; -std::vector<std::wstring> GetNamedList(const wchar_t* name, - const DictionaryValue* prefs) { - std::vector<std::wstring> list; +bool GetGURLFromValue(const Value* in_value, GURL* out_value) { + if (!in_value || !out_value) + return false; + std::string url; + in_value->GetAsString(&url); + GURL gurl(url); + *out_value = gurl; + return true; +} + +std::vector<GURL> GetNamedList(const wchar_t* name, + const DictionaryValue* prefs) { + std::vector<GURL> list; if (!prefs) return list; ListValue* value_list = NULL; @@ -22,12 +33,12 @@ std::vector<std::wstring> GetNamedList(const wchar_t* name, return list; for (size_t i = 0; i < value_list->GetSize(); ++i) { Value* entry; - std::wstring str_entry; - if (!value_list->Get(i, &entry) || !entry->GetAsString(&str_entry)) { + GURL gurl_entry; + if (!value_list->Get(i, &entry) || !GetGURLFromValue(entry, &gurl_entry)) { NOTREACHED(); break; } - list.push_back(str_entry); + list.push_back(gurl_entry); } return list; } @@ -113,18 +124,17 @@ DictionaryValue* ParseDistributionPreferences( return static_cast<DictionaryValue*>(root.release()); } -std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs) { +std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs) { return GetNamedList(L"first_run_tabs", prefs); } -std::vector<std::wstring> GetDefaultBookmarks(const DictionaryValue* prefs) { +std::vector<GURL> GetDefaultBookmarks(const DictionaryValue* prefs) { return GetNamedList(L"default_bookmarks", prefs); } bool SetDistroBooleanPreference(DictionaryValue* prefs, const std::wstring& name, bool value) { - if (!prefs || name.empty()) return false; prefs->SetBoolean(std::wstring(kDistroDict) + L"." + name, value); diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index 96d2fb6..cc7b8a1 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -8,8 +8,11 @@ #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ +#include <vector> + #include "base/file_path.h" #include "base/values.h" +#include "googleurl/src/gurl.h" namespace installer_util { @@ -64,7 +67,7 @@ extern const wchar_t kExtensionsBlock[]; // This is the default name for the master preferences file used to pre-set // values in the user profile at first run. -const wchar_t kDefaultMasterPrefs[] = L"master_preferences"; +const char kDefaultMasterPrefs[] = "master_preferences"; // Gets the value of given boolean preference |name| from |prefs| dictionary // which is assumed to contain a dictionary named "distribution". Returns @@ -138,9 +141,9 @@ DictionaryValue* ParseDistributionPreferences( // // 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 +// This function retuns the list as a vector of GURLs. If the master // preferences file does not contain such list the vector is empty. -std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs); +std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs); // As part of the master preferences an optional section indicates the // pre-installed bookmarks. An example is the following: @@ -154,9 +157,9 @@ std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs); // // Note that the entries need to be urls. // -// This function retuns the list as a vector of strings. If the master +// This function retuns the list as a vector of GURLs. If the master // preferences file does not contain such list the vector is empty. -std::vector<std::wstring> GetDefaultBookmarks(const DictionaryValue* prefs); +std::vector<GURL> GetDefaultBookmarks(const DictionaryValue* prefs); // Sets the value of given boolean preference |name| in "distribution" // dictionary inside |prefs| dictionary. diff --git a/chrome/installer/util/master_preferences_unittest.cc b/chrome/installer/util/master_preferences_unittest.cc index 8ff41e0..17ea387 100644 --- a/chrome/installer/util/master_preferences_unittest.cc +++ b/chrome/installer/util/master_preferences_unittest.cc @@ -10,6 +10,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/json_value_serializer.h" #include "chrome/installer/util/master_preferences.h" +#include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -200,12 +201,12 @@ TEST_F(MasterPreferencesTest, FirstRunTabs) { installer_util::ParseDistributionPreferences(prefs_file())); EXPECT_TRUE(prefs.get() != NULL); - typedef std::vector<std::wstring> TabsVector; + typedef std::vector<GURL> TabsVector; TabsVector tabs = installer_util::GetFirstRunTabs(prefs.get()); 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_EQ(GURL("http://google.com/f1"), tabs[0]); + EXPECT_EQ(GURL("https://google.com/f2"), tabs[1]); + EXPECT_EQ(GURL("new_tab_page"), tabs[2]); } TEST_F(MasterPreferencesTest, FirstRunBookMarks) { @@ -225,11 +226,11 @@ TEST_F(MasterPreferencesTest, FirstRunBookMarks) { installer_util::ParseDistributionPreferences(prefs_file())); EXPECT_TRUE(prefs.get() != NULL); - typedef std::vector<std::wstring> BookmarksVector; + typedef std::vector<GURL> BookmarksVector; BookmarksVector bookmarks = installer_util::GetDefaultBookmarks(prefs.get()); ASSERT_EQ(2, bookmarks.size()); - EXPECT_EQ(L"http://google.com/b1", bookmarks[0]); - EXPECT_EQ(L"https://google.com/b2", bookmarks[1]); + EXPECT_EQ(GURL("http://google.com/b1"), bookmarks[0]); + EXPECT_EQ(GURL("https://google.com/b2"), bookmarks[1]); } // In this test instead of using our synthetic json file, we use an diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index ced94e8..c61251b 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -767,7 +767,7 @@ bool ShellUtil::UpdateChromeShortcut(const std::wstring& chrome_exe, std::wstring chrome_path = file_util::GetDirectoryFromPath(chrome_exe); FilePath prefs_path(chrome_path); - prefs_path = prefs_path.Append(installer_util::kDefaultMasterPrefs); + prefs_path = prefs_path.AppendASCII(installer_util::kDefaultMasterPrefs); scoped_ptr<DictionaryValue> prefs( installer_util::ParseDistributionPreferences(prefs_path)); int icon_index = 0; diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc index 9babd2d..0deb339 100644 --- a/chrome/installer/util/shell_util_unittest.cc +++ b/chrome/installer/util/shell_util_unittest.cc @@ -127,7 +127,8 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { description, 0)); // Now specify an icon index in master prefs and make sure it works. - FilePath prefs_path = test_dir_.Append(installer_util::kDefaultMasterPrefs); + FilePath prefs_path = test_dir_.AppendASCII( + installer_util::kDefaultMasterPrefs); std::ofstream file; file.open(prefs_path.value().c_str()); ASSERT_TRUE(file.is_open()); |