| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const base::Callback<void(const std::string&)>& callback, | 42 const base::Callback<void(const std::string&)>& callback, |
| 43 const std::string& result) { | 43 const std::string& result) { |
| 44 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
| 45 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 45 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 static void RequestPlatformPathFromBlobURL( | 48 static void RequestPlatformPathFromBlobURL( |
| 49 const GURL& url, | 49 const GURL& url, |
| 50 ResourceContext* resource_context, | 50 ResourceContext* resource_context, |
| 51 const base::Callback<void(const std::string&)>& callback) { | 51 const base::Callback<void(const std::string&)>& callback) { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 53 ChromeBlobStorageContext* blob_storage_context = | 53 ChromeBlobStorageContext* blob_storage_context = |
| 54 GetChromeBlobStorageContextForResourceContext(resource_context); | 54 GetChromeBlobStorageContextForResourceContext(resource_context); |
| 55 | 55 |
| 56 scoped_ptr<storage::BlobDataHandle> handle = | 56 scoped_ptr<storage::BlobDataHandle> handle = |
| 57 blob_storage_context->context()->GetBlobDataFromPublicURL(url); | 57 blob_storage_context->context()->GetBlobDataFromPublicURL(url); |
| 58 if (!handle) { | 58 if (!handle) { |
| 59 // There are plenty of cases where handle can be empty. The most trivial is | 59 // There are plenty of cases where handle can be empty. The most trivial is |
| 60 // when JS has aready revoked the given blob URL via URL.revokeObjectURL | 60 // when JS has aready revoked the given blob URL via URL.revokeObjectURL |
| 61 ReturnResultOnUIThread(callback, std::string()); | 61 ReturnResultOnUIThread(callback, std::string()); |
| 62 return; | 62 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 DLOG_IF(WARNING, items.size() != 1u) | 74 DLOG_IF(WARNING, items.size() != 1u) |
| 75 << "More than one blob item is present: " << items.size(); | 75 << "More than one blob item is present: " << items.size(); |
| 76 ReturnResultOnUIThread(callback, items[0]->path().value()); | 76 ReturnResultOnUIThread(callback, items[0]->path().value()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 static void RequestPlaformPathFromFileSystemURL( | 79 static void RequestPlaformPathFromFileSystemURL( |
| 80 const GURL& url, | 80 const GURL& url, |
| 81 int render_process_id, | 81 int render_process_id, |
| 82 scoped_refptr<storage::FileSystemContext> file_system_context, | 82 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 83 const base::Callback<void(const std::string&)>& callback) { | 83 const base::Callback<void(const std::string&)>& callback) { |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 84 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 85 base::FilePath platform_path; | 85 base::FilePath platform_path; |
| 86 SyncGetPlatformPath(file_system_context.get(), | 86 SyncGetPlatformPath(file_system_context.get(), |
| 87 render_process_id, | 87 render_process_id, |
| 88 url, | 88 url, |
| 89 &platform_path); | 89 &platform_path); |
| 90 base::FilePath data_storage_path; | 90 base::FilePath data_storage_path; |
| 91 PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path); | 91 PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path); |
| 92 if (data_storage_path.IsParent(platform_path)) | 92 if (data_storage_path.IsParent(platform_path)) |
| 93 ReturnResultOnUIThread(callback, platform_path.value()); | 93 ReturnResultOnUIThread(callback, platform_path.value()); |
| 94 else | 94 else |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 : context_getter_(browser_context->GetRequestContext()), | 193 : context_getter_(browser_context->GetRequestContext()), |
| 194 resource_context_(browser_context->GetResourceContext()), | 194 resource_context_(browser_context->GetResourceContext()), |
| 195 render_process_id_(render_process_id), | 195 render_process_id_(render_process_id), |
| 196 render_frame_id_(render_frame_id) { | 196 render_frame_id_(render_frame_id) { |
| 197 } | 197 } |
| 198 | 198 |
| 199 MediaResourceGetterTask::~MediaResourceGetterTask() {} | 199 MediaResourceGetterTask::~MediaResourceGetterTask() {} |
| 200 | 200 |
| 201 net::AuthCredentials MediaResourceGetterTask::RequestAuthCredentials( | 201 net::AuthCredentials MediaResourceGetterTask::RequestAuthCredentials( |
| 202 const GURL& url) const { | 202 const GURL& url) const { |
| 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 204 net::HttpTransactionFactory* factory = | 204 net::HttpTransactionFactory* factory = |
| 205 context_getter_->GetURLRequestContext()->http_transaction_factory(); | 205 context_getter_->GetURLRequestContext()->http_transaction_factory(); |
| 206 if (!factory) | 206 if (!factory) |
| 207 return net::AuthCredentials(); | 207 return net::AuthCredentials(); |
| 208 | 208 |
| 209 net::HttpAuthCache* auth_cache = | 209 net::HttpAuthCache* auth_cache = |
| 210 factory->GetSession()->http_auth_cache(); | 210 factory->GetSession()->http_auth_cache(); |
| 211 if (!auth_cache) | 211 if (!auth_cache) |
| 212 return net::AuthCredentials(); | 212 return net::AuthCredentials(); |
| 213 | 213 |
| 214 net::HttpAuthCache::Entry* entry = | 214 net::HttpAuthCache::Entry* entry = |
| 215 auth_cache->LookupByPath(url.GetOrigin(), url.path()); | 215 auth_cache->LookupByPath(url.GetOrigin(), url.path()); |
| 216 | 216 |
| 217 // TODO(qinmin): handle other auth schemes. See http://crbug.com/395219. | 217 // TODO(qinmin): handle other auth schemes. See http://crbug.com/395219. |
| 218 if (entry && entry->scheme() == net::HttpAuth::AUTH_SCHEME_BASIC) | 218 if (entry && entry->scheme() == net::HttpAuth::AUTH_SCHEME_BASIC) |
| 219 return entry->credentials(); | 219 return entry->credentials(); |
| 220 else | 220 else |
| 221 return net::AuthCredentials(); | 221 return net::AuthCredentials(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void MediaResourceGetterTask::RequestCookies( | 224 void MediaResourceGetterTask::RequestCookies( |
| 225 const GURL& url, const GURL& first_party_for_cookies, | 225 const GURL& url, const GURL& first_party_for_cookies, |
| 226 const media::MediaResourceGetter::GetCookieCB& callback) { | 226 const media::MediaResourceGetter::GetCookieCB& callback) { |
| 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 227 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 228 ChildProcessSecurityPolicyImpl* policy = | 228 ChildProcessSecurityPolicyImpl* policy = |
| 229 ChildProcessSecurityPolicyImpl::GetInstance(); | 229 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 230 if (!policy->CanAccessCookiesForOrigin(render_process_id_, url)) { | 230 if (!policy->CanAccessCookiesForOrigin(render_process_id_, url)) { |
| 231 callback.Run(std::string()); | 231 callback.Run(std::string()); |
| 232 return; | 232 return; |
| 233 } | 233 } |
| 234 | 234 |
| 235 net::CookieStore* cookie_store = | 235 net::CookieStore* cookie_store = |
| 236 context_getter_->GetURLRequestContext()->cookie_store(); | 236 context_getter_->GetURLRequestContext()->cookie_store(); |
| 237 if (!cookie_store) { | 237 if (!cookie_store) { |
| 238 callback.Run(std::string()); | 238 callback.Run(std::string()); |
| 239 return; | 239 return; |
| 240 } | 240 } |
| 241 | 241 |
| 242 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); | 242 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
| 243 if (cookie_monster) { | 243 if (cookie_monster) { |
| 244 cookie_monster->GetAllCookiesForURLAsync(url, base::Bind( | 244 cookie_monster->GetAllCookiesForURLAsync(url, base::Bind( |
| 245 &MediaResourceGetterTask::CheckPolicyForCookies, this, | 245 &MediaResourceGetterTask::CheckPolicyForCookies, this, |
| 246 url, first_party_for_cookies, callback)); | 246 url, first_party_for_cookies, callback)); |
| 247 } else { | 247 } else { |
| 248 callback.Run(std::string()); | 248 callback.Run(std::string()); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 void MediaResourceGetterTask::CheckPolicyForCookies( | 252 void MediaResourceGetterTask::CheckPolicyForCookies( |
| 253 const GURL& url, const GURL& first_party_for_cookies, | 253 const GURL& url, const GURL& first_party_for_cookies, |
| 254 const media::MediaResourceGetter::GetCookieCB& callback, | 254 const media::MediaResourceGetter::GetCookieCB& callback, |
| 255 const net::CookieList& cookie_list) { | 255 const net::CookieList& cookie_list) { |
| 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 257 if (GetContentClient()->browser()->AllowGetCookie( | 257 if (GetContentClient()->browser()->AllowGetCookie( |
| 258 url, first_party_for_cookies, cookie_list, | 258 url, first_party_for_cookies, cookie_list, |
| 259 resource_context_, render_process_id_, render_frame_id_)) { | 259 resource_context_, render_process_id_, render_frame_id_)) { |
| 260 net::CookieStore* cookie_store = | 260 net::CookieStore* cookie_store = |
| 261 context_getter_->GetURLRequestContext()->cookie_store(); | 261 context_getter_->GetURLRequestContext()->cookie_store(); |
| 262 net::CookieOptions options; | 262 net::CookieOptions options; |
| 263 options.set_include_httponly(); | 263 options.set_include_httponly(); |
| 264 cookie_store->GetCookiesWithOptionsAsync(url, options, callback); | 264 cookie_store->GetCookiesWithOptionsAsync(url, options, callback); |
| 265 } else { | 265 } else { |
| 266 callback.Run(std::string()); | 266 callback.Run(std::string()); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 MediaResourceGetterImpl::MediaResourceGetterImpl( | 270 MediaResourceGetterImpl::MediaResourceGetterImpl( |
| 271 BrowserContext* browser_context, | 271 BrowserContext* browser_context, |
| 272 storage::FileSystemContext* file_system_context, | 272 storage::FileSystemContext* file_system_context, |
| 273 int render_process_id, | 273 int render_process_id, |
| 274 int render_frame_id) | 274 int render_frame_id) |
| 275 : browser_context_(browser_context), | 275 : browser_context_(browser_context), |
| 276 file_system_context_(file_system_context), | 276 file_system_context_(file_system_context), |
| 277 render_process_id_(render_process_id), | 277 render_process_id_(render_process_id), |
| 278 render_frame_id_(render_frame_id), | 278 render_frame_id_(render_frame_id), |
| 279 weak_factory_(this) { | 279 weak_factory_(this) { |
| 280 } | 280 } |
| 281 | 281 |
| 282 MediaResourceGetterImpl::~MediaResourceGetterImpl() {} | 282 MediaResourceGetterImpl::~MediaResourceGetterImpl() {} |
| 283 | 283 |
| 284 void MediaResourceGetterImpl::GetAuthCredentials( | 284 void MediaResourceGetterImpl::GetAuthCredentials( |
| 285 const GURL& url, const GetAuthCredentialsCB& callback) { | 285 const GURL& url, const GetAuthCredentialsCB& callback) { |
| 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 286 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 287 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( | 287 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( |
| 288 browser_context_, 0, 0); | 288 browser_context_, 0, 0); |
| 289 | 289 |
| 290 BrowserThread::PostTaskAndReplyWithResult( | 290 BrowserThread::PostTaskAndReplyWithResult( |
| 291 BrowserThread::IO, | 291 BrowserThread::IO, |
| 292 FROM_HERE, | 292 FROM_HERE, |
| 293 base::Bind(&MediaResourceGetterTask::RequestAuthCredentials, task, url), | 293 base::Bind(&MediaResourceGetterTask::RequestAuthCredentials, task, url), |
| 294 base::Bind(&MediaResourceGetterImpl::GetAuthCredentialsCallback, | 294 base::Bind(&MediaResourceGetterImpl::GetAuthCredentialsCallback, |
| 295 weak_factory_.GetWeakPtr(), callback)); | 295 weak_factory_.GetWeakPtr(), callback)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void MediaResourceGetterImpl::GetCookies( | 298 void MediaResourceGetterImpl::GetCookies( |
| 299 const GURL& url, const GURL& first_party_for_cookies, | 299 const GURL& url, const GURL& first_party_for_cookies, |
| 300 const GetCookieCB& callback) { | 300 const GetCookieCB& callback) { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 301 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 302 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( | 302 scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( |
| 303 browser_context_, render_process_id_, render_frame_id_); | 303 browser_context_, render_process_id_, render_frame_id_); |
| 304 | 304 |
| 305 GetCookieCB cb = base::Bind(&MediaResourceGetterImpl::GetCookiesCallback, | 305 GetCookieCB cb = base::Bind(&MediaResourceGetterImpl::GetCookiesCallback, |
| 306 weak_factory_.GetWeakPtr(), | 306 weak_factory_.GetWeakPtr(), |
| 307 callback); | 307 callback); |
| 308 BrowserThread::PostTask( | 308 BrowserThread::PostTask( |
| 309 BrowserThread::IO, | 309 BrowserThread::IO, |
| 310 FROM_HERE, | 310 FROM_HERE, |
| 311 base::Bind(&MediaResourceGetterTask::RequestCookies, | 311 base::Bind(&MediaResourceGetterTask::RequestCookies, |
| 312 task, url, first_party_for_cookies, | 312 task, url, first_party_for_cookies, |
| 313 base::Bind(&ReturnResultOnUIThread, cb))); | 313 base::Bind(&ReturnResultOnUIThread, cb))); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void MediaResourceGetterImpl::GetAuthCredentialsCallback( | 316 void MediaResourceGetterImpl::GetAuthCredentialsCallback( |
| 317 const GetAuthCredentialsCB& callback, | 317 const GetAuthCredentialsCB& callback, |
| 318 const net::AuthCredentials& credentials) { | 318 const net::AuthCredentials& credentials) { |
| 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 320 callback.Run(credentials.username(), credentials.password()); | 320 callback.Run(credentials.username(), credentials.password()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void MediaResourceGetterImpl::GetCookiesCallback( | 323 void MediaResourceGetterImpl::GetCookiesCallback( |
| 324 const GetCookieCB& callback, const std::string& cookies) { | 324 const GetCookieCB& callback, const std::string& cookies) { |
| 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 326 callback.Run(cookies); | 326 callback.Run(cookies); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void MediaResourceGetterImpl::GetPlatformPathFromURL( | 329 void MediaResourceGetterImpl::GetPlatformPathFromURL( |
| 330 const GURL& url, const GetPlatformPathCB& callback) { | 330 const GURL& url, const GetPlatformPathCB& callback) { |
| 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 332 DCHECK(url.SchemeIsFileSystem() || url.SchemeIs(url::kBlobScheme)); | 332 DCHECK(url.SchemeIsFileSystem() || url.SchemeIs(url::kBlobScheme)); |
| 333 | 333 |
| 334 GetPlatformPathCB cb = | 334 GetPlatformPathCB cb = |
| 335 base::Bind(&MediaResourceGetterImpl::GetPlatformPathCallback, | 335 base::Bind(&MediaResourceGetterImpl::GetPlatformPathCallback, |
| 336 weak_factory_.GetWeakPtr(), | 336 weak_factory_.GetWeakPtr(), |
| 337 callback); | 337 callback); |
| 338 | 338 |
| 339 if (url.SchemeIs(url::kBlobScheme)) { | 339 if (url.SchemeIs(url::kBlobScheme)) { |
| 340 BrowserThread::PostTask( | 340 BrowserThread::PostTask( |
| 341 BrowserThread::IO, | 341 BrowserThread::IO, |
| 342 FROM_HERE, | 342 FROM_HERE, |
| 343 base::Bind(&RequestPlatformPathFromBlobURL, url, | 343 base::Bind(&RequestPlatformPathFromBlobURL, url, |
| 344 browser_context_->GetResourceContext(), cb)); | 344 browser_context_->GetResourceContext(), cb)); |
| 345 return; | 345 return; |
| 346 } | 346 } |
| 347 | 347 |
| 348 scoped_refptr<storage::FileSystemContext> context(file_system_context_); | 348 scoped_refptr<storage::FileSystemContext> context(file_system_context_); |
| 349 BrowserThread::PostTask( | 349 BrowserThread::PostTask( |
| 350 BrowserThread::FILE, | 350 BrowserThread::FILE, |
| 351 FROM_HERE, | 351 FROM_HERE, |
| 352 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, | 352 base::Bind(&RequestPlaformPathFromFileSystemURL, url, render_process_id_, |
| 353 context, cb)); | 353 context, cb)); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void MediaResourceGetterImpl::GetPlatformPathCallback( | 356 void MediaResourceGetterImpl::GetPlatformPathCallback( |
| 357 const GetPlatformPathCB& callback, const std::string& platform_path) { | 357 const GetPlatformPathCB& callback, const std::string& platform_path) { |
| 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 358 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 359 callback.Run(platform_path); | 359 callback.Run(platform_path); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void MediaResourceGetterImpl::ExtractMediaMetadata( | 362 void MediaResourceGetterImpl::ExtractMediaMetadata( |
| 363 const std::string& url, const std::string& cookies, | 363 const std::string& url, const std::string& cookies, |
| 364 const std::string& user_agent, const ExtractMediaMetadataCB& callback) { | 364 const std::string& user_agent, const ExtractMediaMetadataCB& callback) { |
| 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 365 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 366 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 366 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 367 pool->PostWorkerTask( | 367 pool->PostWorkerTask( |
| 368 FROM_HERE, | 368 FROM_HERE, |
| 369 base::Bind(&GetMediaMetadata, url, cookies, user_agent, callback)); | 369 base::Bind(&GetMediaMetadata, url, cookies, user_agent, callback)); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void MediaResourceGetterImpl::ExtractMediaMetadata( | 372 void MediaResourceGetterImpl::ExtractMediaMetadata( |
| 373 const int fd, const int64 offset, const int64 size, | 373 const int fd, const int64 offset, const int64 size, |
| 374 const ExtractMediaMetadataCB& callback) { | 374 const ExtractMediaMetadataCB& callback) { |
| 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 376 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 376 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 377 pool->PostWorkerTask( | 377 pool->PostWorkerTask( |
| 378 FROM_HERE, | 378 FROM_HERE, |
| 379 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); | 379 base::Bind(&GetMediaMetadataFromFd, fd, offset, size, callback)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 // static | 382 // static |
| 383 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { | 383 bool MediaResourceGetterImpl::RegisterMediaResourceGetter(JNIEnv* env) { |
| 384 return RegisterNativesImpl(env); | 384 return RegisterNativesImpl(env); |
| 385 } | 385 } |
| 386 | 386 |
| 387 } // namespace content | 387 } // namespace content |
| OLD | NEW |