| OLD | NEW |
| 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 901 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
| 902 OnSetScriptingWhitelist) | 902 OnSetScriptingWhitelist) |
| 903 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) | 903 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) |
| 904 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, | 904 IPC_MESSAGE_HANDLER(ExtensionMsg_SetWebViewPartitionID, |
| 905 OnSetWebViewPartitionID) | 905 OnSetWebViewPartitionID) |
| 906 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) | 906 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) |
| 907 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) | 907 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) |
| 908 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) | 908 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) |
| 909 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 909 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
| 910 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 910 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
| 911 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateDefaultPolicyHostRestrictions, |
| 912 OnUpdateDefaultPolicyHostRestrictions) |
| 911 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, | 913 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, |
| 912 OnUpdateTabSpecificPermissions) | 914 OnUpdateTabSpecificPermissions) |
| 913 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, | 915 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, |
| 914 OnClearTabSpecificPermissions) | 916 OnClearTabSpecificPermissions) |
| 915 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, | 917 IPC_MESSAGE_HANDLER(ExtensionMsg_SetActivityLoggingEnabled, |
| 916 OnSetActivityLoggingEnabled) | 918 OnSetActivityLoggingEnabled) |
| 917 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, | 919 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, |
| 918 content_watcher_.get(), | 920 content_watcher_.get(), |
| 919 ContentWatcher::OnWatchPages) | 921 ContentWatcher::OnWatchPages) |
| 920 IPC_MESSAGE_UNHANDLED(handled = false) | 922 IPC_MESSAGE_UNHANDLED(handled = false) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 for (const auto& param : loaded_extensions) { | 1026 for (const auto& param : loaded_extensions) { |
| 1025 std::string error; | 1027 std::string error; |
| 1026 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); | 1028 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); |
| 1027 if (!extension.get()) { | 1029 if (!extension.get()) { |
| 1028 NOTREACHED() << error; | 1030 NOTREACHED() << error; |
| 1029 // Note: in tests |param.id| has been observed to be empty (see comment | 1031 // Note: in tests |param.id| has been observed to be empty (see comment |
| 1030 // just below) so this isn't all that reliable. | 1032 // just below) so this isn't all that reliable. |
| 1031 extension_load_errors_[param.id] = error; | 1033 extension_load_errors_[param.id] = error; |
| 1032 continue; | 1034 continue; |
| 1033 } | 1035 } |
| 1034 | |
| 1035 RendererExtensionRegistry* extension_registry = | 1036 RendererExtensionRegistry* extension_registry = |
| 1036 RendererExtensionRegistry::Get(); | 1037 RendererExtensionRegistry::Get(); |
| 1037 // TODO(kalman): This test is deliberately not a CHECK (though I wish it | 1038 // TODO(kalman): This test is deliberately not a CHECK (though I wish it |
| 1038 // could be) and uses extension->id() not params.id: | 1039 // could be) and uses extension->id() not params.id: |
| 1039 // 1. For some reason params.id can be empty. I've only seen it with | 1040 // 1. For some reason params.id can be empty. I've only seen it with |
| 1040 // the webstore extension, in tests, and I've spent some time trying to | 1041 // the webstore extension, in tests, and I've spent some time trying to |
| 1041 // figure out why - but cost/benefit won. | 1042 // figure out why - but cost/benefit won. |
| 1042 // 2. The browser only sends this IPC to RenderProcessHosts once, but the | 1043 // 2. The browser only sends this IPC to RenderProcessHosts once, but the |
| 1043 // Dispatcher is attached to a RenderThread. Presumably there is a | 1044 // Dispatcher is attached to a RenderThread. Presumably there is a |
| 1044 // mismatch there. In theory one would think it's possible for the | 1045 // mismatch there. In theory one would think it's possible for the |
| 1045 // browser to figure this out itself - but again, cost/benefit. | 1046 // browser to figure this out itself - but again, cost/benefit. |
| 1046 if (!extension_registry->Insert(extension)) { | 1047 if (!extension_registry->Insert(extension)) { |
| 1047 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and | 1048 // TODO(devlin): This may be fixed by crbug.com/528026. Monitor, and |
| 1048 // consider making this a release CHECK. | 1049 // consider making this a release CHECK. |
| 1049 NOTREACHED(); | 1050 NOTREACHED(); |
| 1050 } | 1051 } |
| 1052 if (param.uses_default_policy_blocked_allowed_hosts) { |
| 1053 extension->permissions_data()->SetUsesDefaultHostRestrictions(); |
| 1054 } else { |
| 1055 extension->permissions_data()->SetPolicyHostRestrictions( |
| 1056 param.policy_blocked_hosts, param.policy_allowed_hosts); |
| 1057 } |
| 1051 } | 1058 } |
| 1052 | 1059 |
| 1053 // Update the available bindings for all contexts. These may have changed if | 1060 // Update the available bindings for all contexts. These may have changed if |
| 1054 // an externally_connectable extension was loaded that can connect to an | 1061 // an externally_connectable extension was loaded that can connect to an |
| 1055 // open webpage. | 1062 // open webpage. |
| 1056 UpdateBindings(""); | 1063 UpdateBindings(std::string()); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| 1059 void Dispatcher::OnMessageInvoke(const std::string& extension_id, | 1066 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
| 1060 const std::string& module_name, | 1067 const std::string& module_name, |
| 1061 const std::string& function_name, | 1068 const std::string& function_name, |
| 1062 const base::ListValue& args) { | 1069 const base::ListValue& args) { |
| 1063 InvokeModuleSystemMethod(nullptr, extension_id, module_name, function_name, | 1070 InvokeModuleSystemMethod(nullptr, extension_id, module_name, function_name, |
| 1064 args); | 1071 args); |
| 1065 } | 1072 } |
| 1066 | 1073 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 | 1180 |
| 1174 // Invalidates the messages map for the extension in case the extension is | 1181 // Invalidates the messages map for the extension in case the extension is |
| 1175 // reloaded with a new messages map. | 1182 // reloaded with a new messages map. |
| 1176 EraseL10nMessagesMap(id); | 1183 EraseL10nMessagesMap(id); |
| 1177 | 1184 |
| 1178 // We don't do anything with existing platform-app stylesheets. They will | 1185 // We don't do anything with existing platform-app stylesheets. They will |
| 1179 // stay resident, but the URL pattern corresponding to the unloaded | 1186 // stay resident, but the URL pattern corresponding to the unloaded |
| 1180 // extension's URL just won't match anything anymore. | 1187 // extension's URL just won't match anything anymore. |
| 1181 } | 1188 } |
| 1182 | 1189 |
| 1190 void Dispatcher::OnUpdateDefaultPolicyHostRestrictions( |
| 1191 const ExtensionMsg_UpdateDefaultPolicyHostRestrictions_Params& params) { |
| 1192 PermissionsData::SetDefaultPolicyHostRestrictions( |
| 1193 params.default_policy_blocked_hosts, params.default_policy_allowed_hosts); |
| 1194 UpdateBindings(std::string()); |
| 1195 } |
| 1196 |
| 1183 void Dispatcher::OnUpdatePermissions( | 1197 void Dispatcher::OnUpdatePermissions( |
| 1184 const ExtensionMsg_UpdatePermissions_Params& params) { | 1198 const ExtensionMsg_UpdatePermissions_Params& params) { |
| 1185 const Extension* extension = | 1199 const Extension* extension = |
| 1186 RendererExtensionRegistry::Get()->GetByID(params.extension_id); | 1200 RendererExtensionRegistry::Get()->GetByID(params.extension_id); |
| 1187 if (!extension) | 1201 if (!extension) |
| 1188 return; | 1202 return; |
| 1189 | 1203 |
| 1190 std::unique_ptr<const PermissionSet> active = | 1204 std::unique_ptr<const PermissionSet> active = |
| 1191 params.active_permissions.ToPermissionSet(); | 1205 params.active_permissions.ToPermissionSet(); |
| 1192 std::unique_ptr<const PermissionSet> withheld = | 1206 std::unique_ptr<const PermissionSet> withheld = |
| 1193 params.withheld_permissions.ToPermissionSet(); | 1207 params.withheld_permissions.ToPermissionSet(); |
| 1194 | 1208 |
| 1195 UpdateOriginPermissions( | 1209 UpdateOriginPermissions( |
| 1196 extension->url(), | 1210 extension->url(), |
| 1197 extension->permissions_data()->GetEffectiveHostPermissions(), | 1211 extension->permissions_data()->GetEffectiveHostPermissions(), |
| 1198 active->effective_hosts()); | 1212 active->effective_hosts()); |
| 1199 | 1213 |
| 1200 extension->permissions_data()->SetPermissions(std::move(active), | 1214 extension->permissions_data()->SetPermissions(std::move(active), |
| 1201 std::move(withheld)); | 1215 std::move(withheld)); |
| 1216 if (params.uses_default_policy_host_restrictions) { |
| 1217 extension->permissions_data()->SetUsesDefaultHostRestrictions(); |
| 1218 } else { |
| 1219 extension->permissions_data()->SetPolicyHostRestrictions( |
| 1220 params.policy_blocked_hosts, params.policy_allowed_hosts); |
| 1221 } |
| 1202 UpdateBindings(extension->id()); | 1222 UpdateBindings(extension->id()); |
| 1203 } | 1223 } |
| 1204 | 1224 |
| 1205 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, | 1225 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, |
| 1206 const std::string& extension_id, | 1226 const std::string& extension_id, |
| 1207 const URLPatternSet& new_hosts, | 1227 const URLPatternSet& new_hosts, |
| 1208 bool update_origin_whitelist, | 1228 bool update_origin_whitelist, |
| 1209 int tab_id) { | 1229 int tab_id) { |
| 1210 const Extension* extension = | 1230 const Extension* extension = |
| 1211 RendererExtensionRegistry::Get()->GetByID(extension_id); | 1231 RendererExtensionRegistry::Get()->GetByID(extension_id); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 // The "guestViewDeny" module must always be loaded last. It registers | 1473 // The "guestViewDeny" module must always be loaded last. It registers |
| 1454 // error-providing custom elements for the GuestView types that are not | 1474 // error-providing custom elements for the GuestView types that are not |
| 1455 // available, and thus all of those types must have been checked and loaded | 1475 // available, and thus all of those types must have been checked and loaded |
| 1456 // (or not loaded) beforehand. | 1476 // (or not loaded) beforehand. |
| 1457 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1477 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1458 module_system->Require("guestViewDeny"); | 1478 module_system->Require("guestViewDeny"); |
| 1459 } | 1479 } |
| 1460 } | 1480 } |
| 1461 | 1481 |
| 1462 } // namespace extensions | 1482 } // namespace extensions |
| OLD | NEW |