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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwAssets.java

Issue 401743003: [android_webview] Introduce AwAssets to reference assets inside the apk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pakfiles
Patch Set: One char fix to make clang happy Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | android_webview/native/android_webview_jni_registrar.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/AwAssets.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwAssets.java b/android_webview/java/src/org/chromium/android_webview/AwAssets.java
new file mode 100644
index 0000000000000000000000000000000000000000..97e292ff7a37ff0be2f9088c6ff60b1e9ebaf755
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/AwAssets.java
@@ -0,0 +1,38 @@
+// 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.
+
+package org.chromium.android_webview;
+
+import android.content.Context;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.util.Log;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.io.IOException;
+
+/**
+ * A utility class to retrieve references to uncompressed assets insides the apk. A reference is
+ * defined as tuple (file descriptor, offset, size) enabling direct mapping without deflation.
+ */
+@JNINamespace("android_webview")
+public class AwAssets {
+ private static final String LOGTAG = "AwAssets";
+
+ @CalledByNative
+ public static long[] openAsset(Context context, String fileName) {
+ try {
+ AssetManager manager = context.getAssets();
+ AssetFileDescriptor afd = manager.openFd(fileName);
+ return new long[] { afd.getParcelFileDescriptor().detachFd(),
+ afd.getStartOffset(),
+ afd.getLength() };
+ } catch (IOException e) {
+ Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e.getMessage());
+ return new long[] {-1, -1, -1};
+ }
+ }
+}
« no previous file with comments | « no previous file | android_webview/native/android_webview_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698