OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 if (!extension_id_prompting_.empty()) | 635 if (!extension_id_prompting_.empty()) |
636 return; // Only one prompt at a time. | 636 return; // Only one prompt at a time. |
637 | 637 |
638 extension_id_prompting_ = extension_id; | 638 extension_id_prompting_ = extension_id; |
639 | 639 |
640 bool dont_confirm = false; | 640 bool dont_confirm = false; |
641 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { | 641 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { |
642 scoped_ptr<AutoReset<bool> > auto_reset; | 642 scoped_ptr<AutoReset<bool> > auto_reset; |
643 if (NewTabUI::NTP4Enabled()) | 643 if (NewTabUI::NTP4Enabled()) |
644 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 644 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
645 ExtensionDialogAccepted(); | 645 ExtensionUninstallAccepted(); |
646 } else { | 646 } else { |
647 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); | 647 GetExtensionUninstallDialog()->ConfirmUninstall(extension); |
648 } | 648 } |
649 } | 649 } |
650 | 650 |
651 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 651 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
652 // If the user has intentionally hidden the promotion, we'll uninstall all the | 652 // If the user has intentionally hidden the promotion, we'll uninstall all the |
653 // default apps (we know the user hasn't installed any apps on their own at | 653 // default apps (we know the user hasn't installed any apps on their own at |
654 // this point, or the promotion wouldn't have been shown). | 654 // this point, or the promotion wouldn't have been shown). |
655 // TODO(estade): this isn't used right now as we sort out the future of the | 655 // TODO(estade): this isn't used right now as we sort out the future of the |
656 // apps promo on ntp4. | 656 // apps promo on ntp4. |
657 if (NewTabUI::NTP4Enabled()) { | 657 if (NewTabUI::NTP4Enabled()) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 return; | 906 return; |
907 } | 907 } |
908 | 908 |
909 if (!extension_id_prompting_.empty()) | 909 if (!extension_id_prompting_.empty()) |
910 return; // Only one prompt at a time. | 910 return; // Only one prompt at a time. |
911 | 911 |
912 extension_id_prompting_ = extension_id; | 912 extension_id_prompting_ = extension_id; |
913 GetExtensionInstallUI()->ConfirmReEnable(this, extension); | 913 GetExtensionInstallUI()->ConfirmReEnable(this, extension); |
914 } | 914 } |
915 | 915 |
916 void AppLauncherHandler::ExtensionDialogAccepted() { | 916 void AppLauncherHandler::ExtensionUninstallAccepted() { |
917 // Do the uninstall work here. | 917 // Do the uninstall work here. |
918 DCHECK(!extension_id_prompting_.empty()); | 918 DCHECK(!extension_id_prompting_.empty()); |
919 | 919 |
920 // The extension can be uninstalled in another window while the UI was | 920 // The extension can be uninstalled in another window while the UI was |
921 // showing. Do nothing in that case. | 921 // showing. Do nothing in that case. |
922 const Extension* extension = | 922 const Extension* extension = |
923 extension_service_->GetExtensionById(extension_id_prompting_, true); | 923 extension_service_->GetExtensionById(extension_id_prompting_, true); |
924 if (!extension) | 924 if (!extension) |
925 return; | 925 return; |
926 | 926 |
927 extension_service_->UninstallExtension(extension_id_prompting_, | 927 extension_service_->UninstallExtension(extension_id_prompting_, |
928 false /* external_uninstall */, NULL); | 928 false /* external_uninstall */, NULL); |
929 | 929 |
930 extension_id_prompting_ = ""; | 930 extension_id_prompting_ = ""; |
931 } | 931 } |
932 | 932 |
933 void AppLauncherHandler::ExtensionDialogCanceled() { | 933 void AppLauncherHandler::ExtensionUninstallCanceled() { |
934 extension_id_prompting_ = ""; | 934 extension_id_prompting_ = ""; |
935 } | 935 } |
936 | 936 |
937 void AppLauncherHandler::InstallUIProceed() { | 937 void AppLauncherHandler::InstallUIProceed() { |
938 // Do the re-enable work here. | 938 // Do the re-enable work here. |
939 DCHECK(!extension_id_prompting_.empty()); | 939 DCHECK(!extension_id_prompting_.empty()); |
940 | 940 |
941 // The extension can be uninstalled in another window while the UI was | 941 // The extension can be uninstalled in another window while the UI was |
942 // showing. Do nothing in that case. | 942 // showing. Do nothing in that case. |
943 const Extension* extension = | 943 const Extension* extension = |
944 extension_service_->GetExtensionById(extension_id_prompting_, true); | 944 extension_service_->GetExtensionById(extension_id_prompting_, true); |
945 if (!extension) | 945 if (!extension) |
946 return; | 946 return; |
947 | 947 |
948 extension_service_->GrantPermissionsAndEnableExtension(extension); | 948 extension_service_->GrantPermissionsAndEnableExtension(extension); |
949 | 949 |
950 // We bounce this off the NTP so the browser can update the apps icon. | 950 // We bounce this off the NTP so the browser can update the apps icon. |
951 // If we don't launch the app asynchronously, then the app's disabled | 951 // If we don't launch the app asynchronously, then the app's disabled |
952 // icon disappears but isn't replaced by the enabled icon, making a poor | 952 // icon disappears but isn't replaced by the enabled icon, making a poor |
953 // visual experience. | 953 // visual experience. |
954 scoped_ptr<StringValue> app_id(Value::CreateStringValue(extension->id())); | 954 scoped_ptr<StringValue> app_id(Value::CreateStringValue(extension->id())); |
955 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 955 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
956 | 956 |
957 extension_id_prompting_ = ""; | 957 extension_id_prompting_ = ""; |
958 } | 958 } |
959 | 959 |
960 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { | 960 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { |
961 // We record the histograms here because ExtensionDialogCanceled is also | 961 // We record the histograms here because ExtensionUninstallCanceled is also |
962 // called when the extension uninstall dialog is canceled. | 962 // called when the extension uninstall dialog is canceled. |
963 const Extension* extension = | 963 const Extension* extension = |
964 extension_service_->GetExtensionById(extension_id_prompting_, true); | 964 extension_service_->GetExtensionById(extension_id_prompting_, true); |
965 std::string histogram_name = user_initiated ? | 965 std::string histogram_name = user_initiated ? |
966 "Extensions.Permissions_ReEnableCancel" : | 966 "Extensions.Permissions_ReEnableCancel" : |
967 "Extensions.Permissions_ReEnableAbort"; | 967 "Extensions.Permissions_ReEnableAbort"; |
968 ExtensionService::RecordPermissionMessagesHistogram( | 968 ExtensionService::RecordPermissionMessagesHistogram( |
969 extension, histogram_name.c_str()); | 969 extension, histogram_name.c_str()); |
970 | 970 |
971 ExtensionDialogCanceled(); | 971 ExtensionUninstallCanceled(); |
972 } | 972 } |
973 | 973 |
974 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 974 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
975 if (!extension_uninstall_dialog_.get()) { | 975 if (!extension_uninstall_dialog_.get()) { |
976 extension_uninstall_dialog_.reset( | 976 extension_uninstall_dialog_.reset( |
977 new ExtensionUninstallDialog(Profile::FromWebUI(web_ui_))); | 977 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui_), this)); |
978 } | 978 } |
979 return extension_uninstall_dialog_.get(); | 979 return extension_uninstall_dialog_.get(); |
980 } | 980 } |
981 | 981 |
982 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 982 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
983 if (!extension_install_ui_.get()) { | 983 if (!extension_install_ui_.get()) { |
984 extension_install_ui_.reset( | 984 extension_install_ui_.reset( |
985 new ExtensionInstallUI(Profile::FromWebUI(web_ui_))); | 985 new ExtensionInstallUI(Profile::FromWebUI(web_ui_))); |
986 } | 986 } |
987 return extension_install_ui_.get(); | 987 return extension_install_ui_.get(); |
988 } | 988 } |
989 | 989 |
990 void AppLauncherHandler::UninstallDefaultApps() { | 990 void AppLauncherHandler::UninstallDefaultApps() { |
991 AppsPromo* apps_promo = extension_service_->apps_promo(); | 991 AppsPromo* apps_promo = extension_service_->apps_promo(); |
992 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 992 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
993 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 993 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
994 iter != app_ids.end(); ++iter) { | 994 iter != app_ids.end(); ++iter) { |
995 if (extension_service_->GetExtensionById(*iter, true)) | 995 if (extension_service_->GetExtensionById(*iter, true)) |
996 extension_service_->UninstallExtension(*iter, false, NULL); | 996 extension_service_->UninstallExtension(*iter, false, NULL); |
997 } | 997 } |
998 } | 998 } |
OLD | NEW |