[Android] Redirect obsolete chrome:// URLs to NTP.
[chromium-blink-merge.git] / android_webview / browser / aw_resource_context.cc
blob65682f54270345dfbb4516c055e382c89bec985f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "android_webview/browser/aw_resource_context.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "net/url_request/url_request_context.h"
9 #include "net/url_request/url_request_context_getter.h"
11 using content::BrowserThread;
13 namespace android_webview {
15 AwResourceContext::AwResourceContext(net::URLRequestContextGetter* getter)
16 : getter_(getter) {
17 DCHECK(getter_);
20 AwResourceContext::~AwResourceContext() {
23 void AwResourceContext::SetExtraHeaders(
24 const GURL& url, const std::string& headers) {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI);
26 if (!url.is_valid()) return;
27 base::AutoLock scoped_lock(extra_headers_lock_);
28 if (!headers.empty())
29 extra_headers_[url.spec()] = headers;
30 else
31 extra_headers_.erase(url.spec());
34 std::string AwResourceContext::GetExtraHeaders(const GURL& url) {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36 if (!url.is_valid()) return std::string();
37 base::AutoLock scoped_lock(extra_headers_lock_);
38 std::map<std::string, std::string>::iterator iter =
39 extra_headers_.find(url.spec());
40 return iter != extra_headers_.end() ? iter->second : std::string();
43 net::HostResolver* AwResourceContext::GetHostResolver() {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 return getter_->GetURLRequestContext()->host_resolver();
48 net::URLRequestContext* AwResourceContext::GetRequestContext() {
49 DCHECK_CURRENTLY_ON(BrowserThread::IO);
50 return getter_->GetURLRequestContext();
53 } // namespace android_webview