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