OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/java/gin_java_function_invocation_helper.h" | 5 #include "content/renderer/java/gin_java_function_invocation_helper.h" |
6 | 6 |
7 #include "content/common/android/gin_java_bridge_errors.h" | 7 #include "content/common/android/gin_java_bridge_errors.h" |
8 #include "content/common/android/gin_java_bridge_value.h" | 8 #include "content/common/android/gin_java_bridge_value.h" |
9 #include "content/public/child/v8_value_converter.h" | 9 #include "content/public/child/v8_value_converter.h" |
10 #include "content/renderer/java/gin_java_bridge_object.h" | 10 #include "content/renderer/java/gin_java_bridge_object.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const std::string& method_name, | 27 const std::string& method_name, |
28 const base::WeakPtr<GinJavaBridgeDispatcher>& dispatcher) | 28 const base::WeakPtr<GinJavaBridgeDispatcher>& dispatcher) |
29 : method_name_(method_name), | 29 : method_name_(method_name), |
30 dispatcher_(dispatcher), | 30 dispatcher_(dispatcher), |
31 converter_(new GinJavaBridgeValueConverter()) { | 31 converter_(new GinJavaBridgeValueConverter()) { |
32 } | 32 } |
33 | 33 |
34 GinJavaFunctionInvocationHelper::~GinJavaFunctionInvocationHelper() { | 34 GinJavaFunctionInvocationHelper::~GinJavaFunctionInvocationHelper() { |
35 } | 35 } |
36 | 36 |
37 v8::Handle<v8::Value> GinJavaFunctionInvocationHelper::Invoke( | 37 v8::Local<v8::Value> GinJavaFunctionInvocationHelper::Invoke( |
38 gin::Arguments* args) { | 38 gin::Arguments* args) { |
39 if (!dispatcher_) { | 39 if (!dispatcher_) { |
40 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( | 40 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( |
41 args->isolate(), kMethodInvocationErrorMessage))); | 41 args->isolate(), kMethodInvocationErrorMessage))); |
42 return v8::Undefined(args->isolate()); | 42 return v8::Undefined(args->isolate()); |
43 } | 43 } |
44 | 44 |
45 if (args->IsConstructCall()) { | 45 if (args->IsConstructCall()) { |
46 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( | 46 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( |
47 args->isolate(), kMethodInvocationAsConstructorDisallowed))); | 47 args->isolate(), kMethodInvocationAsConstructorDisallowed))); |
48 return v8::Undefined(args->isolate()); | 48 return v8::Undefined(args->isolate()); |
49 } | 49 } |
50 | 50 |
51 content::GinJavaBridgeObject* object = NULL; | 51 content::GinJavaBridgeObject* object = NULL; |
52 if (!args->GetHolder(&object) || !object) { | 52 if (!args->GetHolder(&object) || !object) { |
53 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( | 53 args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( |
54 args->isolate(), kMethodInvocationOnNonInjectedObjectDisallowed))); | 54 args->isolate(), kMethodInvocationOnNonInjectedObjectDisallowed))); |
55 return v8::Undefined(args->isolate()); | 55 return v8::Undefined(args->isolate()); |
56 } | 56 } |
57 | 57 |
58 base::ListValue arguments; | 58 base::ListValue arguments; |
59 { | 59 { |
60 v8::HandleScope handle_scope(args->isolate()); | 60 v8::HandleScope handle_scope(args->isolate()); |
61 v8::Handle<v8::Context> context = args->isolate()->GetCurrentContext(); | 61 v8::Local<v8::Context> context = args->isolate()->GetCurrentContext(); |
62 v8::Handle<v8::Value> val; | 62 v8::Local<v8::Value> val; |
63 while (args->GetNext(&val)) { | 63 while (args->GetNext(&val)) { |
64 scoped_ptr<base::Value> arg(converter_->FromV8Value(val, context)); | 64 scoped_ptr<base::Value> arg(converter_->FromV8Value(val, context)); |
65 if (arg.get()) { | 65 if (arg.get()) { |
66 arguments.Append(arg.release()); | 66 arguments.Append(arg.release()); |
67 } else { | 67 } else { |
68 arguments.Append(base::Value::CreateNullValue()); | 68 arguments.Append(base::Value::CreateNullValue()); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
(...skipping 27 matching lines...) Expand all Loading... |
100 } | 100 } |
101 } else if (gin_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)) { | 101 } else if (gin_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)) { |
102 float float_value; | 102 float float_value; |
103 gin_value->GetAsNonFinite(&float_value); | 103 gin_value->GetAsNonFinite(&float_value); |
104 return v8::Number::New(args->isolate(), float_value); | 104 return v8::Number::New(args->isolate(), float_value); |
105 } | 105 } |
106 return v8::Undefined(args->isolate()); | 106 return v8::Undefined(args->isolate()); |
107 } | 107 } |
108 | 108 |
109 } // namespace content | 109 } // namespace content |
OLD | NEW |