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

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

Issue 11644077: Put extension enable logic into a ExtensionEnableFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + address comments in #1 Created 7 years, 11 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
13 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
14 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
15 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 16 #include "base/values.h"
18 #include "chrome/browser/extensions/app_notification.h" 17 #include "chrome/browser/extensions/app_notification.h"
19 #include "chrome/browser/extensions/app_notification_manager.h" 18 #include "chrome/browser/extensions/app_notification_manager.h"
20 #include "chrome/browser/extensions/crx_installer.h" 19 #include "chrome/browser/extensions/crx_installer.h"
21 #include "chrome/browser/extensions/extension_prefs.h" 20 #include "chrome/browser/extensions/extension_prefs.h"
22 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_sorting.h" 22 #include "chrome/browser/extensions/extension_sorting.h"
24 #include "chrome/browser/extensions/extension_system.h" 23 #include "chrome/browser/extensions/extension_system.h"
25 #include "chrome/browser/extensions/management_policy.h" 24 #include "chrome/browser/extensions/management_policy.h"
26 #include "chrome/browser/favicon/favicon_service_factory.h" 25 #include "chrome/browser/favicon/favicon_service_factory.h"
27 #include "chrome/browser/prefs/pref_service.h" 26 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/prefs/scoped_user_pref_update.h" 27 #include "chrome/browser/prefs/scoped_user_pref_update.h"
29 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
31 #include "chrome/browser/ui/browser_tabstrip.h" 30 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/extensions/application_launch.h" 32 #include "chrome/browser/ui/extensions/application_launch.h"
33 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
34 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 34 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
35 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 35 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
36 #include "chrome/browser/ui/webui/web_ui_util.h" 36 #include "chrome/browser/ui/webui/web_ui_util.h"
37 #include "chrome/common/chrome_notification_types.h" 37 #include "chrome/common/chrome_notification_types.h"
38 #include "chrome/common/extensions/extension.h" 38 #include "chrome/common/extensions/extension.h"
39 #include "chrome/common/extensions/extension_constants.h" 39 #include "chrome/common/extensions/extension_constants.h"
40 #include "chrome/common/extensions/extension_icon_set.h" 40 #include "chrome/common/extensions/extension_icon_set.h"
41 #include "chrome/common/extensions/extension_resource.h" 41 #include "chrome/common/extensions/extension_resource.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 817
818 GURL url(net::UnescapeURLComponent(escaped_url, kUnescapeRules)); 818 GURL url(net::UnescapeURLComponent(escaped_url, kUnescapeRules));
819 DCHECK(profile->GetExtensionService()); 819 DCHECK(profile->GetExtensionService());
820 if (!profile->GetExtensionService()->IsInstalledApp(url)) 820 if (!profile->GetExtensionService()->IsInstalledApp(url))
821 return; 821 return;
822 822
823 RecordAppLaunchType(bucket); 823 RecordAppLaunchType(bucket);
824 } 824 }
825 825
826 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { 826 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) {
827 const Extension* extension =
828 extension_service_->GetExtensionById(extension_id, true);
829 if (!extension) {
830 extension = extension_service_->GetTerminatedExtension(extension_id);
831 // It's possible (though unlikely) the app could have been uninstalled since
832 // the user clicked on it.
833 if (!extension)
834 return;
835 // If the app was terminated, reload it first. (This reallocates the
836 // Extension object.)
837 extension_service_->ReloadExtension(extension_id);
838 extension = extension_service_->GetExtensionById(extension_id, true);
839 }
840
841 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs();
842 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) {
843 // Enable the extension immediately if its privileges weren't escalated.
844 // This is a no-op if the extension was previously terminated.
845 extension_service_->EnableExtension(extension_id);
846
847 // Launch app asynchronously so the image will update.
848 StringValue app_id(extension_id);
849 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id);
850 return;
851 }
852
853 if (!extension_id_prompting_.empty()) 827 if (!extension_id_prompting_.empty())
854 return; // Only one prompt at a time. 828 return; // Only one prompt at a time.
855 829
856 extension_id_prompting_ = extension_id; 830 extension_id_prompting_ = extension_id;
857 GetExtensionInstallPrompt()->ConfirmReEnable(this, extension); 831 extension_enable_flow_.reset(new ExtensionEnableFlow(
832 Profile::FromWebUI(web_ui()), extension_id, this));
833 extension_enable_flow_->Start();
858 } 834 }
859 835
860 void AppLauncherHandler::ExtensionUninstallAccepted() { 836 void AppLauncherHandler::ExtensionUninstallAccepted() {
861 // Do the uninstall work here. 837 // Do the uninstall work here.
862 DCHECK(!extension_id_prompting_.empty()); 838 DCHECK(!extension_id_prompting_.empty());
863 839
864 // The extension can be uninstalled in another window while the UI was 840 // The extension can be uninstalled in another window while the UI was
865 // showing. Do nothing in that case. 841 // showing. Do nothing in that case.
866 const Extension* extension = 842 const Extension* extension =
867 extension_service_->GetExtensionById(extension_id_prompting_, true); 843 extension_service_->GetExtensionById(extension_id_prompting_, true);
868 if (!extension) 844 if (!extension)
869 return; 845 return;
870 846
871 extension_service_->UninstallExtension(extension_id_prompting_, 847 extension_service_->UninstallExtension(extension_id_prompting_,
872 false /* external_uninstall */, NULL); 848 false /* external_uninstall */, NULL);
873 CleanupAfterUninstall(); 849 CleanupAfterUninstall();
874 } 850 }
875 851
876 void AppLauncherHandler::ExtensionUninstallCanceled() { 852 void AppLauncherHandler::ExtensionUninstallCanceled() {
877 CleanupAfterUninstall(); 853 CleanupAfterUninstall();
878 } 854 }
879 855
880 void AppLauncherHandler::InstallUIProceed() { 856 ExtensionInstallPrompt* AppLauncherHandler::CreateExtensionInstallPrompt() {
881 // Do the re-enable work here. 857 return new ExtensionInstallPrompt(web_ui()->GetWebContents());
882 DCHECK(!extension_id_prompting_.empty()); 858 }
883 859
884 // The extension can be uninstalled in another window while the UI was 860 void AppLauncherHandler::ExtensionEnableFlowFinished() {
885 // showing. Do nothing in that case. 861 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id());
886 const Extension* extension =
887 extension_service_->GetExtensionById(extension_id_prompting_, true);
888 if (!extension)
889 return;
890
891 extension_service_->GrantPermissionsAndEnableExtension(
892 extension, extension_install_ui_->record_oauth2_grant());
893 862
894 // We bounce this off the NTP so the browser can update the apps icon. 863 // We bounce this off the NTP so the browser can update the apps icon.
895 // If we don't launch the app asynchronously, then the app's disabled 864 // If we don't launch the app asynchronously, then the app's disabled
896 // icon disappears but isn't replaced by the enabled icon, making a poor 865 // icon disappears but isn't replaced by the enabled icon, making a poor
897 // visual experience. 866 // visual experience.
898 StringValue app_id(extension->id()); 867 StringValue app_id(extension_id_prompting_);
899 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); 868 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id);
900 869
870 extension_enable_flow_.reset();
901 extension_id_prompting_ = ""; 871 extension_id_prompting_ = "";
902 } 872 }
903 873
904 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { 874 void AppLauncherHandler::ExtensionEnableFlowAborted(bool user_initiated) {
875 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id());
876
905 // We record the histograms here because ExtensionUninstallCanceled is also 877 // We record the histograms here because ExtensionUninstallCanceled is also
906 // called when the extension uninstall dialog is canceled. 878 // called when the extension uninstall dialog is canceled.
907 const Extension* extension = 879 const Extension* extension =
908 extension_service_->GetExtensionById(extension_id_prompting_, true); 880 extension_service_->GetExtensionById(extension_id_prompting_, true);
909 std::string histogram_name = user_initiated ? 881 std::string histogram_name = user_initiated ?
910 "Extensions.Permissions_ReEnableCancel" : 882 "Extensions.Permissions_ReEnableCancel" :
911 "Extensions.Permissions_ReEnableAbort"; 883 "Extensions.Permissions_ReEnableAbort";
912 ExtensionService::RecordPermissionMessagesHistogram( 884 ExtensionService::RecordPermissionMessagesHistogram(
913 extension, histogram_name.c_str()); 885 extension, histogram_name.c_str());
914 886
887 extension_enable_flow_.reset();
915 CleanupAfterUninstall(); 888 CleanupAfterUninstall();
916 } 889 }
917 890
918 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { 891 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() {
919 if (!extension_uninstall_dialog_.get()) { 892 if (!extension_uninstall_dialog_.get()) {
920 Browser* browser = chrome::FindBrowserWithWebContents( 893 Browser* browser = chrome::FindBrowserWithWebContents(
921 web_ui()->GetWebContents()); 894 web_ui()->GetWebContents());
922 extension_uninstall_dialog_.reset( 895 extension_uninstall_dialog_.reset(
923 ExtensionUninstallDialog::Create(browser, this)); 896 ExtensionUninstallDialog::Create(browser, this));
924 } 897 }
925 return extension_uninstall_dialog_.get(); 898 return extension_uninstall_dialog_.get();
926 } 899 }
927
928 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() {
929 if (!extension_install_ui_.get()) {
930 extension_install_ui_.reset(
931 new ExtensionInstallPrompt(web_ui()->GetWebContents()));
932 }
933 return extension_install_ui_.get();
934 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698