Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
| 9 import android.media.MediaMetadataRetriever; | 9 import android.media.MediaMetadataRetriever; |
| 10 import android.net.ConnectivityManager; | 10 import android.net.ConnectivityManager; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 * Java counterpart of android MediaResourceGetter. | 30 * Java counterpart of android MediaResourceGetter. |
| 31 */ | 31 */ |
| 32 @JNINamespace("content") | 32 @JNINamespace("content") |
| 33 class MediaResourceGetter { | 33 class MediaResourceGetter { |
| 34 | 34 |
| 35 private static final String TAG = "MediaResourceGetter"; | 35 private static final String TAG = "MediaResourceGetter"; |
| 36 private final MediaMetadata EMPTY_METADATA = new MediaMetadata(0,0,0,false); | 36 private final MediaMetadata EMPTY_METADATA = new MediaMetadata(0,0,0,false); |
| 37 | 37 |
| 38 private final MediaMetadataRetriever mRetriever = new MediaMetadataRetriever (); | 38 private final MediaMetadataRetriever mRetriever = new MediaMetadataRetriever (); |
| 39 | 39 |
| 40 private static String PACKAGE_NAME = null; | |
| 41 | |
| 40 @VisibleForTesting | 42 @VisibleForTesting |
| 41 static class MediaMetadata { | 43 static class MediaMetadata { |
| 42 private final int mDurationInMilliseconds; | 44 private final int mDurationInMilliseconds; |
| 43 private final int mWidth; | 45 private final int mWidth; |
| 44 private final int mHeight; | 46 private final int mHeight; |
| 45 private final boolean mSuccess; | 47 private final boolean mSuccess; |
| 46 | 48 |
| 47 MediaMetadata(int durationInMilliseconds, int width, int height, boolean success) { | 49 MediaMetadata(int durationInMilliseconds, int width, int height, boolean success) { |
| 48 mDurationInMilliseconds = durationInMilliseconds; | 50 mDurationInMilliseconds = durationInMilliseconds; |
| 49 mWidth = width; | 51 mWidth = width; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 return false; | 108 return false; |
| 107 return true; | 109 return true; |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 @CalledByNative | 113 @CalledByNative |
| 112 private static MediaMetadata extractMediaMetadata(final Context context, | 114 private static MediaMetadata extractMediaMetadata(final Context context, |
| 113 final String url, | 115 final String url, |
| 114 final String cookies, | 116 final String cookies, |
| 115 final String userAgent) { | 117 final String userAgent) { |
| 118 PACKAGE_NAME = context.getPackageName(); | |
| 116 return new MediaResourceGetter().extract( | 119 return new MediaResourceGetter().extract( |
| 117 context, url, cookies, userAgent); | 120 context, url, cookies, userAgent); |
| 118 } | 121 } |
| 119 | 122 |
| 120 @VisibleForTesting | 123 @VisibleForTesting |
| 121 MediaMetadata extract(final Context context, final String url, | 124 MediaMetadata extract(final Context context, final String url, |
| 122 final String cookies, final String userAgent) { | 125 final String cookies, final String userAgent) { |
| 123 if (!androidDeviceOk(android.os.Build.MODEL, android.os.Build.VERSION.SD K_INT)) { | 126 if (!androidDeviceOk(android.os.Build.MODEL, android.os.Build.VERSION.SD K_INT)) { |
| 124 return EMPTY_METADATA; | 127 return EMPTY_METADATA; |
| 125 } | 128 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 Log.d(TAG, "no active network"); | 340 Log.d(TAG, "no active network"); |
| 338 return null; | 341 return null; |
| 339 } | 342 } |
| 340 return info.getType(); | 343 return info.getType(); |
| 341 } | 344 } |
| 342 | 345 |
| 343 private List<String> getRawAcceptableDirectories() { | 346 private List<String> getRawAcceptableDirectories() { |
| 344 List<String> result = new ArrayList<String>(); | 347 List<String> result = new ArrayList<String>(); |
| 345 result.add("/mnt/sdcard/"); | 348 result.add("/mnt/sdcard/"); |
| 346 result.add("/sdcard/"); | 349 result.add("/sdcard/"); |
| 350 result.add("/data/data/" + PACKAGE_NAME + "/cache/"); | |
|
qinmin
2014/08/13 17:33:59
add a check here that PACKAGE_NAME cannot be null
| |
| 347 return result; | 351 return result; |
| 348 } | 352 } |
| 349 | 353 |
| 350 private List<String> canonicalize(List<String> paths) { | 354 private List<String> canonicalize(List<String> paths) { |
| 351 List<String> result = new ArrayList<String>(paths.size()); | 355 List<String> result = new ArrayList<String>(paths.size()); |
| 352 try { | 356 try { |
| 353 for (String path : paths) { | 357 for (String path : paths) { |
| 354 result.add(new File(path).getCanonicalPath()); | 358 result.add(new File(path).getCanonicalPath()); |
| 355 } | 359 } |
| 356 return result; | 360 return result; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 374 @VisibleForTesting | 378 @VisibleForTesting |
| 375 void configure(String path) { | 379 void configure(String path) { |
| 376 mRetriever.setDataSource(path); | 380 mRetriever.setDataSource(path); |
| 377 } | 381 } |
| 378 | 382 |
| 379 @VisibleForTesting | 383 @VisibleForTesting |
| 380 String extractMetadata(int key) { | 384 String extractMetadata(int key) { |
| 381 return mRetriever.extractMetadata(key); | 385 return mRetriever.extractMetadata(key); |
| 382 } | 386 } |
| 383 } | 387 } |
| OLD | NEW |