Allow clients to supply their own NetworkDelegate implementation
This commit is contained in:
parent
09efd19d2f
commit
33b574b434
5 changed files with 20 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "browser_context.h"
|
||||
|
||||
#include "browser/inspectable_web_contents_impl.h"
|
||||
#include "browser/network_delegate.h"
|
||||
#include "common/application_info.h"
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
|
@ -66,11 +67,16 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot
|
|||
GetPath(),
|
||||
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO),
|
||||
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE),
|
||||
CreateNetworkDelegate().Pass(),
|
||||
protocol_handlers);
|
||||
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
||||
return url_request_getter_.get();
|
||||
}
|
||||
|
||||
scoped_ptr<NetworkDelegate> BrowserContext::CreateNetworkDelegate() {
|
||||
return make_scoped_ptr(new NetworkDelegate).Pass();
|
||||
}
|
||||
|
||||
base::FilePath BrowserContext::GetPath() {
|
||||
if (!path_.empty())
|
||||
return path_;
|
||||
|
|
|
@ -13,6 +13,7 @@ class PrefService;
|
|||
|
||||
namespace brightray {
|
||||
|
||||
class NetworkDelegate;
|
||||
class URLRequestContextGetter;
|
||||
|
||||
class BrowserContext : public content::BrowserContext {
|
||||
|
@ -28,6 +29,9 @@ protected:
|
|||
// Subclasses should override this to register custom preferences.
|
||||
virtual void RegisterPrefs(PrefRegistrySimple*) {}
|
||||
|
||||
// Subclasses should override this to provide a custom NetworkDelegate implementation.
|
||||
virtual scoped_ptr<NetworkDelegate> CreateNetworkDelegate();
|
||||
|
||||
virtual base::FilePath GetPath() OVERRIDE;
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
namespace brightray {
|
||||
|
||||
class NetworkDelegate : public net::NetworkDelegate {
|
||||
public:
|
||||
public:
|
||||
NetworkDelegate();
|
||||
virtual ~NetworkDelegate();
|
||||
|
||||
private:
|
||||
protected:
|
||||
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;
|
||||
|
@ -33,6 +33,7 @@ private:
|
|||
virtual int OnBeforeSocketStreamConnect(net::SocketStream* stream, const net::CompletionCallback& callback) OVERRIDE;
|
||||
virtual void OnRequestWaitStateChange(const net::URLRequest& request, RequestWaitState state) OVERRIDE;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(NetworkDelegate);
|
||||
};
|
||||
|
||||
|
|
|
@ -32,10 +32,12 @@ URLRequestContextGetter::URLRequestContextGetter(
|
|||
const base::FilePath& base_path,
|
||||
MessageLoop* io_loop,
|
||||
MessageLoop* file_loop,
|
||||
scoped_ptr<NetworkDelegate> network_delegate,
|
||||
content::ProtocolHandlerMap* protocol_handlers)
|
||||
: base_path_(base_path),
|
||||
io_loop_(io_loop),
|
||||
file_loop_(file_loop) {
|
||||
file_loop_(file_loop),
|
||||
network_delegate_(network_delegate.Pass()) {
|
||||
// Must first be created on the UI thread.
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
||||
|
||||
|
@ -57,7 +59,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext()
|
|||
|
||||
if (!url_request_context_.get()) {
|
||||
url_request_context_.reset(new net::URLRequestContext());
|
||||
network_delegate_.reset(new NetworkDelegate);
|
||||
url_request_context_->set_network_delegate(network_delegate_.get());
|
||||
storage_.reset(
|
||||
new net::URLRequestContextStorage(url_request_context_.get()));
|
||||
|
|
|
@ -16,19 +16,21 @@ class MessageLoop;
|
|||
|
||||
namespace net {
|
||||
class HostResolver;
|
||||
class NetworkDelegate;
|
||||
class ProxyConfigService;
|
||||
class URLRequestContextStorage;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class NetworkDelegate;
|
||||
|
||||
class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
public:
|
||||
URLRequestContextGetter(
|
||||
const base::FilePath& base_path,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
scoped_ptr<NetworkDelegate>,
|
||||
content::ProtocolHandlerMap*);
|
||||
virtual ~URLRequestContextGetter();
|
||||
|
||||
|
@ -43,7 +45,7 @@ private:
|
|||
base::MessageLoop* file_loop_;
|
||||
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
|
||||
scoped_ptr<net::NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<net::URLRequestContextStorage> storage_;
|
||||
scoped_ptr<net::URLRequestContext> url_request_context_;
|
||||
content::ProtocolHandlerMap protocol_handlers_;
|
||||
|
|
Loading…
Reference in a new issue