Merge pull request #2298 from deepak1556/default_protocol_handler_patch
protocol: fix adapter request job for default handlers
This commit is contained in:
commit
5a980497e8
3 changed files with 28 additions and 13 deletions
|
@ -80,16 +80,13 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
registry_(registry) {
|
registry_(registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdapterRequestJob:
|
void GetJobTypeInUI(const Protocol::JsProtocolHandler& callback) {
|
||||||
void GetJobTypeInUI() override {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
v8::Locker locker(registry_->isolate());
|
v8::Locker locker(registry_->isolate());
|
||||||
v8::HandleScope handle_scope(registry_->isolate());
|
v8::HandleScope handle_scope(registry_->isolate());
|
||||||
|
|
||||||
// Call the JS handler.
|
// Call the JS handler.
|
||||||
Protocol::JsProtocolHandler callback =
|
|
||||||
registry_->GetProtocolHandler(request()->url().scheme());
|
|
||||||
v8::Local<v8::Value> result = callback.Run(request());
|
v8::Local<v8::Value> result = callback.Run(request());
|
||||||
|
|
||||||
// Determine the type of the job we are going to create.
|
// Determine the type of the job we are going to create.
|
||||||
|
@ -172,6 +169,14 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
GetWeakPtr(), net::ERR_NOT_IMPLEMENTED));
|
GetWeakPtr(), net::ERR_NOT_IMPLEMENTED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdapterRequestJob:
|
||||||
|
void GetJobType() override {
|
||||||
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
|
base::Bind(&CustomProtocolRequestJob::GetJobTypeInUI,
|
||||||
|
base::Unretained(this),
|
||||||
|
registry_->GetProtocolHandler(request()->url().scheme())));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Protocol* registry_; // Weak, the Protocol class is expected to live forever.
|
Protocol* registry_; // Weak, the Protocol class is expected to live forever.
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,11 +27,7 @@ AdapterRequestJob::AdapterRequestJob(ProtocolHandler* protocol_handler,
|
||||||
|
|
||||||
void AdapterRequestJob::Start() {
|
void AdapterRequestJob::Start() {
|
||||||
DCHECK(!real_job_.get());
|
DCHECK(!real_job_.get());
|
||||||
content::BrowserThread::PostTask(
|
GetJobType();
|
||||||
content::BrowserThread::UI,
|
|
||||||
FROM_HERE,
|
|
||||||
base::Bind(&AdapterRequestJob::GetJobTypeInUI,
|
|
||||||
weak_factory_.GetWeakPtr()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::Kill() {
|
void AdapterRequestJob::Kill() {
|
||||||
|
@ -43,6 +39,10 @@ bool AdapterRequestJob::ReadRawData(net::IOBuffer* buf,
|
||||||
int buf_size,
|
int buf_size,
|
||||||
int *bytes_read) {
|
int *bytes_read) {
|
||||||
DCHECK(!real_job_.get());
|
DCHECK(!real_job_.get());
|
||||||
|
// Read post-filtered data if available.
|
||||||
|
if (real_job_->HasFilter())
|
||||||
|
return real_job_->Read(buf, buf_size, bytes_read);
|
||||||
|
else
|
||||||
return real_job_->ReadRawData(buf, buf_size, bytes_read);
|
return real_job_->ReadRawData(buf, buf_size, bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ int AdapterRequestJob::GetResponseCode() const {
|
||||||
return real_job_->GetResponseCode();
|
return real_job_->GetResponseCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdapterRequestJob::GetLoadTimingInfo(
|
||||||
|
net::LoadTimingInfo* load_timing_info) const {
|
||||||
|
real_job_->GetLoadTimingInfo(load_timing_info);
|
||||||
|
}
|
||||||
|
|
||||||
base::WeakPtr<AdapterRequestJob> AdapterRequestJob::GetWeakPtr() {
|
base::WeakPtr<AdapterRequestJob> AdapterRequestJob::GetWeakPtr() {
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
}
|
}
|
||||||
|
@ -131,10 +136,13 @@ void AdapterRequestJob::CreateHttpJobAndStart(
|
||||||
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
|
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
|
||||||
real_job_ = protocol_handler_->MaybeCreateJob(request(),
|
real_job_ = protocol_handler_->MaybeCreateJob(request(),
|
||||||
network_delegate());
|
network_delegate());
|
||||||
if (!real_job_.get())
|
if (!real_job_.get()) {
|
||||||
CreateErrorJobAndStart(net::ERR_NOT_IMPLEMENTED);
|
CreateErrorJobAndStart(net::ERR_NOT_IMPLEMENTED);
|
||||||
else
|
} else {
|
||||||
|
// Copy headers from original request.
|
||||||
|
real_job_->SetExtraRequestHeaders(request()->extra_request_headers());
|
||||||
real_job_->Start();
|
real_job_->Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -46,13 +46,15 @@ class AdapterRequestJob : public net::URLRequestJob {
|
||||||
bool GetCharset(std::string* charset) override;
|
bool GetCharset(std::string* charset) override;
|
||||||
void GetResponseInfo(net::HttpResponseInfo* info) override;
|
void GetResponseInfo(net::HttpResponseInfo* info) override;
|
||||||
int GetResponseCode() const override;
|
int GetResponseCode() const override;
|
||||||
|
void GetLoadTimingInfo(
|
||||||
|
net::LoadTimingInfo* load_timing_info) const override;
|
||||||
|
|
||||||
base::WeakPtr<AdapterRequestJob> GetWeakPtr();
|
base::WeakPtr<AdapterRequestJob> GetWeakPtr();
|
||||||
|
|
||||||
ProtocolHandler* default_protocol_handler() { return protocol_handler_; }
|
ProtocolHandler* default_protocol_handler() { return protocol_handler_; }
|
||||||
|
|
||||||
// Override this function to determine which job should be started.
|
// Override this function to determine which job should be started.
|
||||||
virtual void GetJobTypeInUI() = 0;
|
virtual void GetJobType() = 0;
|
||||||
|
|
||||||
void CreateErrorJobAndStart(int error_code);
|
void CreateErrorJobAndStart(int error_code);
|
||||||
void CreateStringJobAndStart(const std::string& mime_type,
|
void CreateStringJobAndStart(const std::string& mime_type,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue