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