| 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/content_settings/cookie_settings.h" | 9 #include "chrome/browser/content_settings/cookie_settings.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/resource_request_info.h" | 23 #include "content/public/browser/resource_request_info.h" |
| 24 #include "net/base/host_port_pair.h" | 24 #include "net/base/host_port_pair.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/base/net_log.h" | 26 #include "net/base/net_log.h" |
| 27 #include "net/cookies/cookie_monster.h" | 27 #include "net/cookies/cookie_monster.h" |
| 28 #include "net/http/http_request_headers.h" | 28 #include "net/http/http_request_headers.h" |
| 29 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
| 30 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
| 31 | 31 |
| 32 #if defined(OS_CHROMEOS) |
| 33 #include "base/chromeos/chromeos_version.h" |
| 34 #endif |
| 35 |
| 32 #if defined(ENABLE_CONFIGURATION_POLICY) | 36 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 33 #include "chrome/browser/policy/url_blacklist_manager.h" | 37 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 34 #endif | 38 #endif |
| 35 | 39 |
| 36 using content::BrowserThread; | 40 using content::BrowserThread; |
| 37 using content::RenderViewHost; | 41 using content::RenderViewHost; |
| 38 using content::ResourceRequestInfo; | 42 using content::ResourceRequestInfo; |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 net::URLRequest* request, | 249 net::URLRequest* request, |
| 246 const net::AuthChallengeInfo& auth_info, | 250 const net::AuthChallengeInfo& auth_info, |
| 247 const AuthCallback& callback, | 251 const AuthCallback& callback, |
| 248 net::AuthCredentials* credentials) { | 252 net::AuthCredentials* credentials) { |
| 249 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired( | 253 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired( |
| 250 profile_, extension_info_map_.get(), request, auth_info, | 254 profile_, extension_info_map_.get(), request, auth_info, |
| 251 callback, credentials); | 255 callback, credentials); |
| 252 } | 256 } |
| 253 | 257 |
| 254 bool ChromeNetworkDelegate::CanGetCookies( | 258 bool ChromeNetworkDelegate::CanGetCookies( |
| 255 const net::URLRequest* request, | 259 const net::URLRequest& request, |
| 256 const net::CookieList& cookie_list) { | 260 const net::CookieList& cookie_list) { |
| 257 // NULL during tests, or when we're running in the system context. | 261 // NULL during tests, or when we're running in the system context. |
| 258 if (!cookie_settings_) | 262 if (!cookie_settings_) |
| 259 return true; | 263 return true; |
| 260 | 264 |
| 261 bool allow = cookie_settings_->IsReadingCookieAllowed( | 265 bool allow = cookie_settings_->IsReadingCookieAllowed( |
| 262 request->url(), request->first_party_for_cookies()); | 266 request.url(), request.first_party_for_cookies()); |
| 263 | 267 |
| 264 int render_process_id = -1; | 268 int render_process_id = -1; |
| 265 int render_view_id = -1; | 269 int render_view_id = -1; |
| 266 if (content::ResourceRequestInfo::GetRenderViewForRequest( | 270 if (content::ResourceRequestInfo::GetRenderViewForRequest( |
| 267 request, &render_process_id, &render_view_id)) { | 271 &request, &render_process_id, &render_view_id)) { |
| 268 BrowserThread::PostTask( | 272 BrowserThread::PostTask( |
| 269 BrowserThread::UI, FROM_HERE, | 273 BrowserThread::UI, FROM_HERE, |
| 270 base::Bind(&TabSpecificContentSettings::CookiesRead, | 274 base::Bind(&TabSpecificContentSettings::CookiesRead, |
| 271 render_process_id, render_view_id, | 275 render_process_id, render_view_id, |
| 272 request->url(), request->first_party_for_cookies(), | 276 request.url(), request.first_party_for_cookies(), |
| 273 cookie_list, !allow)); | 277 cookie_list, !allow)); |
| 274 } | 278 } |
| 275 | 279 |
| 276 return allow; | 280 return allow; |
| 277 } | 281 } |
| 278 | 282 |
| 279 bool ChromeNetworkDelegate::CanSetCookie( | 283 bool ChromeNetworkDelegate::CanSetCookie( |
| 280 const net::URLRequest* request, | 284 const net::URLRequest& request, |
| 281 const std::string& cookie_line, | 285 const std::string& cookie_line, |
| 282 net::CookieOptions* options) { | 286 net::CookieOptions* options) { |
| 283 // NULL during tests, or when we're running in the system context. | 287 // NULL during tests, or when we're running in the system context. |
| 284 if (!cookie_settings_) | 288 if (!cookie_settings_) |
| 285 return true; | 289 return true; |
| 286 | 290 |
| 287 bool allow = cookie_settings_->IsSettingCookieAllowed( | 291 bool allow = cookie_settings_->IsSettingCookieAllowed( |
| 288 request->url(), request->first_party_for_cookies()); | 292 request.url(), request.first_party_for_cookies()); |
| 289 | 293 |
| 290 if (cookie_settings_->IsCookieSessionOnly(request->url())) | 294 if (cookie_settings_->IsCookieSessionOnly(request.url())) |
| 291 options->set_force_session(); | 295 options->set_force_session(); |
| 292 | 296 |
| 293 int render_process_id = -1; | 297 int render_process_id = -1; |
| 294 int render_view_id = -1; | 298 int render_view_id = -1; |
| 295 if (content::ResourceRequestInfo::GetRenderViewForRequest( | 299 if (content::ResourceRequestInfo::GetRenderViewForRequest( |
| 296 request, &render_process_id, &render_view_id)) { | 300 &request, &render_process_id, &render_view_id)) { |
| 297 BrowserThread::PostTask( | 301 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, | 302 BrowserThread::UI, FROM_HERE, |
| 299 base::Bind(&TabSpecificContentSettings::CookieChanged, | 303 base::Bind(&TabSpecificContentSettings::CookieChanged, |
| 300 render_process_id, render_view_id, | 304 render_process_id, render_view_id, |
| 301 request->url(), request->first_party_for_cookies(), | 305 request.url(), request.first_party_for_cookies(), |
| 302 cookie_line, *options, !allow)); | 306 cookie_line, *options, !allow)); |
| 303 } | 307 } |
| 304 | 308 |
| 305 return allow; | 309 return allow; |
| 306 } | 310 } |
| 311 |
| 312 bool ChromeNetworkDelegate::CanAccessFile(const net::URLRequest& request, |
| 313 const FilePath& path) const { |
| 314 #if defined(OS_CHROMEOS) |
| 315 // ChromeOS uses a whitelist to only allow access to files residing in the |
| 316 // list of directories below. |
| 317 static const char* const kLocalAccessWhiteList[] = { |
| 318 "/home/chronos/user/Downloads", |
| 319 "/home/chronos/user/log", |
| 320 "/media", |
| 321 "/opt/oem", |
| 322 "/usr/share/chromeos-assets", |
| 323 "/tmp", |
| 324 "/var/log", |
| 325 }; |
| 326 |
| 327 // If we're running Chrome for ChromeOS on Linux, we want to allow file |
| 328 // access. |
| 329 if (!base::chromeos::IsRunningOnChromeOS()) |
| 330 return true; |
| 331 |
| 332 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { |
| 333 const FilePath white_listed_path(kLocalAccessWhiteList[i]); |
| 334 // FilePath::operator== should probably handle trailing separators. |
| 335 if (white_listed_path == path.StripTrailingSeparators() || |
| 336 white_listed_path.IsParent(path)) { |
| 337 return true; |
| 338 } |
| 339 } |
| 340 return false; |
| 341 #else |
| 342 return true; |
| 343 #endif // defined(OS_CHROMEOS) |
| 344 } |
| OLD | NEW |