| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 content::Details<UnloadedExtensionInfo>(details)->extension; | 298 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 299 if (!extension->is_app()) | 299 if (!extension->is_app()) |
| 300 return; | 300 return; |
| 301 | 301 |
| 302 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 302 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
| 303 scoped_ptr<base::FundamentalValue> uninstall_value( | 303 scoped_ptr<base::FundamentalValue> uninstall_value( |
| 304 Value::CreateBooleanValue( | 304 Value::CreateBooleanValue( |
| 305 content::Details<UnloadedExtensionInfo>(details)->reason == | 305 content::Details<UnloadedExtensionInfo>(details)->reason == |
| 306 extension_misc::UNLOAD_REASON_UNINSTALL)); | 306 extension_misc::UNLOAD_REASON_UNINSTALL)); |
| 307 if (app_info.get()) { | 307 if (app_info.get()) { |
| 308 scoped_ptr<base::FundamentalValue> from_page( |
| 309 Value::CreateBooleanValue(!extension_id_prompting_.empty())); |
| 308 web_ui()->CallJavascriptFunction( | 310 web_ui()->CallJavascriptFunction( |
| 309 "ntp4.appRemoved", *app_info, *uninstall_value); | 311 "ntp4.appRemoved", *app_info, *uninstall_value, *from_page); |
| 310 } | 312 } |
| 311 break; | 313 break; |
| 312 } | 314 } |
| 313 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: | 315 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: |
| 314 // The promo may not load until a couple seconds after the first NTP view, | 316 // The promo may not load until a couple seconds after the first NTP view, |
| 315 // so we listen for the load notification and notify the NTP when ready. | 317 // so we listen for the load notification and notify the NTP when ready. |
| 316 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: | 318 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: |
| 317 // TODO(estade): try to get rid of this inefficient operation. | 319 // TODO(estade): Try to get rid of this inefficient operation. |
| 318 HandleGetApps(NULL); | 320 HandleGetApps(NULL); |
| 319 break; | 321 break; |
| 320 case chrome::NOTIFICATION_PREF_CHANGED: { | 322 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 321 DictionaryValue dictionary; | 323 DictionaryValue dictionary; |
| 322 FillAppDictionary(&dictionary); | 324 FillAppDictionary(&dictionary); |
| 323 web_ui()->CallJavascriptFunction("appsPrefChangeCallback", dictionary); | 325 web_ui()->CallJavascriptFunction("appsPrefChangeCallback", dictionary); |
| 324 break; | 326 break; |
| 325 } | 327 } |
| 326 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { | 328 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { |
| 327 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); | 329 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); |
| 328 if (!Profile::FromWebUI(web_ui())->IsSameProfile( | 330 if (!Profile::FromWebUI(web_ui())->IsSameProfile( |
| 329 crx_installer->profile())) { | 331 crx_installer->profile())) { |
| 330 return; | 332 return; |
| 331 } | 333 } |
| 332 // Fall Through. | 334 // Fall through. |
| 333 } | 335 } |
| 334 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { | 336 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { |
| 335 attempted_bookmark_app_install_ = false; | 337 attempted_bookmark_app_install_ = false; |
| 336 break; | 338 break; |
| 337 } | 339 } |
| 338 default: | 340 default: |
| 339 NOTREACHED(); | 341 NOTREACHED(); |
| 340 } | 342 } |
| 341 } | 343 } |
| 342 | 344 |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 highlight_app_id_.clear(); | 837 highlight_app_id_.clear(); |
| 836 } | 838 } |
| 837 | 839 |
| 838 // static | 840 // static |
| 839 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { | 841 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 840 // TODO(csharp): We will want this to be a syncable preference instead. | 842 // TODO(csharp): We will want this to be a syncable preference instead. |
| 841 pref_service->RegisterListPref(prefs::kNTPAppPageNames, | 843 pref_service->RegisterListPref(prefs::kNTPAppPageNames, |
| 842 PrefService::UNSYNCABLE_PREF); | 844 PrefService::UNSYNCABLE_PREF); |
| 843 } | 845 } |
| 844 | 846 |
| 847 void AppLauncherHandler::CleanupAfterUninstall() { |
| 848 extension_id_prompting_.clear(); |
| 849 } |
| 850 |
| 845 // static | 851 // static |
| 846 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { | 852 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { |
| 847 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, | 853 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 848 extension_misc::APP_LAUNCH_NTP_WEBSTORE, | 854 extension_misc::APP_LAUNCH_NTP_WEBSTORE, |
| 849 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 855 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 850 | 856 |
| 851 if (!promo_active) return; | 857 if (!promo_active) return; |
| 852 | 858 |
| 853 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 859 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 854 extension_misc::PROMO_LAUNCH_WEB_STORE, | 860 extension_misc::PROMO_LAUNCH_WEB_STORE, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 926 |
| 921 // The extension can be uninstalled in another window while the UI was | 927 // The extension can be uninstalled in another window while the UI was |
| 922 // showing. Do nothing in that case. | 928 // showing. Do nothing in that case. |
| 923 const Extension* extension = | 929 const Extension* extension = |
| 924 extension_service_->GetExtensionById(extension_id_prompting_, true); | 930 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 925 if (!extension) | 931 if (!extension) |
| 926 return; | 932 return; |
| 927 | 933 |
| 928 extension_service_->UninstallExtension(extension_id_prompting_, | 934 extension_service_->UninstallExtension(extension_id_prompting_, |
| 929 false /* external_uninstall */, NULL); | 935 false /* external_uninstall */, NULL); |
| 930 | 936 CleanupAfterUninstall(); |
| 931 extension_id_prompting_ = ""; | |
| 932 } | 937 } |
| 933 | 938 |
| 934 void AppLauncherHandler::ExtensionUninstallCanceled() { | 939 void AppLauncherHandler::ExtensionUninstallCanceled() { |
| 935 extension_id_prompting_ = ""; | 940 CleanupAfterUninstall(); |
| 936 } | 941 } |
| 937 | 942 |
| 938 void AppLauncherHandler::InstallUIProceed() { | 943 void AppLauncherHandler::InstallUIProceed() { |
| 939 // Do the re-enable work here. | 944 // Do the re-enable work here. |
| 940 DCHECK(!extension_id_prompting_.empty()); | 945 DCHECK(!extension_id_prompting_.empty()); |
| 941 | 946 |
| 942 // The extension can be uninstalled in another window while the UI was | 947 // The extension can be uninstalled in another window while the UI was |
| 943 // showing. Do nothing in that case. | 948 // showing. Do nothing in that case. |
| 944 const Extension* extension = | 949 const Extension* extension = |
| 945 extension_service_->GetExtensionById(extension_id_prompting_, true); | 950 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 962 // We record the histograms here because ExtensionUninstallCanceled is also | 967 // We record the histograms here because ExtensionUninstallCanceled is also |
| 963 // called when the extension uninstall dialog is canceled. | 968 // called when the extension uninstall dialog is canceled. |
| 964 const Extension* extension = | 969 const Extension* extension = |
| 965 extension_service_->GetExtensionById(extension_id_prompting_, true); | 970 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 966 std::string histogram_name = user_initiated ? | 971 std::string histogram_name = user_initiated ? |
| 967 "Extensions.Permissions_ReEnableCancel" : | 972 "Extensions.Permissions_ReEnableCancel" : |
| 968 "Extensions.Permissions_ReEnableAbort"; | 973 "Extensions.Permissions_ReEnableAbort"; |
| 969 ExtensionService::RecordPermissionMessagesHistogram( | 974 ExtensionService::RecordPermissionMessagesHistogram( |
| 970 extension, histogram_name.c_str()); | 975 extension, histogram_name.c_str()); |
| 971 | 976 |
| 972 ExtensionUninstallCanceled(); | 977 CleanupAfterUninstall(); |
| 973 } | 978 } |
| 974 | 979 |
| 975 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 980 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
| 976 if (!extension_uninstall_dialog_.get()) { | 981 if (!extension_uninstall_dialog_.get()) { |
| 977 extension_uninstall_dialog_.reset( | 982 extension_uninstall_dialog_.reset( |
| 978 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); | 983 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); |
| 979 } | 984 } |
| 980 return extension_uninstall_dialog_.get(); | 985 return extension_uninstall_dialog_.get(); |
| 981 } | 986 } |
| 982 | 987 |
| 983 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 988 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
| 984 if (!extension_install_ui_.get()) { | 989 if (!extension_install_ui_.get()) { |
| 985 extension_install_ui_.reset( | 990 extension_install_ui_.reset( |
| 986 new ExtensionInstallUI(Profile::FromWebUI(web_ui()))); | 991 new ExtensionInstallUI(Profile::FromWebUI(web_ui()))); |
| 987 } | 992 } |
| 988 return extension_install_ui_.get(); | 993 return extension_install_ui_.get(); |
| 989 } | 994 } |
| 990 | 995 |
| 991 void AppLauncherHandler::UninstallDefaultApps() { | 996 void AppLauncherHandler::UninstallDefaultApps() { |
| 992 AppsPromo* apps_promo = extension_service_->apps_promo(); | 997 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 993 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 998 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 994 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 999 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 995 iter != app_ids.end(); ++iter) { | 1000 iter != app_ids.end(); ++iter) { |
| 996 if (extension_service_->GetExtensionById(*iter, true)) | 1001 if (extension_service_->GetExtensionById(*iter, true)) |
| 997 extension_service_->UninstallExtension(*iter, false, NULL); | 1002 extension_service_->UninstallExtension(*iter, false, NULL); |
| 998 } | 1003 } |
| 999 } | 1004 } |
| OLD | NEW |