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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Style fixes, prevent heap leak. Created 3 years, 10 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 extension->permissions_data()->SetPolicyHostRestrictions(
1085 param.runtime_blocked_hosts, param.runtime_allowed_hosts,
1086 param.is_default_runtime_blocked_allowed_hosts);
1083 } 1087 }
1084 1088
1085 // Update the available bindings for all contexts. These may have changed if 1089 // Update the available bindings for all contexts. These may have changed if
1086 // an externally_connectable extension was loaded that can connect to an 1090 // an externally_connectable extension was loaded that can connect to an
1087 // open webpage. 1091 // open webpage.
1088 UpdateBindings(""); 1092 UpdateBindings(std::string());
1089 } 1093 }
1090 1094
1091 void Dispatcher::OnMessageInvoke(const std::string& extension_id, 1095 void Dispatcher::OnMessageInvoke(const std::string& extension_id,
1092 const std::string& module_name, 1096 const std::string& module_name,
1093 const std::string& function_name, 1097 const std::string& function_name,
1094 const base::ListValue& args, 1098 const base::ListValue& args,
1095 bool user_gesture) { 1099 bool user_gesture) {
1096 InvokeModuleSystemMethod( 1100 InvokeModuleSystemMethod(
1097 NULL, extension_id, module_name, function_name, args, user_gesture); 1101 NULL, extension_id, module_name, function_name, args, user_gesture);
1098 } 1102 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1184
1181 // Invalidates the messages map for the extension in case the extension is 1185 // Invalidates the messages map for the extension in case the extension is
1182 // reloaded with a new messages map. 1186 // reloaded with a new messages map.
1183 EraseL10nMessagesMap(id); 1187 EraseL10nMessagesMap(id);
1184 1188
1185 // We don't do anything with existing platform-app stylesheets. They will 1189 // We don't do anything with existing platform-app stylesheets. They will
1186 // stay resident, but the URL pattern corresponding to the unloaded 1190 // stay resident, but the URL pattern corresponding to the unloaded
1187 // extension's URL just won't match anything anymore. 1191 // extension's URL just won't match anything anymore.
1188 } 1192 }
1189 1193
1194 void Dispatcher::OnUpdateDefaultPolicyHostRestrictions(
1195 const ExtensionMsg_UpdateDefaultPolicyHostRestrictions_Params& params) {
1196 PermissionsData::SetDefaultPolicyHostRestrictions(
1197 params.default_runtime_blocked_hosts,
1198 params.default_runtime_allowed_hosts);
1199 UpdateBindings(std::string());
1200 }
1201
1190 void Dispatcher::OnUpdatePermissions( 1202 void Dispatcher::OnUpdatePermissions(
1191 const ExtensionMsg_UpdatePermissions_Params& params) { 1203 const ExtensionMsg_UpdatePermissions_Params& params) {
1192 const Extension* extension = 1204 const Extension* extension =
1193 RendererExtensionRegistry::Get()->GetByID(params.extension_id); 1205 RendererExtensionRegistry::Get()->GetByID(params.extension_id);
1194 if (!extension) 1206 if (!extension)
1195 return; 1207 return;
1196 1208
1197 std::unique_ptr<const PermissionSet> active = 1209 std::unique_ptr<const PermissionSet> active =
1198 params.active_permissions.ToPermissionSet(); 1210 params.active_permissions.ToPermissionSet();
1199 std::unique_ptr<const PermissionSet> withheld = 1211 std::unique_ptr<const PermissionSet> withheld =
1200 params.withheld_permissions.ToPermissionSet(); 1212 params.withheld_permissions.ToPermissionSet();
1201 1213
1202 UpdateOriginPermissions( 1214 UpdateOriginPermissions(
1203 extension->url(), 1215 extension->url(),
1204 extension->permissions_data()->GetEffectiveHostPermissions(), 1216 extension->permissions_data()->GetEffectiveHostPermissions(),
1205 active->effective_hosts()); 1217 active->effective_hosts());
1206 1218
1207 extension->permissions_data()->SetPermissions(std::move(active), 1219 extension->permissions_data()->SetPermissions(std::move(active),
1208 std::move(withheld)); 1220 std::move(withheld));
1221 URLPatternSet runtime_blocked_hosts;
1222 URLPatternSet runtime_allowed_hosts;
1223 if (!params.uses_default_policy_host_restrictions) {
1224 runtime_blocked_hosts = params.runtime_blocked_hosts;
Devlin 2017/02/14 23:17:10 won't params.runtime_blocked_hosts be empty if par
nrpeter 2017/03/22 23:47:39 We could, but SetPolicyHostRestrictions has to acq
Devlin 2017/03/29 21:36:49 We unconditionally call SetPolicyHostRestrictions(
nrpeter 2017/03/30 00:06:05 Done.
1225 runtime_allowed_hosts = params.runtime_allowed_hosts;
1226 }
1227 extension->permissions_data()->SetPolicyHostRestrictions(
1228 runtime_blocked_hosts, runtime_allowed_hosts,
1229 params.uses_default_policy_host_restrictions);
1209 UpdateBindings(extension->id()); 1230 UpdateBindings(extension->id());
1210 } 1231 }
1211 1232
1212 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, 1233 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url,
1213 const std::string& extension_id, 1234 const std::string& extension_id,
1214 const URLPatternSet& new_hosts, 1235 const URLPatternSet& new_hosts,
1215 bool update_origin_whitelist, 1236 bool update_origin_whitelist,
1216 int tab_id) { 1237 int tab_id) {
1217 const Extension* extension = 1238 const Extension* extension =
1218 RendererExtensionRegistry::Get()->GetByID(extension_id); 1239 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 1671 // The "guestViewDeny" module must always be loaded last. It registers
1651 // error-providing custom elements for the GuestView types that are not 1672 // 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 1673 // available, and thus all of those types must have been checked and loaded
1653 // (or not loaded) beforehand. 1674 // (or not loaded) beforehand.
1654 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1675 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1655 module_system->Require("guestViewDeny"); 1676 module_system->Require("guestViewDeny");
1656 } 1677 }
1657 } 1678 }
1658 1679
1659 } // namespace extensions 1680 } // namespace extensions
OLDNEW
« extensions/common/url_pattern.cc ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698