Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

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

Powered by Google App Engine
This is Rietveld 408576698