diff options
Diffstat (limited to 'chrome/browser/ui/webui/ntp')
-rw-r--r-- | chrome/browser/ui/webui/ntp/app_launcher_handler.cc | 37 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/app_launcher_handler.h | 12 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc | 34 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/ntp_resource_cache.h | 3 |
4 files changed, 72 insertions, 14 deletions
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index c969580..e6856f9 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -6,6 +6,7 @@ #include <vector> +#include "apps/pref_names.h" #include "base/auto_reset.h" #include "base/bind.h" #include "base/bind_helpers.h" @@ -15,6 +16,7 @@ #include "base/prefs/pref_service.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_service.h" @@ -164,6 +166,14 @@ void AppLauncherHandler::RegisterMessages() { registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, content::Source<WebContents>(web_ui()->GetWebContents())); + // Some tests don't have a local state. + if (g_browser_process->local_state()) { + local_state_pref_change_registrar_.Init(g_browser_process->local_state()); + local_state_pref_change_registrar_.Add( + apps::prefs::kShowAppLauncherPromo, + base::Bind(&AppLauncherHandler::OnLocalStatePreferenceChanged, + base::Unretained(this))); + } web_ui()->RegisterMessageCallback("getApps", base::Bind(&AppLauncherHandler::HandleGetApps, base::Unretained(this))); @@ -194,6 +204,9 @@ void AppLauncherHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("recordAppLaunchByURL", base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByUrl, base::Unretained(this))); + web_ui()->RegisterMessageCallback("stopShowingAppLauncherPromo", + base::Bind(&AppLauncherHandler::StopShowingAppLauncherPromo, + base::Unretained(this))); } void AppLauncherHandler::Observe(int type, @@ -391,12 +404,13 @@ void AppLauncherHandler::HandleGetApps(const ListValue* args) { // the apps as they change. if (!has_loaded_apps_) { base::Closure callback = base::Bind( - &AppLauncherHandler::OnPreferenceChanged, + &AppLauncherHandler::OnExtensionPreferenceChanged, base::Unretained(this)); - pref_change_registrar_.Init( + extension_pref_change_registrar_.Init( extension_service_->extension_prefs()->pref_service()); - pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, callback); - pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); + extension_pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, + callback); + extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, content::Source<Profile>(profile)); @@ -662,6 +676,12 @@ void AppLauncherHandler::HandleRecordAppLaunchByUrl( RecordAppLaunchByUrl(Profile::FromWebUI(web_ui()), url, bucket); } +void AppLauncherHandler::StopShowingAppLauncherPromo( + const base::ListValue* args) { + g_browser_process->local_state()->SetBoolean( + apps::prefs::kShowAppLauncherPromo, false); +} + void AppLauncherHandler::OnFaviconForApp( scoped_ptr<AppInstallInfo> install_info, const history::FaviconImageResult& image_result) { @@ -696,12 +716,19 @@ void AppLauncherHandler::SetAppToBeHighlighted() { highlight_app_id_.clear(); } -void AppLauncherHandler::OnPreferenceChanged() { +void AppLauncherHandler::OnExtensionPreferenceChanged() { DictionaryValue dictionary; FillAppDictionary(&dictionary); web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", dictionary); } +void AppLauncherHandler::OnLocalStatePreferenceChanged() { + web_ui()->CallJavascriptFunction( + "ntp.appLauncherPromoPrefChangeCallback", + base::FundamentalValue(g_browser_process->local_state()->GetBoolean( + apps::prefs::kShowAppLauncherPromo))); +} + // static void AppLauncherHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { registry->RegisterListPref(prefs::kNtpAppPageNames, diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.h b/chrome/browser/ui/webui/ntp/app_launcher_handler.h index 13ffd39..64faff8 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.h +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.h @@ -93,6 +93,9 @@ class AppLauncherHandler : public content::WebUIMessageHandler, // action for UMA. void HandleRecordAppLaunchByUrl(const base::ListValue* args); + // Callback for "stopShowingAppLauncherPromo" message. + void StopShowingAppLauncherPromo(const base::ListValue* args); + // Callback for "closeNotification" message. void HandleNotificationClose(const base::ListValue* args); @@ -151,7 +154,9 @@ class AppLauncherHandler : public content::WebUIMessageHandler, // Sends |highlight_app_id_| to the js. void SetAppToBeHighlighted(); - void OnPreferenceChanged(); + void OnExtensionPreferenceChanged(); + + void OnLocalStatePreferenceChanged(); // The apps are represented in the extensions model, which // outlives us since it's owned by our containing profile. @@ -162,7 +167,10 @@ class AppLauncherHandler : public content::WebUIMessageHandler, content::NotificationRegistrar registrar_; // Monitor extension preference changes so that the Web UI can be notified. - PrefChangeRegistrar pref_change_registrar_; + PrefChangeRegistrar extension_pref_change_registrar_; + + // Monitor the local state pref to control the app launcher promo. + PrefChangeRegistrar local_state_pref_change_registrar_; // Used to show confirmation UI for uninstalling extensions in incognito mode. scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 35c8db4..86e5ce1 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -8,9 +8,12 @@ #include <vector> #include "apps/app_launcher.h" +#include "apps/field_trial_names.h" +#include "apps/pref_names.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/memory/ref_counted_memory.h" +#include "base/metrics/field_trial.h" #include "base/prefs/pref_service.h" #include "base/string16.h" #include "base/stringprintf.h" @@ -180,12 +183,20 @@ NTPResourceCache::NTPResourceCache(Profile* profile) base::Unretained(this)); // Watch for pref changes that cause us to need to invalidate the HTML cache. - pref_change_registrar_.Init(profile_->GetPrefs()); - pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback); - pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); - pref_change_registrar_.Add(prefs::kNtpShownPage, callback); - pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); - pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); + profile_pref_change_registrar_.Init(profile_->GetPrefs()); + profile_pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, + callback); + profile_pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); + profile_pref_change_registrar_.Add(prefs::kNtpShownPage, callback); + profile_pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); + profile_pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); + + // Some tests don't have a local state. + if (g_browser_process->local_state()) { + local_state_pref_change_registrar_.Init(g_browser_process->local_state()); + local_state_pref_change_registrar_.Add(apps::prefs::kShowAppLauncherPromo, + callback); + } } NTPResourceCache::~NTPResourceCache() {} @@ -321,6 +332,7 @@ void NTPResourceCache::CreateNewTabHTML() { // Show the profile name in the title and most visited labels if the current // profile is not the default. PrefService* prefs = profile_->GetPrefs(); + PrefService* local_state = g_browser_process->local_state(); DictionaryValue load_time_data; load_time_data.SetBoolean("bookmarkbarattached", prefs->GetBoolean(prefs::kShowBookmarkBar)); @@ -328,6 +340,14 @@ void NTPResourceCache::CreateNewTabHTML() { ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( IDR_THEME_NTP_ATTRIBUTION)); load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_); + std::string app_launcher_promo_group_name = + base::FieldTrialList::FindFullName(apps::kLauncherPromoTrialName); + bool show_app_launcher_promo = + local_state->GetBoolean(apps::prefs::kShowAppLauncherPromo) && + (app_launcher_promo_group_name == apps::kShowLauncherPromoOnceGroupName || + app_launcher_promo_group_name == + apps::kResetShowLauncherPromoPrefGroupName); + load_time_data.SetBoolean("showAppLauncherPromo", show_app_launcher_promo); load_time_data.SetBoolean("showRecentlyClosed", should_show_recently_closed_menu_); load_time_data.SetString("title", @@ -406,6 +426,8 @@ void NTPResourceCache::CreateNewTabHTML() { l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); load_time_data.SetString("page_switcher_same_title", l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); + load_time_data.SetString("appsPromoTitle", + l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_APPS_PROMO_TITLE)); // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or // forward gesture. Pass through a flag that indicates whether or not that // feature is enabled. diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h index cee7e0e..b30b41f 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h @@ -75,7 +75,8 @@ class NTPResourceCache : public content::NotificationObserver, scoped_refptr<base::RefCountedMemory> new_tab_incognito_css_; scoped_refptr<base::RefCountedMemory> new_tab_css_; content::NotificationRegistrar registrar_; - PrefChangeRegistrar pref_change_registrar_; + PrefChangeRegistrar profile_pref_change_registrar_; + PrefChangeRegistrar local_state_pref_change_registrar_; #endif // Set based on platform_util::IsSwipeTrackingFromScrollEventsEnabled. |