Skip to content

Commit

Permalink
Move android mediaplayer from render process to browser process.
Browse files Browse the repository at this point in the history
Due to UID isolation for security reasons, the render process can no longer have permissions to access internet.
Since Android mediaplayer requires internet permission to work, it has to be moved to the browser process to resolve this. 
Here are the changes included in this patch:
1. Make WebMediaPlayerAndroid a common base class for WebMediaPlayerImplAndroid and WebMediaPlayerInProcessAndroid.
WebMediaPlayerImplAndroid places the android mediaplayer in the brower process, this will be used for future chrome on android releases. 
WebMediaPlayerInProcessAndroid still places the android mediaplayer in the render process, this is being used for Layout tests. We will deprecate this later.

2.Added a commandline flag kMediaPlayerInRenderProcess to
allow switching between these 2 modes

3.MediaPlayerBridge now takes over all the logics originally in WebMediaPlayerAndroid. This is to shield WMPA from knowing the internal state of the mediaplayer.

BUG=


Review URL: https://chromiumcodereview.appspot.com/10919075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157596 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
qinmin@chromium.org committed Sep 19, 2012
1 parent afd2b92 commit 780fc82
Show file tree
Hide file tree
Showing 49 changed files with 2,480 additions and 774 deletions.
7 changes: 0 additions & 7 deletions chrome/renderer/chrome_render_process_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "v8/include/v8.h"

#if defined(OS_ANDROID)
#include "webkit/media/android/webmediaplayer_android.h"
#endif

#if defined(OS_WIN)
#include "base/win/iat_patch_function.h"
#endif
Expand Down Expand Up @@ -242,9 +238,6 @@ bool ChromeRenderProcessObserver::OnControlMessageReceived(
void ChromeRenderProcessObserver::OnSetIsIncognitoProcess(
bool is_incognito_process) {
is_incognito_process_ = is_incognito_process;
#if defined(OS_ANDROID)
webkit_media::WebMediaPlayerAndroid::InitIncognito(is_incognito_process_);
#endif
}

void ChromeRenderProcessObserver::OnSetContentSettingRules(
Expand Down
5 changes: 5 additions & 0 deletions content/browser/android/browser_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
#include "content/browser/android/download_controller.h"
#include "content/browser/android/load_url_params.h"
#include "content/browser/android/sandboxed_process_launcher.h"
#include "content/browser/android/surface_texture_peer_browser_impl.h"
#include "content/browser/android/touch_point.h"
#include "content/browser/android/web_contents_observer_android.h"
#include "content/browser/geolocation/location_api_adapter_android.h"
#include "content/browser/renderer_host/ime_adapter_android.h"
#include "content/browser/renderer_host/java/java_bound_object.h"

using content::SurfaceTexturePeerBrowserImpl;

namespace {
base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "AndroidLocationApiAdapter",
AndroidLocationApiAdapter::RegisterGeolocationService },
{ "AndroidBrowserProcess", content::RegisterAndroidBrowserProcess },
{ "BrowserProcessSurfaceTexture",
SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture },
{ "ContentSettings", content::ContentSettings::RegisterContentSettings },
{ "ContentVideoView", content::ContentVideoView::RegisterContentVideoView },
{ "ContentViewClient", content::RegisterContentViewClient },
Expand Down
153 changes: 153 additions & 0 deletions content/browser/android/cookie_getter_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/android/cookie_getter_impl.h"

#include "base/bind.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "googleurl/src/gurl.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"

namespace content {

static void ReturnCookieOnUIThread(
const media::CookieGetter::GetCookieCB& callback,
const std::string& cookies) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, base::Bind(callback, cookies));
}

// The task object that retrieves cookie on the IO thread.
// TODO(qinmin): refactor this class to make the code reusable by others as
// there are lots of duplicated functionalities elsewhere.
class CookieGetterTask
: public base::RefCountedThreadSafe<CookieGetterTask> {
public:
CookieGetterTask(BrowserContext* browser_context,
int renderer_id, int routing_id);
virtual ~CookieGetterTask();

// Called by CookieGetterImpl to start getting cookies for a URL.
void RequestCookies(
const GURL& url, const GURL& first_party_for_cookies,
const media::CookieGetter::GetCookieCB& callback);

private:
void CheckPolicyForCookies(
const GURL& url, const GURL& first_party_for_cookies,
const media::CookieGetter::GetCookieCB& callback,
const net::CookieList& cookie_list);

// Context getter used to get the CookieStore.
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 renderer_id_;

// Routing id for the render view, used to check tab specific cookie policy.
int routing_id_;

DISALLOW_COPY_AND_ASSIGN(CookieGetterTask);
};

CookieGetterTask::CookieGetterTask(
BrowserContext* browser_context, int renderer_id, int routing_id)
: context_getter_(browser_context->GetRequestContext()),
resource_context_(browser_context->GetResourceContext()),
renderer_id_(renderer_id),
routing_id_(routing_id) {
}

CookieGetterTask::~CookieGetterTask() {}

void CookieGetterTask::RequestCookies(
const GURL& url, const GURL& first_party_for_cookies,
const media::CookieGetter::GetCookieCB& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (!policy->CanUseCookiesForOrigin(renderer_id_, url)) {
callback.Run(std::string());
return;
}

net::CookieStore* cookie_store =
context_getter_->GetURLRequestContext()->cookie_store();
if (!cookie_store) {
callback.Run(std::string());
return;
}

net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
if (cookie_monster) {
cookie_monster->GetAllCookiesForURLAsync(url, base::Bind(
&CookieGetterTask::CheckPolicyForCookies, this,
url, first_party_for_cookies, callback));
} else {
callback.Run(std::string());
}
}

void CookieGetterTask::CheckPolicyForCookies(
const GURL& url, const GURL& first_party_for_cookies,
const media::CookieGetter::GetCookieCB& callback,
const net::CookieList& cookie_list) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (GetContentClient()->browser()->AllowGetCookie(
url, first_party_for_cookies, cookie_list,
resource_context_, renderer_id_, routing_id_)) {
net::CookieStore* cookie_store =
context_getter_->GetURLRequestContext()->cookie_store();
cookie_store->GetCookiesWithOptionsAsync(
url, net::CookieOptions(), callback);
} else {
callback.Run(std::string());
}
}

