diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 05:43:10 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 05:43:10 +0000 |
commit | 22c5f08685db140dd6738b996e122a9f99775ca0 (patch) | |
tree | d30c454dd58e75003358bf49320b6855f5db69f2 /android_webview/lib | |
parent | 99d300519d94cc747a7deb414dd000ff7aea6354 (diff) | |
download | chromium_src-22c5f08685db140dd6738b996e122a9f99775ca0.zip chromium_src-22c5f08685db140dd6738b996e122a9f99775ca0.tar.gz chromium_src-22c5f08685db140dd6738b996e122a9f99775ca0.tar.bz2 |
Add WebView implementation for CookieManager.
Additional details of the requirements can be found from the Android SDK.
http://developer.android.com/reference/android/webkit/CookieManager.html
BUG=
TEST=make forwarder android_webview_apk android_webview_test_apk
Review URL: https://chromiumcodereview.appspot.com/10913074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155331 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/lib')
4 files changed, 111 insertions, 5 deletions
diff --git a/android_webview/lib/aw_browser_dependency_factory_impl.cc b/android_webview/lib/aw_browser_dependency_factory_impl.cc index f940b104..f31bb64 100644 --- a/android_webview/lib/aw_browser_dependency_factory_impl.cc +++ b/android_webview/lib/aw_browser_dependency_factory_impl.cc @@ -5,8 +5,12 @@ #include "android_webview/lib/aw_browser_dependency_factory_impl.h" // TODO(joth): Componentize or remove chrome/... dependencies. +#include "android_webview/browser/net/aw_network_delegate.h" #include "android_webview/native/aw_contents_container.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -14,6 +18,11 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "content/public/browser/web_contents.h" #include "ipc/ipc_message.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_getter.h" + +using content::BrowserContext; +using content::WebContents; namespace android_webview { @@ -49,13 +58,44 @@ void AwBrowserDependencyFactoryImpl::InstallInstance() { SetInstance(g_lazy_instance.Pointer()); } -content::WebContents* -AwBrowserDependencyFactoryImpl::CreateWebContents(bool incognito) { +// Initializing the Network Delegate here is only a temporary solution until we +// build an Android WebView specific BrowserContext that can handle building +// this internally. +void AwBrowserDependencyFactoryImpl::InitializeNetworkDelegateOnIOThread( + net::URLRequestContextGetter* normal_context, + net::URLRequestContextGetter* incognito_context) { + network_delegate_.reset(new AwNetworkDelegate()); + normal_context->GetURLRequestContext()->set_network_delegate( + network_delegate_.get()); + incognito_context->GetURLRequestContext()->set_network_delegate( + network_delegate_.get()); +} + +void AwBrowserDependencyFactoryImpl::EnsureNetworkDelegateInitialized() { + if (initialized_network_delegate_) + return; + initialized_network_delegate_ = true; Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); - if (incognito) - profile = profile->GetOffTheRecordProfile(); + profile->GetRequestContext()->GetNetworkTaskRunner()->PostTask( + FROM_HERE, + base::Bind( + &AwBrowserDependencyFactoryImpl::InitializeNetworkDelegateOnIOThread, + base::Unretained(this), + make_scoped_refptr(profile->GetRequestContext()), + make_scoped_refptr( + profile->GetOffTheRecordProfile()->GetRequestContext()))); +} + +content::BrowserContext* AwBrowserDependencyFactoryImpl::GetBrowserContext( + bool incognito) { + EnsureNetworkDelegateInitialized(); + Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); + return incognito ? profile->GetOffTheRecordProfile() : profile; +} - return content::WebContents::Create(profile, 0, MSG_ROUTING_NONE, 0); +WebContents* AwBrowserDependencyFactoryImpl::CreateWebContents(bool incognito) { + return content::WebContents::Create( + GetBrowserContext(incognito), 0, MSG_ROUTING_NONE, 0); } AwContentsContainer* AwBrowserDependencyFactoryImpl::CreateContentsContainer( diff --git a/android_webview/lib/aw_browser_dependency_factory_impl.h b/android_webview/lib/aw_browser_dependency_factory_impl.h index fae835f..4b9a003 100644 --- a/android_webview/lib/aw_browser_dependency_factory_impl.h +++ b/android_webview/lib/aw_browser_dependency_factory_impl.h @@ -8,9 +8,16 @@ #include "android_webview/native/aw_browser_dependency_factory.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" + +namespace net { +class URLRequestContextGetter; +} namespace android_webview { +class AwNetworkDelegate; + class AwBrowserDependencyFactoryImpl : public AwBrowserDependencyFactory { public: AwBrowserDependencyFactoryImpl(); @@ -20,6 +27,7 @@ class AwBrowserDependencyFactoryImpl : public AwBrowserDependencyFactory { static void InstallInstance(); // AwBrowserDependencyFactory + virtual content::BrowserContext* GetBrowserContext(bool incognito) OVERRIDE; virtual content::WebContents* CreateWebContents(bool incognito) OVERRIDE; virtual AwContentsContainer* CreateContentsContainer( content::WebContents* contents) OVERRIDE; @@ -27,6 +35,16 @@ class AwBrowserDependencyFactoryImpl : public AwBrowserDependencyFactory { OVERRIDE; private: + void InitializeNetworkDelegateOnIOThread( + net::URLRequestContextGetter* normal_context, + net::URLRequestContextGetter* incognito_context); + void EnsureNetworkDelegateInitialized(); + + // Constructed and assigned on the IO thread. + scoped_ptr<AwNetworkDelegate> network_delegate_; + // Set on the UI thread. + bool initialized_network_delegate_; + DISALLOW_COPY_AND_ASSIGN(AwBrowserDependencyFactoryImpl); }; diff --git a/android_webview/lib/aw_content_browser_client.cc b/android_webview/lib/aw_content_browser_client.cc index aeaedf2..2a07343 100644 --- a/android_webview/lib/aw_content_browser_client.cc +++ b/android_webview/lib/aw_content_browser_client.cc @@ -4,6 +4,7 @@ #include "android_webview/lib/aw_content_browser_client.h" +#include "android_webview/browser/aw_cookie_access_policy.h" #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h" namespace android_webview { @@ -20,4 +21,38 @@ void AwContentBrowserClient::ResourceDispatcherHostCreated() { AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated(); } +bool AwContentBrowserClient::AllowGetCookie(const GURL& url, + const GURL& first_party, + const net::CookieList& cookie_list, + content::ResourceContext* context, + int render_process_id, + int render_view_id) { + // Not base-calling into ChromeContentBrowserClient as we are not dependent + // on chrome/ for any cookie policy decisions. + return AwCookieAccessPolicy::GetInstance()->AllowGetCookie(url, + first_party, + cookie_list, + context, + render_process_id, + render_view_id); +} + +bool AwContentBrowserClient::AllowSetCookie(const GURL& url, + const GURL& first_party, + const std::string& cookie_line, + content::ResourceContext* context, + int render_process_id, + int render_view_id, + net::CookieOptions* options) { + // Not base-calling into ChromeContentBrowserClient as we are not dependent + // on chrome/ for any cookie policy decisions. + return AwCookieAccessPolicy::GetInstance()->AllowSetCookie(url, + first_party, + cookie_line, + context, + render_process_id, + render_view_id, + options); +} + } // namespace android_webview diff --git a/android_webview/lib/aw_content_browser_client.h b/android_webview/lib/aw_content_browser_client.h index 0972032..8b75c99 100644 --- a/android_webview/lib/aw_content_browser_client.h +++ b/android_webview/lib/aw_content_browser_client.h @@ -18,6 +18,19 @@ class AwContentBrowserClient : public chrome::ChromeContentBrowserClient { // Overriden methods from ContentBrowserClient. virtual void ResourceDispatcherHostCreated() OVERRIDE; + virtual bool AllowGetCookie(const GURL& url, + const GURL& first_party, + const net::CookieList& cookie_list, + content::ResourceContext* context, + int render_process_id, + int render_view_id) OVERRIDE; + virtual bool AllowSetCookie(const GURL& url, + const GURL& first_party, + const std::string& cookie_line, + content::ResourceContext* context, + int render_process_id, + int render_view_id, + net::CookieOptions* options) OVERRIDE; }; } // namespace android_webview |