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 #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/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "content/browser/child_process_security_policy_impl.h" | 12 #include "content/browser/child_process_security_policy_impl.h" |
| 13 #include "content/browser/fileapi/browser_file_system_helper.h" | 13 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 18 #include "jni/MediaResourceGetter_jni.h" | 18 #include "jni/MediaResourceGetter_jni.h" |
| 19 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
| 20 #include "net/cookies/cookie_store.h" | 20 #include "net/cookies/cookie_store.h" |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 using base::android::ConvertUTF8ToJavaString; | |
| 26 using base::android::ScopedJavaLocalRef; | |
| 27 | |
| 25 namespace content { | 28 namespace content { |
| 26 | 29 |
| 27 static void ReturnResultOnUIThread( | 30 static void ReturnResultOnUIThread( |
| 28 const base::Callback<void(const std::string&)>& callback, | 31 const base::Callback<void(const std::string&)>& callback, |
| 29 const std::string& result) { | 32 const std::string& result) { |
| 30 BrowserThread::PostTask( | 33 BrowserThread::PostTask( |
| 31 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 34 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 32 } | 35 } |
| 33 | 36 |
| 34 // Get the metadata from a media URL. When finished, a task is posted to the UI | 37 // Get the metadata from a media URL. When finished, a task is posted to the UI |
| 35 // thread to run the callback function. | 38 // thread to run the callback function. |
| 36 static void GetMediaMetadata( | 39 static void GetMediaMetadata( |
| 37 const std::string& url, const std::string& cookies, | 40 const std::string& url, const std::string& cookies, |
| 38 const media::MediaResourceGetter::ExtractMediaMetadataCB& callback) { | 41 const media::MediaResourceGetter::ExtractMediaMetadataCB& callback) { |
| 39 JNIEnv* env = base::android::AttachCurrentThread(); | 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 40 | 43 |
| 41 base::android::ScopedJavaLocalRef<jstring> j_url_string = | 44 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); |
| 42 base::android::ConvertUTF8ToJavaString(env, url); | 45 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString(env, cookies); |
| 43 base::android::ScopedJavaLocalRef<jstring> j_cookies = | |
| 44 base::android::ConvertUTF8ToJavaString(env, cookies); | |
| 45 jobject j_context = base::android::GetApplicationContext(); | 46 jobject j_context = base::android::GetApplicationContext(); |
| 46 base::android::ScopedJavaLocalRef<jobject> j_metadata = | 47 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( |
| 47 Java_MediaResourceGetter_extractMediaMetadata( | 48 env, GetUserAgent(GURL(url))); |
|
qinmin
2014/01/09 04:48:44
you can pass useragent to GetMediaMetadata() from
Jinsuk Kim
2014/01/09 05:22:55
Done. See if this is done as you suggested.
| |
| 48 env, j_context, j_url_string.obj(), j_cookies.obj()); | 49 ScopedJavaLocalRef<jobject> j_metadata = |
| 50 Java_MediaResourceGetter_extractMediaMetadata(env, | |
| 51 j_context, | |
| 52 j_url_string.obj(), | |
| 53 j_cookies.obj(), | |
| 54 j_user_agent.obj()); | |
| 49 BrowserThread::PostTask( | 55 BrowserThread::PostTask( |
| 50 BrowserThread::UI, FROM_HERE, | 56 BrowserThread::UI, FROM_HERE, |
| 51 base::Bind(callback, base::TimeDelta::FromMilliseconds( | 57 base::Bind(callback, base::TimeDelta::FromMilliseconds( |
| 52 Java_MediaMetadata_getDurationInMilliseconds( | 58 Java_MediaMetadata_getDurationInMilliseconds( |
| 53 env, j_metadata.obj())), | 59 env, j_metadata.obj())), |
| 54 Java_MediaMetadata_getWidth(env, j_metadata.obj()), | 60 Java_MediaMetadata_getWidth(env, j_metadata.obj()), |
| 55 Java_MediaMetadata_getHeight(env, j_metadata.obj()), | 61 Java_MediaMetadata_getHeight(env, j_metadata.obj()), |
| 56 Java_MediaMetadata_isSuccess(env, j_metadata.obj()))); | 62 Java_MediaMetadata_isSuccess(env, j_metadata.obj()))); |
| 57 } | 63 } |
| 58 | 64 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 pool->PostWorkerTask( | 273 pool->PostWorkerTask( |
| 268 FROM_HERE, base::Bind(&GetMediaMetadata, url, cookies, callback)); | 274 FROM_HERE, base::Bind(&GetMediaMetadata, url, cookies, callback)); |
| 269 } | 275 } |
| 270 | 276 |
| 271 // static | 277 // static |
| 272 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { | 278 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { |
| 273 return RegisterNativesImpl(env); | 279 return RegisterNativesImpl(env); |
| 274 } | 280 } |
| 275 | 281 |
| 276 } // namespace content | 282 } // namespace content |
| OLD | NEW |