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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 714133002: Add more management policy checking after extension installed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fix Created 6 years, 1 month 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
OLDNEW
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
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 int disable_reasons = GetDisableReasonsOnInstalled(extension);
1571 std::string install_parameter; 1571 std::string install_parameter;
1572 const extensions::PendingExtensionInfo* pending_extension_info = 1572 const extensions::PendingExtensionInfo* pending_extension_info =
1573 pending_extension_manager()->GetById(id); 1573 pending_extension_manager()->GetById(id);
1574 if (pending_extension_info) { 1574 if (pending_extension_info) {
1575 if (!pending_extension_info->ShouldAllowInstall(extension)) { 1575 if (!pending_extension_info->ShouldAllowInstall(extension)) {
1576 pending_extension_manager()->Remove(id); 1576 pending_extension_manager()->Remove(id);
1577 1577
1578 LOG(WARNING) << "ShouldAllowInstall() returned false for " 1578 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1579 << id << " of type " << extension->GetType() 1579 << id << " of type " << extension->GetType()
1580 << " and update URL " 1580 << " and update URL "
(...skipping 12 matching lines...) Expand all
1593 return; 1593 return;
1594 } 1594 }
1595 1595
1596 install_parameter = pending_extension_info->install_parameter(); 1596 install_parameter = pending_extension_info->install_parameter();
1597 pending_extension_manager()->Remove(id); 1597 pending_extension_manager()->Remove(id);
1598 } else { 1598 } else {
1599 // We explicitly want to re-enable an uninstalled external 1599 // We explicitly want to re-enable an uninstalled external
1600 // extension; if we're here, that means the user is manually 1600 // extension; if we're here, that means the user is manually
1601 // installing the extension. 1601 // installing the extension.
1602 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { 1602 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
1603 initial_enable = true; 1603 disable_reasons = Extension::DISABLE_NONE;
1604 } 1604 }
1605 } 1605 }
1606 1606
1607 // Unsupported requirements overrides the management policy. 1607 // Unsupported requirements overrides the management policy.
1608 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { 1608 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
1609 initial_enable = false; 1609 disable_reasons = Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
not at google - send to devlin 2014/11/14 18:34:51 This should probably be &= not =
binjin 2014/11/14 18:38:26 Do you mean |= ?
not at google - send to devlin 2014/11/14 18:39:34 Oops, yes.
binjin 2014/11/14 18:59:21 Done.
1610 extension_prefs_->AddDisableReason(
1611 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1612 // If the extension was disabled because of unsupported requirements but 1610 // If the extension was disabled because of unsupported requirements but
1613 // now supports all requirements after an update and there are not other 1611 // now supports all requirements after an update and there are not other
1614 // disable reasons, enable it. 1612 // disable reasons, enable it.
1615 } else if (extension_prefs_->GetDisableReasons(id) == 1613 } else if (extension_prefs_->GetDisableReasons(id) ==
1616 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { 1614 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
1617 initial_enable = true; 1615 disable_reasons = Extension::DISABLE_NONE;
1618 extension_prefs_->ClearDisableReasons(id); 1616 extension_prefs_->ClearDisableReasons(id);
1619 } 1617 }
1620 1618
1621 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { 1619 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
1622 // Installation of a blacklisted extension can happen from sync, policy, 1620 // Installation of a blacklisted extension can happen from sync, policy,
1623 // etc, where to maintain consistency we need to install it, just never 1621 // 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 1622 // load it (see AddExtension). Usually it should be the job of callers to
1625 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even 1623 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1626 // showing the install dialogue). 1624 // showing the install dialogue).
1627 extension_prefs_->AcknowledgeBlacklistedExtension(id); 1625 extension_prefs_->AcknowledgeBlacklistedExtension(id);
(...skipping 15 matching lines...) Expand all
1643 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", 1641 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
1644 extension->location(), Manifest::NUM_LOCATIONS); 1642 extension->location(), Manifest::NUM_LOCATIONS);
1645 1643
1646 // A fully installed app cannot be demoted to an ephemeral app. 1644 // A fully installed app cannot be demoted to an ephemeral app.
1647 if ((install_flags & extensions::kInstallFlagIsEphemeral) && 1645 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1648 !extension_prefs_->IsEphemeralApp(id)) { 1646 !extension_prefs_->IsEphemeralApp(id)) {
1649 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); 1647 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1650 } 1648 }
1651 } 1649 }
1652 1650
1651 if (disable_reasons)
1652 extension_prefs_->AddDisableReasons(id, disable_reasons);
1653
1653 const Extension::State initial_state = 1654 const Extension::State initial_state =
1654 initial_enable ? Extension::ENABLED : Extension::DISABLED; 1655 disable_reasons == 0 ? Extension::ENABLED : Extension::DISABLED;
not at google - send to devlin 2014/11/14 18:34:51 Use DISABLE_NONE not 0.
binjin 2014/11/14 18:59:22 Done.
1656
1655 if (ShouldDelayExtensionUpdate( 1657 if (ShouldDelayExtensionUpdate(
1656 id, 1658 id,
1657 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { 1659 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
1658 extension_prefs_->SetDelayedInstallInfo( 1660 extension_prefs_->SetDelayedInstallInfo(
1659 extension, 1661 extension,
1660 initial_state, 1662 initial_state,
1661 install_flags, 1663 install_flags,
1662 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, 1664 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
1663 page_ordinal, 1665 page_ordinal,
1664 install_parameter); 1666 install_parameter);
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { 2143 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2142 OnProfileDestructionStarted(); 2144 OnProfileDestructionStarted();
2143 break; 2145 break;
2144 } 2146 }
2145 2147
2146 default: 2148 default:
2147 NOTREACHED() << "Unexpected notification type."; 2149 NOTREACHED() << "Unexpected notification type.";
2148 } 2150 }
2149 } 2151 }
2150 2152
2151 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { 2153 int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
2154 Extension::DisableReason disable_reason;
2155 // Extensions disabled by management policy should always be disabled, even
2156 // if it's force-installed.
2157 if (system_->management_policy()->MustRemainDisabled(
2158 extension, &disable_reason, nullptr)) {
2159 // A specified reason is required to disable the extension.
2160 DCHECK(disable_reason != Extension::DISABLE_NONE);
2161 return disable_reason;
2162 }
2163
2152 // Extensions installed by policy can't be disabled. So even if a previous 2164 // Extensions installed by policy can't be disabled. So even if a previous
2153 // installation disabled the extension, make sure it is now enabled. 2165 // installation disabled the extension, make sure it is now enabled.
2154 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) 2166 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2155 return true; 2167 return Extension::DISABLE_NONE;
2156 2168
2157 if (extension_prefs_->IsExtensionDisabled(extension->id())) 2169 // An already disabled extension should inherit the disable reasons and
2158 return false; 2170 // remain disabled.
2171 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2172 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2173 // If an extension was disabled without specified reason, presume it's
2174 // disabled by user.
2175 return disable_reasons == 0 ? Extension::DISABLE_USER_ACTION
2176 : disable_reasons;
2177 }
2159 2178
2160 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { 2179 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
2161 // External extensions are initially disabled. We prompt the user before 2180 // External extensions are initially disabled. We prompt the user before
2162 // enabling them. Hosted apps are excepted because they are not dangerous 2181 // enabling them. Hosted apps are excepted because they are not dangerous
2163 // (they need to be launched by the user anyway). 2182 // (they need to be launched by the user anyway).
2164 if (extension->GetType() != Manifest::TYPE_HOSTED_APP && 2183 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2165 Manifest::IsExternalLocation(extension->location()) && 2184 Manifest::IsExternalLocation(extension->location()) &&
2166 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { 2185 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2167 return false; 2186 return Extension::DISABLE_EXTERNAL_EXTENSION;
2168 } 2187 }
2169 } 2188 }
2170 2189
2171 return true; 2190 return Extension::DISABLE_NONE;
2172 } 2191 }
2173 2192
2174 bool ExtensionService::ShouldDelayExtensionUpdate( 2193 bool ExtensionService::ShouldDelayExtensionUpdate(
2175 const std::string& extension_id, 2194 const std::string& extension_id,
2176 bool install_immediately) const { 2195 bool install_immediately) const {
2177 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; 2196 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2178 2197
2179 // If delayed updates are globally disabled, or just for this extension, 2198 // If delayed updates are globally disabled, or just for this extension,
2180 // don't delay. 2199 // don't delay.
2181 if (!install_updates_when_idle_ || install_immediately) 2200 if (!install_updates_when_idle_ || install_immediately)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 } 2403 }
2385 2404
2386 void ExtensionService::OnProfileDestructionStarted() { 2405 void ExtensionService::OnProfileDestructionStarted() {
2387 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2406 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2388 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2407 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2389 it != ids_to_unload.end(); 2408 it != ids_to_unload.end();
2390 ++it) { 2409 ++it) {
2391 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2410 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2392 } 2411 }
2393 } 2412 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698