OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/storage_area.h" | 5 #include "extensions/renderer/storage_area.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "extensions/common/api/storage.h" | 9 #include "extensions/common/api/storage.h" |
10 #include "extensions/renderer/api_request_handler.h" | 10 #include "extensions/renderer/api_request_handler.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 176 } |
177 return object; | 177 return object; |
178 } | 178 } |
179 | 179 |
180 void StorageArea::HandleFunctionCall(const std::string& method_name, | 180 void StorageArea::HandleFunctionCall(const std::string& method_name, |
181 gin::Arguments* arguments) { | 181 gin::Arguments* arguments) { |
182 v8::Isolate* isolate = arguments->isolate(); | 182 v8::Isolate* isolate = arguments->isolate(); |
183 v8::HandleScope handle_scope(isolate); | 183 v8::HandleScope handle_scope(isolate); |
184 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 184 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
185 | 185 |
186 std::vector<v8::Local<v8::Value>> argument_list; | 186 std::vector<v8::Local<v8::Value>> argument_list = arguments->GetAll(); |
187 if (arguments->Length() > 0) { | |
188 // Just copying handles should never fail. | |
189 CHECK(arguments->GetRemaining(&argument_list)); | |
190 } | |
191 | 187 |
192 std::unique_ptr<base::ListValue> converted_arguments; | 188 std::unique_ptr<base::ListValue> converted_arguments; |
193 v8::Local<v8::Function> callback; | 189 v8::Local<v8::Function> callback; |
194 std::string error; | 190 std::string error; |
195 const APISignature* signature = type_refs_->GetTypeMethodSignature( | 191 const APISignature* signature = type_refs_->GetTypeMethodSignature( |
196 base::StringPrintf("%s.%s", "storage.StorageArea", method_name.c_str())); | 192 base::StringPrintf("%s.%s", "storage.StorageArea", method_name.c_str())); |
197 DCHECK(signature); | 193 DCHECK(signature); |
198 if (!signature->ParseArgumentsToJSON(context, argument_list, *type_refs_, | 194 if (!signature->ParseArgumentsToJSON(context, argument_list, *type_refs_, |
199 &converted_arguments, &callback, | 195 &converted_arguments, &callback, |
200 &error)) { | 196 &error)) { |
201 arguments->ThrowTypeError("Invalid invocation"); | 197 arguments->ThrowTypeError("Invalid invocation"); |
202 return; | 198 return; |
203 } | 199 } |
204 | 200 |
205 converted_arguments->Insert(0u, base::MakeUnique<base::Value>(name_)); | 201 converted_arguments->Insert(0u, base::MakeUnique<base::Value>(name_)); |
206 request_handler_->StartRequest( | 202 request_handler_->StartRequest( |
207 context, "storage." + method_name, std::move(converted_arguments), | 203 context, "storage." + method_name, std::move(converted_arguments), |
208 callback, v8::Local<v8::Function>(), binding::RequestThread::UI); | 204 callback, v8::Local<v8::Function>(), binding::RequestThread::UI); |
209 } | 205 } |
210 | 206 |
211 } // namespace extensions | 207 } // namespace extensions |
OLD | NEW |