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

Side by Side Diff: extensions/renderer/dispatcher.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: -Removed old includes, added lock check to SetUsesDefaultHostRestrictions Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/dispatcher.h" 5 #include "extensions/renderer/dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, 927 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist,
928 OnSetScriptingWhitelist) 928 OnSetScriptingWhitelist)
929 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) 929 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont)
930 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, 930 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID,
931 OnSetWebViewPartitionID) 931 OnSetWebViewPartitionID)
932 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) 932 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend)
933 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) 933 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend)
934 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) 934 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs)
935 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) 935 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded)
936 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) 936 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions)
937 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateDefaultPolicyHostRestrictions,
938 OnUpdateDefaultPolicyHostRestrictions)
937 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, 939 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions,
938 OnUpdateTabSpecificPermissions) 940 OnUpdateTabSpecificPermissions)
939 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, 941 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions,
940 OnClearTabSpecificPermissions) 942 OnClearTabSpecificPermissions)
941 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, 943 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled,
942 OnSetActivityLoggingEnabled) 944 OnSetActivityLoggingEnabled)
943 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, 945 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages,
944 content_watcher_.get(), 946 content_watcher_.get(),
945 ContentWatcher::OnWatchPages) 947 ContentWatcher::OnWatchPages)
946 IPC_MESSAGE_UNHANDLED(handled = false) 948 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 for (const auto& param : loaded_extensions) { 1058 for (const auto& param : loaded_extensions) {
1057 std::string error; 1059 std::string error;
1058 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); 1060 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error);
1059 if (!extension.get()) { 1061 if (!extension.get()) {
1060 NOTREACHED() << error; 1062 NOTREACHED() << error;
1061 // Note: in tests |param.id| has been observed to be empty (see comment 1063 // Note: in tests |param.id| has been observed to be empty (see comment
1062 // just below) so this isn't all that reliable. 1064 // just below) so this isn't all that reliable.
1063 extension_load_errors_[param.id] = error; 1065 extension_load_errors_[param.id] = error;
1064 continue; 1066 continue;
1065 } 1067 }
1066
1067 RendererExtensionRegistry* extension_registry = 1068 RendererExtensionRegistry* extension_registry =
1068 RendererExtensionRegistry::Get(); 1069 RendererExtensionRegistry::Get();
1069 // TODO(kalman): This test is deliberately not a CHECK (though I wish it 1070 // TODO(kalman): This test is deliberately not a CHECK (though I wish it
1070 // could be) and uses extension->id() not params.id: 1071 // could be) and uses extension->id() not params.id:
1071 // 1. For some reason params.id can be empty. I've only seen it with 1072 // 1. For some reason params.id can be empty. I've only seen it with
1072 // the webstore extension, in tests, and I've spent some time trying to 1073 // the webstore extension, in tests, and I've spent some time trying to
1073 // figure out why - but cost/benefit won. 1074 // figure out why - but cost/benefit won.
1074 // 2. The browser only sends this IPC to RenderProcessHosts once, but the 1075 // 2. The browser only sends this IPC to RenderProcessHosts once, but the
1075 // Dispatcher is attached to a RenderThread. Presumably there is a 1076 // Dispatcher is attached to a RenderThread. Presumably there is a
1076 // mismatch there. In theory one would think it's possible for the 1077 // mismatch there. In theory one would think it's possible for the
1077 // browser to figure this out itself - but again, cost/benefit. 1078 // browser to figure this out itself - but again, cost/benefit.
1078 if (!extension_registry->Insert(extension)) { 1079 if (!extension_registry->Insert(extension)) {
1079 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and 1080 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and
1080 // consider making this a release CHECK. 1081 // consider making this a release CHECK.
1081 NOTREACHED(); 1082 NOTREACHED();
1082 } 1083 }
1084 if (!param.uses_default_policy_blocked_allowed_hosts) {
1085 extension->permissions_data()->SetPolicyHostRestrictions(
1086 param.policy_blocked_hosts, param.policy_allowed_hosts);
1087 }
1088 extension->permissions_data()->SetUsesDefaultHostRestrictions(
Devlin 2017/04/03 15:52:23 see comment in extension_service.cc
nrpeter 2017/04/03 22:35:48 Done.
1089 param.uses_default_policy_blocked_allowed_hosts);
1083 } 1090 }
1084 1091
1085 // Update the available bindings for all contexts. These may have changed if 1092 // Update the available bindings for all contexts. These may have changed if
1086 // an externally_connectable extension was loaded that can connect to an 1093 // an externally_connectable extension was loaded that can connect to an
1087 // open webpage. 1094 // open webpage.
1088 UpdateBindings(""); 1095 UpdateBindings(std::string());
1089 } 1096 }
1090 1097
1091 void Dispatcher::OnMessageInvoke(const std::string& extension_id, 1098 void Dispatcher::OnMessageInvoke(const std::string& extension_id,
1092 const std::string& module_name, 1099 const std::string& module_name,
1093 const std::string& function_name, 1100 const std::string& function_name,
1094 const base::ListValue& args, 1101 const base::ListValue& args,
1095 bool user_gesture) { 1102 bool user_gesture) {
1096 InvokeModuleSystemMethod( 1103 InvokeModuleSystemMethod(
1097 NULL, extension_id, module_name, function_name, args, user_gesture); 1104 NULL, extension_id, module_name, function_name, args, user_gesture);
1098 } 1105 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1187
1181 // Invalidates the messages map for the extension in case the extension is 1188 // Invalidates the messages map for the extension in case the extension is
1182 // reloaded with a new messages map. 1189 // reloaded with a new messages map.
1183 EraseL10nMessagesMap(id); 1190 EraseL10nMessagesMap(id);
1184 1191
1185 // We don't do anything with existing platform-app stylesheets. They will 1192 // We don't do anything with existing platform-app stylesheets. They will
1186 // stay resident, but the URL pattern corresponding to the unloaded 1193 // stay resident, but the URL pattern corresponding to the unloaded
1187 // extension's URL just won't match anything anymore. 1194 // extension's URL just won't match anything anymore.
1188 } 1195 }
1189 1196
1197 void Dispatcher::OnUpdateDefaultPolicyHostRestrictions(
1198 const ExtensionMsg_UpdateDefaultPolicyHostRestrictions_Params& params) {
1199 PermissionsData::SetDefaultPolicyHostRestrictions(
1200 params.default_policy_blocked_hosts, params.default_policy_allowed_hosts);
1201 UpdateBindings(std::string());
1202 }
1203
1190 void Dispatcher::OnUpdatePermissions( 1204 void Dispatcher::OnUpdatePermissions(
1191 const ExtensionMsg_UpdatePermissions_Params& params) { 1205 const ExtensionMsg_UpdatePermissions_Params& params) {
1192 const Extension* extension = 1206 const Extension* extension =
1193 RendererExtensionRegistry::Get()->GetByID(params.extension_id); 1207 RendererExtensionRegistry::Get()->GetByID(params.extension_id);
1194 if (!extension) 1208 if (!extension)
1195 return; 1209 return;
1196 1210
1197 std::unique_ptr<const PermissionSet> active = 1211 std::unique_ptr<const PermissionSet> active =
1198 params.active_permissions.ToPermissionSet(); 1212 params.active_permissions.ToPermissionSet();
1199 std::unique_ptr<const PermissionSet> withheld = 1213 std::unique_ptr<const PermissionSet> withheld =
1200 params.withheld_permissions.ToPermissionSet(); 1214 params.withheld_permissions.ToPermissionSet();
1201 1215
1202 UpdateOriginPermissions( 1216 UpdateOriginPermissions(
1203 extension->url(), 1217 extension->url(),
1204 extension->permissions_data()->GetEffectiveHostPermissions(), 1218 extension->permissions_data()->GetEffectiveHostPermissions(),
1205 active->effective_hosts()); 1219 active->effective_hosts());
1206 1220
1207 extension->permissions_data()->SetPermissions(std::move(active), 1221 extension->permissions_data()->SetPermissions(std::move(active),
1208 std::move(withheld)); 1222 std::move(withheld));
1223 if (!params.uses_default_policy_host_restrictions) {
1224 extension->permissions_data()->SetPolicyHostRestrictions(
1225 params.policy_blocked_hosts, params.policy_allowed_hosts);
1226 }
1227 extension->permissions_data()->SetUsesDefaultHostRestrictions(
Devlin 2017/04/03 15:52:23 see comment in extension_service.cc
nrpeter 2017/04/03 22:35:48 Done.
1228 params.uses_default_policy_host_restrictions);
1209 UpdateBindings(extension->id()); 1229 UpdateBindings(extension->id());
1210 } 1230 }
1211 1231
1212 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, 1232 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url,
1213 const std::string& extension_id, 1233 const std::string& extension_id,
1214 const URLPatternSet& new_hosts, 1234 const URLPatternSet& new_hosts,
1215 bool update_origin_whitelist, 1235 bool update_origin_whitelist,
1216 int tab_id) { 1236 int tab_id) {
1217 const Extension* extension = 1237 const Extension* extension =
1218 RendererExtensionRegistry::Get()->GetByID(extension_id); 1238 RendererExtensionRegistry::Get()->GetByID(extension_id);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 // The "guestViewDeny" module must always be loaded last. It registers 1670 // The "guestViewDeny" module must always be loaded last. It registers
1651 // error-providing custom elements for the GuestView types that are not 1671 // error-providing custom elements for the GuestView types that are not
1652 // available, and thus all of those types must have been checked and loaded 1672 // available, and thus all of those types must have been checked and loaded
1653 // (or not loaded) beforehand. 1673 // (or not loaded) beforehand.
1654 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1674 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1655 module_system->Require("guestViewDeny"); 1675 module_system->Require("guestViewDeny");
1656 } 1676 }
1657 } 1677 }
1658 1678
1659 } // namespace extensions 1679 } // namespace extensions
OLDNEW
« extensions/common/permissions/permissions_data.cc ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698