OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/lib/aw_browser_dependency_factory_impl.h" | 5 #include "android_webview/lib/aw_browser_dependency_factory_impl.h" |
6 | 6 |
7 // TODO(joth): Componentize or remove chrome/... dependencies. | 7 // TODO(joth): Componentize or remove chrome/... dependencies. |
| 8 #include "android_webview/browser/net/aw_network_delegate.h" |
8 #include "android_webview/native/aw_contents_container.h" | 9 #include "android_webview/native/aw_contents_container.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" | 17 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
16 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
| 21 #include "net/url_request/url_request_context.h" |
| 22 #include "net/url_request/url_request_context_getter.h" |
| 23 |
| 24 using content::BrowserContext; |
| 25 using content::WebContents; |
17 | 26 |
18 namespace android_webview { | 27 namespace android_webview { |
19 | 28 |
20 namespace { | 29 namespace { |
21 | 30 |
22 base::LazyInstance<AwBrowserDependencyFactoryImpl>::Leaky g_lazy_instance; | 31 base::LazyInstance<AwBrowserDependencyFactoryImpl>::Leaky g_lazy_instance; |
23 | 32 |
24 class TabContentsWrapper : public AwContentsContainer { | 33 class TabContentsWrapper : public AwContentsContainer { |
25 public: | 34 public: |
26 TabContentsWrapper(TabContents* tab_contents) { | 35 TabContentsWrapper(TabContents* tab_contents) { |
(...skipping 15 matching lines...) Expand all Loading... |
42 | 51 |
43 AwBrowserDependencyFactoryImpl::AwBrowserDependencyFactoryImpl() {} | 52 AwBrowserDependencyFactoryImpl::AwBrowserDependencyFactoryImpl() {} |
44 | 53 |
45 AwBrowserDependencyFactoryImpl::~AwBrowserDependencyFactoryImpl() {} | 54 AwBrowserDependencyFactoryImpl::~AwBrowserDependencyFactoryImpl() {} |
46 | 55 |
47 // static | 56 // static |
48 void AwBrowserDependencyFactoryImpl::InstallInstance() { | 57 void AwBrowserDependencyFactoryImpl::InstallInstance() { |
49 SetInstance(g_lazy_instance.Pointer()); | 58 SetInstance(g_lazy_instance.Pointer()); |
50 } | 59 } |
51 | 60 |
52 content::WebContents* | 61 // Initializing the Network Delegate here is only a temporary solution until we |
53 AwBrowserDependencyFactoryImpl::CreateWebContents(bool incognito) { | 62 // build an Android WebView specific BrowserContext that can handle building |
| 63 // this internally. |
| 64 void AwBrowserDependencyFactoryImpl::InitializeNetworkDelegateOnIOThread( |
| 65 net::URLRequestContextGetter* normal_context, |
| 66 net::URLRequestContextGetter* incognito_context) { |
| 67 network_delegate_.reset(new AwNetworkDelegate()); |
| 68 normal_context->GetURLRequestContext()->set_network_delegate( |
| 69 network_delegate_.get()); |
| 70 incognito_context->GetURLRequestContext()->set_network_delegate( |
| 71 network_delegate_.get()); |
| 72 } |
| 73 |
| 74 void AwBrowserDependencyFactoryImpl::EnsureNetworkDelegateInitialized() { |
| 75 if (initialized_network_delegate_) |
| 76 return; |
| 77 initialized_network_delegate_ = true; |
54 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | 78 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
55 if (incognito) | 79 profile->GetRequestContext()->GetNetworkTaskRunner()->PostTask( |
56 profile = profile->GetOffTheRecordProfile(); | 80 FROM_HERE, |
| 81 base::Bind( |
| 82 &AwBrowserDependencyFactoryImpl::InitializeNetworkDelegateOnIOThread, |
| 83 base::Unretained(this), |
| 84 make_scoped_refptr(profile->GetRequestContext()), |
| 85 make_scoped_refptr( |
| 86 profile->GetOffTheRecordProfile()->GetRequestContext()))); |
| 87 } |
57 | 88 |
58 return content::WebContents::Create(profile, 0, MSG_ROUTING_NONE, 0); | 89 content::BrowserContext* AwBrowserDependencyFactoryImpl::GetBrowserContext( |
| 90 bool incognito) { |
| 91 EnsureNetworkDelegateInitialized(); |
| 92 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
| 93 return incognito ? profile->GetOffTheRecordProfile() : profile; |
| 94 } |
| 95 |
| 96 WebContents* AwBrowserDependencyFactoryImpl::CreateWebContents(bool incognito) { |
| 97 return content::WebContents::Create( |
| 98 GetBrowserContext(incognito), 0, MSG_ROUTING_NONE, 0); |
59 } | 99 } |
60 | 100 |
61 AwContentsContainer* AwBrowserDependencyFactoryImpl::CreateContentsContainer( | 101 AwContentsContainer* AwBrowserDependencyFactoryImpl::CreateContentsContainer( |
62 content::WebContents* contents) { | 102 content::WebContents* contents) { |
63 return new TabContentsWrapper( | 103 return new TabContentsWrapper( |
64 TabContents::Factory::CreateTabContents(contents)); | 104 TabContents::Factory::CreateTabContents(contents)); |
65 } | 105 } |
66 | 106 |
67 content::JavaScriptDialogCreator* | 107 content::JavaScriptDialogCreator* |
68 AwBrowserDependencyFactoryImpl::GetJavaScriptDialogCreator() { | 108 AwBrowserDependencyFactoryImpl::GetJavaScriptDialogCreator() { |
69 return GetJavaScriptDialogCreatorInstance(); | 109 return GetJavaScriptDialogCreatorInstance(); |
70 } | 110 } |
71 | 111 |
72 } // namespace android_webview | 112 } // namespace android_webview |
OLD | NEW |