Commit c55c06c5 authored by Pritam's avatar Pritam Committed by Commit Bot

Converts Android-specific cookie accesses to Mojo.

Converts all instances of access to net::CookieStore over to
network::mojom::CookieManager.

Addressed the uses of cookie store in the following android-specific files:
  - content/browser/media/android

This is a follow-up CL to #903307.

Bug: 792672
Change-Id: Ifb5ee30dfb746e66aa4c06674abb8e9e22ec1d1b
Reviewed-on: https://chromium-review.googlesource.com/952954Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Pritam Nikam <pritam.nikam@samsung.com>
Cr-Commit-Position: refs/heads/master@{#543297}
parent f5e91fee
...@@ -37,20 +37,61 @@ using base::android::ScopedJavaLocalRef; ...@@ -37,20 +37,61 @@ using base::android::ScopedJavaLocalRef;
namespace content { namespace content {
static void ReturnStringResultOnUIThread( namespace {
// Returns the cookie service for the |browser_context| at the client end of the
// mojo pipe.
network::mojom::CookieManager* GetCookieServiceForContext(
BrowserContext* browser_context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return BrowserContext::GetDefaultStoragePartition(browser_context)
->GetCookieManagerForBrowserProcess();
}
void ReturnResultOnUIThread(
base::OnceCallback<void(const std::string&)> callback, base::OnceCallback<void(const std::string&)> callback,
const std::string& result) { const std::string& result) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::BindOnce(std::move(callback), result)); base::BindOnce(std::move(callback), result));
} }
static void ReturnCookieListResultOnUIThread( // Checks the policy for get cookies and returns the cookie line if allowed.
net::CookieStore::GetCookieListCallback callback, std::string GetCookiesOnIO(const GURL& url,
const net::CookieList& result) { const GURL& site_for_cookies,
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, content::ResourceContext* resource_context,
base::BindOnce(std::move(callback), result)); int render_process_id,
int render_frame_id,
const net::CookieList& cookie_list) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!GetContentClient()->browser()->AllowGetCookie(
url, site_for_cookies, cookie_list, resource_context,
render_process_id, render_frame_id)) {
return std::string();
}
return net::CanonicalCookie::BuildCookieLine(cookie_list);
}
void CheckPolicyForCookies(const GURL& url,
const GURL& site_for_cookies,
content::ResourceContext* resource_context,
int render_process_id,
int render_frame_id,
MediaResourceGetterImpl::GetCookieCB callback,
const net::CookieList& cookie_list) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// AllowGetCookie has to be called on IO thread.
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&GetCookiesOnIO, url, site_for_cookies, resource_context,
render_process_id, render_frame_id, cookie_list),
std::move(callback));
} }
} // namespace
static void RequestPlaformPathFromFileSystemURL( static void RequestPlaformPathFromFileSystemURL(
const GURL& url, const GURL& url,
int render_process_id, int render_process_id,
...@@ -66,9 +107,9 @@ static void RequestPlaformPathFromFileSystemURL( ...@@ -66,9 +107,9 @@ static void RequestPlaformPathFromFileSystemURL(
base::FilePath data_storage_path; base::FilePath data_storage_path;
PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path); PathService::Get(base::DIR_ANDROID_APP_DATA, &data_storage_path);
if (data_storage_path.IsParent(platform_path)) if (data_storage_path.IsParent(platform_path))
ReturnStringResultOnUIThread(std::move(callback), platform_path.value()); ReturnResultOnUIThread(std::move(callback), platform_path.value());
else else
ReturnStringResultOnUIThread(std::move(callback), std::string()); ReturnResultOnUIThread(std::move(callback), std::string());
} }
// Posts a task to the UI thread to run the callback function. // Posts a task to the UI thread to run the callback function.
...@@ -129,17 +170,11 @@ static void GetMediaMetadataFromFd( ...@@ -129,17 +170,11 @@ static void GetMediaMetadataFromFd(
class MediaResourceGetterTask class MediaResourceGetterTask
: public base::RefCountedThreadSafe<MediaResourceGetterTask> { : public base::RefCountedThreadSafe<MediaResourceGetterTask> {
public: public:
MediaResourceGetterTask(BrowserContext* browser_context, MediaResourceGetterTask(BrowserContext* browser_context);
int render_process_id, int render_frame_id);
// Called by MediaResourceGetterImpl to start getting auth credentials. // Called by MediaResourceGetterImpl to start getting auth credentials.
net::AuthCredentials RequestAuthCredentials(const GURL& url) const; net::AuthCredentials RequestAuthCredentials(const GURL& url) const;
// Called by MediaResourceGetterImpl to start getting cookies for a URL.
void RequestCookies(const GURL& url,
const GURL& site_for_cookies,
net::CookieStore::GetCookieListCallback callback);
// Returns the task runner that all methods should be called. // Returns the task runner that all methods should be called.
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const; scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const;
...@@ -147,34 +182,17 @@ class MediaResourceGetterTask ...@@ -147,34 +182,17 @@ class MediaResourceGetterTask
friend class base::RefCountedThreadSafe<MediaResourceGetterTask>; friend class base::RefCountedThreadSafe<MediaResourceGetterTask>;
virtual ~MediaResourceGetterTask(); virtual ~MediaResourceGetterTask();
void CheckPolicyForCookies(const GURL& url,
const GURL& site_for_cookies,
net::CookieStore::GetCookieListCallback callback,
const net::CookieList& cookie_list);
// Context getter used to get the CookieStore and auth cache. // Context getter used to get the CookieStore and auth cache.
net::URLRequestContextGetter* context_getter_; net::URLRequestContextGetter* context_getter_;
// Resource context for checking cookie policies.
ResourceContext* resource_context_;
// Render process id, used to check whether the process can access cookies.
int render_process_id_;
// Render frame id, used to check tab specific cookie policy.
int render_frame_id_;
DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterTask); DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterTask);
}; };
MediaResourceGetterTask::MediaResourceGetterTask( MediaResourceGetterTask::MediaResourceGetterTask(
BrowserContext* browser_context, int render_process_id, int render_frame_id) BrowserContext* browser_context)
: context_getter_(BrowserContext::GetDefaultStoragePartition( : context_getter_(
browser_context)->GetURLRequestContext()), BrowserContext::GetDefaultStoragePartition(browser_context)
resource_context_(browser_context->GetResourceContext()), ->GetURLRequestContext()) {}
render_process_id_(render_process_id),
render_frame_id_(render_frame_id) {
}
MediaResourceGetterTask::~MediaResourceGetterTask() {} MediaResourceGetterTask::~MediaResourceGetterTask() {}
...@@ -201,49 +219,11 @@ net::AuthCredentials MediaResourceGetterTask::RequestAuthCredentials( ...@@ -201,49 +219,11 @@ net::AuthCredentials MediaResourceGetterTask::RequestAuthCredentials(
return net::AuthCredentials(); return net::AuthCredentials();
} }
void MediaResourceGetterTask::RequestCookies(
const GURL& url,
const GURL& site_for_cookies,
net::CookieStore::GetCookieListCallback callback) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (!policy->CanAccessDataForOrigin(render_process_id_, url)) {
std::move(callback).Run(net::CookieList());
return;
}
net::CookieStore* cookie_store =
context_getter_->GetURLRequestContext()->cookie_store();
if (!cookie_store) {
std::move(callback).Run(net::CookieList());
return;
}
cookie_store->GetAllCookiesForURLAsync(
url, base::BindOnce(&MediaResourceGetterTask::CheckPolicyForCookies, this,
url, site_for_cookies, std::move(callback)));
}
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
MediaResourceGetterTask::GetTaskRunner() const { MediaResourceGetterTask::GetTaskRunner() const {
return context_getter_->GetNetworkTaskRunner(); return context_getter_->GetNetworkTaskRunner();
} }
void MediaResourceGetterTask::CheckPolicyForCookies(
const GURL& url,
const GURL& site_for_cookies,
net::CookieStore::GetCookieListCallback callback,
const net::CookieList& cookie_list) {
if (GetContentClient()->browser()->AllowGetCookie(
url, site_for_cookies, cookie_list, resource_context_,
render_process_id_, render_frame_id_)) {
std::move(callback).Run(cookie_list);
} else {
std::move(callback).Run(net::CookieList());
}
}
MediaResourceGetterImpl::MediaResourceGetterImpl( MediaResourceGetterImpl::MediaResourceGetterImpl(
BrowserContext* browser_context, BrowserContext* browser_context,
storage::FileSystemContext* file_system_context, storage::FileSystemContext* file_system_context,
...@@ -262,8 +242,7 @@ void MediaResourceGetterImpl::GetAuthCredentials( ...@@ -262,8 +242,7 @@ void MediaResourceGetterImpl::GetAuthCredentials(
const GURL& url, const GURL& url,
GetAuthCredentialsCB callback) { GetAuthCredentialsCB callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask( auto task = base::MakeRefCounted<MediaResourceGetterTask>(browser_context_);
browser_context_, 0, 0);
PostTaskAndReplyWithResult( PostTaskAndReplyWithResult(
task->GetTaskRunner().get(), FROM_HERE, task->GetTaskRunner().get(), FROM_HERE,
...@@ -277,17 +256,28 @@ void MediaResourceGetterImpl::GetCookies(const GURL& url, ...@@ -277,17 +256,28 @@ void MediaResourceGetterImpl::GetCookies(const GURL& url,
const GURL& site_for_cookies, const GURL& site_for_cookies,
GetCookieCB callback) { GetCookieCB callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
scoped_refptr<MediaResourceGetterTask> task = new MediaResourceGetterTask(
browser_context_, render_process_id_, render_frame_id_);
net::CookieStore::GetCookieListCallback cb = ChildProcessSecurityPolicyImpl* policy =
base::BindOnce(&MediaResourceGetterImpl::GetCookiesCallback, ChildProcessSecurityPolicyImpl::GetInstance();
weak_factory_.GetWeakPtr(), std::move(callback)); if (!policy->CanAccessDataForOrigin(render_process_id_, url)) {
task->GetTaskRunner()->PostTask( // Running the callback asynchronously on the caller thread to avoid
FROM_HERE, // reentrancy issues.
base::BindOnce( ReturnResultOnUIThread(std::move(callback), std::string());
&MediaResourceGetterTask::RequestCookies, task, url, site_for_cookies, return;
base::BindOnce(&ReturnCookieListResultOnUIThread, std::move(cb)))); }
net::CookieOptions options;
options.set_include_httponly();
options.set_same_site_cookie_mode(
net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
options.set_do_not_update_access_time();
GetCookieServiceForContext(browser_context_)
->GetCookieList(
url, options,
base::BindOnce(&CheckPolicyForCookies, url, site_for_cookies,
browser_context_->GetResourceContext(),
render_process_id_, render_frame_id_,
std::move(callback)));
} }
void MediaResourceGetterImpl::GetAuthCredentialsCallback( void MediaResourceGetterImpl::GetAuthCredentialsCallback(
...@@ -297,14 +287,6 @@ void MediaResourceGetterImpl::GetAuthCredentialsCallback( ...@@ -297,14 +287,6 @@ void MediaResourceGetterImpl::GetAuthCredentialsCallback(
std::move(callback).Run(credentials.username(), credentials.password()); std::move(callback).Run(credentials.username(), credentials.password());
} }
void MediaResourceGetterImpl::GetCookiesCallback(
GetCookieCB callback,
const net::CookieList& cookie_list) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string cookie_line = net::CanonicalCookie::BuildCookieLine(cookie_list);
std::move(callback).Run(std::move(cookie_line));
}
void MediaResourceGetterImpl::GetPlatformPathFromURL( void MediaResourceGetterImpl::GetPlatformPathFromURL(
const GURL& url, const GURL& url,
GetPlatformPathCB callback) { GetPlatformPathCB callback) {
......
...@@ -63,10 +63,6 @@ class MediaResourceGetterImpl : public media::MediaResourceGetter { ...@@ -63,10 +63,6 @@ class MediaResourceGetterImpl : public media::MediaResourceGetter {
void GetAuthCredentialsCallback(GetAuthCredentialsCB callback, void GetAuthCredentialsCallback(GetAuthCredentialsCB callback,
const net::AuthCredentials& credentials); const net::AuthCredentials& credentials);
// Called when GetCookies() finishes.
void GetCookiesCallback(GetCookieCB callback,
const net::CookieList& cookie_list);
// Called when GetPlatformPathFromFileSystemURL() finishes. // Called when GetPlatformPathFromFileSystemURL() finishes.
void GetPlatformPathCallback(GetPlatformPathCB callback, void GetPlatformPathCallback(GetPlatformPathCB callback,
const std::string& platform_path); const std::string& platform_path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment