Pass net::URLRequestContextGetter in scoped_refptr
This commit is contained in:
parent
c295979270
commit
0644129fbe
7 changed files with 31 additions and 33 deletions
|
@ -35,23 +35,6 @@ struct Converter<const net::URLRequest*> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Converter<net::URLRequestContextGetter*> {
|
|
||||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
||||||
net::URLRequestContextGetter** out) {
|
|
||||||
if (val->IsNull()) {
|
|
||||||
*out = nullptr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
atom::api::Session* session;
|
|
||||||
if (!Converter<atom::api::Session*>::FromV8(isolate, val, &session))
|
|
||||||
return false;
|
|
||||||
*out = session->browser_context()->GetRequestContext();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -141,16 +124,27 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
} else if (name == "RequestHttpJob") {
|
} else if (name == "RequestHttpJob") {
|
||||||
GURL url;
|
GURL url;
|
||||||
std::string method, referrer;
|
std::string method, referrer;
|
||||||
net::URLRequestContextGetter* getter =
|
|
||||||
registry_->browser_context()->GetRequestContext();
|
|
||||||
dict.Get("url", &url);
|
dict.Get("url", &url);
|
||||||
dict.Get("method", &method);
|
dict.Get("method", &method);
|
||||||
dict.Get("referrer", &referrer);
|
dict.Get("referrer", &referrer);
|
||||||
dict.Get("session", &getter);
|
|
||||||
|
v8::Local<v8::Value> value;
|
||||||
|
mate::Handle<Session> session;
|
||||||
|
scoped_refptr<net::URLRequestContextGetter> request_context_getter;
|
||||||
|
// "session" null -> pass nullptr;
|
||||||
|
// "session" a Session object -> use passed session.
|
||||||
|
// "session" undefined -> use current session;
|
||||||
|
if (dict.Get("session", &session))
|
||||||
|
request_context_getter =
|
||||||
|
session->browser_context()->GetRequestContext();
|
||||||
|
else if (dict.Get("session", &value) && value->IsNull())
|
||||||
|
request_context_getter = nullptr;
|
||||||
|
else
|
||||||
|
request_context_getter = registry_->request_context_getter();
|
||||||
|
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&AdapterRequestJob::CreateHttpJobAndStart, GetWeakPtr(),
|
base::Bind(&AdapterRequestJob::CreateHttpJobAndStart, GetWeakPtr(),
|
||||||
base::Unretained(getter), url, method, referrer));
|
request_context_getter, url, method, referrer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +231,7 @@ std::string ConvertErrorCode(int error_code) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Protocol::Protocol(AtomBrowserContext* browser_context)
|
Protocol::Protocol(AtomBrowserContext* browser_context)
|
||||||
: browser_context_(browser_context),
|
: request_context_getter_(browser_context->GetRequestContext()),
|
||||||
job_factory_(browser_context->job_factory()) {
|
job_factory_(browser_context->job_factory()) {
|
||||||
CHECK(job_factory_);
|
CHECK(job_factory_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
namespace net {
|
namespace net {
|
||||||
class URLRequest;
|
class URLRequest;
|
||||||
|
class URLRequestContextGetter;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -46,7 +47,9 @@ class Protocol : public mate::EventEmitter {
|
||||||
|
|
||||||
JsProtocolHandler GetProtocolHandler(const std::string& scheme);
|
JsProtocolHandler GetProtocolHandler(const std::string& scheme);
|
||||||
|
|
||||||
AtomBrowserContext* browser_context() const { return browser_context_; }
|
net::URLRequestContextGetter* request_context_getter() {
|
||||||
|
return request_context_getter_.get();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Protocol(AtomBrowserContext* browser_context);
|
explicit Protocol(AtomBrowserContext* browser_context);
|
||||||
|
@ -94,7 +97,8 @@ class Protocol : public mate::EventEmitter {
|
||||||
const JsProtocolHandler& handler);
|
const JsProtocolHandler& handler);
|
||||||
int UninterceptProtocolInIO(const std::string& scheme);
|
int UninterceptProtocolInIO(const std::string& scheme);
|
||||||
|
|
||||||
AtomBrowserContext* browser_context_;
|
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
|
||||||
|
|
||||||
AtomURLRequestJobFactory* job_factory_;
|
AtomURLRequestJobFactory* job_factory_;
|
||||||
ProtocolHandlersMap protocol_handlers_;
|
ProtocolHandlersMap protocol_handlers_;
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
|
|
||||||
class GURL;
|
class GURL;
|
||||||
|
|
||||||
namespace mate {
|
|
||||||
class Arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class FilePath;
|
class FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
class Arguments;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomBrowserContext;
|
class AtomBrowserContext;
|
||||||
|
|
|
@ -119,7 +119,7 @@ void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateHttpJobAndStart(
|
void AdapterRequestJob::CreateHttpJobAndStart(
|
||||||
net::URLRequestContextGetter* request_context_getter,
|
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
const std::string& method,
|
const std::string& method,
|
||||||
const std::string& referrer) {
|
const std::string& referrer) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ class AdapterRequestJob : public net::URLRequestJob {
|
||||||
scoped_refptr<base::RefCountedBytes> data);
|
scoped_refptr<base::RefCountedBytes> data);
|
||||||
void CreateFileJobAndStart(const base::FilePath& path);
|
void CreateFileJobAndStart(const base::FilePath& path);
|
||||||
void CreateHttpJobAndStart(
|
void CreateHttpJobAndStart(
|
||||||
net::URLRequestContextGetter* request_context_getter,
|
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
const std::string& method,
|
const std::string& method,
|
||||||
const std::string& referrer);
|
const std::string& referrer);
|
||||||
|
|
|
@ -75,7 +75,7 @@ class ResponsePiper : public net::URLFetcherResponseWriter {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
URLRequestFetchJob::URLRequestFetchJob(
|
URLRequestFetchJob::URLRequestFetchJob(
|
||||||
net::URLRequestContextGetter* request_context_getter,
|
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
net::NetworkDelegate* network_delegate,
|
net::NetworkDelegate* network_delegate,
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
|
@ -93,7 +93,7 @@ URLRequestFetchJob::URLRequestFetchJob(
|
||||||
fetcher_.reset(net::URLFetcher::Create(url, request_type, this));
|
fetcher_.reset(net::URLFetcher::Create(url, request_type, this));
|
||||||
// Use request context if provided else create one.
|
// Use request context if provided else create one.
|
||||||
if (request_context_getter)
|
if (request_context_getter)
|
||||||
fetcher_->SetRequestContext(request_context_getter);
|
fetcher_->SetRequestContext(request_context_getter.get());
|
||||||
else
|
else
|
||||||
fetcher_->SetRequestContext(GetRequestContext());
|
fetcher_->SetRequestContext(GetRequestContext());
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AtomBrowserContext;
|
||||||
class URLRequestFetchJob : public net::URLRequestJob,
|
class URLRequestFetchJob : public net::URLRequestJob,
|
||||||
public net::URLFetcherDelegate {
|
public net::URLFetcherDelegate {
|
||||||
public:
|
public:
|
||||||
URLRequestFetchJob(net::URLRequestContextGetter* request_context_getter,
|
URLRequestFetchJob(scoped_refptr<net::URLRequestContextGetter> context_getter,
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
net::NetworkDelegate* network_delegate,
|
net::NetworkDelegate* network_delegate,
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue