Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/extensions/extensions_service.h" | 11 #include "chrome/browser/extensions/extensions_service.h" |
| 12 #include "chrome/browser/extensions/user_script_master.h" | 12 #include "chrome/browser/extensions/user_script_master.h" |
| 13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
| 18 #include "net/http/http_util.h" | |
| 18 #include "net/proxy/proxy_service.h" | 19 #include "net/proxy/proxy_service.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 20 #include "webkit/glue/webkit_glue.h" |
| 20 | 21 |
| 21 // Sets up proxy info if it was specified, otherwise returns NULL. The | 22 // Sets up proxy info if it was specified, otherwise returns NULL. The |
| 22 // returned pointer MUST be deleted by the caller if non-NULL. | 23 // returned pointer MUST be deleted by the caller if non-NULL. |
| 23 static net::ProxyInfo* CreateProxyInfo() { | 24 static net::ProxyInfo* CreateProxyInfo() { |
| 24 net::ProxyInfo* proxy_info = NULL; | 25 net::ProxyInfo* proxy_info = NULL; |
| 25 | 26 |
| 26 CommandLine command_line; | 27 CommandLine command_line; |
| 27 if (command_line.HasSwitch(switches::kProxyServer)) { | 28 if (command_line.HasSwitch(switches::kProxyServer)) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 context->cookie_store_ = new net::CookieMonster; | 89 context->cookie_store_ = new net::CookieMonster; |
| 89 | 90 |
| 90 return context; | 91 return context; |
| 91 } | 92 } |
| 92 | 93 |
| 93 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) | 94 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) |
| 94 : prefs_(profile->GetPrefs()), | 95 : prefs_(profile->GetPrefs()), |
| 95 is_off_the_record_(profile->IsOffTheRecord()) { | 96 is_off_the_record_(profile->IsOffTheRecord()) { |
| 96 user_agent_ = webkit_glue::GetUserAgent(); | 97 user_agent_ = webkit_glue::GetUserAgent(); |
| 97 | 98 |
| 98 // set up Accept-Language and Accept-Charset header values | 99 // Set up Accept-Language and Accept-Charset header values |
| 99 // TODO(jungshik) : This may slow down http requests. Perhaps, | 100 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
| 100 // we have to come up with a better way to set up these values. | 101 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); |
| 101 accept_language_ = WideToASCII(prefs_->GetString(prefs::kAcceptLanguages)); | 102 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader( |
| 102 accept_charset_ = WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); | 103 WideToASCII(prefs_->GetString(prefs::kDefaultCharset))); |
| 103 accept_charset_ += ",*,utf-8"; | |
|
wtc
2009/01/14 02:21:48
In the old code, we put * before utf-8. In
the ne
| |
| 104 | 104 |
| 105 cookie_policy_.SetType(net::CookiePolicy::FromInt( | 105 cookie_policy_.SetType(net::CookiePolicy::FromInt( |
| 106 prefs_->GetInteger(prefs::kCookieBehavior))); | 106 prefs_->GetInteger(prefs::kCookieBehavior))); |
| 107 | 107 |
| 108 const ExtensionList* extensions = | 108 const ExtensionList* extensions = |
| 109 profile->GetExtensionsService()->extensions(); | 109 profile->GetExtensionsService()->extensions(); |
| 110 for (ExtensionList::const_iterator iter = extensions->begin(); | 110 for (ExtensionList::const_iterator iter = extensions->begin(); |
| 111 iter != extensions->end(); ++iter) { | 111 iter != extensions->end(); ++iter) { |
| 112 extension_paths_[(*iter)->id()] = (*iter)->path(); | 112 extension_paths_[(*iter)->id()] = (*iter)->path(); |
| 113 } | 113 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 if (iter != extension_paths_.end()) { | 176 if (iter != extension_paths_.end()) { |
| 177 return iter->second; | 177 return iter->second; |
| 178 } else { | 178 } else { |
| 179 return FilePath(); | 179 return FilePath(); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void ChromeURLRequestContext::OnAcceptLanguageChange(std::string accept_language ) { | 183 void ChromeURLRequestContext::OnAcceptLanguageChange(std::string accept_language ) { |
| 184 DCHECK(MessageLoop::current() == | 184 DCHECK(MessageLoop::current() == |
| 185 ChromeThread::GetMessageLoop(ChromeThread::IO)); | 185 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
| 186 accept_language_ = accept_language; | 186 accept_language_ = |
| 187 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); | |
| 187 } | 188 } |
| 188 | 189 |
| 189 void ChromeURLRequestContext::OnCookiePolicyChange(net::CookiePolicy::Type type) { | 190 void ChromeURLRequestContext::OnCookiePolicyChange(net::CookiePolicy::Type type) { |
| 190 DCHECK(MessageLoop::current() == | 191 DCHECK(MessageLoop::current() == |
| 191 ChromeThread::GetMessageLoop(ChromeThread::IO)); | 192 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
| 192 cookie_policy_.SetType(type); | 193 cookie_policy_.SetType(type); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void ChromeURLRequestContext::OnNewExtensions(ExtensionPaths* new_paths) { | 196 void ChromeURLRequestContext::OnNewExtensions(ExtensionPaths* new_paths) { |
| 196 extension_paths_.insert(new_paths->begin(), new_paths->end()); | 197 extension_paths_.insert(new_paths->begin(), new_paths->end()); |
| 197 delete new_paths; | 198 delete new_paths; |
| 198 } | 199 } |
| 199 | 200 |
| 200 ChromeURLRequestContext::~ChromeURLRequestContext() { | 201 ChromeURLRequestContext::~ChromeURLRequestContext() { |
| 201 DCHECK(NULL == prefs_); | 202 DCHECK(NULL == prefs_); |
| 202 | 203 |
| 203 NotificationService::current()->Notify(NOTIFY_URL_REQUEST_CONTEXT_RELEASED, | 204 NotificationService::current()->Notify(NOTIFY_URL_REQUEST_CONTEXT_RELEASED, |
| 204 Source<URLRequestContext>(this), | 205 Source<URLRequestContext>(this), |
| 205 NotificationService::NoDetails()); | 206 NotificationService::NoDetails()); |
| 206 | 207 |
| 207 delete cookie_store_; | 208 delete cookie_store_; |
| 208 delete http_transaction_factory_; | 209 delete http_transaction_factory_; |
| 209 | 210 |
| 210 // Do not delete the proxy service in the case of OTR, as it is owned by the | 211 // Do not delete the proxy service in the case of OTR, as it is owned by the |
| 211 // original URLRequestContext. | 212 // original URLRequestContext. |
| 212 if (!is_off_the_record_) | 213 if (!is_off_the_record_) |
| 213 delete proxy_service_; | 214 delete proxy_service_; |
| 214 } | 215 } |
| OLD | NEW |