OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/api_binding_js_util.h" | 5 #include "extensions/renderer/api_binding_js_util.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "extensions/renderer/api_event_handler.h" | 8 #include "extensions/renderer/api_event_handler.h" |
9 #include "extensions/renderer/api_request_handler.h" | 9 #include "extensions/renderer/api_request_handler.h" |
10 #include "extensions/renderer/api_signature.h" | 10 #include "extensions/renderer/api_signature.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // NOTE: We don't throw any errors here if forIOThread or customCallback are | 72 // NOTE: We don't throw any errors here if forIOThread or customCallback are |
73 // of invalid types. We could, if we wanted to be a bit more verbose. | 73 // of invalid types. We could, if we wanted to be a bit more verbose. |
74 bool for_io_thread = false; | 74 bool for_io_thread = false; |
75 if (options_dict.Get("forIOThread", &for_io_thread) && for_io_thread) | 75 if (options_dict.Get("forIOThread", &for_io_thread) && for_io_thread) |
76 thread = binding::RequestThread::IO; | 76 thread = binding::RequestThread::IO; |
77 options_dict.Get("customCallback", &custom_callback); | 77 options_dict.Get("customCallback", &custom_callback); |
78 } | 78 } |
79 | 79 |
80 std::unique_ptr<base::ListValue> converted_arguments; | 80 std::unique_ptr<base::ListValue> converted_arguments; |
81 v8::Local<v8::Function> callback; | 81 v8::Local<v8::Function> callback; |
82 std::string error; | 82 |
83 CHECK(signature->ParseArgumentsToJSON(context, request_args, *type_refs_, | 83 // Some APIs (like fileSystem and contextMenus) don't provide arguments that |
84 &converted_arguments, &callback, | 84 // match the expected schema. For now, we need to ignore these and trust the |
85 &error)); | 85 // JS gives us something we expect. |
| 86 // TODO(devlin): We should ideally always be able to validate these, meaning |
| 87 // that we either need to make the APIs give us the expected signature, or |
| 88 // need to have a way of indicating an internal signature. |
| 89 CHECK(signature->ConvertArgumentsIgnoringSchema( |
| 90 context, request_args, &converted_arguments, &callback)); |
86 | 91 |
87 request_handler_->StartRequest(context, name, std::move(converted_arguments), | 92 request_handler_->StartRequest(context, name, std::move(converted_arguments), |
88 callback, custom_callback, thread); | 93 callback, custom_callback, thread); |
89 } | 94 } |
90 | 95 |
91 void APIBindingJSUtil::RegisterEventArgumentMassager( | 96 void APIBindingJSUtil::RegisterEventArgumentMassager( |
92 gin::Arguments* arguments, | 97 gin::Arguments* arguments, |
93 const std::string& event_name, | 98 const std::string& event_name, |
94 v8::Local<v8::Function> massager) { | 99 v8::Local<v8::Function> massager) { |
95 v8::Isolate* isolate = arguments->isolate(); | 100 v8::Isolate* isolate = arguments->isolate(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 177 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
173 | 178 |
174 request_handler_->last_error()->SetError(context, error); | 179 request_handler_->last_error()->SetError(context, error); |
175 run_js_.Run(callback, context, 0, nullptr); | 180 run_js_.Run(callback, context, 0, nullptr); |
176 | 181 |
177 bool report_if_unchecked = true; | 182 bool report_if_unchecked = true; |
178 request_handler_->last_error()->ClearError(context, report_if_unchecked); | 183 request_handler_->last_error()->ClearError(context, report_if_unchecked); |
179 } | 184 } |
180 | 185 |
181 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |