summaryrefslogtreecommitdiffstats
path: root/extensions/browser/extension_function_util.cc
blob: 4f599800e4e42f43337192346b6c4e080cc6737a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/extension_function_util.h"

namespace extensions {

bool ReadOneOrMoreIntegers(base::Value* value, std::vector<int>* result) {
  if (value->IsType(base::Value::TYPE_INTEGER)) {
    int v = -1;
    if (!value->GetAsInteger(&v))
      return false;
    result->push_back(v);
    return true;

  } else if (value->IsType(base::Value::TYPE_LIST)) {
    base::ListValue* values = static_cast<base::ListValue*>(value);
    for (size_t i = 0; i < values->GetSize(); ++i) {
      int v = -1;
      if (!values->GetInteger(i, &v))
        return false;
      result->push_back(v);
    }
    return true;
  }
  return false;
}

} // namespace extensions