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 #include "content/browser/media/android/media_resource_getter_impl.h" | 5 #include "content/browser/media/android/media_resource_getter_impl.h" |
6 | 6 |
7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
16 #include "content/browser/fileapi/browser_file_system_helper.h" | 17 #include "content/browser/fileapi/browser_file_system_helper.h" |
17 #include "content/browser/resource_context_impl.h" | 18 #include "content/browser/resource_context_impl.h" |
18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
21 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
24 #include "jni/MediaResourceGetter_jni.h" | 25 #include "jni/MediaResourceGetter_jni.h" |
25 #include "media/base/android/media_url_interceptor.h" | 26 #include "media/base/android/media_url_interceptor.h" |
26 #include "net/base/auth.h" | 27 #include "net/base/auth.h" |
27 #include "net/cookies/cookie_store.h" | 28 #include "net/cookies/cookie_store.h" |
28 #include "net/http/http_auth.h" | 29 #include "net/http/http_auth.h" |
29 #include "net/http/http_transaction_factory.h" | 30 #include "net/http/http_transaction_factory.h" |
30 #include "net/url_request/url_request_context.h" | 31 #include "net/url_request/url_request_context.h" |
31 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
32 #include "storage/browser/blob/blob_data_handle.h" | 33 #include "storage/browser/blob/blob_data_handle.h" |
33 #include "storage/browser/blob/blob_data_item.h" | 34 #include "storage/browser/blob/blob_data_item.h" |
34 #include "storage/browser/blob/blob_data_snapshot.h" | 35 #include "storage/browser/blob/blob_data_snapshot.h" |
35 #include "storage/browser/blob/blob_storage_context.h" | 36 #include "storage/browser/blob/blob_storage_context.h" |
36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
37 | 38 |
38 using base::android::ConvertUTF8ToJavaString; | 39 using base::android::ConvertUTF8ToJavaString; |
| 40 using base::android::JavaRef; |
39 using base::android::ScopedJavaLocalRef; | 41 using base::android::ScopedJavaLocalRef; |
40 | 42 |
41 namespace content { | 43 namespace content { |
42 | 44 |
43 static void ReturnResultOnUIThread( | 45 static void ReturnResultOnUIThread( |
44 const base::Callback<void(const std::string&)>& callback, | 46 const base::Callback<void(const std::string&)>& callback, |
45 const std::string& result) { | 47 const std::string& result) { |
46 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
47 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 49 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
48 } | 50 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // Gets the metadata from a media URL. When finished, a task is posted to the UI | 116 // Gets the metadata from a media URL. When finished, a task is posted to the UI |
115 // thread to run the callback function. | 117 // thread to run the callback function. |
116 static void GetMediaMetadata( | 118 static void GetMediaMetadata( |
117 const std::string& url, const std::string& cookies, | 119 const std::string& url, const std::string& cookies, |
118 const std::string& user_agent, | 120 const std::string& user_agent, |
119 const media::MediaResourceGetter::ExtractMediaMetadataCB& callback) { | 121 const media::MediaResourceGetter::ExtractMediaMetadataCB& callback) { |
120 JNIEnv* env = base::android::AttachCurrentThread(); | 122 JNIEnv* env = base::android::AttachCurrentThread(); |
121 | 123 |
122 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); | 124 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); |
123 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString(env, cookies); | 125 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString(env, cookies); |
124 jobject j_context = base::android::GetApplicationContext(); | 126 const JavaRef<jobject>& j_context = base::android::GetApplicationContext(); |
125 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( | 127 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( |
126 env, user_agent); | 128 env, user_agent); |
127 ScopedJavaLocalRef<jobject> j_metadata = | 129 ScopedJavaLocalRef<jobject> j_metadata = |
128 Java_MediaResourceGetter_extractMediaMetadata(env, | 130 Java_MediaResourceGetter_extractMediaMetadata(env, |
129 j_context, | 131 j_context, |
130 j_url_string.obj(), | 132 j_url_string.obj(), |
131 j_cookies.obj(), | 133 j_cookies.obj(), |
132 j_user_agent.obj()); | 134 j_user_agent.obj()); |
133 | 135 |
134 PostMediaMetadataCallbackTask(callback, env, j_metadata); | 136 PostMediaMetadataCallbackTask(callback, env, j_metadata); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 const int64_t size, | 377 const int64_t size, |
376 const ExtractMediaMetadataCB& callback) { | 378 const ExtractMediaMetadataCB& callback) { |
377 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
378 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 380 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
379 pool->PostWorkerTask( | 381 pool->PostWorkerTask( |
380 FROM_HERE, | 382 FROM_HERE, |
381 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); | 383 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); |
382 } | 384 } |
383 | 385 |
384 } // namespace content | 386 } // namespace content |
OLD | NEW |