| 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/net/aw_url_request_context_getter.h" | 5 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_request_interceptor.h" | 10 #include "android_webview/browser/aw_request_interceptor.h" |
| 9 #include "android_webview/browser/net/aw_network_delegate.h" | 11 #include "android_webview/browser/net/aw_network_delegate.h" |
| 10 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 12 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| 11 #include "android_webview/browser/net/init_native_callback.h" | 13 #include "android_webview/browser/net/init_native_callback.h" |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 14 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 15 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 16 #include "net/cookies/cookie_store.h" | 18 #include "net/cookies/cookie_store.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DCHECK(set_protocol); | 117 DCHECK(set_protocol); |
| 116 set_protocol = job_factory->SetProtocolHandler( | 118 set_protocol = job_factory->SetProtocolHandler( |
| 117 chrome::kChromeUIScheme, | 119 chrome::kChromeUIScheme, |
| 118 protocol_handlers_[chrome::kChromeUIScheme].release()); | 120 protocol_handlers_[chrome::kChromeUIScheme].release()); |
| 119 DCHECK(set_protocol); | 121 DCHECK(set_protocol); |
| 120 set_protocol = job_factory->SetProtocolHandler( | 122 set_protocol = job_factory->SetProtocolHandler( |
| 121 chrome::kChromeDevToolsScheme, | 123 chrome::kChromeDevToolsScheme, |
| 122 protocol_handlers_[chrome::kChromeDevToolsScheme].release()); | 124 protocol_handlers_[chrome::kChromeDevToolsScheme].release()); |
| 123 DCHECK(set_protocol); | 125 DCHECK(set_protocol); |
| 124 protocol_handlers_.clear(); | 126 protocol_handlers_.clear(); |
| 125 // Create a chain of URLRequestJobFactories. Keep |job_factory_| pointed | 127 |
| 126 // at the beginning of the chain. | 128 // Create a chain of URLRequestJobFactories. The handlers will be invoked |
| 127 job_factory_ = CreateAndroidJobFactory(job_factory.Pass()); | 129 // in the order in which they appear in the protocol_handlers vector. |
| 128 job_factory_.reset(new net::ProtocolInterceptJobFactory( | 130 typedef std::vector<net::URLRequestJobFactory::ProtocolHandler*> |
| 129 job_factory_.Pass(), | 131 ProtocolHandlerVector; |
| 130 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 132 ProtocolHandlerVector protocol_interceptors; |
| 131 new AwRequestInterceptor()))); | 133 |
| 134 // Note that even though the content:// scheme handler is created here, |
| 135 // it cannot be used by child processes until access to it is granted via |
| 136 // ChildProcessSecurityPolicy::GrantScheme(). This is done in |
| 137 // AwContentBrowserClient. |
| 138 protocol_interceptors.push_back( |
| 139 CreateAndroidContentProtocolHandler().release()); |
| 140 protocol_interceptors.push_back( |
| 141 CreateAndroidAssetFileProtocolHandler().release()); |
| 142 // The AwRequestInterceptor must come after the content and asset file job |
| 143 // factories. This for WebViewClassic compatibility where it was not |
| 144 // possible to intercept resource loads to resolvable content:// and |
| 145 // file:// URIs. |
| 146 // This logical dependency is also the reason why the Content |
| 147 // ProtocolHandler has to be added as a ProtocolInterceptJobFactory rather |
| 148 // than via SetProtocolHandler. |
| 149 protocol_interceptors.push_back(new AwRequestInterceptor()); |
| 150 |
| 151 // The chain of responsibility will execute the handlers in reverse to the |
| 152 // order in which the elements of the chain are created. |
| 153 job_factory_ = job_factory.PassAs<net::URLRequestJobFactory>(); |
| 154 for (ProtocolHandlerVector::reverse_iterator |
| 155 i = protocol_interceptors.rbegin(); |
| 156 i != protocol_interceptors.rend(); |
| 157 ++i) { |
| 158 job_factory_.reset(new net::ProtocolInterceptJobFactory( |
| 159 job_factory_.Pass(), make_scoped_ptr(*i))); |
| 160 } |
| 161 |
| 132 url_request_context_->set_job_factory(job_factory_.get()); | 162 url_request_context_->set_job_factory(job_factory_.get()); |
| 133 } | 163 } |
| 164 |
| 134 return url_request_context_.get(); | 165 return url_request_context_.get(); |
| 135 } | 166 } |
| 136 | 167 |
| 137 scoped_refptr<base::SingleThreadTaskRunner> | 168 scoped_refptr<base::SingleThreadTaskRunner> |
| 138 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 169 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 139 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 170 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 140 } | 171 } |
| 141 | 172 |
| 142 void AwURLRequestContextGetter::SetProtocolHandlers( | 173 void AwURLRequestContextGetter::SetProtocolHandlers( |
| 143 content::ProtocolHandlerMap* protocol_handlers) { | 174 content::ProtocolHandlerMap* protocol_handlers) { |
| 144 std::swap(protocol_handlers_, *protocol_handlers); | 175 std::swap(protocol_handlers_, *protocol_handlers); |
| 145 } | 176 } |
| 146 | 177 |
| 147 } // namespace android_webview | 178 } // namespace android_webview |
| OLD | NEW |