OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "chrome/browser/ui/extensions/application_launch.h" | 37 #include "chrome/browser/ui/extensions/application_launch.h" |
38 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 38 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
40 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | 40 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" |
41 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 41 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
42 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 42 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
43 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/extensions/extension_constants.h" | 44 #include "chrome/common/extensions/extension_constants.h" |
45 #include "chrome/common/extensions/extension_metrics.h" | 45 #include "chrome/common/extensions/extension_metrics.h" |
46 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 46 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 47 #include "chrome/common/features.h" |
47 #include "chrome/common/pref_names.h" | 48 #include "chrome/common/pref_names.h" |
48 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
49 #include "chrome/common/web_application_info.h" | 50 #include "chrome/common/web_application_info.h" |
50 #include "chrome/grit/generated_resources.h" | 51 #include "chrome/grit/generated_resources.h" |
51 #include "components/favicon_base/favicon_types.h" | 52 #include "components/favicon_base/favicon_types.h" |
52 #include "components/pref_registry/pref_registry_syncable.h" | 53 #include "components/pref_registry/pref_registry_syncable.h" |
53 #include "components/prefs/pref_service.h" | 54 #include "components/prefs/pref_service.h" |
54 #include "components/prefs/scoped_user_pref_update.h" | 55 #include "components/prefs/scoped_user_pref_update.h" |
55 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
56 #include "content/public/browser/web_ui.h" | 57 #include "content/public/browser/web_ui.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void AppLauncherHandler::RegisterProfilePrefs( | 226 void AppLauncherHandler::RegisterProfilePrefs( |
226 user_prefs::PrefRegistrySyncable* registry) { | 227 user_prefs::PrefRegistrySyncable* registry) { |
227 registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID); | 228 registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID); |
228 } | 229 } |
229 | 230 |
230 void AppLauncherHandler::RegisterMessages() { | 231 void AppLauncherHandler::RegisterMessages() { |
231 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | 232 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
232 content::Source<WebContents>(web_ui()->GetWebContents())); | 233 content::Source<WebContents>(web_ui()->GetWebContents())); |
233 | 234 |
234 // Some tests don't have a local state. | 235 // Some tests don't have a local state. |
235 #if defined(ENABLE_APP_LIST) | 236 #if BUILDFLAG(ENABLE_APP_LIST) |
236 if (g_browser_process->local_state()) { | 237 if (g_browser_process->local_state()) { |
237 local_state_pref_change_registrar_.Init(g_browser_process->local_state()); | 238 local_state_pref_change_registrar_.Init(g_browser_process->local_state()); |
238 local_state_pref_change_registrar_.Add( | 239 local_state_pref_change_registrar_.Add( |
239 prefs::kShowAppLauncherPromo, | 240 prefs::kShowAppLauncherPromo, |
240 base::Bind(&AppLauncherHandler::OnLocalStatePreferenceChanged, | 241 base::Bind(&AppLauncherHandler::OnLocalStatePreferenceChanged, |
241 base::Unretained(this))); | 242 base::Unretained(this))); |
242 } | 243 } |
243 #endif | 244 #endif |
244 web_ui()->RegisterMessageCallback("getApps", | 245 web_ui()->RegisterMessageCallback("getApps", |
245 base::Bind(&AppLauncherHandler::HandleGetApps, | 246 base::Bind(&AppLauncherHandler::HandleGetApps, |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 favicon_service->GetFaviconImageForPageURL( | 731 favicon_service->GetFaviconImageForPageURL( |
731 launch_url, | 732 launch_url, |
732 base::Bind(&AppLauncherHandler::OnFaviconForApp, | 733 base::Bind(&AppLauncherHandler::OnFaviconForApp, |
733 base::Unretained(this), | 734 base::Unretained(this), |
734 base::Passed(&install_info)), | 735 base::Passed(&install_info)), |
735 &cancelable_task_tracker_); | 736 &cancelable_task_tracker_); |
736 } | 737 } |
737 | 738 |
738 void AppLauncherHandler::HandleStopShowingAppLauncherPromo( | 739 void AppLauncherHandler::HandleStopShowingAppLauncherPromo( |
739 const base::ListValue* args) { | 740 const base::ListValue* args) { |
740 #if defined(ENABLE_APP_LIST) | 741 #if BUILDFLAG(ENABLE_APP_LIST) |
741 g_browser_process->local_state()->SetBoolean( | 742 g_browser_process->local_state()->SetBoolean( |
742 prefs::kShowAppLauncherPromo, false); | 743 prefs::kShowAppLauncherPromo, false); |
743 RecordAppLauncherPromoHistogram(apps::APP_LAUNCHER_PROMO_DISMISSED); | 744 RecordAppLauncherPromoHistogram(apps::APP_LAUNCHER_PROMO_DISMISSED); |
744 #endif | 745 #endif |
745 } | 746 } |
746 | 747 |
747 void AppLauncherHandler::HandleOnLearnMore(const base::ListValue* args) { | 748 void AppLauncherHandler::HandleOnLearnMore(const base::ListValue* args) { |
748 RecordAppLauncherPromoHistogram(apps::APP_LAUNCHER_PROMO_LEARN_MORE); | 749 RecordAppLauncherPromoHistogram(apps::APP_LAUNCHER_PROMO_LEARN_MORE); |
749 } | 750 } |
750 | 751 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 } | 791 } |
791 | 792 |
792 void AppLauncherHandler::OnExtensionPreferenceChanged() { | 793 void AppLauncherHandler::OnExtensionPreferenceChanged() { |
793 base::DictionaryValue dictionary; | 794 base::DictionaryValue dictionary; |
794 FillAppDictionary(&dictionary); | 795 FillAppDictionary(&dictionary); |
795 web_ui()->CallJavascriptFunctionUnsafe("ntp.appsPrefChangeCallback", | 796 web_ui()->CallJavascriptFunctionUnsafe("ntp.appsPrefChangeCallback", |
796 dictionary); | 797 dictionary); |
797 } | 798 } |
798 | 799 |
799 void AppLauncherHandler::OnLocalStatePreferenceChanged() { | 800 void AppLauncherHandler::OnLocalStatePreferenceChanged() { |
800 #if defined(ENABLE_APP_LIST) | 801 #if BUILDFLAG(ENABLE_APP_LIST) |
801 web_ui()->CallJavascriptFunctionUnsafe( | 802 web_ui()->CallJavascriptFunctionUnsafe( |
802 "ntp.appLauncherPromoPrefChangeCallback", | 803 "ntp.appLauncherPromoPrefChangeCallback", |
803 base::FundamentalValue(g_browser_process->local_state()->GetBoolean( | 804 base::FundamentalValue(g_browser_process->local_state()->GetBoolean( |
804 prefs::kShowAppLauncherPromo))); | 805 prefs::kShowAppLauncherPromo))); |
805 #endif | 806 #endif |
806 } | 807 } |
807 | 808 |
808 void AppLauncherHandler::CleanupAfterUninstall() { | 809 void AppLauncherHandler::CleanupAfterUninstall() { |
809 extension_id_prompting_.clear(); | 810 extension_id_prompting_.clear(); |
810 } | 811 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 base::FundamentalValue(!extension_id_prompting_.empty())); | 884 base::FundamentalValue(!extension_id_prompting_.empty())); |
884 } | 885 } |
885 | 886 |
886 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { | 887 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { |
887 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) | 888 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) |
888 return false; | 889 return false; |
889 | 890 |
890 Profile* profile = Profile::FromWebUI(web_ui()); | 891 Profile* profile = Profile::FromWebUI(web_ui()); |
891 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); | 892 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); |
892 } | 893 } |
OLD | NEW |