CookieGetterImpl::CookieGetterImpl(
BrowserContext* browser_context, int renderer_id, int routing_id)
: browser_context_(browser_context),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)),
renderer_id_(renderer_id),
routing_id_(routing_id) {
}

CookieGetterImpl::~CookieGetterImpl() {}

void CookieGetterImpl::GetCookies(const std::string& url,
const std::string& first_party_for_cookies,
const GetCookieCB& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_refptr<CookieGetterTask> task = new CookieGetterTask(
browser_context_, renderer_id_, routing_id_);

GetCookieCB cb = base::Bind(
&CookieGetterImpl::GetCookiesCallback, weak_this_.GetWeakPtr(), callback);
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
base::Bind(&CookieGetterTask::RequestCookies,
task, GURL(url), GURL(first_party_for_cookies),
base::Bind(&ReturnCookieOnUIThread, cb)));
}

void CookieGetterImpl::GetCookiesCallback(
const GetCookieCB& callback, const std::string& cookies) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
callback.Run(cookies);
}

} // namespace content
63 changes: 63 additions & 0 deletions content/browser/android/cookie_getter_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_
#define CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_

#include <string>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "media/base/android/cookie_getter.h"
#include "net/cookies/canonical_cookie.h"

namespace net {
class URLRequestContextGetter;
}

namespace content {

class BrowserContext;
class ResourceContext;

// This class implements media::CookieGetter to retrive cookies
// asynchronously on the UI thread.
class CookieGetterImpl : public media::CookieGetter {
public:
// Construct a CookieGetterImpl by passing the BrowserContext reference
// and renderer_id to retrieve the CookieStore later.
CookieGetterImpl(
BrowserContext* browser_context, int renderer_id, int routing_id);
virtual ~CookieGetterImpl();

// media::CookieGetter implementation.
// Must be called on the UI thread.
virtual void GetCookies(const std::string& url,
const std::string& first_party_for_cookies,
const GetCookieCB& callback) OVERRIDE;

private:
// Called when GetCookies() finishes.
void GetCookiesCallback(
const GetCookieCB& callback, const std::string& cookies);

// BrowserContext to retrieve URLRequestContext and ResourceContext.
BrowserContext* browser_context_;

// Used to post tasks.
base::WeakPtrFactory<CookieGetterImpl> weak_this_;

// Render process id, used to check whether the process can access cookies.
int renderer_id_;

// Routing id for the render view, used to check tab specific cookie policy.
int routing_id_;

DISALLOW_COPY_AND_ASSIGN(CookieGetterImpl);
};

} // namespace content

#endif // CONTENT_BROWSER_ANDROID_COOKIE_GETTER_IMPL_H_
Loading

0 comments on commit 780fc82

Please sign in to comment.