| 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/values.h" | 11 #include "base/values.h" |
| 12 | 12 |
| 13 using base::Value; | 13 using base::Value; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 std::unique_ptr<base::ListValue> CopyBinaryValueToIntegerList( | 17 std::unique_ptr<base::ListValue> CopyBinaryValueToIntegerList( |
| 18 const Value* input) { | 18 const Value* input) { |
| 19 std::unique_ptr<base::ListValue> output(new base::ListValue()); | 19 std::unique_ptr<base::ListValue> output(new base::ListValue()); |
| 20 const char* input_buffer = input->GetBuffer(); | 20 for (char c : input->GetBlob()) { |
| 21 for (size_t i = 0; i < input->GetSize(); i++) { | 21 output->AppendInteger(c); |
| 22 output->AppendInteger(input_buffer[i]); | |
| 23 } | 22 } |
| 24 return output; | 23 return output; |
| 25 } | 24 } |
| 26 | 25 |
| 27 } // namespace | 26 } // namespace |
| 28 | 27 |
| 29 ExtensionFunction::ResponseAction IdltestSendArrayBufferFunction::Run() { | 28 ExtensionFunction::ResponseAction IdltestSendArrayBufferFunction::Run() { |
| 30 Value* input = NULL; | 29 Value* input = NULL; |
| 31 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 30 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
| 32 return RespondNow(OneArgument(CopyBinaryValueToIntegerList(input))); | 31 return RespondNow(OneArgument(CopyBinaryValueToIntegerList(input))); |
| 33 } | 32 } |
| 34 | 33 |
| 35 ExtensionFunction::ResponseAction IdltestSendArrayBufferViewFunction::Run() { | 34 ExtensionFunction::ResponseAction IdltestSendArrayBufferViewFunction::Run() { |
| 36 Value* input = NULL; | 35 Value* input = NULL; |
| 37 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 36 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
| 38 return RespondNow(OneArgument(CopyBinaryValueToIntegerList(input))); | 37 return RespondNow(OneArgument(CopyBinaryValueToIntegerList(input))); |
| 39 } | 38 } |
| 40 | 39 |
| 41 ExtensionFunction::ResponseAction IdltestGetArrayBufferFunction::Run() { | 40 ExtensionFunction::ResponseAction IdltestGetArrayBufferFunction::Run() { |
| 42 std::string hello = "hello world"; | 41 std::string hello = "hello world"; |
| 43 return RespondNow( | 42 return RespondNow( |
| 44 OneArgument(Value::CreateWithCopiedBuffer(hello.c_str(), hello.size()))); | 43 OneArgument(Value::CreateWithCopiedBuffer(hello.c_str(), hello.size()))); |
| 45 } | 44 } |
| OLD | NEW |