| Index: android_webview/lib/aw_browser_dependency_factory_impl.cc
|
| diff --git a/android_webview/lib/aw_browser_dependency_factory_impl.cc b/android_webview/lib/aw_browser_dependency_factory_impl.cc
|
| index f940b104abb1d740273cc733568b72d9c04cb577..f31bb64e7971921c0621145bfd3b64042f4b2cb7 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(
|
|
|