| 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/object_backed_native_handler.h" | 5 #include "extensions/renderer/object_backed_native_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // don't inject many bindings into worker threads. | 67 // don't inject many bindings into worker threads. |
| 68 // TODO(devlin): Figure out a way around this. | 68 // TODO(devlin): Figure out a way around this. |
| 69 if (content::WorkerThread::GetCurrentId() == 0) { | 69 if (content::WorkerThread::GetCurrentId() == 0) { |
| 70 ScriptContext* script_context = | 70 ScriptContext* script_context = |
| 71 ScriptContextSet::GetContextByV8Context(context); | 71 ScriptContextSet::GetContextByV8Context(context); |
| 72 v8::Local<v8::String> feature_name_string = | 72 v8::Local<v8::String> feature_name_string = |
| 73 feature_name_value->ToString(context).ToLocalChecked(); | 73 feature_name_value->ToString(context).ToLocalChecked(); |
| 74 std::string feature_name = *v8::String::Utf8Value(feature_name_string); | 74 std::string feature_name = *v8::String::Utf8Value(feature_name_string); |
| 75 // TODO(devlin): Eventually, we should fail if either script_context is null | 75 // TODO(devlin): Eventually, we should fail if either script_context is null |
| 76 // or feature_name is empty. | 76 // or feature_name is empty. |
| 77 if (script_context && | 77 if (script_context && !feature_name.empty()) { |
| 78 !feature_name.empty() && | 78 Feature::Availability availability = |
| 79 !script_context->GetAvailability(feature_name).is_available()) { | 79 script_context->GetAvailability(feature_name); |
| 80 return; | 80 if (!availability.is_available()) { |
| 81 DVLOG(1) << feature_name |
| 82 << " is not available: " << availability.message(); |
| 83 return; |
| 84 } |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 // This CHECK is *important*. Otherwise, we'll go around happily executing | 87 // This CHECK is *important*. Otherwise, we'll go around happily executing |
| 84 // something random. See crbug.com/548273. | 88 // something random. See crbug.com/548273. |
| 85 CHECK(handler_function_value->IsExternal()); | 89 CHECK(handler_function_value->IsExternal()); |
| 86 static_cast<HandlerFunction*>( | 90 static_cast<HandlerFunction*>( |
| 87 handler_function_value.As<v8::External>()->Value())->Run(args); | 91 handler_function_value.As<v8::External>()->Value())->Run(args); |
| 88 | 92 |
| 89 // Verify that the return value, if any, is accessible by the context. | 93 // Verify that the return value, if any, is accessible by the context. |
| 90 v8::ReturnValue<v8::Value> ret = args.GetReturnValue(); | 94 v8::ReturnValue<v8::Value> ret = args.GetReturnValue(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 v8::Local<v8::Object> obj, | 217 v8::Local<v8::Object> obj, |
| 214 const char* key) { | 218 const char* key) { |
| 215 obj->DeletePrivate(context, | 219 obj->DeletePrivate(context, |
| 216 v8::Private::ForApi( | 220 v8::Private::ForApi( |
| 217 context->GetIsolate(), | 221 context->GetIsolate(), |
| 218 v8::String::NewFromUtf8(context->GetIsolate(), key))) | 222 v8::String::NewFromUtf8(context->GetIsolate(), key))) |
| 219 .FromJust(); | 223 .FromJust(); |
| 220 } | 224 } |
| 221 | 225 |
| 222 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |