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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_api.h" | 26 #include "extensions/common/extension_api.h" |
27 #include "extensions/common/extension_messages.h" | 27 #include "extensions/common/extension_messages.h" |
28 #include "extensions/common/extension_urls.h" | 28 #include "extensions/common/extension_urls.h" |
29 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
30 #include "extensions/common/features/feature.h" | 30 #include "extensions/common/features/feature.h" |
31 #include "extensions/common/features/feature_provider.h" | 31 #include "extensions/common/features/feature_provider.h" |
32 #include "extensions/common/manifest.h" | 32 #include "extensions/common/manifest.h" |
33 #include "extensions/common/manifest_constants.h" | 33 #include "extensions/common/manifest_constants.h" |
34 #include "extensions/common/manifest_handlers/background_info.h" | 34 #include "extensions/common/manifest_handlers/background_info.h" |
| 35 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
35 #include "extensions/common/manifest_handlers/externally_connectable.h" | 36 #include "extensions/common/manifest_handlers/externally_connectable.h" |
36 #include "extensions/common/manifest_handlers/options_page_info.h" | 37 #include "extensions/common/manifest_handlers/options_page_info.h" |
37 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | 38 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
38 #include "extensions/common/message_bundle.h" | 39 #include "extensions/common/message_bundle.h" |
39 #include "extensions/common/permissions/permission_set.h" | 40 #include "extensions/common/permissions/permission_set.h" |
40 #include "extensions/common/permissions/permissions_data.h" | 41 #include "extensions/common/permissions/permissions_data.h" |
41 #include "extensions/common/switches.h" | 42 #include "extensions/common/switches.h" |
42 #include "extensions/common/view_type.h" | 43 #include "extensions/common/view_type.h" |
43 #include "extensions/renderer/api_activity_logger.h" | 44 #include "extensions/renderer/api_activity_logger.h" |
44 #include "extensions/renderer/api_definitions_natives.h" | 45 #include "extensions/renderer/api_definitions_natives.h" |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 | 1098 |
1098 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1099 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
1099 v8::HandleScope handle_scope(context->isolate()); | 1100 v8::HandleScope handle_scope(context->isolate()); |
1100 v8::Context::Scope context_scope(context->v8_context()); | 1101 v8::Context::Scope context_scope(context->v8_context()); |
1101 | 1102 |
1102 // TODO(kalman): Make the bindings registration have zero overhead then run | 1103 // TODO(kalman): Make the bindings registration have zero overhead then run |
1103 // the same code regardless of context type. | 1104 // the same code regardless of context type. |
1104 switch (context->context_type()) { | 1105 switch (context->context_type()) { |
1105 case Feature::UNSPECIFIED_CONTEXT: | 1106 case Feature::UNSPECIFIED_CONTEXT: |
1106 case Feature::WEB_PAGE_CONTEXT: | 1107 case Feature::WEB_PAGE_CONTEXT: |
1107 case Feature::BLESSED_WEB_PAGE_CONTEXT: { | 1108 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
1108 // Web page context; it's too expensive to run the full bindings code. | 1109 // Web page context; it's too expensive to run the full bindings code. |
1109 // Hard-code that the app and webstore APIs are available... | 1110 // Hard-code that the app and webstore APIs are available... |
1110 if (context->GetAvailability("app").is_available()) | 1111 if (context->GetAvailability("app").is_available()) |
1111 RegisterBinding("app", context); | 1112 RegisterBinding("app", context); |
1112 | |
1113 if (context->GetAvailability("webstore").is_available()) | 1113 if (context->GetAvailability("webstore").is_available()) |
1114 RegisterBinding("webstore", context); | 1114 RegisterBinding("webstore", context); |
1115 | 1115 if (IsRuntimeAvailableToContext(context)) |
1116 // ... and that the runtime API might be available if any extension can | |
1117 // connect to it. | |
1118 bool runtime_is_available = | |
1119 extensions::FeatureSwitch::worker_frame()->IsEnabled() && | |
1120 context->GetAvailability("workerFrameInternal").is_available(); | |
1121 for (ExtensionSet::const_iterator it = extensions_.begin(); | |
1122 it != extensions_.end(); | |
1123 ++it) { | |
1124 ExternallyConnectableInfo* info = | |
1125 static_cast<ExternallyConnectableInfo*>( | |
1126 (*it)->GetManifestData(manifest_keys::kExternallyConnectable)); | |
1127 if (info && info->matches.MatchesURL(context->GetURL())) { | |
1128 runtime_is_available = true; | |
1129 break; | |
1130 } | |
1131 } | |
1132 if (runtime_is_available) | |
1133 RegisterBinding("runtime", context); | 1116 RegisterBinding("runtime", context); |
| 1117 UpdateContentCapabilities(context); |
1134 break; | 1118 break; |
1135 } | |
1136 | 1119 |
1137 case Feature::BLESSED_EXTENSION_CONTEXT: | 1120 case Feature::BLESSED_EXTENSION_CONTEXT: |
1138 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1121 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
1139 case Feature::CONTENT_SCRIPT_CONTEXT: | 1122 case Feature::CONTENT_SCRIPT_CONTEXT: |
1140 case Feature::WEBUI_CONTEXT: { | 1123 case Feature::WEBUI_CONTEXT: { |
1141 // Extension context; iterate through all the APIs and bind the available | 1124 // Extension context; iterate through all the APIs and bind the available |
1142 // ones. | 1125 // ones. |
1143 const FeatureProvider* api_feature_provider = | 1126 const FeatureProvider* api_feature_provider = |
1144 FeatureProvider::GetAPIFeatures(); | 1127 FeatureProvider::GetAPIFeatures(); |
1145 const std::vector<std::string>& apis = | 1128 const std::vector<std::string>& apis = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 context, | 1220 context, |
1238 context->GetExtensionID(), | 1221 context->GetExtensionID(), |
1239 context->GetContextTypeDescription(), | 1222 context->GetContextTypeDescription(), |
1240 ExtensionsRendererClient::Get()->IsIncognitoProcess(), | 1223 ExtensionsRendererClient::Get()->IsIncognitoProcess(), |
1241 manifest_version, | 1224 manifest_version, |
1242 send_request_disabled))); | 1225 send_request_disabled))); |
1243 | 1226 |
1244 delegate_->RegisterNativeHandlers(this, module_system, context); | 1227 delegate_->RegisterNativeHandlers(this, module_system, context); |
1245 } | 1228 } |
1246 | 1229 |
| 1230 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
| 1231 if (extensions::FeatureSwitch::worker_frame()->IsEnabled() && |
| 1232 context->GetAvailability("workerFrameInternal").is_available()) { |
| 1233 return true; |
| 1234 } |
| 1235 for (const auto& extension : extensions_) { |
| 1236 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
| 1237 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
| 1238 if (info && info->matches.MatchesURL(context->GetURL())) |
| 1239 return true; |
| 1240 } |
| 1241 return false; |
| 1242 } |
| 1243 |
| 1244 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
| 1245 APIPermissionSet permissions; |
| 1246 for (const auto& extension : extensions_) { |
| 1247 const ContentCapabilitiesInfo& info = |
| 1248 ContentCapabilitiesInfo::Get(extension.get()); |
| 1249 if (info.url_patterns.MatchesURL(context->GetURL())) { |
| 1250 APIPermissionSet new_permissions; |
| 1251 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); |
| 1252 permissions = new_permissions; |
| 1253 } |
| 1254 } |
| 1255 context->SetContentCapabilities(permissions); |
| 1256 } |
| 1257 |
1247 void Dispatcher::PopulateSourceMap() { | 1258 void Dispatcher::PopulateSourceMap() { |
1248 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); | 1259 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1249 for (std::vector<std::pair<std::string, int> >::const_iterator resource = | 1260 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1250 resources.begin(); | 1261 resources.begin(); |
1251 resource != resources.end(); | 1262 resource != resources.end(); |
1252 ++resource) { | 1263 ++resource) { |
1253 source_map_.RegisterSource(resource->first, resource->second); | 1264 source_map_.RegisterSource(resource->first, resource->second); |
1254 } | 1265 } |
1255 delegate_->PopulateSourceMap(&source_map_); | 1266 delegate_->PopulateSourceMap(&source_map_); |
1256 } | 1267 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1401 return v8::Handle<v8::Object>(); | 1412 return v8::Handle<v8::Object>(); |
1402 | 1413 |
1403 if (bind_name) | 1414 if (bind_name) |
1404 *bind_name = split.back(); | 1415 *bind_name = split.back(); |
1405 | 1416 |
1406 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1417 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1407 : bind_object; | 1418 : bind_object; |
1408 } | 1419 } |
1409 | 1420 |
1410 } // namespace extensions | 1421 } // namespace extensions |
OLD | NEW |