| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 | 370 |
| 371 bool Dispatcher::CheckContextAccessToExtensionAPI( | 371 bool Dispatcher::CheckContextAccessToExtensionAPI( |
| 372 const std::string& function_name, | 372 const std::string& function_name, |
| 373 ScriptContext* context) const { | 373 ScriptContext* context) const { |
| 374 if (!context) { | 374 if (!context) { |
| 375 DLOG(ERROR) << "Not in a v8::Context"; | 375 DLOG(ERROR) << "Not in a v8::Context"; |
| 376 return false; | 376 return false; |
| 377 } | 377 } |
| 378 | 378 |
| 379 if (!context->extension()) { | |
| 380 context->isolate()->ThrowException(v8::Exception::Error( | |
| 381 v8::String::NewFromUtf8(context->isolate(), "Not in an extension."))); | |
| 382 return false; | |
| 383 } | |
| 384 | |
| 385 // Theoretically we could end up with bindings being injected into sandboxed | 379 // Theoretically we could end up with bindings being injected into sandboxed |
| 386 // frames, for example content scripts. Don't let them execute API functions. | 380 // frames, for example content scripts. Don't let them execute API functions. |
| 387 blink::WebFrame* frame = context->web_frame(); | 381 blink::WebFrame* frame = context->web_frame(); |
| 388 if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) { | 382 if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) { |
| 389 static const char kMessage[] = | 383 static const char kMessage[] = |
| 390 "%s cannot be used within a sandboxed frame."; | 384 "%s cannot be used within a sandboxed frame."; |
| 391 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 385 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 392 context->isolate()->ThrowException(v8::Exception::Error( | 386 context->isolate()->ThrowException(v8::Exception::Error( |
| 393 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); | 387 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); |
| 394 return false; | 388 return false; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 break; | 845 break; |
| 852 } | 846 } |
| 853 } | 847 } |
| 854 if (runtime_is_available) | 848 if (runtime_is_available) |
| 855 RegisterBinding("runtime", context); | 849 RegisterBinding("runtime", context); |
| 856 break; | 850 break; |
| 857 } | 851 } |
| 858 | 852 |
| 859 case Feature::BLESSED_EXTENSION_CONTEXT: | 853 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 860 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 854 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 861 case Feature::CONTENT_SCRIPT_CONTEXT: { | 855 case Feature::CONTENT_SCRIPT_CONTEXT: |
| 856 case Feature::WEBUI_CONTEXT: { |
| 862 // Extension context; iterate through all the APIs and bind the available | 857 // Extension context; iterate through all the APIs and bind the available |
| 863 // ones. | 858 // ones. |
| 864 const FeatureProvider* api_feature_provider = | 859 const FeatureProvider* api_feature_provider = |
| 865 FeatureProvider::GetAPIFeatures(); | 860 FeatureProvider::GetAPIFeatures(); |
| 866 const std::vector<std::string>& apis = | 861 const std::vector<std::string>& apis = |
| 867 api_feature_provider->GetAllFeatureNames(); | 862 api_feature_provider->GetAllFeatureNames(); |
| 868 for (std::vector<std::string>::const_iterator it = apis.begin(); | 863 for (std::vector<std::string>::const_iterator it = apis.begin(); |
| 869 it != apis.end(); | 864 it != apis.end(); |
| 870 ++it) { | 865 ++it) { |
| 871 const std::string& api_name = *it; | 866 const std::string& api_name = *it; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 | 1124 |
| 1130 // TODO(kalman): This isUnique() check is wrong, it should be performed as | 1125 // TODO(kalman): This isUnique() check is wrong, it should be performed as |
| 1131 // part of IsSandboxedPage(). | 1126 // part of IsSandboxedPage(). |
| 1132 if (!origin.isUnique() && extensions_.ExtensionBindingsAllowed(url)) { | 1127 if (!origin.isUnique() && extensions_.ExtensionBindingsAllowed(url)) { |
| 1133 if (!extension) // TODO(kalman): when does this happen? | 1128 if (!extension) // TODO(kalman): when does this happen? |
| 1134 return Feature::UNSPECIFIED_CONTEXT; | 1129 return Feature::UNSPECIFIED_CONTEXT; |
| 1135 return extension->is_hosted_app() ? Feature::BLESSED_WEB_PAGE_CONTEXT | 1130 return extension->is_hosted_app() ? Feature::BLESSED_WEB_PAGE_CONTEXT |
| 1136 : Feature::UNBLESSED_EXTENSION_CONTEXT; | 1131 : Feature::UNBLESSED_EXTENSION_CONTEXT; |
| 1137 } | 1132 } |
| 1138 | 1133 |
| 1139 if (url.is_valid()) | 1134 if (!url.is_valid()) |
| 1140 return Feature::WEB_PAGE_CONTEXT; | 1135 return Feature::UNSPECIFIED_CONTEXT; |
| 1141 | 1136 |
| 1142 return Feature::UNSPECIFIED_CONTEXT; | 1137 if (url.SchemeIs(content::kChromeUIScheme)) |
| 1138 return Feature::WEBUI_CONTEXT; |
| 1139 |
| 1140 return Feature::WEB_PAGE_CONTEXT; |
| 1143 } | 1141 } |
| 1144 | 1142 |
| 1145 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( | 1143 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( |
| 1146 const v8::Handle<v8::Object>& object, | 1144 const v8::Handle<v8::Object>& object, |
| 1147 const std::string& field, | 1145 const std::string& field, |
| 1148 v8::Isolate* isolate) { | 1146 v8::Isolate* isolate) { |
| 1149 v8::Handle<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); | 1147 v8::Handle<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str()); |
| 1150 // If the object has a callback property, it is assumed it is an unavailable | 1148 // If the object has a callback property, it is assumed it is an unavailable |
| 1151 // API, so it is safe to delete. This is checked before GetOrCreateObject is | 1149 // API, so it is safe to delete. This is checked before GetOrCreateObject is |
| 1152 // called. | 1150 // called. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 return v8::Handle<v8::Object>(); | 1206 return v8::Handle<v8::Object>(); |
| 1209 | 1207 |
| 1210 if (bind_name) | 1208 if (bind_name) |
| 1211 *bind_name = split.back(); | 1209 *bind_name = split.back(); |
| 1212 | 1210 |
| 1213 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1211 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
| 1214 : bind_object; | 1212 : bind_object; |
| 1215 } | 1213 } |
| 1216 | 1214 |
| 1217 } // namespace extensions | 1215 } // namespace extensions |
| OLD | NEW |