| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/external_install_manager.h" | 5 #include "chrome/browser/extensions/external_install_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 for (const auto& extension : | 77 for (const auto& extension : |
| 78 ExtensionRegistry::Get(browser_context)->disabled_extensions()) { | 78 ExtensionRegistry::Get(browser_context)->disabled_extensions()) { |
| 79 if (IsUnacknowledgedExternalExtension(*extension)) | 79 if (IsUnacknowledgedExternalExtension(*extension)) |
| 80 unacknowledged_ids_.insert(extension->id()); | 80 unacknowledged_ids_.insert(extension->id()); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 ExternalInstallManager::~ExternalInstallManager() { | 84 ExternalInstallManager::~ExternalInstallManager() { |
| 85 } | 85 } |
| 86 | 86 |
| 87 | |
| 88 bool ExternalInstallManager::IsPromptingEnabled() { | |
| 89 // Enable this feature on canary on mac. | |
| 90 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) | |
| 91 return GetCurrentChannel() <= version_info::Channel::CANARY; | |
| 92 #else | |
| 93 return FeatureSwitch::prompt_for_external_extensions()->IsEnabled(); | |
| 94 #endif | |
| 95 } | |
| 96 | |
| 97 void ExternalInstallManager::AddExternalInstallError(const Extension* extension, | 87 void ExternalInstallManager::AddExternalInstallError(const Extension* extension, |
| 98 bool is_new_profile) { | 88 bool is_new_profile) { |
| 99 // Error already exists or has been previously shown. | 89 // Error already exists or has been previously shown. |
| 100 if (base::ContainsKey(errors_, extension->id()) || | 90 if (base::ContainsKey(errors_, extension->id()) || |
| 101 shown_ids_.count(extension->id()) > 0) | 91 shown_ids_.count(extension->id()) > 0) |
| 102 return; | 92 return; |
| 103 | 93 |
| 104 ExternalInstallError::AlertType alert_type = | 94 ExternalInstallError::AlertType alert_type = |
| 105 (ManifestURL::UpdatesFromGallery(extension) && !is_new_profile) | 95 (ManifestURL::UpdatesFromGallery(extension) && !is_new_profile) |
| 106 ? ExternalInstallError::BUBBLE_ALERT | 96 ? ExternalInstallError::BUBBLE_ALERT |
| (...skipping 12 matching lines...) Expand all Loading... |
| 119 if (iter->second.get() == currently_visible_install_alert_) | 109 if (iter->second.get() == currently_visible_install_alert_) |
| 120 currently_visible_install_alert_ = nullptr; | 110 currently_visible_install_alert_ = nullptr; |
| 121 errors_.erase(iter); | 111 errors_.erase(iter); |
| 122 unacknowledged_ids_.erase(extension_id); | 112 unacknowledged_ids_.erase(extension_id); |
| 123 UpdateExternalExtensionAlert(); | 113 UpdateExternalExtensionAlert(); |
| 124 } | 114 } |
| 125 } | 115 } |
| 126 | 116 |
| 127 void ExternalInstallManager::UpdateExternalExtensionAlert() { | 117 void ExternalInstallManager::UpdateExternalExtensionAlert() { |
| 128 // If the feature is not enabled do nothing. | 118 // If the feature is not enabled do nothing. |
| 129 if (!IsPromptingEnabled()) | 119 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
| 130 return; | 120 return; |
| 131 | 121 |
| 132 // Look for any extensions that were disabled because of being unacknowledged | 122 // Look for any extensions that were disabled because of being unacknowledged |
| 133 // external extensions. | 123 // external extensions. |
| 134 const ExtensionSet& disabled_extensions = | 124 const ExtensionSet& disabled_extensions = |
| 135 ExtensionRegistry::Get(browser_context_)->disabled_extensions(); | 125 ExtensionRegistry::Get(browser_context_)->disabled_extensions(); |
| 136 for (const auto& id : unacknowledged_ids_) { | 126 for (const auto& id : unacknowledged_ids_) { |
| 137 if (base::ContainsKey(errors_, id) || shown_ids_.count(id) > 0) | 127 if (base::ContainsKey(errors_, id) || shown_ids_.count(id) > 0) |
| 138 continue; | 128 continue; |
| 139 | 129 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void ExternalInstallManager::OnExtensionUninstalled( | 212 void ExternalInstallManager::OnExtensionUninstalled( |
| 223 content::BrowserContext* browser_context, | 213 content::BrowserContext* browser_context, |
| 224 const Extension* extension, | 214 const Extension* extension, |
| 225 extensions::UninstallReason reason) { | 215 extensions::UninstallReason reason) { |
| 226 if (unacknowledged_ids_.erase(extension->id())) | 216 if (unacknowledged_ids_.erase(extension->id())) |
| 227 LogExternalExtensionEvent(extension, EXTERNAL_EXTENSION_UNINSTALLED); | 217 LogExternalExtensionEvent(extension, EXTERNAL_EXTENSION_UNINSTALLED); |
| 228 } | 218 } |
| 229 | 219 |
| 230 bool ExternalInstallManager::IsUnacknowledgedExternalExtension( | 220 bool ExternalInstallManager::IsUnacknowledgedExternalExtension( |
| 231 const Extension& extension) const { | 221 const Extension& extension) const { |
| 232 if (!IsPromptingEnabled()) | 222 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
| 233 return false; | 223 return false; |
| 234 | 224 |
| 235 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); | 225 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); |
| 236 bool is_from_sideload_wipeout = | 226 bool is_from_sideload_wipeout = |
| 237 (disable_reasons & Extension::DISABLE_SIDELOAD_WIPEOUT) != 0; | 227 (disable_reasons & Extension::DISABLE_SIDELOAD_WIPEOUT) != 0; |
| 238 // We don't consider extensions that weren't disabled for being external so | 228 // We don't consider extensions that weren't disabled for being external so |
| 239 // that we grandfather in extensions. External extensions are only disabled on | 229 // that we grandfather in extensions. External extensions are only disabled on |
| 240 // install with the "prompt for external extensions" feature enabled. | 230 // install with the "prompt for external extensions" feature enabled. |
| 241 bool is_disabled_external = | 231 bool is_disabled_external = |
| 242 (disable_reasons & Extension::DISABLE_EXTERNAL_EXTENSION) != 0; | 232 (disable_reasons & Extension::DISABLE_EXTERNAL_EXTENSION) != 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 // It's a shame we have to use the notification system (instead of the | 244 // It's a shame we have to use the notification system (instead of the |
| 255 // registry observer) for this, but the ExtensionUnloaded notification is | 245 // registry observer) for this, but the ExtensionUnloaded notification is |
| 256 // not sent out if the extension is disabled (which it is here). | 246 // not sent out if the extension is disabled (which it is here). |
| 257 const std::string& extension_id = | 247 const std::string& extension_id = |
| 258 content::Details<const Extension>(details).ptr()->id(); | 248 content::Details<const Extension>(details).ptr()->id(); |
| 259 if (base::ContainsKey(errors_, extension_id)) | 249 if (base::ContainsKey(errors_, extension_id)) |
| 260 RemoveExternalInstallError(extension_id); | 250 RemoveExternalInstallError(extension_id); |
| 261 } | 251 } |
| 262 | 252 |
| 263 } // namespace extensions | 253 } // namespace extensions |
| OLD | NEW |