Adding systematic checks on the atom_request_ pointer as it may be reset to null.

This commit is contained in:
ali.ibrahim 2016-10-04 18:09:36 +02:00
parent a655cca0a1
commit 8c5751e9f7

View file

@ -278,7 +278,7 @@ void URLRequest::Cancel() {
bool URLRequest::SetExtraHeader(const std::string& name,
const std::string& value) {
// State must be equal to not started.
// Request state must be in the initial non started state.
if (!request_state_.NotStarted()) {
// Cannot change headers after send.
return false;
@ -292,7 +292,10 @@ bool URLRequest::SetExtraHeader(const std::string& name,
return false;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->SetExtraHeader(name, value);
}
return true;
}
@ -302,8 +305,11 @@ void URLRequest::RemoveExtraHeader(const std::string& name) {
// Cannot change headers after send.
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->RemoveExtraHeader(name);
}
}
void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
// State must be equal to not started.
@ -311,11 +317,24 @@ void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
// Cannot change headers after send.
return;
}
DCHECK(atom_request_);
if (atom_request_) {
atom_request_->SetChunkedUpload(is_chunked_upload);
}
}
void URLRequest::OnAuthenticationRequired(
scoped_refptr<const net::AuthChallengeInfo> auth_info) {
if (request_state_.Canceled() ||
request_state_.Closed()) {
return;
}
DCHECK(atom_request_);
if (!atom_request_) {
return;
}
EmitRequestEvent(
false,
"login",
@ -367,15 +386,15 @@ void URLRequest::OnResponseCompleted() {
}
void URLRequest::OnRequestError(const std::string& error) {
request_state_.SetFlag(RequestStateFlags::kFailed);
auto error_object = v8::Exception::Error(mate::StringToV8(isolate(), error));
request_state_.SetFlag(RequestStateFlags::kFailed);
EmitRequestEvent(false, "error", error_object);
Close();
}
void URLRequest::OnResponseError(const std::string& error) {
response_state_.SetFlag(ResponseStateFlags::kFailed);
auto error_object = v8::Exception::Error(mate::StringToV8(isolate(), error));
response_state_.SetFlag(ResponseStateFlags::kFailed);
EmitResponseEvent(false, "error", error_object);
Close();
}