// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ #pragma once #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "net/base/network_delegate.h" class CookieSettings; class ExtensionEventRouterForwarder; class ExtensionInfoMap; class PrefService; template class PrefMember; typedef PrefMember BooleanPrefMember; namespace policy { class URLBlacklistManager; } // ChromeNetworkDelegate is the central point from within the chrome code to // add hooks into the network stack. class ChromeNetworkDelegate : public net::NetworkDelegate { public: // If |profile| is NULL, events will be broadcasted to all profiles, // otherwise they will only be sent to the specified profile. // |enable_referrers| should be initialized on the UI thread (see below) // beforehand. This object's owner is responsible for cleaning it up at // shutdown. If |cookie_settings| is NULL, all cookies are enabled, // otherwise, the settings are enforced on all observed network requests. ChromeNetworkDelegate( ExtensionEventRouterForwarder* event_router, ExtensionInfoMap* extension_info_map, const policy::URLBlacklistManager* url_blacklist_manager, void* profile, CookieSettings* cookie_settings, BooleanPrefMember* enable_referrers); virtual ~ChromeNetworkDelegate(); // Binds |enable_referrers| to |pref_service| and moves it to the IO thread. // This method should be called on the UI thread. static void InitializeReferrersEnabled(BooleanPrefMember* enable_referrers, PrefService* pref_service); // When called, all file:// URLs will now be accessible. If this is not // called, then some platforms restrict access to file:// paths. static void AllowAccessToAllFiles(); private: // NetworkDelegate implementation. virtual int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) OVERRIDE; virtual int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) OVERRIDE; virtual void OnSendHeaders(net::URLRequest* request, const net::HttpRequestHeaders& headers) OVERRIDE; virtual int OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, net::HttpResponseHeaders* original_response_headers, scoped_refptr* override_response_headers) OVERRIDE; virtual void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) OVERRIDE; virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; virtual void OnRawBytesRead(const net::URLRequest& request, int bytes_read) OVERRIDE; virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; virtual void OnPACScriptError(int line_number, const string16& error) OVERRIDE; virtual net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( net::URLRequest* request, const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; virtual bool OnCanGetCookies(const net::URLRequest& request, const net::CookieList& cookie_list) OVERRIDE; virtual bool OnCanSetCookie(const net::URLRequest& request, const std::string& cookie_line, net::CookieOptions* options) OVERRIDE; virtual bool OnCanAccessFile(const net::URLRequest& request, const FilePath& path) const OVERRIDE; scoped_refptr event_router_; void* profile_; scoped_refptr cookie_settings_; scoped_refptr extension_info_map_; // Weak, owned by our owner. BooleanPrefMember* enable_referrers_; // Weak, owned by our owner. const policy::URLBlacklistManager* url_blacklist_manager_; // When true, allow access to all file:// URLs. static bool g_allow_file_access_; DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); }; #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_