| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 323 } |
| 324 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { | 324 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { |
| 325 attempted_bookmark_app_install_ = false; | 325 attempted_bookmark_app_install_ = false; |
| 326 break; | 326 break; |
| 327 } | 327 } |
| 328 default: | 328 default: |
| 329 NOTREACHED(); | 329 NOTREACHED(); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 void AppLauncherHandler::OnPreferenceChanged(PrefServiceBase* service, | |
| 334 const std::string& pref_name) { | |
| 335 DictionaryValue dictionary; | |
| 336 FillAppDictionary(&dictionary); | |
| 337 web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", | |
| 338 dictionary); | |
| 339 } | |
| 340 | |
| 341 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { | 333 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
| 342 // CreateAppInfo and ClearOrdinals can change the extension prefs. | 334 // CreateAppInfo and ClearOrdinals can change the extension prefs. |
| 343 AutoReset<bool> auto_reset(&ignore_changes_, true); | 335 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 344 | 336 |
| 345 ListValue* list = new ListValue(); | 337 ListValue* list = new ListValue(); |
| 346 | 338 |
| 347 for (std::set<std::string>::iterator it = visible_apps_.begin(); | 339 for (std::set<std::string>::iterator it = visible_apps_.begin(); |
| 348 it != visible_apps_.end(); ++it) { | 340 it != visible_apps_.end(); ++it) { |
| 349 const Extension* extension = extension_service_->GetInstalledExtension(*it); | 341 const Extension* extension = extension_service_->GetInstalledExtension(*it); |
| 350 if (extension && extension->ShouldDisplayInNewTabPage()) { | 342 if (extension && extension->ShouldDisplayInNewTabPage()) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 424 } |
| 433 } | 425 } |
| 434 | 426 |
| 435 SetAppToBeHighlighted(); | 427 SetAppToBeHighlighted(); |
| 436 FillAppDictionary(&dictionary); | 428 FillAppDictionary(&dictionary); |
| 437 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); | 429 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); |
| 438 | 430 |
| 439 // First time we get here we set up the observer so that we can tell update | 431 // First time we get here we set up the observer so that we can tell update |
| 440 // the apps as they change. | 432 // the apps as they change. |
| 441 if (!has_loaded_apps_) { | 433 if (!has_loaded_apps_) { |
| 434 base::Closure callback = base::Bind( |
| 435 &AppLauncherHandler::OnPreferencesChanged, |
| 436 base::Unretained(this)); |
| 442 pref_change_registrar_.Init( | 437 pref_change_registrar_.Init( |
| 443 extension_service_->extension_prefs()->pref_service()); | 438 extension_service_->extension_prefs()->pref_service()); |
| 444 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); | 439 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, callback); |
| 445 pref_change_registrar_.Add(prefs::kNtpAppPageNames, this); | 440 pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); |
| 446 | 441 |
| 447 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 442 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
| 448 content::Source<Profile>(profile)); | 443 content::Source<Profile>(profile)); |
| 449 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 444 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 450 content::Source<Profile>(profile)); | 445 content::Source<Profile>(profile)); |
| 451 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 446 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 452 content::Source<Profile>(profile)); | 447 content::Source<Profile>(profile)); |
| 453 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 448 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
| 454 content::Source<ExtensionSorting>( | 449 content::Source<ExtensionSorting>( |
| 455 extension_service_->extension_prefs()->extension_sorting())); | 450 extension_service_->extension_prefs()->extension_sorting())); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 763 |
| 769 void AppLauncherHandler::SetAppToBeHighlighted() { | 764 void AppLauncherHandler::SetAppToBeHighlighted() { |
| 770 if (highlight_app_id_.empty()) | 765 if (highlight_app_id_.empty()) |
| 771 return; | 766 return; |
| 772 | 767 |
| 773 StringValue app_id(highlight_app_id_); | 768 StringValue app_id(highlight_app_id_); |
| 774 web_ui()->CallJavascriptFunction("ntp.setAppToBeHighlighted", app_id); | 769 web_ui()->CallJavascriptFunction("ntp.setAppToBeHighlighted", app_id); |
| 775 highlight_app_id_.clear(); | 770 highlight_app_id_.clear(); |
| 776 } | 771 } |
| 777 | 772 |
| 773 void AppLauncherHandler::OnPreferencesChanged() { |
| 774 DictionaryValue dictionary; |
| 775 FillAppDictionary(&dictionary); |
| 776 web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", dictionary); |
| 777 } |
| 778 |
| 778 // static | 779 // static |
| 779 void AppLauncherHandler::RegisterUserPrefs(PrefServiceBase* pref_service) { | 780 void AppLauncherHandler::RegisterUserPrefs(PrefServiceBase* pref_service) { |
| 780 pref_service->RegisterListPref(prefs::kNtpAppPageNames, | 781 pref_service->RegisterListPref(prefs::kNtpAppPageNames, |
| 781 PrefService::SYNCABLE_PREF); | 782 PrefService::SYNCABLE_PREF); |
| 782 } | 783 } |
| 783 | 784 |
| 784 void AppLauncherHandler::CleanupAfterUninstall() { | 785 void AppLauncherHandler::CleanupAfterUninstall() { |
| 785 extension_id_prompting_.clear(); | 786 extension_id_prompting_.clear(); |
| 786 } | 787 } |
| 787 | 788 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 return extension_uninstall_dialog_.get(); | 923 return extension_uninstall_dialog_.get(); |
| 923 } | 924 } |
| 924 | 925 |
| 925 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { | 926 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { |
| 926 if (!extension_install_ui_.get()) { | 927 if (!extension_install_ui_.get()) { |
| 927 extension_install_ui_.reset( | 928 extension_install_ui_.reset( |
| 928 new ExtensionInstallPrompt(web_ui()->GetWebContents())); | 929 new ExtensionInstallPrompt(web_ui()->GetWebContents())); |
| 929 } | 930 } |
| 930 return extension_install_ui_.get(); | 931 return extension_install_ui_.get(); |
| 931 } | 932 } |
| OLD | NEW |