| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 extension_service_->GetInstalledExtension(*id); | 304 extension_service_->GetInstalledExtension(*id); |
| 305 if (!extension) { | 305 if (!extension) { |
| 306 // Extension could still be downloading or installing. | 306 // Extension could still be downloading or installing. |
| 307 return; | 307 return; |
| 308 } | 308 } |
| 309 | 309 |
| 310 base::DictionaryValue app_info; | 310 base::DictionaryValue app_info; |
| 311 CreateAppInfo(extension, | 311 CreateAppInfo(extension, |
| 312 extension_service_, | 312 extension_service_, |
| 313 &app_info); | 313 &app_info); |
| 314 web_ui()->CallJavascriptFunction("ntp.appMoved", app_info); | 314 web_ui()->CallJavascriptFunctionUnsafe("ntp.appMoved", app_info); |
| 315 } else { | 315 } else { |
| 316 HandleGetApps(NULL); | 316 HandleGetApps(NULL); |
| 317 } | 317 } |
| 318 break; | 318 break; |
| 319 } | 319 } |
| 320 case extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR: { | 320 case extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR: { |
| 321 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); | 321 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); |
| 322 if (!Profile::FromWebUI(web_ui())->IsSameProfile( | 322 if (!Profile::FromWebUI(web_ui())->IsSameProfile( |
| 323 crx_installer->profile())) { | 323 crx_installer->profile())) { |
| 324 return; | 324 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 342 | 342 |
| 343 std::unique_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 343 std::unique_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
| 344 if (!app_info.get()) | 344 if (!app_info.get()) |
| 345 return; | 345 return; |
| 346 | 346 |
| 347 visible_apps_.insert(extension->id()); | 347 visible_apps_.insert(extension->id()); |
| 348 ExtensionPrefs* prefs = ExtensionPrefs::Get(extension_service_->profile()); | 348 ExtensionPrefs* prefs = ExtensionPrefs::Get(extension_service_->profile()); |
| 349 base::FundamentalValue highlight(prefs->IsFromBookmark(extension->id()) && | 349 base::FundamentalValue highlight(prefs->IsFromBookmark(extension->id()) && |
| 350 attempted_bookmark_app_install_); | 350 attempted_bookmark_app_install_); |
| 351 attempted_bookmark_app_install_ = false; | 351 attempted_bookmark_app_install_ = false; |
| 352 web_ui()->CallJavascriptFunction("ntp.appAdded", *app_info, highlight); | 352 web_ui()->CallJavascriptFunctionUnsafe("ntp.appAdded", *app_info, highlight); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void AppLauncherHandler::OnExtensionUnloaded( | 355 void AppLauncherHandler::OnExtensionUnloaded( |
| 356 content::BrowserContext* browser_context, | 356 content::BrowserContext* browser_context, |
| 357 const Extension* extension, | 357 const Extension* extension, |
| 358 extensions::UnloadedExtensionInfo::Reason reason) { | 358 extensions::UnloadedExtensionInfo::Reason reason) { |
| 359 AppRemoved(extension, false); | 359 AppRemoved(extension, false); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void AppLauncherHandler::OnExtensionUninstalled( | 362 void AppLauncherHandler::OnExtensionUninstalled( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 443 |
| 444 const ExtensionSet& terminated_set = registry->terminated_extensions(); | 444 const ExtensionSet& terminated_set = registry->terminated_extensions(); |
| 445 for (ExtensionSet::const_iterator it = terminated_set.begin(); | 445 for (ExtensionSet::const_iterator it = terminated_set.begin(); |
| 446 it != terminated_set.end(); ++it) { | 446 it != terminated_set.end(); ++it) { |
| 447 visible_apps_.insert((*it)->id()); | 447 visible_apps_.insert((*it)->id()); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 SetAppToBeHighlighted(); | 451 SetAppToBeHighlighted(); |
| 452 FillAppDictionary(&dictionary); | 452 FillAppDictionary(&dictionary); |
| 453 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); | 453 web_ui()->CallJavascriptFunctionUnsafe("ntp.getAppsCallback", dictionary); |
| 454 | 454 |
| 455 // First time we get here we set up the observer so that we can tell update | 455 // First time we get here we set up the observer so that we can tell update |
| 456 // the apps as they change. | 456 // the apps as they change. |
| 457 if (!has_loaded_apps_) { | 457 if (!has_loaded_apps_) { |
| 458 base::Closure callback = base::Bind( | 458 base::Closure callback = base::Bind( |
| 459 &AppLauncherHandler::OnExtensionPreferenceChanged, | 459 &AppLauncherHandler::OnExtensionPreferenceChanged, |
| 460 base::Unretained(this)); | 460 base::Unretained(this)); |
| 461 extension_pref_change_registrar_.Init( | 461 extension_pref_change_registrar_.Init( |
| 462 ExtensionPrefs::Get(profile)->pref_service()); | 462 ExtensionPrefs::Get(profile)->pref_service()); |
| 463 extension_pref_change_registrar_.Add( | 463 extension_pref_change_registrar_.Add( |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 installer->set_page_ordinal(install_info->page_ordinal); | 777 installer->set_page_ordinal(install_info->page_ordinal); |
| 778 installer->InstallWebApp(*web_app); | 778 installer->InstallWebApp(*web_app); |
| 779 attempted_bookmark_app_install_ = true; | 779 attempted_bookmark_app_install_ = true; |
| 780 } | 780 } |
| 781 | 781 |
| 782 void AppLauncherHandler::SetAppToBeHighlighted() { | 782 void AppLauncherHandler::SetAppToBeHighlighted() { |
| 783 if (highlight_app_id_.empty()) | 783 if (highlight_app_id_.empty()) |
| 784 return; | 784 return; |
| 785 | 785 |
| 786 base::StringValue app_id(highlight_app_id_); | 786 base::StringValue app_id(highlight_app_id_); |
| 787 web_ui()->CallJavascriptFunction("ntp.setAppToBeHighlighted", app_id); | 787 web_ui()->CallJavascriptFunctionUnsafe("ntp.setAppToBeHighlighted", app_id); |
| 788 highlight_app_id_.clear(); | 788 highlight_app_id_.clear(); |
| 789 } | 789 } |
| 790 | 790 |
| 791 void AppLauncherHandler::OnExtensionPreferenceChanged() { | 791 void AppLauncherHandler::OnExtensionPreferenceChanged() { |
| 792 base::DictionaryValue dictionary; | 792 base::DictionaryValue dictionary; |
| 793 FillAppDictionary(&dictionary); | 793 FillAppDictionary(&dictionary); |
| 794 web_ui()->CallJavascriptFunction("ntp.appsPrefChangeCallback", dictionary); | 794 web_ui()->CallJavascriptFunctionUnsafe("ntp.appsPrefChangeCallback", |
| 795 dictionary); |
| 795 } | 796 } |
| 796 | 797 |
| 797 void AppLauncherHandler::OnLocalStatePreferenceChanged() { | 798 void AppLauncherHandler::OnLocalStatePreferenceChanged() { |
| 798 #if defined(ENABLE_APP_LIST) | 799 #if defined(ENABLE_APP_LIST) |
| 799 web_ui()->CallJavascriptFunction( | 800 web_ui()->CallJavascriptFunctionUnsafe( |
| 800 "ntp.appLauncherPromoPrefChangeCallback", | 801 "ntp.appLauncherPromoPrefChangeCallback", |
| 801 base::FundamentalValue(g_browser_process->local_state()->GetBoolean( | 802 base::FundamentalValue(g_browser_process->local_state()->GetBoolean( |
| 802 prefs::kShowAppLauncherPromo))); | 803 prefs::kShowAppLauncherPromo))); |
| 803 #endif | 804 #endif |
| 804 } | 805 } |
| 805 | 806 |
| 806 void AppLauncherHandler::CleanupAfterUninstall() { | 807 void AppLauncherHandler::CleanupAfterUninstall() { |
| 807 extension_id_prompting_.clear(); | 808 extension_id_prompting_.clear(); |
| 808 } | 809 } |
| 809 | 810 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 824 } | 825 } |
| 825 | 826 |
| 826 void AppLauncherHandler::ExtensionEnableFlowFinished() { | 827 void AppLauncherHandler::ExtensionEnableFlowFinished() { |
| 827 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); | 828 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); |
| 828 | 829 |
| 829 // We bounce this off the NTP so the browser can update the apps icon. | 830 // We bounce this off the NTP so the browser can update the apps icon. |
| 830 // If we don't launch the app asynchronously, then the app's disabled | 831 // If we don't launch the app asynchronously, then the app's disabled |
| 831 // icon disappears but isn't replaced by the enabled icon, making a poor | 832 // icon disappears but isn't replaced by the enabled icon, making a poor |
| 832 // visual experience. | 833 // visual experience. |
| 833 base::StringValue app_id(extension_id_prompting_); | 834 base::StringValue app_id(extension_id_prompting_); |
| 834 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); | 835 web_ui()->CallJavascriptFunctionUnsafe("ntp.launchAppAfterEnable", app_id); |
| 835 | 836 |
| 836 extension_enable_flow_.reset(); | 837 extension_enable_flow_.reset(); |
| 837 extension_id_prompting_ = ""; | 838 extension_id_prompting_ = ""; |
| 838 } | 839 } |
| 839 | 840 |
| 840 void AppLauncherHandler::ExtensionEnableFlowAborted(bool user_initiated) { | 841 void AppLauncherHandler::ExtensionEnableFlowAborted(bool user_initiated) { |
| 841 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); | 842 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); |
| 842 | 843 |
| 843 // We record the histograms here because ExtensionUninstallCanceled is also | 844 // We record the histograms here because ExtensionUninstallCanceled is also |
| 844 // called when the extension uninstall dialog is canceled. | 845 // called when the extension uninstall dialog is canceled. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 869 | 870 |
| 870 void AppLauncherHandler::AppRemoved(const Extension* extension, | 871 void AppLauncherHandler::AppRemoved(const Extension* extension, |
| 871 bool is_uninstall) { | 872 bool is_uninstall) { |
| 872 if (!ShouldShow(extension)) | 873 if (!ShouldShow(extension)) |
| 873 return; | 874 return; |
| 874 | 875 |
| 875 std::unique_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 876 std::unique_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
| 876 if (!app_info.get()) | 877 if (!app_info.get()) |
| 877 return; | 878 return; |
| 878 | 879 |
| 879 web_ui()->CallJavascriptFunction( | 880 web_ui()->CallJavascriptFunctionUnsafe( |
| 880 "ntp.appRemoved", *app_info, base::FundamentalValue(is_uninstall), | 881 "ntp.appRemoved", *app_info, base::FundamentalValue(is_uninstall), |
| 881 base::FundamentalValue(!extension_id_prompting_.empty())); | 882 base::FundamentalValue(!extension_id_prompting_.empty())); |
| 882 } | 883 } |
| 883 | 884 |
| 884 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { | 885 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { |
| 885 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) | 886 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) |
| 886 return false; | 887 return false; |
| 887 | 888 |
| 888 Profile* profile = Profile::FromWebUI(web_ui()); | 889 Profile* profile = Profile::FromWebUI(web_ui()); |
| 889 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); | 890 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); |
| 890 } | 891 } |
| OLD | NEW |