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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Add URLPattern effective TLD whitelisting, Switched IPC to UpdatePermissions, Removed shared memor… Created 3 years, 11 months 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 859
860 void ExtensionService::EnableExtension(const std::string& extension_id) { 860 void ExtensionService::EnableExtension(const std::string& extension_id) {
861 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 861 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
862 862
863 if (IsExtensionEnabled(extension_id) || 863 if (IsExtensionEnabled(extension_id) ||
864 extension_prefs_->IsExtensionBlacklisted(extension_id)) 864 extension_prefs_->IsExtensionBlacklisted(extension_id))
865 return; 865 return;
866 const Extension* extension = 866 const Extension* extension =
867 registry_->disabled_extensions().GetByID(extension_id); 867 registry_->disabled_extensions().GetByID(extension_id);
868 868
869 extensions::ExtensionManagement* management =
870 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
871
869 ManagementPolicy* policy = system_->management_policy(); 872 ManagementPolicy* policy = system_->management_policy();
870 if (extension && policy->MustRemainDisabled(extension, nullptr, nullptr)) { 873 if (extension && policy->MustRemainDisabled(extension, nullptr, nullptr)) {
871 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1); 874 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
872 return; 875 return;
873 } 876 }
877 extensions::PermissionsUpdater(profile()).SetPolicyHostRestrictions(
Devlin 2017/01/26 22:47:39 We seem to be calling this an awful lot. We shoul
nrpeter 2017/02/03 19:32:24 The call under CheckManagementPolicy handles the s
878 extension, management->GetRuntimeBlockedHosts(extension),
879 management->GetRuntimeAllowedHosts(extension),
880 management->UsesDefaultRuntimeHostRestrictions(extension));
874 881
875 extension_prefs_->SetExtensionEnabled(extension_id); 882 extension_prefs_->SetExtensionEnabled(extension_id);
876 883
877 // This can happen if sync enables an extension that is not installed yet. 884 // This can happen if sync enables an extension that is not installed yet.
878 if (!extension) 885 if (!extension)
879 return; 886 return;
880 887
881 // Move it over to the enabled list. 888 // Move it over to the enabled list.
882 registry_->AddEnabled(make_scoped_refptr(extension)); 889 registry_->AddEnabled(make_scoped_refptr(extension));
883 registry_->RemoveDisabled(extension->id()); 890 registry_->RemoveDisabled(extension->id());
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr)) 1212 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
1206 to_unload.push_back(extension->id()); 1213 to_unload.push_back(extension->id());
1207 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; 1214 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1208 if (system_->management_policy()->MustRemainDisabled( 1215 if (system_->management_policy()->MustRemainDisabled(
1209 extension.get(), &disable_reason, nullptr)) 1216 extension.get(), &disable_reason, nullptr))
1210 to_disable[extension->id()] = disable_reason; 1217 to_disable[extension->id()] = disable_reason;
1211 } 1218 }
1212 1219
1213 extensions::ExtensionManagement* management = 1220 extensions::ExtensionManagement* management =
1214 extensions::ExtensionManagementFactory::GetForBrowserContext(profile()); 1221 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1222 for (const auto& extension : registry_->enabled_extensions()) {
1223 extensions::PermissionsUpdater(profile()).SetPolicyHostRestrictions(
1224 extension.get(), management->GetRuntimeBlockedHosts(extension.get()),
1225 management->GetRuntimeAllowedHosts(extension.get()),
1226 management->UsesDefaultRuntimeHostRestrictions(extension.get()));
1227 }
1228 extensions::PermissionsUpdater(profile())
1229 .SetDefaultPolicyHostRestrictions(
1230 management->GetDefaultRuntimeBlockedHosts(),
1231 management->GetDefaultRuntimeAllowedHosts());
1215 1232
1216 // Loop through the disabled extension list, find extensions to re-enable 1233 // Loop through the disabled extension list, find extensions to re-enable
1217 // automatically. These extensions are exclusive from the |to_disable| and 1234 // automatically. These extensions are exclusive from the |to_disable| and
1218 // |to_unload| lists constructed above, since disabled_extensions() and 1235 // |to_unload| lists constructed above, since disabled_extensions() and
1219 // enabled_extensions() are supposed to be mutually exclusive. 1236 // enabled_extensions() are supposed to be mutually exclusive.
1220 for (const auto& extension : registry_->disabled_extensions()) { 1237 for (const auto& extension : registry_->disabled_extensions()) {
1221 // Find all disabled extensions disabled due to minimum version requirement, 1238 // Find all disabled extensions disabled due to minimum version requirement,
1222 // but now satisfying it. 1239 // but now satisfying it.
1223 if (management->CheckMinimumVersion(extension.get(), nullptr) && 1240 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1224 extension_prefs_->HasDisableReason( 1241 extension_prefs_->HasDisableReason(
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 updater_->Start(); 1453 updater_->Start();
1437 1454
1438 // Enable any Shared Modules that incorrectly got disabled previously. 1455 // Enable any Shared Modules that incorrectly got disabled previously.
1439 // This is temporary code to fix incorrect behavior from previous versions of 1456 // This is temporary code to fix incorrect behavior from previous versions of
1440 // Chrome and can be removed after several releases (perhaps M60). 1457 // Chrome and can be removed after several releases (perhaps M60).
1441 extensions::ExtensionList to_enable; 1458 extensions::ExtensionList to_enable;
1442 for (const auto& extension : registry_->disabled_extensions()) { 1459 for (const auto& extension : registry_->disabled_extensions()) {
1443 if (SharedModuleInfo::IsSharedModule(extension.get())) 1460 if (SharedModuleInfo::IsSharedModule(extension.get()))
1444 to_enable.push_back(extension); 1461 to_enable.push_back(extension);
1445 } 1462 }
1463 extensions::ExtensionManagement* management =
1464 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1465 extensions::PermissionsUpdater(profile())
1466 .SetDefaultPolicyHostRestrictions(
1467 management->GetDefaultRuntimeBlockedHosts(),
1468 management->GetDefaultRuntimeAllowedHosts());
1469
1446 for (const auto& extension : to_enable) { 1470 for (const auto& extension : to_enable) {
1447 EnableExtension(extension->id()); 1471 EnableExtension(extension->id());
1448 } 1472 }
1449 1473
1450 OnBlacklistUpdated(); 1474 OnBlacklistUpdated();
1451 } 1475 }
1452 1476
1453 void ExtensionService::AddExtension(const Extension* extension) { 1477 void ExtensionService::AddExtension(const Extension* extension) {
1454 // TODO(jstritar): We may be able to get rid of this branch by overriding the 1478 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1455 // default extension state to DISABLED when the --disable-extensions flag 1479 // default extension state to DISABLED when the --disable-extensions flag
1456 // is set (http://crbug.com/29067). 1480 // is set (http://crbug.com/29067).
1457 if (!extensions_enabled() && !extension->is_theme() && 1481 if (!extensions_enabled() && !extension->is_theme() &&
1458 extension->location() != Manifest::COMPONENT && 1482 extension->location() != Manifest::COMPONENT &&
1459 !Manifest::IsExternalLocation(extension->location()) && 1483 !Manifest::IsExternalLocation(extension->location()) &&
1460 disable_flag_exempted_extensions_.count(extension->id()) == 0) { 1484 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
1461 return; 1485 return;
1462 } 1486 }
1463 1487
1488 extensions::ExtensionManagement* settings =
1489 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1490 DCHECK(settings);
1491 extensions::PermissionsUpdater(profile()).SetPolicyHostRestrictions(
1492 extension, settings->GetRuntimeBlockedHosts(extension),
1493 settings->GetRuntimeAllowedHosts(extension),
1494 settings->UsesDefaultRuntimeHostRestrictions(extension));
1495
1464 bool is_extension_upgrade = false; 1496 bool is_extension_upgrade = false;
1465 bool is_extension_loaded = false; 1497 bool is_extension_loaded = false;
1466 const Extension* old = GetInstalledExtension(extension->id()); 1498 const Extension* old = GetInstalledExtension(extension->id());
1467 if (old) { 1499 if (old) {
1468 is_extension_loaded = true; 1500 is_extension_loaded = true;
1469 int version_compare_result = 1501 int version_compare_result =
1470 extension->version()->CompareTo(*(old->version())); 1502 extension->version()->CompareTo(*(old->version()));
1471 is_extension_upgrade = version_compare_result > 0; 1503 is_extension_upgrade = version_compare_result > 0;
1472 // Other than for unpacked extensions, CrxInstaller should have guaranteed 1504 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1473 // that we aren't downgrading. 1505 // that we aren't downgrading.
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 } 2509 }
2478 2510
2479 void ExtensionService::OnProfileDestructionStarted() { 2511 void ExtensionService::OnProfileDestructionStarted() {
2480 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2512 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2481 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2513 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2482 it != ids_to_unload.end(); 2514 it != ids_to_unload.end();
2483 ++it) { 2515 ++it) {
2484 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2516 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2485 } 2517 }
2486 } 2518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698