| 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/browser/resource_context_impl.h" |
| 15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 20 #include "jni/MediaResourceGetter_jni.h" | 21 #include "jni/MediaResourceGetter_jni.h" |
| 21 #include "media/base/android/media_url_interceptor.h" | 22 #include "media/base/android/media_url_interceptor.h" |
| 22 #include "net/base/auth.h" | 23 #include "net/base/auth.h" |
| 23 #include "net/cookies/cookie_monster.h" | 24 #include "net/cookies/cookie_monster.h" |
| 24 #include "net/cookies/cookie_store.h" | 25 #include "net/cookies/cookie_store.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 static void ReturnResultOnUIThread( | 39 static void ReturnResultOnUIThread( |
| 39 const base::Callback<void(const std::string&)>& callback, | 40 const base::Callback<void(const std::string&)>& callback, |
| 40 const std::string& result) { | 41 const std::string& result) { |
| 41 BrowserThread::PostTask( | 42 BrowserThread::PostTask( |
| 42 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 43 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 43 } | 44 } |
| 44 | 45 |
| 45 static void RequestPlatformPathFromBlobURL( | 46 static void RequestPlatformPathFromBlobURL( |
| 46 const GURL& url, | 47 const GURL& url, |
| 47 BrowserContext* browser_context, | 48 ResourceContext* resource_context, |
| 48 const base::Callback<void(const std::string&)>& callback) { | 49 const base::Callback<void(const std::string&)>& callback) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 50 ChromeBlobStorageContext* context = | 51 ChromeBlobStorageContext* blob_storage_context = |
| 51 ChromeBlobStorageContext::GetFor(browser_context); | 52 GetChromeBlobStorageContextForResourceContext(resource_context); |
| 53 |
| 52 scoped_ptr<storage::BlobDataHandle> handle = | 54 scoped_ptr<storage::BlobDataHandle> handle = |
| 53 context->context()->GetBlobDataFromPublicURL(url); | 55 blob_storage_context->context()->GetBlobDataFromPublicURL(url); |
| 56 if (!handle) { |
| 57 // There are plenty of cases where handle can be empty. The most trivial is |
| 58 // when JS has aready revoked the given blob URL via URL.revokeObjectURL |
| 59 ReturnResultOnUIThread(callback, std::string()); |
| 60 return; |
| 61 } |
| 54 storage::BlobData* data = handle->data(); | 62 storage::BlobData* data = handle->data(); |
| 55 if (!data) { | 63 if (!data) { |
| 56 ReturnResultOnUIThread(callback, ""); | 64 ReturnResultOnUIThread(callback, std::string()); |
| 57 NOTREACHED(); | 65 NOTREACHED(); |
| 58 return; | 66 return; |
| 59 } | 67 } |
| 60 const std::vector<storage::BlobData::Item> items = data->items(); | 68 const std::vector<storage::BlobData::Item> items = data->items(); |
| 61 | 69 |
| 62 // TODO(qinmin): handle the case when the blob data is not a single file. | 70 // TODO(qinmin): handle the case when the blob data is not a single file. |
| 63 DLOG_IF(WARNING, items.size() != 1u) | 71 DLOG_IF(WARNING, items.size() != 1u) |
| 64 << "More than one blob data are present: " << items.size(); | 72 << "More than one blob data are present: " << items.size(); |
| 65 ReturnResultOnUIThread(callback, items[0].path().value()); | 73 ReturnResultOnUIThread(callback, items[0].path().value()); |
| 66 } | 74 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 330 |
| 323 GetPlatformPathCB cb = | 331 GetPlatformPathCB cb = |
| 324 base::Bind(&MediaResourceGetterImpl::GetPlatformPathCallback, | 332 base::Bind(&MediaResourceGetterImpl::GetPlatformPathCallback, |
| 325 weak_factory_.GetWeakPtr(), | 333 weak_factory_.GetWeakPtr(), |
| 326 callback); | 334 callback); |
| 327 | 335 |
| 328 if (url.SchemeIs(url::kBlobScheme)) { | 336 if (url.SchemeIs(url::kBlobScheme)) { |
| 329 BrowserThread::PostTask( | 337 BrowserThread::PostTask( |
| 330 BrowserThread::IO, | 338 BrowserThread::IO, |
| 331 FROM_HERE, | 339 FROM_HERE, |
| 332 base::Bind(&RequestPlatformPathFromBlobURL, url, browser_context_, cb)); | 340 base::Bind(&RequestPlatformPathFromBlobURL, url, |
| 341 browser_context_->GetResourceContext(), cb)); |
| 333 return; | 342 return; |
| 334 } | 343 } |
| 335 | 344 |
| 336 scoped_refptr<storage::FileSystemContext> context(file_system_context_); | 345 scoped_refptr<storage::FileSystemContext> context(file_system_context_); |
| 337 BrowserThread::PostTask( | 346 BrowserThread::PostTask( |
| 338 BrowserThread::FILE, | 347 BrowserThread::FILE, |
| 339 FROM_HERE, | 348 FROM_HERE, |
| 340 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, | 349 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, |
| 341 context, cb)); | 350 context, cb)); |
| 342 } | 351 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 366 FROM_HERE, | 375 FROM_HERE, |
| 367 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); | 376 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); |
| 368 } | 377 } |
| 369 | 378 |
| 370 // static | 379 // static |
| 371 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { | 380 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { |
| 372 return RegisterNativesImpl(env); | 381 return RegisterNativesImpl(env); |
| 373 } | 382 } |
| 374 | 383 |
| 375 } // namespace content | 384 } // namespace content |
| OLD | NEW |