Allow setting referrer
This commit is contained in:
parent
e07f5cd53f
commit
543c4d5597
6 changed files with 20 additions and 8 deletions
|
@ -125,13 +125,14 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
return;
|
return;
|
||||||
} else if (name == "RequestHttpJob") {
|
} else if (name == "RequestHttpJob") {
|
||||||
GURL url;
|
GURL url;
|
||||||
std::string method;
|
std::string method, referrer;
|
||||||
dict.Get("url", &url);
|
dict.Get("url", &url);
|
||||||
dict.Get("method", &method);
|
dict.Get("method", &method);
|
||||||
|
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(), url, method));
|
GetWeakPtr(), url, method, referrer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,6 @@ class RequestErrorJob
|
||||||
|
|
||||||
protocol.RequestHttpJob =
|
protocol.RequestHttpJob =
|
||||||
class RequestHttpJob
|
class RequestHttpJob
|
||||||
constructor: ({@url, @method}) ->
|
constructor: ({@url, @method, @referrer}) ->
|
||||||
|
|
||||||
module.exports = protocol
|
module.exports = protocol
|
||||||
|
|
|
@ -115,14 +115,15 @@ void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateHttpJobAndStart(const GURL& url,
|
void AdapterRequestJob::CreateHttpJobAndStart(const GURL& url,
|
||||||
const std::string& method) {
|
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(request(), network_delegate(), url,
|
||||||
method);
|
method, referrer);
|
||||||
real_job_->Start();
|
real_job_->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,9 @@ 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, const std::string& method);
|
void CreateHttpJobAndStart(const GURL& url,
|
||||||
|
const std::string& method,
|
||||||
|
const std::string& referrer);
|
||||||
void CreateJobFromProtocolHandlerAndStart();
|
void CreateJobFromProtocolHandlerAndStart();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -76,7 +76,8 @@ URLRequestFetchJob::URLRequestFetchJob(
|
||||||
net::URLRequest* request,
|
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,
|
||||||
|
const std::string& referrer)
|
||||||
: net::URLRequestJob(request, network_delegate),
|
: net::URLRequestJob(request, network_delegate),
|
||||||
pending_buffer_size_(0) {
|
pending_buffer_size_(0) {
|
||||||
// Use |request|'s method if |method| is not specified.
|
// Use |request|'s method if |method| is not specified.
|
||||||
|
@ -90,6 +91,12 @@ URLRequestFetchJob::URLRequestFetchJob(
|
||||||
auto context = AtomBrowserContext::Get()->url_request_context_getter();
|
auto context = AtomBrowserContext::Get()->url_request_context_getter();
|
||||||
fetcher_->SetRequestContext(context);
|
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.
|
||||||
|
if (referrer.empty())
|
||||||
|
fetcher_->SetReferrer(request->referrer());
|
||||||
|
else
|
||||||
|
fetcher_->SetReferrer(referrer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void URLRequestFetchJob::HeadersCompleted() {
|
void URLRequestFetchJob::HeadersCompleted() {
|
||||||
|
|
|
@ -16,7 +16,8 @@ class URLRequestFetchJob : public net::URLRequestJob,
|
||||||
URLRequestFetchJob(net::URLRequest* request,
|
URLRequestFetchJob(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,
|
||||||
|
const std::string& referrer);
|
||||||
|
|
||||||
void HeadersCompleted();
|
void HeadersCompleted();
|
||||||
int DataAvailable(net::IOBuffer* buffer, int num_bytes);
|
int DataAvailable(net::IOBuffer* buffer, int num_bytes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue