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/privacy_blacklist/blacklist.h" | 10 #include "chrome/browser/privacy_blacklist/blacklist.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 return context; | 264 return context; |
265 } | 265 } |
266 | 266 |
267 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) | 267 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) |
268 : prefs_(profile->GetPrefs()), | 268 : prefs_(profile->GetPrefs()), |
269 is_media_(false), | 269 is_media_(false), |
270 is_off_the_record_(profile->IsOffTheRecord()) { | 270 is_off_the_record_(profile->IsOffTheRecord()) { |
271 // Set up Accept-Language and Accept-Charset header values | 271 // Set up Accept-Language and Accept-Charset header values |
272 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( | 272 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( |
273 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); | 273 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); |
274 accept_charset_ = net::HttpUtil::GenerateAcceptCharsetHeader( | 274 std::string default_charset = |
275 WideToASCII(prefs_->GetString(prefs::kDefaultCharset))); | 275 WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); |
276 accept_charset_ = | |
277 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); | |
276 | 278 |
277 // At this point, we don't know the charset of the referring page | 279 // At this point, we don't know the charset of the referring page |
278 // where a url request originates from. This is used to get a suggested | 280 // where a url request originates from. This is used to get a suggested |
279 // filename from Content-Disposition header made of raw 8bit characters. | 281 // filename from Content-Disposition header made of raw 8bit characters. |
280 // Down the road, it can be overriden if it becomes known (for instance, | 282 // Down the road, it can be overriden if it becomes known (for instance, |
281 // when download request is made through the context menu in a web page). | 283 // when download request is made through the context menu in a web page). |
282 // At the moment, it'll remain 'undeterministic' when a user | 284 // At the moment, it'll remain 'undeterministic' when a user |
283 // types a URL in the omnibar or click on a download link in a page. | 285 // types a URL in the omnibar or click on a download link in a page. |
284 // For the latter, we need a change on the webkit-side. | 286 // For the latter, we need a change on the webkit-side. |
285 // We initialize it to the default charset here and a user will | 287 // We initialize it to the default charset here and a user will |
286 // have an *arguably* better default charset for interpreting a raw 8bit | 288 // have an *arguably* better default charset for interpreting a raw 8bit |
287 // C-D header field. It means the native OS codepage fallback in | 289 // C-D header field. It means the native OS codepage fallback in |
288 // net_util::GetSuggestedFilename is unlikely to be taken. | 290 // net_util::GetSuggestedFilename is unlikely to be taken. |
289 referrer_charset_ = accept_charset_; | 291 referrer_charset_ = default_charset; |
wtc
2009/07/16 01:14:47
Question: so referrer_charset_ should contain a si
| |
290 | 292 |
291 cookie_policy_.SetType(net::CookiePolicy::FromInt( | 293 cookie_policy_.SetType(net::CookiePolicy::FromInt( |
292 prefs_->GetInteger(prefs::kCookieBehavior))); | 294 prefs_->GetInteger(prefs::kCookieBehavior))); |
293 | 295 |
294 blacklist_ = profile->GetBlacklist(); | 296 blacklist_ = profile->GetBlacklist(); |
295 | 297 |
296 force_tls_state_ = profile->GetForceTLSState(); | 298 force_tls_state_ = profile->GetForceTLSState(); |
297 | 299 |
298 if (profile->GetExtensionsService()) { | 300 if (profile->GetExtensionsService()) { |
299 const ExtensionList* extensions = | 301 const ExtensionList* extensions = |
300 profile->GetExtensionsService()->extensions(); | 302 profile->GetExtensionsService()->extensions(); |
301 for (ExtensionList::const_iterator iter = extensions->begin(); | 303 for (ExtensionList::const_iterator iter = extensions->begin(); |
302 iter != extensions->end(); ++iter) { | 304 iter != extensions->end(); ++iter) { |
303 extension_paths_[(*iter)->id()] = (*iter)->path(); | 305 extension_paths_[(*iter)->id()] = (*iter)->path(); |
304 } | 306 } |
305 } | 307 } |
306 | 308 |
307 if (profile->GetUserScriptMaster()) | 309 if (profile->GetUserScriptMaster()) |
308 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); | 310 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); |
309 | 311 |
310 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); | 312 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); |
311 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); | 313 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); |
314 prefs_->AddPrefObserver(prefs::kDefaultCharset, this); | |
312 | 315 |
313 if (!is_off_the_record_) { | 316 if (!is_off_the_record_) { |
314 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, | 317 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, |
315 NotificationService::AllSources()); | 318 NotificationService::AllSources()); |
316 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 319 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
317 NotificationService::AllSources()); | 320 NotificationService::AllSources()); |
318 } | 321 } |
319 } | 322 } |
320 | 323 |
321 // NotificationObserver implementation. | 324 // NotificationObserver implementation. |
(...skipping 11 matching lines...) Expand all Loading... | |
333 NewRunnableMethod(this, | 336 NewRunnableMethod(this, |
334 &ChromeURLRequestContext::OnAcceptLanguageChange, | 337 &ChromeURLRequestContext::OnAcceptLanguageChange, |
335 accept_language)); | 338 accept_language)); |
336 } else if (*pref_name_in == prefs::kCookieBehavior) { | 339 } else if (*pref_name_in == prefs::kCookieBehavior) { |
337 net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( | 340 net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( |
338 prefs_->GetInteger(prefs::kCookieBehavior)); | 341 prefs_->GetInteger(prefs::kCookieBehavior)); |
339 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 342 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
340 NewRunnableMethod(this, | 343 NewRunnableMethod(this, |
341 &ChromeURLRequestContext::OnCookiePolicyChange, | 344 &ChromeURLRequestContext::OnCookiePolicyChange, |
342 policy_type)); | 345 policy_type)); |
346 } else if (*pref_name_in == prefs::kDefaultCharset) { | |
347 std::string default_charset = | |
348 WideToASCII(prefs->GetString(prefs::kDefaultCharset)); | |
349 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
350 NewRunnableMethod(this, | |
351 &ChromeURLRequestContext::OnDefaultCharsetChange, | |
352 default_charset)); | |
343 } | 353 } |
344 } else if (NotificationType::EXTENSIONS_LOADED == type) { | 354 } else if (NotificationType::EXTENSIONS_LOADED == type) { |
345 ExtensionPaths* new_paths = new ExtensionPaths; | 355 ExtensionPaths* new_paths = new ExtensionPaths; |
346 ExtensionList* extensions = Details<ExtensionList>(details).ptr(); | 356 ExtensionList* extensions = Details<ExtensionList>(details).ptr(); |
347 DCHECK(extensions); | 357 DCHECK(extensions); |
348 for (ExtensionList::const_iterator iter = extensions->begin(); | 358 for (ExtensionList::const_iterator iter = extensions->begin(); |
349 iter != extensions->end(); ++iter) { | 359 iter != extensions->end(); ++iter) { |
350 new_paths->insert(ExtensionPaths::value_type((*iter)->id(), | 360 new_paths->insert(ExtensionPaths::value_type((*iter)->id(), |
351 (*iter)->path())); | 361 (*iter)->path())); |
352 } | 362 } |
353 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 363 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
354 NewRunnableMethod(this, &ChromeURLRequestContext::OnNewExtensions, | 364 NewRunnableMethod(this, &ChromeURLRequestContext::OnNewExtensions, |
355 new_paths)); | 365 new_paths)); |
356 } else if (NotificationType::EXTENSION_UNLOADED == type) { | 366 } else if (NotificationType::EXTENSION_UNLOADED == type) { |
357 Extension* extension = Details<Extension>(details).ptr(); | 367 Extension* extension = Details<Extension>(details).ptr(); |
358 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 368 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
359 NewRunnableMethod(this, &ChromeURLRequestContext::OnUnloadedExtension, | 369 NewRunnableMethod(this, &ChromeURLRequestContext::OnUnloadedExtension, |
360 extension->id())); | 370 extension->id())); |
361 } else { | 371 } else { |
362 NOTREACHED(); | 372 NOTREACHED(); |
363 } | 373 } |
364 } | 374 } |
365 | 375 |
366 void ChromeURLRequestContext::CleanupOnUIThread() { | 376 void ChromeURLRequestContext::CleanupOnUIThread() { |
367 // Unregister for pref notifications. | 377 // Unregister for pref notifications. |
368 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); | 378 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); |
369 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); | 379 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); |
380 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this); | |
370 prefs_ = NULL; | 381 prefs_ = NULL; |
371 | 382 |
372 registrar_.RemoveAll(); | 383 registrar_.RemoveAll(); |
373 } | 384 } |
374 | 385 |
375 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) { | 386 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) { |
376 ExtensionPaths::iterator iter = extension_paths_.find(id); | 387 ExtensionPaths::iterator iter = extension_paths_.find(id); |
377 if (iter != extension_paths_.end()) { | 388 if (iter != extension_paths_.end()) { |
378 return iter->second; | 389 return iter->second; |
379 } else { | 390 } else { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); | 436 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); |
426 } | 437 } |
427 | 438 |
428 void ChromeURLRequestContext::OnCookiePolicyChange( | 439 void ChromeURLRequestContext::OnCookiePolicyChange( |
429 net::CookiePolicy::Type type) { | 440 net::CookiePolicy::Type type) { |
430 DCHECK(MessageLoop::current() == | 441 DCHECK(MessageLoop::current() == |
431 ChromeThread::GetMessageLoop(ChromeThread::IO)); | 442 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
432 cookie_policy_.SetType(type); | 443 cookie_policy_.SetType(type); |
433 } | 444 } |
434 | 445 |
446 void ChromeURLRequestContext::OnDefaultCharsetChange( | |
447 const std::string& default_charset) { | |
448 DCHECK(MessageLoop::current() == | |
449 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
450 referrer_charset_ = default_charset; | |
451 accept_charset_ = | |
452 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); | |
453 } | |
454 | |
435 void ChromeURLRequestContext::OnNewExtensions(ExtensionPaths* new_paths) { | 455 void ChromeURLRequestContext::OnNewExtensions(ExtensionPaths* new_paths) { |
436 extension_paths_.insert(new_paths->begin(), new_paths->end()); | 456 extension_paths_.insert(new_paths->begin(), new_paths->end()); |
437 delete new_paths; | 457 delete new_paths; |
438 } | 458 } |
439 | 459 |
440 void ChromeURLRequestContext::OnUnloadedExtension( | 460 void ChromeURLRequestContext::OnUnloadedExtension( |
441 const std::string& extension_id) { | 461 const std::string& extension_id) { |
442 ExtensionPaths::iterator iter = extension_paths_.find(extension_id); | 462 ExtensionPaths::iterator iter = extension_paths_.find(extension_id); |
443 DCHECK(iter != extension_paths_.end()); | 463 DCHECK(iter != extension_paths_.end()); |
444 extension_paths_.erase(iter); | 464 extension_paths_.erase(iter); |
(...skipping 13 matching lines...) Expand all Loading... | |
458 // Do not delete the cookie store in the case of the media context, as it is | 478 // Do not delete the cookie store in the case of the media context, as it is |
459 // owned by the original context. | 479 // owned by the original context. |
460 if (!is_media_) | 480 if (!is_media_) |
461 delete cookie_store_; | 481 delete cookie_store_; |
462 | 482 |
463 // Do not delete the proxy service in the case of OTR or media contexts, as | 483 // Do not delete the proxy service in the case of OTR or media contexts, as |
464 // it is owned by the original URLRequestContext. | 484 // it is owned by the original URLRequestContext. |
465 if (!is_off_the_record_ && !is_media_) | 485 if (!is_off_the_record_ && !is_media_) |
466 delete proxy_service_; | 486 delete proxy_service_; |
467 } | 487 } |
OLD | NEW |