Chromium Code Reviews| 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/browser/aw_browser_context.h" | 5 #include "android_webview/browser/aw_browser_context.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/net/aw_url_request_context_getter.h" | 7 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
| 8 #include "components/visitedlink/browser/visitedlink_master.h" | 8 #include "components/visitedlink/browser/visitedlink_master.h" |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/resource_context.h" | |
| 11 #include "content/public/browser/storage_partition.h" | |
| 9 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "net/url_request/url_request_context.h" | |
| 10 | 14 |
| 11 namespace android_webview { | 15 namespace android_webview { |
| 12 | 16 |
| 17 class AwBrowserContext::AwResourceContext : public content::ResourceContext { | |
|
awong
2013/02/02 03:26:12
Any reason this isn't just file-scoped in an anony
pauljensen
2013/02/04 14:18:54
We need a pointer to it inside AwBrowserContext so
| |
| 18 public: | |
| 19 AwResourceContext(net::URLRequestContextGetter* getter) : getter_(getter) {} | |
|
awong
2013/02/02 03:26:12
explicit
pauljensen
2013/02/04 14:18:54
Done.
| |
| 20 virtual ~AwResourceContext() {} | |
| 21 | |
| 22 // content::ResourceContext implementation: | |
|
awong
2013/02/02 03:26:12
: -> .
Seems to match the prevailing convention f
pauljensen
2013/02/04 14:18:54
Done.
| |
| 23 virtual net::HostResolver* GetHostResolver() OVERRIDE { | |
| 24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 25 return getter_->GetURLRequestContext()->host_resolver(); | |
| 26 } | |
| 27 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { | |
| 28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 29 return getter_->GetURLRequestContext(); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 net::URLRequestContextGetter* getter_; | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); | |
| 36 }; | |
| 37 | |
| 13 AwBrowserContext::AwBrowserContext( | 38 AwBrowserContext::AwBrowserContext( |
| 14 const FilePath path, | 39 const FilePath path, |
| 15 GeolocationPermissionFactoryFn* geolocation_permission_factory) | 40 GeolocationPermissionFactoryFn* geolocation_permission_factory) |
| 16 : context_storage_path_(path), | 41 : context_storage_path_(path), |
| 17 geolocation_permission_factory_(geolocation_permission_factory) { | 42 geolocation_permission_factory_(geolocation_permission_factory) { |
| 18 } | 43 } |
| 19 | 44 |
| 20 AwBrowserContext::~AwBrowserContext() { | 45 AwBrowserContext::~AwBrowserContext() { |
| 21 } | 46 } |
| 22 | 47 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 FilePath AwBrowserContext::GetPath() { | 71 FilePath AwBrowserContext::GetPath() { |
| 47 return context_storage_path_; | 72 return context_storage_path_; |
| 48 } | 73 } |
| 49 | 74 |
| 50 bool AwBrowserContext::IsOffTheRecord() const { | 75 bool AwBrowserContext::IsOffTheRecord() const { |
| 51 // Android WebView does not support off the record profile yet. | 76 // Android WebView does not support off the record profile yet. |
| 52 return false; | 77 return false; |
| 53 } | 78 } |
| 54 | 79 |
| 55 net::URLRequestContextGetter* AwBrowserContext::GetRequestContext() { | 80 net::URLRequestContextGetter* AwBrowserContext::GetRequestContext() { |
| 56 DCHECK(url_request_context_getter_); | 81 content::StoragePartition* storage_partition = |
| 57 return url_request_context_getter_; | 82 BrowserContext::GetStoragePartition(this, NULL); |
| 83 return storage_partition->GetURLRequestContext(); | |
| 58 } | 84 } |
| 59 | 85 |
| 60 net::URLRequestContextGetter* | 86 net::URLRequestContextGetter* |
| 61 AwBrowserContext::GetRequestContextForRenderProcess( | 87 AwBrowserContext::GetRequestContextForRenderProcess( |
| 62 int renderer_child_id) { | 88 int renderer_child_id) { |
| 63 return GetRequestContext(); | 89 return GetRequestContext(); |
| 64 } | 90 } |
| 65 | 91 |
| 66 net::URLRequestContextGetter* | |
| 67 AwBrowserContext::GetRequestContextForStoragePartition( | |
| 68 const FilePath& partition_path, | |
| 69 bool in_memory) { | |
| 70 return GetRequestContext(); | |
| 71 } | |
| 72 | |
| 73 net::URLRequestContextGetter* AwBrowserContext::GetMediaRequestContext() { | 92 net::URLRequestContextGetter* AwBrowserContext::GetMediaRequestContext() { |
| 74 return GetRequestContext(); | 93 return GetRequestContext(); |
| 75 } | 94 } |
| 76 | 95 |
| 77 net::URLRequestContextGetter* | 96 net::URLRequestContextGetter* |
| 78 AwBrowserContext::GetMediaRequestContextForRenderProcess( | 97 AwBrowserContext::GetMediaRequestContextForRenderProcess( |
| 79 int renderer_child_id) { | 98 int renderer_child_id) { |
| 80 return GetRequestContext(); | 99 return GetRequestContext(); |
| 81 } | 100 } |
| 82 | 101 |
| 83 net::URLRequestContextGetter* | 102 net::URLRequestContextGetter* |
| 84 AwBrowserContext::GetMediaRequestContextForStoragePartition( | 103 AwBrowserContext::GetMediaRequestContextForStoragePartition( |
| 85 const FilePath& partition_path, | 104 const FilePath& partition_path, |
| 86 bool in_memory) { | 105 bool in_memory) { |
| 87 return GetRequestContext(); | 106 return GetRequestContext(); |
| 88 } | 107 } |
| 89 | 108 |
| 90 content::ResourceContext* AwBrowserContext::GetResourceContext() { | 109 content::ResourceContext* AwBrowserContext::GetResourceContext() { |
| 91 return url_request_context_getter_->GetResourceContext(); | 110 if (!resource_context_) { |
| 111 CHECK(url_request_context_getter_); | |
| 112 resource_context_.reset(new AwResourceContext( | |
| 113 url_request_context_getter_.get())); | |
| 114 } | |
| 115 return resource_context_.get(); | |
| 92 } | 116 } |
| 93 | 117 |
| 94 content::DownloadManagerDelegate* | 118 content::DownloadManagerDelegate* |
| 95 AwBrowserContext::GetDownloadManagerDelegate() { | 119 AwBrowserContext::GetDownloadManagerDelegate() { |
| 96 return &download_manager_delegate_; | 120 return &download_manager_delegate_; |
| 97 } | 121 } |
| 98 | 122 |
| 99 content::GeolocationPermissionContext* | 123 content::GeolocationPermissionContext* |
| 100 AwBrowserContext::GetGeolocationPermissionContext() { | 124 AwBrowserContext::GetGeolocationPermissionContext() { |
| 101 if (!geolocation_permission_context_) { | 125 if (!geolocation_permission_context_) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 117 } | 141 } |
| 118 | 142 |
| 119 void AwBrowserContext::RebuildTable( | 143 void AwBrowserContext::RebuildTable( |
| 120 const scoped_refptr<URLEnumerator>& enumerator) { | 144 const scoped_refptr<URLEnumerator>& enumerator) { |
| 121 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client | 145 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client |
| 122 // can change in the lifetime of this WebView and may not yet be set here. | 146 // can change in the lifetime of this WebView and may not yet be set here. |
| 123 // Therefore this initialization path is not used. | 147 // Therefore this initialization path is not used. |
| 124 enumerator->OnComplete(true); | 148 enumerator->OnComplete(true); |
| 125 } | 149 } |
| 126 | 150 |
| 151 net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext( | |
| 152 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 153 blob_protocol_handler, | |
| 154 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 155 file_system_protocol_handler, | |
| 156 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 157 developer_protocol_handler, | |
| 158 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 159 chrome_protocol_handler, | |
| 160 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 161 chrome_devtools_protocol_handler) { | |
| 162 CHECK(url_request_context_getter_); | |
| 163 url_request_context_getter_->SetProtocolHandlers( | |
| 164 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), | |
| 165 developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), | |
| 166 chrome_devtools_protocol_handler.Pass()); | |
| 167 return url_request_context_getter_.get(); | |
| 168 } | |
| 169 | |
| 170 net::URLRequestContextGetter* | |
| 171 AwBrowserContext::CreateRequestContextForStoragePartition( | |
| 172 const FilePath& partition_path, | |
| 173 bool in_memory, | |
| 174 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 175 blob_protocol_handler, | |
| 176 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 177 file_system_protocol_handler, | |
| 178 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 179 developer_protocol_handler, | |
| 180 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 181 chrome_protocol_handler, | |
| 182 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 183 chrome_devtools_protocol_handler) { | |
| 184 CHECK(url_request_context_getter_); | |
| 185 return url_request_context_getter_.get(); | |
| 186 } | |
| 187 | |
| 127 } // namespace android_webview | 188 } // namespace android_webview |
| OLD | NEW |