Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: android_webview/native/aw_assets.cc

Issue 937863003: Add AwAssets into android_webview/native/public (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Just move aw_assets to public totally Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « android_webview/native/aw_assets.h ('k') | android_webview/native/aw_media_url_interceptor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
14 namespace android_webview {
15 namespace AwAssets {
16
17 bool 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<jlong> 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 bool RegisterAssetWithGlobalDescriptors(base::GlobalDescriptors::Key key,
36 const std::string& asset_filename) {
37 int asset_fd = 0;
38 int64 asset_off = 0;
39 int64 asset_len = 0;
40 bool result =
41 AwAssets::OpenAsset(asset_filename, &asset_fd, &asset_off, &asset_len);
42 if (result) {
43 base::GlobalDescriptors::GetInstance()->Set(
44 key, asset_fd, base::MemoryMappedFile::Region(asset_off, asset_len));
45 }
46 return result;
47 }
48
49 } // namespace AwAssets
50
51 bool RegisterAwAssets(JNIEnv* env) {
52 return RegisterNativesImpl(env);
53 }
54
55 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_assets.h ('k') | android_webview/native/aw_media_url_interceptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698