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

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

Issue 109023011: Do not use CalledByNativeUnchecked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 12 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_protocol_handler.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/AndroidProtocolHandler.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AndroidProtocolHandler.java b/android_webview/java/src/org/chromium/android_webview/AndroidProtocolHandler.java
index 6c057023486c3c530ea0a529c91137aafd892b82..3951ae7919e2f34733e2b8faaa55b9544d8d8281 100644
--- a/android_webview/java/src/org/chromium/android_webview/AndroidProtocolHandler.java
+++ b/android_webview/java/src/org/chromium/android_webview/AndroidProtocolHandler.java
@@ -10,7 +10,7 @@ import android.net.Uri;
import android.util.Log;
import android.util.TypedValue;
-import org.chromium.base.CalledByNativeUnchecked;
+import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import java.io.IOException;
@@ -37,23 +37,25 @@ public class AndroidProtocolHandler {
* @param url The url to load.
* @return An InputStream to the Android resource.
*/
- // TODO(bulach): this should have either a throw clause, or
- // handle the exception in the java side rather than the native side.
- @CalledByNativeUnchecked
+ @CalledByNative
public static InputStream open(Context context, String url) {
Uri uri = verifyUrl(url);
if (uri == null) {
return null;
}
- String path = uri.getPath();
- if (uri.getScheme().equals(FILE_SCHEME)) {
- if (path.startsWith(nativeGetAndroidAssetPath())) {
- return openAsset(context, uri);
- } else if (path.startsWith(nativeGetAndroidResourcePath())) {
- return openResource(context, uri);
+ try {
+ String path = uri.getPath();
+ if (uri.getScheme().equals(FILE_SCHEME)) {
+ if (path.startsWith(nativeGetAndroidAssetPath())) {
+ return openAsset(context, uri);
+ } else if (path.startsWith(nativeGetAndroidResourcePath())) {
+ return openResource(context, uri);
+ }
+ } else if (uri.getScheme().equals(CONTENT_SCHEME)) {
+ return openContent(context, uri);
}
- } else if (uri.getScheme().equals(CONTENT_SCHEME)) {
- return openContent(context, uri);
+ } catch (Exception ex) {
+ Log.e(TAG, "Error opening inputstream: " + url);
}
return null;
}
@@ -152,25 +154,28 @@ public class AndroidProtocolHandler {
* @param url The url from which the stream was opened.
* @return The mime type or null if the type is unknown.
*/
- // TODO(bulach): this should have either a throw clause, or
- // handle the exception in the java side rather than the native side.
- @CalledByNativeUnchecked
+ @CalledByNative
public static String getMimeType(Context context, InputStream stream, String url) {
Uri uri = verifyUrl(url);
if (uri == null) {
return null;
}
- String path = uri.getPath();
- // The content URL type can be queried directly.
- if (uri.getScheme().equals(CONTENT_SCHEME)) {
- return context.getContentResolver().getType(uri);
- // Asset files may have a known extension.
- } else if (uri.getScheme().equals(FILE_SCHEME) &&
- path.startsWith(nativeGetAndroidAssetPath())) {
- String mimeType = URLConnection.guessContentTypeFromName(path);
- if (mimeType != null) {
- return mimeType;
+ try {
+ String path = uri.getPath();
+ // The content URL type can be queried directly.
+ if (uri.getScheme().equals(CONTENT_SCHEME)) {
+ return context.getContentResolver().getType(uri);
+ // Asset files may have a known extension.
+ } else if (uri.getScheme().equals(FILE_SCHEME) &&
+ path.startsWith(nativeGetAndroidAssetPath())) {
+ String mimeType = URLConnection.guessContentTypeFromName(path);
+ if (mimeType != null) {
+ return mimeType;
+ }
}
+ } catch (Exception ex) {
+ Log.e(TAG, "Unable to get mime type" + url);
+ return null;
}
// Fall back to sniffing the type from the stream.
try {
« no previous file with comments | « no previous file | android_webview/native/android_protocol_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698