1// Copyright 2014 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.
4
5#include <jni.h>
6
7#include "android_webview/native/aw_assets.h"
8
9#include "base/android/jni_array.h"
10#include "base/android/jni_string.h"
11#include "base/android/scoped_java_ref.h"
12#include "jni/AwAssets_jni.h"
13
14namespace android_webview {
15namespace AwAssets {
16
17bool OpenAsset(const std::string& filename,
18               int* fd,
19               int64* offset,
20               int64* size) {
21  JNIEnv* env = base::android::AttachCurrentThread();
22  ScopedJavaLocalRef<jlongArray> jarr = Java_AwAssets_openAsset(
23      env,
24      base::android::GetApplicationContext(),
25      base::android::ConvertUTF8ToJavaString(env, filename).Release());
26  std::vector<long> results;
27  base::android::JavaLongArrayToLongVector(env, jarr.obj(), &results);
28  DCHECK_EQ(3U, results.size());
29  *fd = static_cast<int>(results[0]);
30  *offset = results[1];
31  *size = results[2];
32  return *fd != -1;
33}
34
35}  // namespace AwAssets
36
37bool RegisterAwAssets(JNIEnv* env) {
38  return RegisterNativesImpl(env);
39}
40
41}  // namespace android_webview
42