| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extensions/extension_install_ui.h" | 5 #include "chrome/browser/extensions/extension_install_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 13 #include "chrome/browser/extensions/theme_preview_infobar_delegate.h" | 13 #include "chrome/browser/extensions/theme_preview_infobar_delegate.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 18 #include "grit/generated_resources.h" |
| 18 | 19 |
| 19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 20 #include "app/win_util.h" | 21 #include "app/win_util.h" |
| 21 #elif defined(OS_MACOSX) | 22 #elif defined(OS_MACOSX) |
| 22 #include "base/scoped_cftyperef.h" | 23 #include "base/scoped_cftyperef.h" |
| 23 #include "base/sys_string_conversions.h" | 24 #include "base/sys_string_conversions.h" |
| 24 #include <CoreFoundation/CFUserNotification.h> | 25 #include <CoreFoundation/CFUserNotification.h> |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 28 namespace { |
| 29 |
| 30 static std::wstring GetInstallWarning(Extension* extension) { |
| 31 // If the extension has a plugin, it's easy: the plugin has the most severe |
| 32 // warning. |
| 33 if (!extension->plugins().empty()) |
| 34 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_FULL_ACCESS); |
| 35 |
| 36 // Otherwise, we go in descending order of severity: all hosts, several hosts, |
| 37 // a single host, no hosts. For each of these, we also have a variation of the |
| 38 // message for when api permissions are also requested. |
| 39 if (extension->HasAccessToAllHosts()) { |
| 40 if (extension->api_permissions().empty()) |
| 41 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_ALL_HOSTS); |
| 42 else |
| 43 return l10n_util::GetString( |
| 44 IDS_EXTENSION_PROMPT_WARNING_NEW_ALL_HOSTS_AND_BROWSER); |
| 45 } |
| 46 |
| 47 const std::set<std::string> hosts = extension->GetEffectiveHostPermissions(); |
| 48 if (hosts.size() > 1) { |
| 49 if (extension->api_permissions().empty()) |
| 50 return l10n_util::GetString( |
| 51 IDS_EXTENSION_PROMPT_WARNING_NEW_MULTIPLE_HOSTS); |
| 52 else |
| 53 return l10n_util::GetString( |
| 54 IDS_EXTENSION_PROMPT_WARNING_NEW_MULTIPLE_HOSTS_AND_BROWSER); |
| 55 } |
| 56 |
| 57 if (hosts.size() == 1) { |
| 58 if (extension->api_permissions().empty()) |
| 59 return l10n_util::GetStringF( |
| 60 IDS_EXTENSION_PROMPT_WARNING_NEW_SINGLE_HOST, |
| 61 UTF8ToWide(*hosts.begin())); |
| 62 else |
| 63 return l10n_util::GetStringF( |
| 64 IDS_EXTENSION_PROMPT_WARNING_NEW_SINGLE_HOST_AND_BROWSER, |
| 65 UTF8ToWide(*hosts.begin())); |
| 66 } |
| 67 |
| 68 DCHECK(hosts.size() == 0); |
| 69 if (extension->api_permissions().empty()) |
| 70 return L""; |
| 71 else |
| 72 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); |
| 73 } |
| 74 |
| 75 } |
| 76 |
| 27 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 77 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
| 28 : profile_(profile), ui_loop_(MessageLoop::current()) { | 78 : profile_(profile), ui_loop_(MessageLoop::current()) { |
| 29 } | 79 } |
| 30 | 80 |
| 31 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, | 81 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, |
| 32 Extension* extension, | 82 Extension* extension, |
| 33 SkBitmap* install_icon) { | 83 SkBitmap* install_icon) { |
| 34 DCHECK(ui_loop_ == MessageLoop::current()); | 84 DCHECK(ui_loop_ == MessageLoop::current()); |
| 35 | 85 |
| 36 // We special-case themes to not show any confirm UI. Instead they are | 86 // We special-case themes to not show any confirm UI. Instead they are |
| 37 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 87 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 38 // to allow the user to revert if they don't like it. | 88 // to allow the user to revert if they don't like it. |
| 39 if (extension->IsTheme()) { | 89 if (extension->IsTheme()) { |
| 40 // Remember the current theme in case the user pressed undo. | 90 // Remember the current theme in case the user pressed undo. |
| 41 Extension* previous_theme = profile_->GetTheme(); | 91 Extension* previous_theme = profile_->GetTheme(); |
| 42 if (previous_theme) | 92 if (previous_theme) |
| 43 previous_theme_id_ = previous_theme->id(); | 93 previous_theme_id_ = previous_theme->id(); |
| 44 | 94 |
| 45 delegate->ContinueInstall(); | 95 delegate->ContinueInstall(); |
| 46 return; | 96 return; |
| 47 } | 97 } |
| 48 | 98 |
| 49 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
| 50 ShowExtensionInstallPrompt(profile_, delegate, extension, install_icon); | 100 ShowExtensionInstallPrompt(profile_, delegate, extension, install_icon, |
| 101 GetInstallWarning(extension)); |
| 51 | 102 |
| 52 #elif defined(OS_MACOSX) | 103 #elif defined(OS_MACOSX) |
| 53 // TODO(port): Implement nicer UI. | 104 // TODO(port): Implement nicer UI. |
| 54 // Using CoreFoundation to do this dialog is unimaginably lame but will do | 105 // Using CoreFoundation to do this dialog is unimaginably lame but will do |
| 55 // until the UI is redone. | 106 // until the UI is redone. |
| 56 scoped_cftyperef<CFStringRef> product_name( | 107 scoped_cftyperef<CFStringRef> product_name( |
| 57 base::SysWideToCFStringRef(l10n_util::GetString(IDS_PRODUCT_NAME))); | 108 base::SysWideToCFStringRef(l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 58 CFOptionFlags response; | 109 CFOptionFlags response; |
| 59 if (kCFUserNotificationAlternateResponse == CFUserNotificationDisplayAlert( | 110 if (kCFUserNotificationAlternateResponse == CFUserNotificationDisplayAlert( |
| 60 0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL, | 111 0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 180 |
| 130 // Then either replace that old one or add a new one. | 181 // Then either replace that old one or add a new one. |
| 131 InfoBarDelegate* new_delegate = new ThemePreviewInfobarDelegate(tab_contents, | 182 InfoBarDelegate* new_delegate = new ThemePreviewInfobarDelegate(tab_contents, |
| 132 new_theme->name(), previous_theme_id_); | 183 new_theme->name(), previous_theme_id_); |
| 133 | 184 |
| 134 if (old_delegate) | 185 if (old_delegate) |
| 135 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); | 186 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); |
| 136 else | 187 else |
| 137 tab_contents->AddInfoBar(new_delegate); | 188 tab_contents->AddInfoBar(new_delegate); |
| 138 } | 189 } |
| OLD | NEW |