Use the BrowserContext from protocol

This commit is contained in:
Cheng Zhao 2015-06-18 17:18:11 +08:00
parent e209312459
commit 923296b4ee
6 changed files with 21 additions and 11 deletions

View file

@ -132,8 +132,8 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
dict.Get("referrer", &referrer); dict.Get("referrer", &referrer);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&AdapterRequestJob::CreateHttpJobAndStart, base::Bind(&AdapterRequestJob::CreateHttpJobAndStart, GetWeakPtr(),
GetWeakPtr(), url, method, referrer)); registry_->browser_context(), url, method, referrer));
return; return;
} }
} }

View file

@ -33,6 +33,8 @@ class Protocol : public mate::EventEmitter {
JsProtocolHandler GetProtocolHandler(const std::string& scheme); JsProtocolHandler GetProtocolHandler(const std::string& scheme);
AtomBrowserContext* browser_context() const { return browser_context_; }
protected: protected:
explicit Protocol(AtomBrowserContext* browser_context); explicit Protocol(AtomBrowserContext* browser_context);

View file

@ -114,16 +114,18 @@ void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
real_job_->Start(); real_job_->Start();
} }
void AdapterRequestJob::CreateHttpJobAndStart(const GURL& url, void AdapterRequestJob::CreateHttpJobAndStart(
const std::string& method, AtomBrowserContext* browser_context,
const std::string& referrer) { const GURL& url,
const std::string& method,
const std::string& referrer) {
if (!url.is_valid()) { if (!url.is_valid()) {
CreateErrorJobAndStart(net::ERR_INVALID_URL); CreateErrorJobAndStart(net::ERR_INVALID_URL);
return; return;
} }
real_job_ = new URLRequestFetchJob(request(), network_delegate(), url, real_job_ = new URLRequestFetchJob(browser_context, request(),
method, referrer); network_delegate(), url, method, referrer);
real_job_->Start(); real_job_->Start();
} }

View file

@ -20,6 +20,8 @@ class FilePath;
namespace atom { namespace atom {
class AtomBrowserContext;
// Ask JS which type of job it wants, and then delegate corresponding methods. // Ask JS which type of job it wants, and then delegate corresponding methods.
class AdapterRequestJob : public net::URLRequestJob { class AdapterRequestJob : public net::URLRequestJob {
public: public:
@ -59,7 +61,8 @@ class AdapterRequestJob : public net::URLRequestJob {
const std::string& charset, const std::string& charset,
scoped_refptr<base::RefCountedBytes> data); scoped_refptr<base::RefCountedBytes> data);
void CreateFileJobAndStart(const base::FilePath& path); void CreateFileJobAndStart(const base::FilePath& path);
void CreateHttpJobAndStart(const GURL& url, void CreateHttpJobAndStart(AtomBrowserContext* browser_context,
const GURL& url,
const std::string& method, const std::string& method,
const std::string& referrer); const std::string& referrer);
void CreateJobFromProtocolHandlerAndStart(); void CreateJobFromProtocolHandlerAndStart();

View file

@ -74,6 +74,7 @@ class ResponsePiper : public net::URLFetcherResponseWriter {
} // namespace } // namespace
URLRequestFetchJob::URLRequestFetchJob( URLRequestFetchJob::URLRequestFetchJob(
AtomBrowserContext* browser_context,
net::URLRequest* request, net::URLRequest* request,
net::NetworkDelegate* network_delegate, net::NetworkDelegate* network_delegate,
const GURL& url, const GURL& url,
@ -89,8 +90,7 @@ URLRequestFetchJob::URLRequestFetchJob(
request_type = GetRequestType(method); request_type = GetRequestType(method);
fetcher_.reset(net::URLFetcher::Create(url, request_type, this)); fetcher_.reset(net::URLFetcher::Create(url, request_type, this));
auto context = AtomBrowserContext::Get()->url_request_context_getter(); fetcher_->SetRequestContext(browser_context->url_request_context_getter());
fetcher_->SetRequestContext(context);
fetcher_->SaveResponseWithWriter(make_scoped_ptr(new ResponsePiper(this))); fetcher_->SaveResponseWithWriter(make_scoped_ptr(new ResponsePiper(this)));
// Use |request|'s referrer if |referrer| is not specified. // Use |request|'s referrer if |referrer| is not specified.

View file

@ -12,10 +12,13 @@
namespace atom { namespace atom {
class AtomBrowserContext;
class URLRequestFetchJob : public net::URLRequestJob, class URLRequestFetchJob : public net::URLRequestJob,
public net::URLFetcherDelegate { public net::URLFetcherDelegate {
public: public:
URLRequestFetchJob(net::URLRequest* request, URLRequestFetchJob(AtomBrowserContext* browser_context,
net::URLRequest* request,
net::NetworkDelegate* network_delegate, net::NetworkDelegate* network_delegate,
const GURL& url, const GURL& url,
const std::string& method, const std::string& method,