Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / idltest / idltest_api.cc
blob71af4ac4e5e05ae32ca029463a13abe60c0a726e
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/idltest/idltest_api.h"
7 #include "base/values.h"
9 using base::BinaryValue;
11 namespace {
13 base::ListValue* CopyBinaryValueToIntegerList(const BinaryValue* input) {
14 base::ListValue* output = new base::ListValue();
15 const char* input_buffer = input->GetBuffer();
16 for (size_t i = 0; i < input->GetSize(); i++) {
17 output->Append(new base::FundamentalValue(input_buffer[i]));
19 return output;
22 } // namespace
24 bool IdltestSendArrayBufferFunction::RunSync() {
25 BinaryValue* input = NULL;
26 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input));
27 SetResult(CopyBinaryValueToIntegerList(input));
28 return true;
31 bool IdltestSendArrayBufferViewFunction::RunSync() {
32 BinaryValue* input = NULL;
33 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input));
34 SetResult(CopyBinaryValueToIntegerList(input));
35 return true;
38 bool IdltestGetArrayBufferFunction::RunSync() {
39 std::string hello = "hello world";
40 BinaryValue* output =
41 BinaryValue::CreateWithCopiedBuffer(hello.c_str(), hello.size());
42 SetResult(output);
43 return true;