OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/idltest/idltest_api.h" | 5 #include "chrome/browser/extensions/api/idltest/idltest_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 | 13 |
14 using base::BinaryValue; | 14 using base::BinaryValue; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 std::unique_ptr<base::ListValue> CopyBinaryValueToIntegerList( | 18 std::unique_ptr<base::ListValue> CopyBinaryValueToIntegerList( |
19 const BinaryValue* input) { | 19 const BinaryValue* input) { |
20 std::unique_ptr<base::ListValue> output(new base::ListValue()); | 20 std::unique_ptr<base::ListValue> output(new base::ListValue()); |
21 const char* input_buffer = input->GetBuffer(); | 21 const char* input_buffer = input->GetBuffer(); |
22 for (size_t i = 0; i < input->GetSize(); i++) { | 22 for (size_t i = 0; i < input->GetSize(); i++) { |
23 output->Append(new base::FundamentalValue(input_buffer[i])); | 23 output->AppendInteger(input_buffer[i]); |
24 } | 24 } |
25 return output; | 25 return output; |
26 } | 26 } |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 bool IdltestSendArrayBufferFunction::RunSync() { | 30 bool IdltestSendArrayBufferFunction::RunSync() { |
31 BinaryValue* input = NULL; | 31 BinaryValue* input = NULL; |
32 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 32 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
33 SetResult(CopyBinaryValueToIntegerList(input)); | 33 SetResult(CopyBinaryValueToIntegerList(input)); |
34 return true; | 34 return true; |
35 } | 35 } |
36 | 36 |
37 bool IdltestSendArrayBufferViewFunction::RunSync() { | 37 bool IdltestSendArrayBufferViewFunction::RunSync() { |
38 BinaryValue* input = NULL; | 38 BinaryValue* input = NULL; |
39 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 39 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
40 SetResult(CopyBinaryValueToIntegerList(input)); | 40 SetResult(CopyBinaryValueToIntegerList(input)); |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 bool IdltestGetArrayBufferFunction::RunSync() { | 44 bool IdltestGetArrayBufferFunction::RunSync() { |
45 std::string hello = "hello world"; | 45 std::string hello = "hello world"; |
46 BinaryValue* output = | 46 BinaryValue* output = |
47 BinaryValue::CreateWithCopiedBuffer(hello.c_str(), hello.size()); | 47 BinaryValue::CreateWithCopiedBuffer(hello.c_str(), hello.size()); |
48 SetResult(base::WrapUnique(output)); | 48 SetResult(base::WrapUnique(output)); |
49 return true; | 49 return true; |
50 } | 50 } |
OLD | NEW |