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

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