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
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59

content / browser / android / java / java_type.h [blame]

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ANDROID_JAVA_JAVA_TYPE_H_
#define CONTENT_BROWSER_ANDROID_JAVA_JAVA_TYPE_H_

#include <memory>
#include <string>

#include "base/android/scoped_java_ref.h"
#include "content/common/content_export.h"

namespace content {

// The type of a Java value. A light-weight enum-like structure intended for
// use by value and in STL containers.
struct CONTENT_EXPORT JavaType {
  JavaType();
  JavaType(const JavaType& other);
  ~JavaType();
  JavaType& operator=(const JavaType& other);

  // Java's reflection API represents types as a string using an extended
  // 'binary name'.
  static JavaType CreateFromBinaryName(const std::string& binary_name);

  // JNIName is used with FindClass.
  std::string JNIName() const;
  // JNISignature is used for creating method signatures.
  std::string JNISignature() const;

  enum Type {
    TypeBoolean,
    TypeByte,
    TypeChar,
    TypeShort,
    TypeInt,
    TypeLong,
    TypeFloat,
    TypeDouble,
    // This is only used as a return type, so we should never convert from
    // JavaScript with this type.
    TypeVoid,
    TypeArray,
    // We special-case strings, as they get special handling when coercing.
    TypeString,
    TypeObject,
  };

  Type type;
  std::unique_ptr<JavaType> inner_type;  // Used for TypeArray only.
  std::string class_jni_name;  // Used for TypeString and TypeObject only.
  base::android::ScopedJavaGlobalRef<jclass> class_ref;  // TypeObject only.
};

}  // namespace content

#endif  // CONTENT_BROWSER_ANDROID_JAVA_JAVA_TYPE_H_