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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Created 4 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 <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 }
874 877
878 extensions::PermissionsUpdater(profile()).SetRuntimeBlockedAllowedHosts(
879 extension, management->GetRuntimeBlockedHosts(extension),
880 management->GetRuntimeAllowedHosts(extension));
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());
884 891
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
1215 1222
1223 for (const auto& extension : registry_->enabled_extensions()) {
1224 extensions::PermissionsUpdater(profile()).SetRuntimeBlockedAllowedHosts(
1225 extension.get(), management->GetRuntimeBlockedHosts(extension.get()),
1226 management->GetRuntimeAllowedHosts(extension.get()));
1227 }
1228
1216 // Loop through the disabled extension list, find extensions to re-enable 1229 // Loop through the disabled extension list, find extensions to re-enable
1217 // automatically. These extensions are exclusive from the |to_disable| and 1230 // automatically. These extensions are exclusive from the |to_disable| and
1218 // |to_unload| lists constructed above, since disabled_extensions() and 1231 // |to_unload| lists constructed above, since disabled_extensions() and
1219 // enabled_extensions() are supposed to be mutually exclusive. 1232 // enabled_extensions() are supposed to be mutually exclusive.
1220 for (const auto& extension : registry_->disabled_extensions()) { 1233 for (const auto& extension : registry_->disabled_extensions()) {
1221 // Find all disabled extensions disabled due to minimum version requirement, 1234 // Find all disabled extensions disabled due to minimum version requirement,
1222 // but now satisfying it. 1235 // but now satisfying it.
1223 if (management->CheckMinimumVersion(extension.get(), nullptr) && 1236 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1224 extension_prefs_->HasDisableReason( 1237 extension_prefs_->HasDisableReason(
1225 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { 1238 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 // TODO(jstritar): We may be able to get rid of this branch by overriding the 1467 // 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 1468 // default extension state to DISABLED when the --disable-extensions flag
1456 // is set (http://crbug.com/29067). 1469 // is set (http://crbug.com/29067).
1457 if (!extensions_enabled() && !extension->is_theme() && 1470 if (!extensions_enabled() && !extension->is_theme() &&
1458 extension->location() != Manifest::COMPONENT && 1471 extension->location() != Manifest::COMPONENT &&
1459 !Manifest::IsExternalLocation(extension->location()) && 1472 !Manifest::IsExternalLocation(extension->location()) &&
1460 disable_flag_exempted_extensions_.count(extension->id()) == 0) { 1473 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
1461 return; 1474 return;
1462 } 1475 }
1463 1476
1477 extensions::ExtensionManagement* settings =
1478 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1479 CHECK(settings);
1480 extensions::PermissionsUpdater(profile()).SetRuntimeBlockedAllowedHosts(
1481 extension, settings->GetRuntimeBlockedHosts(extension),
1482 settings->GetRuntimeAllowedHosts(extension));
1483
1464 bool is_extension_upgrade = false; 1484 bool is_extension_upgrade = false;
1465 bool is_extension_loaded = false; 1485 bool is_extension_loaded = false;
1466 const Extension* old = GetInstalledExtension(extension->id()); 1486 const Extension* old = GetInstalledExtension(extension->id());
1467 if (old) { 1487 if (old) {
1468 is_extension_loaded = true; 1488 is_extension_loaded = true;
1469 int version_compare_result = 1489 int version_compare_result =
1470 extension->version()->CompareTo(*(old->version())); 1490 extension->version()->CompareTo(*(old->version()));
1471 is_extension_upgrade = version_compare_result > 0; 1491 is_extension_upgrade = version_compare_result > 0;
1472 // Other than for unpacked extensions, CrxInstaller should have guaranteed 1492 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1473 // that we aren't downgrading. 1493 // that we aren't downgrading.
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 CHECK(settings); 1883 CHECK(settings);
1864 std::unique_ptr<ExtensionSet> all_extensions( 1884 std::unique_ptr<ExtensionSet> all_extensions(
1865 registry_->GenerateInstalledExtensionsSet()); 1885 registry_->GenerateInstalledExtensionsSet());
1866 for (const auto& extension : *all_extensions) { 1886 for (const auto& extension : *all_extensions) {
1867 if (!settings->IsPermissionSetAllowed( 1887 if (!settings->IsPermissionSetAllowed(
1868 extension.get(), 1888 extension.get(),
1869 extension->permissions_data()->active_permissions())) { 1889 extension->permissions_data()->active_permissions())) {
1870 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe( 1890 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
1871 extension.get(), *settings->GetBlockedPermissions(extension.get())); 1891 extension.get(), *settings->GetBlockedPermissions(extension.get()));
1872 } 1892 }
1893 extensions::PermissionsUpdater(profile()).SetRuntimeBlockedAllowedHosts(
1894 extension.get(), settings->GetRuntimeBlockedHosts(extension.get()),
1895 settings->GetRuntimeAllowedHosts(extension.get()));
1873 } 1896 }
1874 1897
1875 CheckManagementPolicy(); 1898 CheckManagementPolicy();
1876 } 1899 }
1877 1900
1878 void ExtensionService::AddNewOrUpdatedExtension( 1901 void ExtensionService::AddNewOrUpdatedExtension(
1879 const Extension* extension, 1902 const Extension* extension,
1880 Extension::State initial_state, 1903 Extension::State initial_state,
1881 int install_flags, 1904 int install_flags,
1882 const syncer::StringOrdinal& page_ordinal, 1905 const syncer::StringOrdinal& page_ordinal,
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 } 2500 }
2478 2501
2479 void ExtensionService::OnProfileDestructionStarted() { 2502 void ExtensionService::OnProfileDestructionStarted() {
2480 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2503 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2481 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2504 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2482 it != ids_to_unload.end(); 2505 it != ids_to_unload.end();
2483 ++it) { 2506 ++it) {
2484 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2507 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2485 } 2508 }
2486 } 2509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698