| 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/browser/fileapi/chrome_blob_storage_context.h" | 14 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 20 #include "jni/MediaResourceGetter_jni.h" | 20 #include "jni/MediaResourceGetter_jni.h" |
| 21 #include "media/base/android/media_url_interceptor.h" | 21 #include "media/base/android/media_url_interceptor.h" |
| 22 #include "net/base/auth.h" | 22 #include "net/base/auth.h" |
| 23 #include "net/cookies/cookie_monster.h" | 23 #include "net/cookies/cookie_monster.h" |
| 24 #include "net/cookies/cookie_store.h" | 24 #include "net/cookies/cookie_store.h" |
| 25 #include "net/http/http_auth.h" | 25 #include "net/http/http_auth.h" |
| 26 #include "net/http/http_transaction_factory.h" | 26 #include "net/http/http_transaction_factory.h" |
| 27 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 28 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 #include "webkit/browser/blob/blob_data_handle.h" | 30 #include "storage/browser/blob/blob_data_handle.h" |
| 31 #include "webkit/browser/blob/blob_storage_context.h" | 31 #include "storage/browser/blob/blob_storage_context.h" |
| 32 | 32 |
| 33 using base::android::ConvertUTF8ToJavaString; | 33 using base::android::ConvertUTF8ToJavaString; |
| 34 using base::android::ScopedJavaLocalRef; | 34 using base::android::ScopedJavaLocalRef; |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 static void ReturnResultOnUIThread( | 38 static void ReturnResultOnUIThread( |
| 39 const base::Callback<void(const std::string&)>& callback, | 39 const base::Callback<void(const std::string&)>& callback, |
| 40 const std::string& result) { | 40 const std::string& result) { |
| 41 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 42 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 42 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 static void RequestPlatformPathFromBlobURL( | 45 static void RequestPlatformPathFromBlobURL( |
| 46 const GURL& url, | 46 const GURL& url, |
| 47 BrowserContext* browser_context, | 47 BrowserContext* browser_context, |
| 48 const base::Callback<void(const std::string&)>& callback) { | 48 const base::Callback<void(const std::string&)>& callback) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 50 ChromeBlobStorageContext* context = | 50 ChromeBlobStorageContext* context = |
| 51 ChromeBlobStorageContext::GetFor(browser_context); | 51 ChromeBlobStorageContext::GetFor(browser_context); |
| 52 scoped_ptr<webkit_blob::BlobDataHandle> handle = | 52 scoped_ptr<storage::BlobDataHandle> handle = |
| 53 context->context()->GetBlobDataFromPublicURL(url); | 53 context->context()->GetBlobDataFromPublicURL(url); |
| 54 const std::vector<webkit_blob::BlobData::Item> items = | 54 const std::vector<storage::BlobData::Item> items = handle->data()->items(); |
| 55 handle->data()->items(); | |
| 56 | 55 |
| 57 // TODO(qinmin): handle the case when the blob data is not a single file. | 56 // TODO(qinmin): handle the case when the blob data is not a single file. |
| 58 DLOG_IF(WARNING, items.size() != 1u) | 57 DLOG_IF(WARNING, items.size() != 1u) |
| 59 << "More than one blob data are present: " << items.size(); | 58 << "More than one blob data are present: " << items.size(); |
| 60 ReturnResultOnUIThread(callback, items[0].path().value()); | 59 ReturnResultOnUIThread(callback, items[0].path().value()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 static void RequestPlaformPathFromFileSystemURL( | 62 static void RequestPlaformPathFromFileSystemURL( |
| 64 const GURL& url, | 63 const GURL& url, |
| 65 int render_process_id, | 64 int render_process_id, |
| 66 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 65 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 67 const base::Callback<void(const std::string&)>& callback) { | 66 const base::Callback<void(const std::string&)>& callback) { |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 69 base::FilePath platform_path; | 68 base::FilePath platform_path; |
| 70 SyncGetPlatformPath(file_system_context.get(), | 69 SyncGetPlatformPath(file_system_context.get(), |
| 71 render_process_id, | 70 render_process_id, |
| 72 url, | 71 url, |
| 73 &platform_path); | 72 &platform_path); |
| 74 base::FilePath data_storage_path; | 73 base::FilePath data_storage_path; |
| 75 PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path); | 74 PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path); |
| 76 if (data_storage_path.IsParent(platform_path)) | 75 if (data_storage_path.IsParent(platform_path)) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 net::CookieOptions options; | 245 net::CookieOptions options; |
| 247 options.set_include_httponly(); | 246 options.set_include_httponly(); |
| 248 cookie_store->GetCookiesWithOptionsAsync(url, options, callback); | 247 cookie_store->GetCookiesWithOptionsAsync(url, options, callback); |
| 249 } else { | 248 } else { |
| 250 callback.Run(std::string()); | 249 callback.Run(std::string()); |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 | 252 |
| 254 MediaResourceGetterImpl::MediaResourceGetterImpl( | 253 MediaResourceGetterImpl::MediaResourceGetterImpl( |
| 255 BrowserContext* browser_context, | 254 BrowserContext* browser_context, |
| 256 fileapi::FileSystemContext* file_system_context, | 255 storage::FileSystemContext* file_system_context, |
| 257 int render_process_id, | 256 int render_process_id, |
| 258 int render_frame_id) | 257 int render_frame_id) |
| 259 : browser_context_(browser_context), | 258 : browser_context_(browser_context), |
| 260 file_system_context_(file_system_context), | 259 file_system_context_(file_system_context), |
| 261 render_process_id_(render_process_id), | 260 render_process_id_(render_process_id), |
| 262 render_frame_id_(render_frame_id), | 261 render_frame_id_(render_frame_id), |
| 263 weak_factory_(this) {} | 262 weak_factory_(this) { |
| 263 } |
| 264 | 264 |
| 265 MediaResourceGetterImpl::~MediaResourceGetterImpl() {} | 265 MediaResourceGetterImpl::~MediaResourceGetterImpl() {} |
| 266 | 266 |
| 267 void MediaResourceGetterImpl::GetAuthCredentials( | 267 void MediaResourceGetterImpl::GetAuthCredentials( |
| 268 const GURL& url, const GetAuthCredentialsCB& callback) { | 268 const GURL& url, const GetAuthCredentialsCB& callback) { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 270 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( | 270 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( |
| 271 browser_context_, 0, 0); | 271 browser_context_, 0, 0); |
| 272 | 272 |
| 273 BrowserThread::PostTaskAndReplyWithResult( | 273 BrowserThread::PostTaskAndReplyWithResult( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 callback); | 320 callback); |
| 321 | 321 |
| 322 if (url.SchemeIs(url::kBlobScheme)) { | 322 if (url.SchemeIs(url::kBlobScheme)) { |
| 323 BrowserThread::PostTask( | 323 BrowserThread::PostTask( |
| 324 BrowserThread::IO, | 324 BrowserThread::IO, |
| 325 FROM_HERE, | 325 FROM_HERE, |
| 326 base::Bind(&RequestPlatformPathFromBlobURL, url, browser_context_, cb)); | 326 base::Bind(&RequestPlatformPathFromBlobURL, url, browser_context_, cb)); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 scoped_refptr<fileapi::FileSystemContext> context(file_system_context_); | 330 scoped_refptr<storage::FileSystemContext> context(file_system_context_); |
| 331 BrowserThread::PostTask( | 331 BrowserThread::PostTask( |
| 332 BrowserThread::FILE, | 332 BrowserThread::FILE, |
| 333 FROM_HERE, | 333 FROM_HERE, |
| 334 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, | 334 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, |
| 335 context, cb)); | 335 context, cb)); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void MediaResourceGetterImpl::GetPlatformPathCallback( | 338 void MediaResourceGetterImpl::GetPlatformPathCallback( |
| 339 const GetPlatformPathCB& callback, const std::string& platform_path) { | 339 const GetPlatformPathCB& callback, const std::string& platform_path) { |
| 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 360 FROM_HERE, | 360 FROM_HERE, |
| 361 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); | 361 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // static | 364 // static |
| 365 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { | 365 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { |
| 366 return RegisterNativesImpl(env); | 366 return RegisterNativesImpl(env); |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace content | 369 } // namespace content |
| OLD | NEW |