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 <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "apps/pref_names.h" |
9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/extensions/crx_installer.h" | 20 #include "chrome/browser/extensions/crx_installer.h" |
19 #include "chrome/browser/extensions/extension_prefs.h" | 21 #include "chrome/browser/extensions/extension_prefs.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_sorting.h" | 23 #include "chrome/browser/extensions/extension_sorting.h" |
22 #include "chrome/browser/extensions/extension_system.h" | 24 #include "chrome/browser/extensions/extension_system.h" |
23 #include "chrome/browser/extensions/management_policy.h" | 25 #include "chrome/browser/extensions/management_policy.h" |
24 #include "chrome/browser/favicon/favicon_service_factory.h" | 26 #include "chrome/browser/favicon/favicon_service_factory.h" |
25 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
26 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 sorting->CreateNextAppLaunchOrdinal(page_ordinal); | 160 sorting->CreateNextAppLaunchOrdinal(page_ordinal); |
159 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); | 161 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); |
160 } | 162 } |
161 value->SetString("app_launch_ordinal", app_launch_ordinal.ToInternalValue()); | 163 value->SetString("app_launch_ordinal", app_launch_ordinal.ToInternalValue()); |
162 } | 164 } |
163 | 165 |
164 void AppLauncherHandler::RegisterMessages() { | 166 void AppLauncherHandler::RegisterMessages() { |
165 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | 167 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
166 content::Source<WebContents>(web_ui()->GetWebContents())); | 168 content::Source<WebContents>(web_ui()->GetWebContents())); |
167 | 169 |
| 170 local_state_pref_change_registrar_.Init(g_browser_process->local_state()); |
| 171 local_state_pref_change_registrar_.Add( |
| 172 apps::prefs::kShowAppLauncherPromo, |
| 173 base::Bind(&AppLauncherHandler::OnLocalStatePreferenceChanged, |
| 174 base::Unretained(this))); |
| 175 |
168 web_ui()->RegisterMessageCallback("getApps", | 176 web_ui()->RegisterMessageCallback("getApps", |
169 base::Bind(&AppLauncherHandler::HandleGetApps, | 177 base::Bind(&AppLauncherHandler::HandleGetApps, |
170 base::Unretained(this))); | 178 base::Unretained(this))); |
171 web_ui()->RegisterMessageCallback("launchApp", | 179 web_ui()->RegisterMessageCallback("launchApp", |
172 base::Bind(&AppLauncherHandler::HandleLaunchApp, | 180 base::Bind(&AppLauncherHandler::HandleLaunchApp, |
173 base::Unretained(this))); | 181 base::Unretained(this))); |
174 web_ui()->RegisterMessageCallback("setLaunchType", | 182 web_ui()->RegisterMessageCallback("setLaunchType", |
175 base::Bind(&AppLauncherHandler::HandleSetLaunchType, | 183 base::Bind(&AppLauncherHandler::HandleSetLaunchType, |
176 base::Unretained(this))); | 184 base::Unretained(this))); |
177 web_ui()->RegisterMessageCallback("uninstallApp", | 185 web_ui()->RegisterMessageCallback("uninstallApp", |
(...skipping 10 matching lines...) Expand all Loading... |
188 base::Unretained(this))); | 196 base::Unretained(this))); |
189 web_ui()->RegisterMessageCallback("saveAppPageName", | 197 web_ui()->RegisterMessageCallback("saveAppPageName", |
190 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, | 198 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, |
191 base::Unretained(this))); | 199 base::Unretained(this))); |
192 web_ui()->RegisterMessageCallback("generateAppForLink", | 200 web_ui()->RegisterMessageCallback("generateAppForLink", |
193 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, | 201 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, |
194 base::Unretained(this))); | 202 base::Unretained(this))); |
195 web_ui()->RegisterMessageCallback("recordAppLaunchByURL", | 203 web_ui()->RegisterMessageCallback("recordAppLaunchByURL", |
196 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByUrl, | 204 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByUrl, |
197 base::Unretained(this))); | 205 base::Unretained(this))); |
| 206 web_ui()->RegisterMessageCallback("stopShowingAppLauncherPromo", |
| 207 base::Bind(&AppLauncherHandler::StopShowingAppLauncherPromo, |
| 208 base::Unretained(this))); |
198 } | 209 } |
199 | 210 |
200 void AppLauncherHandler::Observe(int type, | 211 void AppLauncherHandler::Observe(int type, |
201 const content::NotificationSource& source, | 212 const content::NotificationSource& source, |
202 const content::NotificationDetails& details) { | 213 const content::NotificationDetails& details) { |
203 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP) { | 214 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP) { |
204 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); | 215 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); |
205 if (has_loaded_apps_) | 216 if (has_loaded_apps_) |
206 SetAppToBeHighlighted(); | 217 SetAppToBeHighlighted(); |
207 return; | 218 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 396 } |
386 | 397 |
387 SetAppToBeHighlighted(); | 398 SetAppToBeHighlighted(); |
388 FillAppDictionary(&dictionary); | 399 FillAppDictionary(&dictionary); |
389 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); | 400 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); |
390 | 401 |
391 // First time we get here we set up the observer so that we can tell update | 402 // First time we get here we set up the observer so that we can tell update |
392 // the apps as they change. | 403 // the apps as they change. |
393 if (!has_loaded_apps_) { | 404 if (!has_loaded_apps_) { |
394 base::Closure callback = base::Bind( | 405 base::Closure callback = base::Bind( |
395 &AppLauncherHandler::OnPreferenceChanged, | 406 &AppLauncherHandler::OnExtensionPreferenceChanged, |
396 base::Unretained(this)); | 407 base::Unretained(this)); |
397 pref_change_registrar_.Init( | 408 extension_pref_change_registrar_.Init( |
398 extension_service_->extension_prefs()->pref_service()); | 409 extension_service_->extension_prefs()->pref_service()); |
399 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, callback); | 410 extension_pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, |
400 pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); | 411 callback); |
| 412 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); |
401 | 413 |
402 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 414 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
403 content::Source<Profile>(profile)); | 415 content::Source<Profile>(profile)); |
404 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 416 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
405 content::Source<Profile>(profile)); | 417 content::Source<Profile>(profile)); |
406 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 418 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
407 content::Source<ExtensionSorting>( | 419 content::Source<ExtensionSorting>( |
408 extension_service_->extension_prefs()->extension_sorting())); | 420 extension_service_->extension_prefs()->extension_sorting())); |
409 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 421 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
410 content::Source<Profile>(profile)); | 422 content::Source<Profile>(profile)); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 double source; | 667 double source; |
656 CHECK(args->GetDouble(1, &source)); | 668 CHECK(args->GetDouble(1, &source)); |
657 | 669 |
658 extension_misc::AppLaunchBucket bucket = | 670 extension_misc::AppLaunchBucket bucket = |
659 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); | 671 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); |
660 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 672 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
661 | 673 |
662 RecordAppLaunchByUrl(Profile::FromWebUI(web_ui()), url, bucket); | 674 RecordAppLaunchByUrl(Profile::FromWebUI(web_ui()), url, bucket); |
663 } | 675 } |
664 | 676 |
| 677 void AppLauncherHandler::StopShowingAppLauncherPromo( |
| 678 const base::ListValue* args) { |
| 679 g_browser_process->local_state()->SetBoolean( |
| 680 apps::prefs::kShowAppLauncherPromo, false); |
| 681 } |
| 682 |
665 void AppLauncherHandler::OnFaviconForApp( | 683 void AppLauncherHandler::OnFaviconForApp( |
666 scoped_ptr<AppInstallInfo> install_info, | 684 scoped_ptr<AppInstallInfo> install_info, |
667 const history::FaviconImageResult& image_result) { | 685 const history::FaviconImageResult& image_result) { |
668 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); | 686 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); |
669 web_app->is_bookmark_app = install_info->is_bookmark_app; | 687 web_app->is_bookmark_app = install_info->is_bookmark_app; |
670 web_app->title = install_info->title; | 688 web_app->title = install_info->title; |
671 web_app->app_url = install_info->app_url; | 689 web_app->app_url = install_info->app_url; |
672 web_app->urls.push_back(install_info->app_url); | 690 web_app->urls.push_back(install_info->app_url); |
673 | 691 |
674 if (!image_result.image.IsEmpty()) { | 692 if (!image_result.image.IsEmpty()) { |
(...skipping 14 matching lines...) Expand all Loading... |
689 | 707 |
690 void AppLauncherHandler::SetAppToBeHighlighted() { | 708 void AppLauncherHandler::SetAppToBeHighlighted() { |
691 if (highlight_app_id_.empty()) | 709 if (highlight_app_id_.empty()) |
692 return; | 710 return; |
693 | 711 |
694 StringValue app_id(highlight_app_id_); | 712 StringValue app_id(highlight_app_id_); |
695 web_ui()->CallJavascriptFunction("ntp.setAppToBeHighlighted", app_id); | 713 web_ui()->CallJavascriptFunction("ntp.setAppToBeHighlighted", app_id); |
696 highlight_app_id_.clear(); | 714 highlight_app_id_.clear(); |
697 } | 715 } |
698 | 716 |
699 void AppLauncherHandler::OnPreferenceChanged() { | 717 void AppLauncherHandler::OnExtensionPreferenceChanged() { |
700 DictionaryValue dictionary; | 718 DictionaryValue dictionary; |
701 FillAppDictionary(&dictionary); | 719 FillAppDictionary(&dictionary); |
702 web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", dictionary); | 720 web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", dictionary); |
703 } | 721 } |
704 | 722 |
| 723 void AppLauncherHandler::OnLocalStatePreferenceChanged() { |
| 724 web_ui()->CallJavascriptFunction( |
| 725 "ntp.appLauncherPromoPrefChangeCallback", |
| 726 base::FundamentalValue(g_browser_process->local_state()->GetBoolean( |
| 727 apps::prefs::kShowAppLauncherPromo))); |
| 728 } |
| 729 |
705 // static | 730 // static |
706 void AppLauncherHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 731 void AppLauncherHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
707 registry->RegisterListPref(prefs::kNtpAppPageNames, | 732 registry->RegisterListPref(prefs::kNtpAppPageNames, |
708 PrefRegistrySyncable::SYNCABLE_PREF); | 733 PrefRegistrySyncable::SYNCABLE_PREF); |
709 } | 734 } |
710 | 735 |
711 void AppLauncherHandler::CleanupAfterUninstall() { | 736 void AppLauncherHandler::CleanupAfterUninstall() { |
712 extension_id_prompting_.clear(); | 737 extension_id_prompting_.clear(); |
713 } | 738 } |
714 | 739 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 836 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
812 if (!extension_uninstall_dialog_.get()) { | 837 if (!extension_uninstall_dialog_.get()) { |
813 Browser* browser = chrome::FindBrowserWithWebContents( | 838 Browser* browser = chrome::FindBrowserWithWebContents( |
814 web_ui()->GetWebContents()); | 839 web_ui()->GetWebContents()); |
815 extension_uninstall_dialog_.reset( | 840 extension_uninstall_dialog_.reset( |
816 ExtensionUninstallDialog::Create(extension_service_->profile(), | 841 ExtensionUninstallDialog::Create(extension_service_->profile(), |
817 browser, this)); | 842 browser, this)); |
818 } | 843 } |
819 return extension_uninstall_dialog_.get(); | 844 return extension_uninstall_dialog_.get(); |
820 } | 845 } |
OLD | NEW |