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> | |
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 Loading... | |
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; |
Evan Stade
2012/12/21 22:45:26
can you get rid of extension_id_prompting_ and jus
xiyuan
2012/12/22 00:35:43
extension_id_prompting_ used to guard both uninsta
Evan Stade
2013/01/02 21:55:38
that's a reasonable explanation. Can you add "(eit
xiyuan
2013/01/07 18:13:12
Done.
| |
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 ExtensionEnableFlow* flow) { |
886 const Extension* extension = | 862 DCHECK_EQ(extension_enable_flow_.get(), flow); |
887 extension_service_->GetExtensionById(extension_id_prompting_, true); | 863 DCHECK_EQ(extension_id_prompting_, flow->extension_id()); |
888 if (!extension) | |
889 return; | |
890 | |
891 extension_service_->GrantPermissionsAndEnableExtension( | |
892 extension, extension_install_ui_->record_oauth2_grant()); | |
893 | 864 |
894 // We bounce this off the NTP so the browser can update the apps icon. | 865 // 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 | 866 // 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 | 867 // icon disappears but isn't replaced by the enabled icon, making a poor |
897 // visual experience. | 868 // visual experience. |
898 StringValue app_id(extension->id()); | 869 StringValue app_id(flow->extension_id()); |
899 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); | 870 web_ui()->CallJavascriptFunction("ntp.launchAppAfterEnable", app_id); |
900 | 871 |
872 extension_enable_flow_.reset(); | |
901 extension_id_prompting_ = ""; | 873 extension_id_prompting_ = ""; |
902 } | 874 } |
903 | 875 |
904 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { | 876 void AppLauncherHandler::ExtensionEnableFlowAborted(ExtensionEnableFlow* flow, |
877 bool user_initiated) { | |
878 DCHECK_EQ(extension_enable_flow_.get(), flow); | |
879 DCHECK_EQ(extension_id_prompting_, flow->extension_id()); | |
880 | |
905 // We record the histograms here because ExtensionUninstallCanceled is also | 881 // We record the histograms here because ExtensionUninstallCanceled is also |
906 // called when the extension uninstall dialog is canceled. | 882 // called when the extension uninstall dialog is canceled. |
907 const Extension* extension = | 883 const Extension* extension = |
908 extension_service_->GetExtensionById(extension_id_prompting_, true); | 884 extension_service_->GetExtensionById(extension_id_prompting_, true); |
909 std::string histogram_name = user_initiated ? | 885 std::string histogram_name = user_initiated ? |
910 "Extensions.Permissions_ReEnableCancel" : | 886 "Extensions.Permissions_ReEnableCancel" : |
911 "Extensions.Permissions_ReEnableAbort"; | 887 "Extensions.Permissions_ReEnableAbort"; |
912 ExtensionService::RecordPermissionMessagesHistogram( | 888 ExtensionService::RecordPermissionMessagesHistogram( |
913 extension, histogram_name.c_str()); | 889 extension, histogram_name.c_str()); |
914 | 890 |
891 extension_enable_flow_.reset(); | |
915 CleanupAfterUninstall(); | 892 CleanupAfterUninstall(); |
916 } | 893 } |
917 | 894 |
918 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 895 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
919 if (!extension_uninstall_dialog_.get()) { | 896 if (!extension_uninstall_dialog_.get()) { |
920 Browser* browser = chrome::FindBrowserWithWebContents( | 897 Browser* browser = chrome::FindBrowserWithWebContents( |
921 web_ui()->GetWebContents()); | 898 web_ui()->GetWebContents()); |
922 extension_uninstall_dialog_.reset( | 899 extension_uninstall_dialog_.reset( |
923 ExtensionUninstallDialog::Create(browser, this)); | 900 ExtensionUninstallDialog::Create(browser, this)); |
924 } | 901 } |
925 return extension_uninstall_dialog_.get(); | 902 return extension_uninstall_dialog_.get(); |
926 } | 903 } |
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 } | |
OLD | NEW |