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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java

Issue 289653002: Skip network availabity check for localhost in MediaResourceGetter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added the tests. Created 6 years, 7 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 | content/public/android/javatests/src/org/chromium/content/browser/MediaResourceGetterTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java b/content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java
index 5e334820aeadc2ddb147b9039c406b963a3017c2..5da4676758bca8e8c9a7afbe1b91fb7697340115 100644
--- a/content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java
+++ b/content/public/android/java/src/org/chromium/content/browser/MediaResourceGetter.java
@@ -9,7 +9,6 @@ import android.content.pm.PackageManager;
import android.media.MediaMetadataRetriever;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
@@ -21,6 +20,7 @@ import org.chromium.base.PathUtils;
import java.io.File;
import java.io.IOException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -188,7 +188,7 @@ class MediaResourceGetter {
@VisibleForTesting
boolean configure(Context context, String url, String cookies, String userAgent) {
- Uri uri = Uri.parse(url);
+ URI uri = URI.create(url);
String scheme = uri.getScheme();
if (scheme == null || scheme.equals("file")) {
File file = uriToFile(uri.getPath());
@@ -208,7 +208,8 @@ class MediaResourceGetter {
return false;
}
} else {
- if (!isNetworkReliable(context)) {
+ final String host = uri.getHost();
+ if (!isLoopbackAddress(host) && !isNetworkReliable(context)) {
Log.w(TAG, "non-file URI can't be read due to unsuitable network conditions");
return false;
}
@@ -260,6 +261,14 @@ class MediaResourceGetter {
}
}
+ // This method covers only typcial expressions for the loopback address
+ // to resolve the hostname without a DNS loopup.
+ private boolean isLoopbackAddress(String host) {
+ return host != null && (host.equalsIgnoreCase("localhost") // typical hostname
+ || host.equals("127.0.0.1") // typical IP v4 expression
+ || host.equals("[::1]")); // typical IP v6 expression
+ }
+
/**
* @param file the file whose path should be checked
* @return true if and only if the file is in a location that we consider
« no previous file with comments | « no previous file | content/public/android/javatests/src/org/chromium/content/browser/MediaResourceGetterTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698