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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Fixed static non-pod, removed default params, fixed formatting, fixed nits, simplified code 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 URLPatternSet runtime_blocked_hosts = param.runtime_blocked_hosts;
dcheng 2017/02/06 07:05:29 const URLPatternSet& here and below (the current i
nrpeter 2017/02/06 22:53:15 Done.
1085 URLPatternSet runtime_allowed_hosts = param.runtime_allowed_hosts;
1086 extension->permissions_data()->SetPolicyHostRestrictions(
1087 runtime_blocked_hosts, runtime_allowed_hosts,
1088 param.is_default_runtime_blocked_allowed_hosts);
1083 } 1089 }
1084 1090
1085 // Update the available bindings for all contexts. These may have changed if 1091 // Update the available bindings for all contexts. These may have changed if
1086 // an externally_connectable extension was loaded that can connect to an 1092 // an externally_connectable extension was loaded that can connect to an
1087 // open webpage. 1093 // open webpage.
1088 UpdateBindings(""); 1094 UpdateBindings("");
1089 } 1095 }
1090 1096
1091 void Dispatcher::OnMessageInvoke(const std::string& extension_id, 1097 void Dispatcher::OnMessageInvoke(const std::string& extension_id,
1092 const std::string& module_name, 1098 const std::string& module_name,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1186
1181 // Invalidates the messages map for the extension in case the extension is 1187 // Invalidates the messages map for the extension in case the extension is
1182 // reloaded with a new messages map. 1188 // reloaded with a new messages map.
1183 EraseL10nMessagesMap(id); 1189 EraseL10nMessagesMap(id);
1184 1190
1185 // We don't do anything with existing platform-app stylesheets. They will 1191 // We don't do anything with existing platform-app stylesheets. They will
1186 // stay resident, but the URL pattern corresponding to the unloaded 1192 // stay resident, but the URL pattern corresponding to the unloaded
1187 // extension's URL just won't match anything anymore. 1193 // extension's URL just won't match anything anymore.
1188 } 1194 }
1189 1195
1196 void Dispatcher::OnUpdateDefaultPolicyHostRestrictions(
1197 const ExtensionMsg_UpdateDefaultPolicyHostRestrictions_Params& params) {
1198 URLPatternSet blocked = params.default_runtime_blocked_hosts;
1199 URLPatternSet allowed = params.default_runtime_allowed_hosts;
1200 PermissionsData::SetDefaultPolicyHostRestrictions(blocked, allowed);
1201 UpdateBindings("");
dcheng 2017/02/06 07:05:29 Nit: std::string() rather than ""
nrpeter 2017/02/06 22:53:15 Done. FYI: Everywhere else in the file that we us
dcheng 2017/02/07 07:47:12 Yeah, it's more about long-term consistency here.
nrpeter 2017/03/22 23:47:38 Done.
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 URLPatternSet runtime_blocked_hosts;
1224 URLPatternSet runtime_allowed_hosts;
1225 if (!params.uses_default_policy_host_restrictions) {
1226 runtime_blocked_hosts = params.runtime_blocked_hosts;
1227 runtime_allowed_hosts = params.runtime_allowed_hosts;
1228 }
1229 extension->permissions_data()->SetPolicyHostRestrictions(
1230 runtime_blocked_hosts, runtime_allowed_hosts,
1231 params.uses_default_policy_host_restrictions);
1209 UpdateBindings(extension->id()); 1232 UpdateBindings(extension->id());
1210 } 1233 }
1211 1234
1212 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, 1235 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url,
1213 const std::string& extension_id, 1236 const std::string& extension_id,
1214 const URLPatternSet& new_hosts, 1237 const URLPatternSet& new_hosts,
1215 bool update_origin_whitelist, 1238 bool update_origin_whitelist,
1216 int tab_id) { 1239 int tab_id) {
1217 const Extension* extension = 1240 const Extension* extension =
1218 RendererExtensionRegistry::Get()->GetByID(extension_id); 1241 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 1673 // The "guestViewDeny" module must always be loaded last. It registers
1651 // error-providing custom elements for the GuestView types that are not 1674 // 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 1675 // available, and thus all of those types must have been checked and loaded
1653 // (or not loaded) beforehand. 1676 // (or not loaded) beforehand.
1654 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1677 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1655 module_system->Require("guestViewDeny"); 1678 module_system->Require("guestViewDeny");
1656 } 1679 }
1657 } 1680 }
1658 1681
1659 } // namespace extensions 1682 } // namespace extensions
OLDNEW
« extensions/common/url_pattern.h ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698