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 13 matching lines...) Expand all Loading... |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
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/features/feature.h" | 29 #include "extensions/common/features/feature.h" |
30 #include "extensions/common/features/feature_provider.h" | 30 #include "extensions/common/features/feature_provider.h" |
31 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
32 #include "extensions/common/manifest_constants.h" | 32 #include "extensions/common/manifest_constants.h" |
33 #include "extensions/common/manifest_handlers/background_info.h" | 33 #include "extensions/common/manifest_handlers/background_info.h" |
| 34 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
34 #include "extensions/common/manifest_handlers/externally_connectable.h" | 35 #include "extensions/common/manifest_handlers/externally_connectable.h" |
35 #include "extensions/common/manifest_handlers/options_page_info.h" | 36 #include "extensions/common/manifest_handlers/options_page_info.h" |
36 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | 37 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
37 #include "extensions/common/message_bundle.h" | 38 #include "extensions/common/message_bundle.h" |
38 #include "extensions/common/permissions/permission_set.h" | 39 #include "extensions/common/permissions/permission_set.h" |
39 #include "extensions/common/permissions/permissions_data.h" | 40 #include "extensions/common/permissions/permissions_data.h" |
40 #include "extensions/common/switches.h" | 41 #include "extensions/common/switches.h" |
41 #include "extensions/common/view_type.h" | 42 #include "extensions/common/view_type.h" |
42 #include "extensions/renderer/api_activity_logger.h" | 43 #include "extensions/renderer/api_activity_logger.h" |
43 #include "extensions/renderer/api_definitions_natives.h" | 44 #include "extensions/renderer/api_definitions_natives.h" |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1088 |
1088 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1089 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
1089 v8::HandleScope handle_scope(context->isolate()); | 1090 v8::HandleScope handle_scope(context->isolate()); |
1090 v8::Context::Scope context_scope(context->v8_context()); | 1091 v8::Context::Scope context_scope(context->v8_context()); |
1091 | 1092 |
1092 // TODO(kalman): Make the bindings registration have zero overhead then run | 1093 // TODO(kalman): Make the bindings registration have zero overhead then run |
1093 // the same code regardless of context type. | 1094 // the same code regardless of context type. |
1094 switch (context->context_type()) { | 1095 switch (context->context_type()) { |
1095 case Feature::UNSPECIFIED_CONTEXT: | 1096 case Feature::UNSPECIFIED_CONTEXT: |
1096 case Feature::WEB_PAGE_CONTEXT: | 1097 case Feature::WEB_PAGE_CONTEXT: |
1097 case Feature::BLESSED_WEB_PAGE_CONTEXT: { | 1098 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
1098 // Web page context; it's too expensive to run the full bindings code. | 1099 // Web page context; it's too expensive to run the full bindings code. |
1099 // Hard-code that the app and webstore APIs are available... | 1100 // Hard-code that the app and webstore APIs are available... |
1100 if (context->GetAvailability("app").is_available()) | 1101 if (context->GetAvailability("app").is_available()) |
1101 RegisterBinding("app", context); | 1102 RegisterBinding("app", context); |
1102 | |
1103 if (context->GetAvailability("webstore").is_available()) | 1103 if (context->GetAvailability("webstore").is_available()) |
1104 RegisterBinding("webstore", context); | 1104 RegisterBinding("webstore", context); |
1105 | 1105 if (IsRuntimeAvailableToContext(context)) |
1106 // ... and that the runtime API might be available if any extension can | |
1107 // connect to it. | |
1108 bool runtime_is_available = false; | |
1109 for (ExtensionSet::const_iterator it = extensions_.begin(); | |
1110 it != extensions_.end(); | |
1111 ++it) { | |
1112 ExternallyConnectableInfo* info = | |
1113 static_cast<ExternallyConnectableInfo*>( | |
1114 (*it)->GetManifestData(manifest_keys::kExternallyConnectable)); | |
1115 if (info && info->matches.MatchesURL(context->GetURL())) { | |
1116 runtime_is_available = true; | |
1117 break; | |
1118 } | |
1119 } | |
1120 if (runtime_is_available) | |
1121 RegisterBinding("runtime", context); | 1106 RegisterBinding("runtime", context); |
| 1107 UpdateContentCapabilities(context); |
1122 break; | 1108 break; |
1123 } | |
1124 | 1109 |
1125 case Feature::BLESSED_EXTENSION_CONTEXT: | 1110 case Feature::BLESSED_EXTENSION_CONTEXT: |
1126 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1111 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
1127 case Feature::CONTENT_SCRIPT_CONTEXT: | 1112 case Feature::CONTENT_SCRIPT_CONTEXT: |
1128 case Feature::WEBUI_CONTEXT: { | 1113 case Feature::WEBUI_CONTEXT: { |
1129 // Extension context; iterate through all the APIs and bind the available | 1114 // Extension context; iterate through all the APIs and bind the available |
1130 // ones. | 1115 // ones. |
1131 const FeatureProvider* api_feature_provider = | 1116 const FeatureProvider* api_feature_provider = |
1132 FeatureProvider::GetAPIFeatures(); | 1117 FeatureProvider::GetAPIFeatures(); |
1133 const std::vector<std::string>& apis = | 1118 const std::vector<std::string>& apis = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 context, | 1210 context, |
1226 context->GetExtensionID(), | 1211 context->GetExtensionID(), |
1227 context->GetContextTypeDescription(), | 1212 context->GetContextTypeDescription(), |
1228 ExtensionsRendererClient::Get()->IsIncognitoProcess(), | 1213 ExtensionsRendererClient::Get()->IsIncognitoProcess(), |
1229 manifest_version, | 1214 manifest_version, |
1230 send_request_disabled))); | 1215 send_request_disabled))); |
1231 | 1216 |
1232 delegate_->RegisterNativeHandlers(this, module_system, context); | 1217 delegate_->RegisterNativeHandlers(this, module_system, context); |
1233 } | 1218 } |
1234 | 1219 |
| 1220 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
| 1221 for (const auto& extension : extensions_) { |
| 1222 ExternallyConnectableInfo* info = |
| 1223 static_cast<ExternallyConnectableInfo*>( |
| 1224 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
| 1225 if (info && info->matches.MatchesURL(context->GetURL())) |
| 1226 return true; |
| 1227 } |
| 1228 return false; |
| 1229 } |
| 1230 |
| 1231 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
| 1232 APIPermissionSet permissions; |
| 1233 for (const auto& extension : extensions_) { |
| 1234 const ContentCapabilitiesInfo& info = ContentCapabilitiesInfo::Get( |
| 1235 extension.get()); |
| 1236 if (info.url_patterns.MatchesURL(context->GetURL())) { |
| 1237 APIPermissionSet new_permissions; |
| 1238 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); |
| 1239 permissions = new_permissions; |
| 1240 } |
| 1241 } |
| 1242 context->SetContentCapabilities(permissions); |
| 1243 } |
| 1244 |
1235 void Dispatcher::PopulateSourceMap() { | 1245 void Dispatcher::PopulateSourceMap() { |
1236 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); | 1246 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1237 for (std::vector<std::pair<std::string, int> >::const_iterator resource = | 1247 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1238 resources.begin(); | 1248 resources.begin(); |
1239 resource != resources.end(); | 1249 resource != resources.end(); |
1240 ++resource) { | 1250 ++resource) { |
1241 source_map_.RegisterSource(resource->first, resource->second); | 1251 source_map_.RegisterSource(resource->first, resource->second); |
1242 } | 1252 } |
1243 delegate_->PopulateSourceMap(&source_map_); | 1253 delegate_->PopulateSourceMap(&source_map_); |
1244 } | 1254 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 return v8::Handle<v8::Object>(); | 1399 return v8::Handle<v8::Object>(); |
1390 | 1400 |
1391 if (bind_name) | 1401 if (bind_name) |
1392 *bind_name = split.back(); | 1402 *bind_name = split.back(); |
1393 | 1403 |
1394 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1404 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1395 : bind_object; | 1405 : bind_object; |
1396 } | 1406 } |
1397 | 1407 |
1398 } // namespace extensions | 1408 } // namespace extensions |
OLD | NEW |