| 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/utils_native_handler.h" | 5 #include "extensions/renderer/utils_native_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "extensions/renderer/script_context.h" | 8 #include "extensions/renderer/script_context.h" |
| 9 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 9 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 10 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | 10 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 "})", | 53 "})", |
| 54 name.c_str(), name.c_str(), name.c_str()).c_str()); | 54 name.c_str(), name.c_str(), name.c_str()).c_str()); |
| 55 v8::Local<v8::Value> func_as_value = context()->module_system()->RunString( | 55 v8::Local<v8::Value> func_as_value = context()->module_system()->RunString( |
| 56 source, v8::String::NewFromUtf8(GetIsolate(), name.c_str())); | 56 source, v8::String::NewFromUtf8(GetIsolate(), name.c_str())); |
| 57 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) { | 57 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) { |
| 58 args.GetReturnValue().SetUndefined(); | 58 args.GetReturnValue().SetUndefined(); |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // TODO(fsamuel): Move privates from ModuleSystem to a shared location. | 62 // TODO(fsamuel): Move privates from ModuleSystem to a shared location. |
| 63 v8::Local<v8::Object> natives(context()->module_system()->NewInstance()); | 63 v8::Local<v8::Object> natives; |
| 64 CHECK(!natives.IsEmpty()); // this can happen if v8 has issues | 64 if (!context()->module_system()->NewInstance().ToLocal(&natives)) |
| 65 NOTREACHED(); // this can happen if v8 has issues |
| 65 v8::Local<v8::Function> func = func_as_value.As<v8::Function>(); | 66 v8::Local<v8::Function> func = func_as_value.As<v8::Function>(); |
| 66 v8::Local<v8::Value> func_args[] = { | 67 v8::Local<v8::Value> func_args[] = { |
| 67 context()->safe_builtins()->GetObjekt(), | 68 context()->safe_builtins()->GetObjekt(), |
| 68 context()->safe_builtins()->GetFunction(), | 69 context()->safe_builtins()->GetFunction(), |
| 69 natives->Get(v8::String::NewFromUtf8(GetIsolate(), "privates", | 70 natives->Get(v8::String::NewFromUtf8(GetIsolate(), "privates", |
| 70 v8::String::kInternalizedString)), | 71 v8::String::kInternalizedString)), |
| 71 cls, | 72 cls, |
| 72 superclass}; | 73 superclass}; |
| 73 v8::Local<v8::Value> result; | 74 v8::Local<v8::Value> result; |
| 74 { | 75 { |
| 75 v8::TryCatch try_catch; | 76 v8::TryCatch try_catch; |
| 76 try_catch.SetCaptureMessage(true); | 77 try_catch.SetCaptureMessage(true); |
| 77 result = context()->CallFunction(func, arraysize(func_args), func_args); | 78 result = context()->CallFunction(func, arraysize(func_args), func_args); |
| 78 if (try_catch.HasCaught()) { | 79 if (try_catch.HasCaught()) { |
| 79 args.GetReturnValue().SetUndefined(); | 80 args.GetReturnValue().SetUndefined(); |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 args.GetReturnValue().Set(result); | 84 args.GetReturnValue().Set(result); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void UtilsNativeHandler::DeepCopy( | 87 void UtilsNativeHandler::DeepCopy( |
| 87 const v8::FunctionCallbackInfo<v8::Value>& args) { | 88 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 88 CHECK_EQ(1, args.Length()); | 89 CHECK_EQ(1, args.Length()); |
| 89 args.GetReturnValue().Set( | 90 args.GetReturnValue().Set( |
| 90 blink::WebSerializedScriptValue::serialize(args[0]).deserialize()); | 91 blink::WebSerializedScriptValue::serialize(args[0]).deserialize()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 } // namespace extensions | 94 } // namespace extensions |
| OLD | NEW |