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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
996 v8::Context::Scope context_scope(context->v8_context()); | 996 v8::Context::Scope context_scope(context->v8_context()); |
997 | 997 |
998 // TODO(kalman): Make the bindings registration have zero overhead then run | 998 // TODO(kalman): Make the bindings registration have zero overhead then run |
999 // the same code regardless of context type. | 999 // the same code regardless of context type. |
1000 switch (context->context_type()) { | 1000 switch (context->context_type()) { |
1001 case Feature::UNSPECIFIED_CONTEXT: | 1001 case Feature::UNSPECIFIED_CONTEXT: |
1002 case Feature::WEB_PAGE_CONTEXT: | 1002 case Feature::WEB_PAGE_CONTEXT: |
1003 case Feature::BLESSED_WEB_PAGE_CONTEXT: { | 1003 case Feature::BLESSED_WEB_PAGE_CONTEXT: { |
1004 // Web page context; it's too expensive to run the full bindings code. | 1004 // Web page context; it's too expensive to run the full bindings code. |
1005 // Hard-code that the app and webstore APIs are available... | 1005 // Hard-code that the app and webstore APIs are available... |
1006 RegisterBinding("app", context); | 1006 if (IsApiAvailable(std::string("app"), context)) |
not at google - send to devlin
2014/08/05 22:43:39
it's easier to do
if (context->GetAvailability("a
sadrul
2014/08/05 22:51:02
Nice! Done.
| |
1007 RegisterBinding("webstore", context); | 1007 RegisterBinding("app", context); |
1008 | |
1009 if (IsApiAvailable(std::string("webstore"), context)) | |
not at google - send to devlin
2014/08/05 22:43:39
also, no need to explicitly construct a std::strin
sadrul
2014/08/05 22:51:02
Acknowledged.
| |
1010 RegisterBinding("webstore", context); | |
not at google - send to devlin
2014/08/05 22:43:39
indentation
sadrul
2014/08/05 22:51:02
Done.
| |
1008 | 1011 |
1009 // ... and that the runtime API might be available if any extension can | 1012 // ... and that the runtime API might be available if any extension can |
1010 // connect to it. | 1013 // connect to it. |
1011 bool runtime_is_available = false; | 1014 bool runtime_is_available = false; |
1012 for (ExtensionSet::const_iterator it = extensions_.begin(); | 1015 for (ExtensionSet::const_iterator it = extensions_.begin(); |
1013 it != extensions_.end(); | 1016 it != extensions_.end(); |
1014 ++it) { | 1017 ++it) { |
1015 ExternallyConnectableInfo* info = | 1018 ExternallyConnectableInfo* info = |
1016 static_cast<ExternallyConnectableInfo*>( | 1019 static_cast<ExternallyConnectableInfo*>( |
1017 (*it)->GetManifestData(manifest_keys::kExternallyConnectable)); | 1020 (*it)->GetManifestData(manifest_keys::kExternallyConnectable)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1159 bool Dispatcher::IsSandboxedPage(const GURL& url) const { | 1162 bool Dispatcher::IsSandboxedPage(const GURL& url) const { |
1160 if (url.SchemeIs(kExtensionScheme)) { | 1163 if (url.SchemeIs(kExtensionScheme)) { |
1161 const Extension* extension = extensions_.GetByID(url.host()); | 1164 const Extension* extension = extensions_.GetByID(url.host()); |
1162 if (extension) { | 1165 if (extension) { |
1163 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); | 1166 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); |
1164 } | 1167 } |
1165 } | 1168 } |
1166 return false; | 1169 return false; |
1167 } | 1170 } |
1168 | 1171 |
1172 bool Dispatcher::IsApiAvailable(const std::string& api_name, | |
1173 ScriptContext* context) { | |
1174 return ExtensionAPI::GetSharedInstance()->IsAvailable( | |
1175 api_name, context->extension(), context->context_type(), | |
1176 context->GetURL()).is_available(); | |
1177 } | |
1178 | |
1169 Feature::Context Dispatcher::ClassifyJavaScriptContext( | 1179 Feature::Context Dispatcher::ClassifyJavaScriptContext( |
1170 const Extension* extension, | 1180 const Extension* extension, |
1171 int extension_group, | 1181 int extension_group, |
1172 const GURL& url, | 1182 const GURL& url, |
1173 const blink::WebSecurityOrigin& origin) { | 1183 const blink::WebSecurityOrigin& origin) { |
1174 DCHECK_GE(extension_group, 0); | 1184 DCHECK_GE(extension_group, 0); |
1175 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { | 1185 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { |
1176 return extension ? // TODO(kalman): when does this happen? | 1186 return extension ? // TODO(kalman): when does this happen? |
1177 Feature::CONTENT_SCRIPT_CONTEXT | 1187 Feature::CONTENT_SCRIPT_CONTEXT |
1178 : Feature::UNSPECIFIED_CONTEXT; | 1188 : Feature::UNSPECIFIED_CONTEXT; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 return v8::Handle<v8::Object>(); | 1295 return v8::Handle<v8::Object>(); |
1286 | 1296 |
1287 if (bind_name) | 1297 if (bind_name) |
1288 *bind_name = split.back(); | 1298 *bind_name = split.back(); |
1289 | 1299 |
1290 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1300 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1291 : bind_object; | 1301 : bind_object; |
1292 } | 1302 } |
1293 | 1303 |
1294 } // namespace extensions | 1304 } // namespace extensions |
OLD | NEW |