OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1560 crash_keys::SetActiveExtensions(extension_ids); | 1560 crash_keys::SetActiveExtensions(extension_ids); |
1561 } | 1561 } |
1562 | 1562 |
1563 void ExtensionService::OnExtensionInstalled( | 1563 void ExtensionService::OnExtensionInstalled( |
1564 const Extension* extension, | 1564 const Extension* extension, |
1565 const syncer::StringOrdinal& page_ordinal, | 1565 const syncer::StringOrdinal& page_ordinal, |
1566 int install_flags) { | 1566 int install_flags) { |
1567 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1567 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1568 | 1568 |
1569 const std::string& id = extension->id(); | 1569 const std::string& id = extension->id(); |
1570 bool initial_enable = ShouldEnableOnInstall(extension); | 1570 Extension::DisableReason disable_reason = |
1571 GetDisableReasonOnInstalled(extension); | |
1571 std::string install_parameter; | 1572 std::string install_parameter; |
1572 const extensions::PendingExtensionInfo* pending_extension_info = | 1573 const extensions::PendingExtensionInfo* pending_extension_info = |
1573 pending_extension_manager()->GetById(id); | 1574 pending_extension_manager()->GetById(id); |
1574 if (pending_extension_info) { | 1575 if (pending_extension_info) { |
1575 if (!pending_extension_info->ShouldAllowInstall(extension)) { | 1576 if (!pending_extension_info->ShouldAllowInstall(extension)) { |
1576 pending_extension_manager()->Remove(id); | 1577 pending_extension_manager()->Remove(id); |
1577 | 1578 |
1578 LOG(WARNING) << "ShouldAllowInstall() returned false for " | 1579 LOG(WARNING) << "ShouldAllowInstall() returned false for " |
1579 << id << " of type " << extension->GetType() | 1580 << id << " of type " << extension->GetType() |
1580 << " and update URL " | 1581 << " and update URL " |
(...skipping 12 matching lines...) Expand all Loading... | |
1593 return; | 1594 return; |
1594 } | 1595 } |
1595 | 1596 |
1596 install_parameter = pending_extension_info->install_parameter(); | 1597 install_parameter = pending_extension_info->install_parameter(); |
1597 pending_extension_manager()->Remove(id); | 1598 pending_extension_manager()->Remove(id); |
1598 } else { | 1599 } else { |
1599 // We explicitly want to re-enable an uninstalled external | 1600 // We explicitly want to re-enable an uninstalled external |
1600 // extension; if we're here, that means the user is manually | 1601 // extension; if we're here, that means the user is manually |
1601 // installing the extension. | 1602 // installing the extension. |
1602 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { | 1603 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { |
1603 initial_enable = true; | 1604 disable_reason = Extension::DISABLE_NONE; |
1604 } | 1605 } |
1605 } | 1606 } |
1606 | 1607 |
1607 // Unsupported requirements overrides the management policy. | 1608 // Unsupported requirements overrides the management policy. |
1608 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { | 1609 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { |
1609 initial_enable = false; | 1610 disable_reason = Extension::DISABLE_UNSUPPORTED_REQUIREMENT; |
1610 extension_prefs_->AddDisableReason( | |
1611 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | |
1612 // If the extension was disabled because of unsupported requirements but | 1611 // If the extension was disabled because of unsupported requirements but |
1613 // now supports all requirements after an update and there are not other | 1612 // now supports all requirements after an update and there are not other |
1614 // disable reasons, enable it. | 1613 // disable reasons, enable it. |
1615 } else if (extension_prefs_->GetDisableReasons(id) == | 1614 } else if (extension_prefs_->GetDisableReasons(id) == |
1616 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { | 1615 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
1617 initial_enable = true; | 1616 disable_reason = Extension::DISABLE_NONE; |
1618 extension_prefs_->ClearDisableReasons(id); | 1617 extension_prefs_->ClearDisableReasons(id); |
1619 } | 1618 } |
1620 | 1619 |
1621 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { | 1620 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |
1622 // Installation of a blacklisted extension can happen from sync, policy, | 1621 // Installation of a blacklisted extension can happen from sync, policy, |
1623 // etc, where to maintain consistency we need to install it, just never | 1622 // etc, where to maintain consistency we need to install it, just never |
1624 // load it (see AddExtension). Usually it should be the job of callers to | 1623 // load it (see AddExtension). Usually it should be the job of callers to |
1625 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even | 1624 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
1626 // showing the install dialogue). | 1625 // showing the install dialogue). |
1627 extension_prefs_->AcknowledgeBlacklistedExtension(id); | 1626 extension_prefs_->AcknowledgeBlacklistedExtension(id); |
(...skipping 15 matching lines...) Expand all Loading... | |
1643 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1642 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
1644 extension->location(), Manifest::NUM_LOCATIONS); | 1643 extension->location(), Manifest::NUM_LOCATIONS); |
1645 | 1644 |
1646 // A fully installed app cannot be demoted to an ephemeral app. | 1645 // A fully installed app cannot be demoted to an ephemeral app. |
1647 if ((install_flags & extensions::kInstallFlagIsEphemeral) && | 1646 if ((install_flags & extensions::kInstallFlagIsEphemeral) && |
1648 !extension_prefs_->IsEphemeralApp(id)) { | 1647 !extension_prefs_->IsEphemeralApp(id)) { |
1649 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); | 1648 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); |
1650 } | 1649 } |
1651 } | 1650 } |
1652 | 1651 |
1652 if (disable_reason != Extension::DISABLE_NONE) | |
1653 extension_prefs_->AddDisableReason(id, disable_reason); | |
1654 | |
1653 const Extension::State initial_state = | 1655 const Extension::State initial_state = |
1654 initial_enable ? Extension::ENABLED : Extension::DISABLED; | 1656 disable_reason == Extension::DISABLE_NONE ? Extension::ENABLED |
1657 : Extension::DISABLED; | |
1655 if (ShouldDelayExtensionUpdate( | 1658 if (ShouldDelayExtensionUpdate( |
1656 id, | 1659 id, |
1657 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { | 1660 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { |
1658 extension_prefs_->SetDelayedInstallInfo( | 1661 extension_prefs_->SetDelayedInstallInfo( |
1659 extension, | 1662 extension, |
1660 initial_state, | 1663 initial_state, |
1661 install_flags, | 1664 install_flags, |
1662 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, | 1665 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
1663 page_ordinal, | 1666 page_ordinal, |
1664 install_parameter); | 1667 install_parameter); |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2141 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { | 2144 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { |
2142 OnProfileDestructionStarted(); | 2145 OnProfileDestructionStarted(); |
2143 break; | 2146 break; |
2144 } | 2147 } |
2145 | 2148 |
2146 default: | 2149 default: |
2147 NOTREACHED() << "Unexpected notification type."; | 2150 NOTREACHED() << "Unexpected notification type."; |
2148 } | 2151 } |
2149 } | 2152 } |
2150 | 2153 |
2151 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { | 2154 Extension::DisableReason ExtensionService::GetDisableReasonOnInstalled( |
2155 const Extension* extension) { | |
2156 Extension::DisableReason disable_reason; | |
2157 // Extensions disabled by management policy should always be disabled, even | |
2158 // if it's force-installed. | |
2159 if (system_->management_policy()->MustRemainDisabled( | |
2160 extension, &disable_reason, nullptr)) { | |
2161 // A specified reason is required to disable the extension. | |
2162 DCHECK(disable_reason != Extension::DISABLE_NONE); | |
2163 return disable_reason; | |
2164 } | |
2165 | |
2152 // Extensions installed by policy can't be disabled. So even if a previous | 2166 // Extensions installed by policy can't be disabled. So even if a previous |
2153 // installation disabled the extension, make sure it is now enabled. | 2167 // installation disabled the extension, make sure it is now enabled. |
2154 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) | 2168 if (system_->management_policy()->MustRemainEnabled(extension, nullptr)) |
2155 return true; | 2169 return Extension::DISABLE_NONE; |
2156 | 2170 |
2157 if (extension_prefs_->IsExtensionDisabled(extension->id())) | 2171 // An already disabled extension should inherit the disable reasons and |
2158 return false; | 2172 // remain disabled. |
2173 if (extension_prefs_->IsExtensionDisabled(extension->id())) { | |
2174 disable_reason = static_cast<Extension::DisableReason>( | |
not at google - send to devlin
2014/11/14 17:20:43
Damn, ok, this static_cast<> isn't actually right.
binjin
2014/11/14 18:21:58
Done.
| |
2175 extension_prefs_->GetDisableReasons(extension->id())); | |
2176 // If an extension was disabled without specified reason, presume it's | |
2177 // disabled by user. | |
2178 return disable_reason == Extension::DISABLE_NONE | |
2179 ? Extension::DISABLE_USER_ACTION | |
2180 : disable_reason; | |
2181 } | |
2159 | 2182 |
2160 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { | 2183 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
2161 // External extensions are initially disabled. We prompt the user before | 2184 // External extensions are initially disabled. We prompt the user before |
2162 // enabling them. Hosted apps are excepted because they are not dangerous | 2185 // enabling them. Hosted apps are excepted because they are not dangerous |
2163 // (they need to be launched by the user anyway). | 2186 // (they need to be launched by the user anyway). |
2164 if (extension->GetType() != Manifest::TYPE_HOSTED_APP && | 2187 if (extension->GetType() != Manifest::TYPE_HOSTED_APP && |
2165 Manifest::IsExternalLocation(extension->location()) && | 2188 Manifest::IsExternalLocation(extension->location()) && |
2166 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { | 2189 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { |
2167 return false; | 2190 return Extension::DISABLE_EXTERNAL_EXTENSION; |
2168 } | 2191 } |
2169 } | 2192 } |
2170 | 2193 |
2171 return true; | 2194 return Extension::DISABLE_NONE; |
2172 } | 2195 } |
2173 | 2196 |
2174 bool ExtensionService::ShouldDelayExtensionUpdate( | 2197 bool ExtensionService::ShouldDelayExtensionUpdate( |
2175 const std::string& extension_id, | 2198 const std::string& extension_id, |
2176 bool install_immediately) const { | 2199 bool install_immediately) const { |
2177 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; | 2200 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
2178 | 2201 |
2179 // If delayed updates are globally disabled, or just for this extension, | 2202 // If delayed updates are globally disabled, or just for this extension, |
2180 // don't delay. | 2203 // don't delay. |
2181 if (!install_updates_when_idle_ || install_immediately) | 2204 if (!install_updates_when_idle_ || install_immediately) |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2384 } | 2407 } |
2385 | 2408 |
2386 void ExtensionService::OnProfileDestructionStarted() { | 2409 void ExtensionService::OnProfileDestructionStarted() { |
2387 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2410 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2388 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2411 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2389 it != ids_to_unload.end(); | 2412 it != ids_to_unload.end(); |
2390 ++it) { | 2413 ++it) { |
2391 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2414 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2392 } | 2415 } |
2393 } | 2416 } |
OLD | NEW |