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.
7 #include "android_webview/native/public/aw_assets.h"
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"
14 namespace android_webview
{
17 bool OpenAsset(const std::string
& filename
,
21 JNIEnv
* env
= base::android::AttachCurrentThread();
22 ScopedJavaLocalRef
<jlongArray
> jarr
= Java_AwAssets_openAsset(
24 base::android::GetApplicationContext(),
25 base::android::ConvertUTF8ToJavaString(env
, filename
).Release());
26 std::vector
<jlong
> results
;
27 base::android::JavaLongArrayToLongVector(env
, jarr
.obj(), &results
);
28 DCHECK_EQ(3U, results
.size());
29 *fd
= static_cast<int>(results
[0]);
35 bool RegisterAssetWithGlobalDescriptors(base::GlobalDescriptors::Key key
,
36 const std::string
& asset_filename
) {
41 AwAssets::OpenAsset(asset_filename
, &asset_fd
, &asset_off
, &asset_len
);
43 base::GlobalDescriptors::GetInstance()->Set(
44 key
, asset_fd
, base::MemoryMappedFile::Region(asset_off
, asset_len
));
49 } // namespace AwAssets
51 bool RegisterAwAssets(JNIEnv
* env
) {
52 return RegisterNativesImpl(env
);
55 } // namespace android_webview