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

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

Issue 561743003: Remove static PACKAGE_NAME variable and refactor getRawAcceptableDirectories method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing test case failure for MediaResourceGetterTest class Created 6 years, 3 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
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 5091868ea9ceddb8f17634698bc378775459ba93..bdc55e0848216a1d45daadc6281bc8063ad5b90b 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
@@ -38,8 +38,6 @@ class MediaResourceGetter {
private final MediaMetadataRetriever mRetriever = new MediaMetadataRetriever();
- private static String PACKAGE_NAME = null;
-
@VisibleForTesting
static class MediaMetadata {
private final int mDurationInMilliseconds;
@@ -116,7 +114,6 @@ class MediaResourceGetter {
final String url,
final String cookies,
final String userAgent) {
- PACKAGE_NAME = context.getPackageName();
return new MediaResourceGetter().extract(
context, url, cookies, userAgent);
}
@@ -226,7 +223,7 @@ class MediaResourceGetter {
Log.e(TAG, "File does not exist.");
return false;
}
- if (!filePathAcceptable(file)) {
+ if (!filePathAcceptable(file, context)) {
Log.e(TAG, "Refusing to read from unsafe file location.");
return false;
}
@@ -305,7 +302,7 @@ class MediaResourceGetter {
* safe to read from, such as /mnt/sdcard.
*/
@VisibleForTesting
- boolean filePathAcceptable(File file) {
+ boolean filePathAcceptable(File file, Context context) {
final String path;
try {
path = file.getCanonicalPath();
@@ -318,7 +315,7 @@ class MediaResourceGetter {
// well-known paths we are matching against. If we don't, then we can
// get unusual results in testing systems or possibly on rooted devices.
// Note that canonicalized directory paths always end with '/'.
- List<String> acceptablePaths = canonicalize(getRawAcceptableDirectories());
+ List<String> acceptablePaths = canonicalize(getRawAcceptableDirectories(context));
acceptablePaths.add(getExternalStorageDirectory());
Log.d(TAG, "canonicalized file path: " + path);
for (String acceptablePath : acceptablePaths) {
@@ -364,12 +361,11 @@ class MediaResourceGetter {
return info.getType();
}
- private List<String> getRawAcceptableDirectories() {
+ private List<String> getRawAcceptableDirectories(Context context) {
List<String> result = new ArrayList<String>();
result.add("/mnt/sdcard/");
result.add("/sdcard/");
- if (PACKAGE_NAME != null)
- result.add("/data/data/" + PACKAGE_NAME + "/cache/");
+ result.add("/data/data/" + context.getPackageName() + "/cache/");
return result;
}
« no previous file with comments | « AUTHORS ('k') | 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