| 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 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 1148 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
| 1149 v8::HandleScope handle_scope(context->isolate()); | 1149 v8::HandleScope handle_scope(context->isolate()); |
| 1150 v8::Context::Scope context_scope(context->v8_context()); | 1150 v8::Context::Scope context_scope(context->v8_context()); |
| 1151 | 1151 |
| 1152 // TODO(kalman): Make the bindings registration have zero overhead then run | 1152 // TODO(kalman): Make the bindings registration have zero overhead then run |
| 1153 // the same code regardless of context type. | 1153 // the same code regardless of context type. |
| 1154 switch (context->context_type()) { | 1154 switch (context->context_type()) { |
| 1155 case Feature::UNSPECIFIED_CONTEXT: | 1155 case Feature::UNSPECIFIED_CONTEXT: |
| 1156 case Feature::WEB_PAGE_CONTEXT: | 1156 case Feature::WEB_PAGE_CONTEXT: |
| 1157 case Feature::BLESSED_WEB_PAGE_CONTEXT: | 1157 case Feature::BLESSED_WEB_PAGE_CONTEXT: |
| 1158 // Web page context; it's too expensive to run the full bindings code. | 1158 // Hard-code registration of any APIs that are exposed to webpage-like |
| 1159 // Hard-code that the app and webstore APIs are available... | 1159 // contexts, because it's too expensive to run the full bindings code. |
| 1160 // All of the same permission checks will still apply. |
| 1160 if (context->GetAvailability("app").is_available()) | 1161 if (context->GetAvailability("app").is_available()) |
| 1161 RegisterBinding("app", context); | 1162 RegisterBinding("app", context); |
| 1162 if (context->GetAvailability("webstore").is_available()) | 1163 if (context->GetAvailability("webstore").is_available()) |
| 1163 RegisterBinding("webstore", context); | 1164 RegisterBinding("webstore", context); |
| 1165 if (context->GetAvailability("dashboardPrivate").is_available()) |
| 1166 RegisterBinding("dashboardPrivate", context); |
| 1164 if (IsRuntimeAvailableToContext(context)) | 1167 if (IsRuntimeAvailableToContext(context)) |
| 1165 RegisterBinding("runtime", context); | 1168 RegisterBinding("runtime", context); |
| 1166 UpdateContentCapabilities(context); | 1169 UpdateContentCapabilities(context); |
| 1167 break; | 1170 break; |
| 1168 | 1171 |
| 1169 case Feature::BLESSED_EXTENSION_CONTEXT: | 1172 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 1170 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 1173 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 1171 case Feature::CONTENT_SCRIPT_CONTEXT: | 1174 case Feature::CONTENT_SCRIPT_CONTEXT: |
| 1172 case Feature::WEBUI_CONTEXT: { | 1175 case Feature::WEBUI_CONTEXT: { |
| 1173 // Extension context; iterate through all the APIs and bind the available | 1176 // Extension context; iterate through all the APIs and bind the available |
| 1174 // ones. | 1177 // ones. |
| 1175 const FeatureProvider* api_feature_provider = | 1178 const FeatureProvider* api_feature_provider = |
| 1176 FeatureProvider::GetAPIFeatures(); | 1179 FeatureProvider::GetAPIFeatures(); |
| 1177 const std::vector<std::string>& apis = | 1180 const std::vector<std::string>& apis = |
| 1178 api_feature_provider->GetAllFeatureNames(); | 1181 api_feature_provider->GetAllFeatureNames(); |
| 1179 for (std::vector<std::string>::const_iterator it = apis.begin(); | 1182 for (const std::string& api_name : apis) { |
| 1180 it != apis.end(); | |
| 1181 ++it) { | |
| 1182 const std::string& api_name = *it; | |
| 1183 Feature* feature = api_feature_provider->GetFeature(api_name); | 1183 Feature* feature = api_feature_provider->GetFeature(api_name); |
| 1184 DCHECK(feature); | 1184 DCHECK(feature); |
| 1185 | 1185 |
| 1186 // Internal APIs are included via require(api_name) from internal code | 1186 // Internal APIs are included via require(api_name) from internal code |
| 1187 // rather than chrome[api_name]. | 1187 // rather than chrome[api_name]. |
| 1188 if (feature->IsInternal()) | 1188 if (feature->IsInternal()) |
| 1189 continue; | 1189 continue; |
| 1190 | 1190 |
| 1191 // If this API has a parent feature (and isn't marked 'noparent'), | 1191 // If this API has a parent feature (and isn't marked 'noparent'), |
| 1192 // then this must be a function or event, so we should not register. | 1192 // then this must be a function or event, so we should not register. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 void Dispatcher::AddChannelSpecificFeatures() { | 1452 void Dispatcher::AddChannelSpecificFeatures() { |
| 1453 // chrome-extension: resources should be allowed to register a Service Worker. | 1453 // chrome-extension: resources should be allowed to register a Service Worker. |
| 1454 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) | 1454 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) |
| 1455 ->IsAvailableToEnvironment() | 1455 ->IsAvailableToEnvironment() |
| 1456 .is_available()) | 1456 .is_available()) |
| 1457 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( | 1457 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( |
| 1458 WebString::fromUTF8(kExtensionScheme)); | 1458 WebString::fromUTF8(kExtensionScheme)); |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 } // namespace extensions | 1461 } // namespace extensions |
| OLD | NEW |