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