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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: nits 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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, 915 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist,
916 OnSetScriptingWhitelist) 916 OnSetScriptingWhitelist)
917 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) 917 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont)
918 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, 918 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID,
919 OnSetWebViewPartitionID) 919 OnSetWebViewPartitionID)
920 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) 920 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend)
921 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) 921 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend)
922 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) 922 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs)
923 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) 923 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded)
924 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) 924 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions)
925 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateDefaultPolicyHostRestrictions,
926 OnUpdateDefaultPolicyHostRestrictions)
925 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, 927 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions,
926 OnUpdateTabSpecificPermissions) 928 OnUpdateTabSpecificPermissions)
927 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, 929 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions,
928 OnClearTabSpecificPermissions) 930 OnClearTabSpecificPermissions)
929 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, 931 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled,
930 OnSetActivityLoggingEnabled) 932 OnSetActivityLoggingEnabled)
931 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, 933 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages,
932 content_watcher_.get(), 934 content_watcher_.get(),
933 ContentWatcher::OnWatchPages) 935 ContentWatcher::OnWatchPages)
934 IPC_MESSAGE_UNHANDLED(handled = false) 936 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 for (const auto& param : loaded_extensions) { 1040 for (const auto& param : loaded_extensions) {
1039 std::string error; 1041 std::string error;
1040 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); 1042 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error);
1041 if (!extension.get()) { 1043 if (!extension.get()) {
1042 NOTREACHED() << error; 1044 NOTREACHED() << error;
1043 // Note: in tests |param.id| has been observed to be empty (see comment 1045 // Note: in tests |param.id| has been observed to be empty (see comment
1044 // just below) so this isn't all that reliable. 1046 // just below) so this isn't all that reliable.
1045 extension_load_errors_[param.id] = error; 1047 extension_load_errors_[param.id] = error;
1046 continue; 1048 continue;
1047 } 1049 }
1048
1049 RendererExtensionRegistry* extension_registry = 1050 RendererExtensionRegistry* extension_registry =
1050 RendererExtensionRegistry::Get(); 1051 RendererExtensionRegistry::Get();
1051 // TODO(kalman): This test is deliberately not a CHECK (though I wish it 1052 // TODO(kalman): This test is deliberately not a CHECK (though I wish it
1052 // could be) and uses extension->id() not params.id: 1053 // could be) and uses extension->id() not params.id:
1053 // 1. For some reason params.id can be empty. I've only seen it with 1054 // 1. For some reason params.id can be empty. I've only seen it with
1054 // the webstore extension, in tests, and I've spent some time trying to 1055 // the webstore extension, in tests, and I've spent some time trying to
1055 // figure out why - but cost/benefit won. 1056 // figure out why - but cost/benefit won.
1056 // 2. The browser only sends this IPC to RenderProcessHosts once, but the 1057 // 2. The browser only sends this IPC to RenderProcessHosts once, but the
1057 // Dispatcher is attached to a RenderThread. Presumably there is a 1058 // Dispatcher is attached to a RenderThread. Presumably there is a
1058 // mismatch there. In theory one would think it's possible for the 1059 // mismatch there. In theory one would think it's possible for the
1059 // browser to figure this out itself - but again, cost/benefit. 1060 // browser to figure this out itself - but again, cost/benefit.
1060 if (!extension_registry->Insert(extension)) { 1061 if (!extension_registry->Insert(extension)) {
1061 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and 1062 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and
1062 // consider making this a release CHECK. 1063 // consider making this a release CHECK.
1063 NOTREACHED(); 1064 NOTREACHED();
1064 } 1065 }
1066 if (param.uses_default_policy_blocked_allowed_hosts) {
1067 extension->permissions_data()->SetUsesDefaultHostRestrictions();
1068 } else {
1069 extension->permissions_data()->SetPolicyHostRestrictions(
1070 param.policy_blocked_hosts, param.policy_allowed_hosts);
1071 }
1065 } 1072 }
1066 1073
1067 // Update the available bindings for all contexts. These may have changed if 1074 // Update the available bindings for all contexts. These may have changed if
1068 // an externally_connectable extension was loaded that can connect to an 1075 // an externally_connectable extension was loaded that can connect to an
1069 // open webpage. 1076 // open webpage.
1070 UpdateBindings(""); 1077 UpdateBindings(std::string());
1071 } 1078 }
1072 1079
1073 void Dispatcher::OnMessageInvoke(const std::string& extension_id, 1080 void Dispatcher::OnMessageInvoke(const std::string& extension_id,
1074 const std::string& module_name, 1081 const std::string& module_name,
1075 const std::string& function_name, 1082 const std::string& function_name,
1076 const base::ListValue& args) { 1083 const base::ListValue& args) {
1077 InvokeModuleSystemMethod(nullptr, extension_id, module_name, function_name, 1084 InvokeModuleSystemMethod(nullptr, extension_id, module_name, function_name,
1078 args); 1085 args);
1079 } 1086 }
1080 1087
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1194
1188 // Invalidates the messages map for the extension in case the extension is 1195 // Invalidates the messages map for the extension in case the extension is
1189 // reloaded with a new messages map. 1196 // reloaded with a new messages map.
1190 EraseL10nMessagesMap(id); 1197 EraseL10nMessagesMap(id);
1191 1198
1192 // We don't do anything with existing platform-app stylesheets. They will 1199 // We don't do anything with existing platform-app stylesheets. They will
1193 // stay resident, but the URL pattern corresponding to the unloaded 1200 // stay resident, but the URL pattern corresponding to the unloaded
1194 // extension's URL just won't match anything anymore. 1201 // extension's URL just won't match anything anymore.
1195 } 1202 }
1196 1203
1204 void Dispatcher::OnUpdateDefaultPolicyHostRestrictions(
1205 const ExtensionMsg_UpdateDefaultPolicyHostRestrictions_Params& params) {
1206 PermissionsData::SetDefaultPolicyHostRestrictions(
1207 params.default_policy_blocked_hosts, params.default_policy_allowed_hosts);
1208 UpdateBindings(std::string());
1209 }
1210
1197 void Dispatcher::OnUpdatePermissions( 1211 void Dispatcher::OnUpdatePermissions(
1198 const ExtensionMsg_UpdatePermissions_Params& params) { 1212 const ExtensionMsg_UpdatePermissions_Params& params) {
1199 const Extension* extension = 1213 const Extension* extension =
1200 RendererExtensionRegistry::Get()->GetByID(params.extension_id); 1214 RendererExtensionRegistry::Get()->GetByID(params.extension_id);
1201 if (!extension) 1215 if (!extension)
1202 return; 1216 return;
1203 1217
1204 std::unique_ptr<const PermissionSet> active = 1218 std::unique_ptr<const PermissionSet> active =
1205 params.active_permissions.ToPermissionSet(); 1219 params.active_permissions.ToPermissionSet();
1206 std::unique_ptr<const PermissionSet> withheld = 1220 std::unique_ptr<const PermissionSet> withheld =
1207 params.withheld_permissions.ToPermissionSet(); 1221 params.withheld_permissions.ToPermissionSet();
1208 1222
1209 UpdateOriginPermissions( 1223 UpdateOriginPermissions(
1210 extension->url(), 1224 extension->url(),
1211 extension->permissions_data()->GetEffectiveHostPermissions(), 1225 extension->permissions_data()->GetEffectiveHostPermissions(),
1212 active->effective_hosts()); 1226 active->effective_hosts());
1213 1227
1214 extension->permissions_data()->SetPermissions(std::move(active), 1228 extension->permissions_data()->SetPermissions(std::move(active),
1215 std::move(withheld)); 1229 std::move(withheld));
1230 if (params.uses_default_policy_host_restrictions) {
1231 extension->permissions_data()->SetUsesDefaultHostRestrictions();
1232 } else {
1233 extension->permissions_data()->SetPolicyHostRestrictions(
1234 params.policy_blocked_hosts, params.policy_allowed_hosts);
1235 }
1216 UpdateBindings(extension->id()); 1236 UpdateBindings(extension->id());
1217 } 1237 }
1218 1238
1219 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, 1239 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url,
1220 const std::string& extension_id, 1240 const std::string& extension_id,
1221 const URLPatternSet& new_hosts, 1241 const URLPatternSet& new_hosts,
1222 bool update_origin_whitelist, 1242 bool update_origin_whitelist,
1223 int tab_id) { 1243 int tab_id) {
1224 const Extension* extension = 1244 const Extension* extension =
1225 RendererExtensionRegistry::Get()->GetByID(extension_id); 1245 RendererExtensionRegistry::Get()->GetByID(extension_id);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 // The "guestViewDeny" module must always be loaded last. It registers 1487 // The "guestViewDeny" module must always be loaded last. It registers
1468 // error-providing custom elements for the GuestView types that are not 1488 // error-providing custom elements for the GuestView types that are not
1469 // available, and thus all of those types must have been checked and loaded 1489 // available, and thus all of those types must have been checked and loaded
1470 // (or not loaded) beforehand. 1490 // (or not loaded) beforehand.
1471 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1491 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1472 module_system->Require("guestViewDeny"); 1492 module_system->Require("guestViewDeny");
1473 } 1493 }
1474 } 1494 }
1475 1495
1476 } // namespace extensions 1496 } // namespace extensions
OLDNEW
« extensions/common/extension_messages.h ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698