Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/extensions/extension_webrequest_api_helpers.cc

Issue 8894003: Fix crasher if onBeforeSendHeaders contains no new headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_webrequest_api_helpers.h" 5 #include "chrome/browser/extensions/extension_webrequest_api_helpers.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_webrequest_api.h" 9 #include "chrome/browser/extensions/extension_webrequest_api.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 EventResponseDelta* CalculateOnBeforeSendHeadersDelta( 133 EventResponseDelta* CalculateOnBeforeSendHeadersDelta(
134 const std::string& extension_id, 134 const std::string& extension_id,
135 const base::Time& extension_install_time, 135 const base::Time& extension_install_time,
136 bool cancel, 136 bool cancel,
137 net::HttpRequestHeaders* old_headers, 137 net::HttpRequestHeaders* old_headers,
138 net::HttpRequestHeaders* new_headers) { 138 net::HttpRequestHeaders* new_headers) {
139 EventResponseDelta* result = 139 EventResponseDelta* result =
140 new EventResponseDelta(extension_id, extension_install_time); 140 new EventResponseDelta(extension_id, extension_install_time);
141 result->cancel = cancel; 141 result->cancel = cancel;
142 142
143 // Find deleted headers. 143 // The event listener might not have passed any new headers if he
144 { 144 // just wanted to cancel the request.
145 net::HttpRequestHeaders::Iterator i(*old_headers); 145 if (new_headers) {
146 while (i.GetNext()) { 146 // Find deleted headers.
147 if (!new_headers->HasHeader(i.name())) { 147 {
148 result->deleted_request_headers.push_back(i.name()); 148 net::HttpRequestHeaders::Iterator i(*old_headers);
149 while (i.GetNext()) {
150 if (!new_headers->HasHeader(i.name())) {
151 result->deleted_request_headers.push_back(i.name());
152 }
153 }
154 }
155
156 // Find modified headers.
157 {
158 net::HttpRequestHeaders::Iterator i(*new_headers);
159 while (i.GetNext()) {
160 std::string value;
161 if (!old_headers->GetHeader(i.name(), &value) || i.value() != value) {
162 result->modified_request_headers.SetHeader(i.name(), i.value());
163 }
149 } 164 }
150 } 165 }
151 } 166 }
152
153 // Find modified headers.
154 {
155 net::HttpRequestHeaders::Iterator i(*new_headers);
156 while (i.GetNext()) {
157 std::string value;
158 if (!old_headers->GetHeader(i.name(), &value) || i.value() != value) {
159 result->modified_request_headers.SetHeader(i.name(), i.value());
160 }
161 }
162 }
163 return result; 167 return result;
164 } 168 }
165 169
166 EventResponseDelta* CalculateOnHeadersReceivedDelta( 170 EventResponseDelta* CalculateOnHeadersReceivedDelta(
167 const std::string& extension_id, 171 const std::string& extension_id,
168 const base::Time& extension_install_time, 172 const base::Time& extension_install_time,
169 bool cancel, 173 bool cancel,
170 net::HttpResponseHeaders* old_response_headers, 174 net::HttpResponseHeaders* old_response_headers,
171 ResponseHeaders* new_response_headers) { 175 ResponseHeaders* new_response_headers) {
172 EventResponseDelta* result = 176 EventResponseDelta* result =
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 new NetLogExtensionIdParameter((*delta)->extension_id))); 538 new NetLogExtensionIdParameter((*delta)->extension_id)));
535 event_log_entries->push_back(log_entry); 539 event_log_entries->push_back(log_entry);
536 *auth_credentials = *(*delta)->auth_credentials; 540 *auth_credentials = *(*delta)->auth_credentials;
537 credentials_set = true; 541 credentials_set = true;
538 } 542 }
539 } 543 }
540 return credentials_set; 544 return credentials_set;
541 } 545 }
542 546
543 } // namespace extension_webrequest_api_helpers 547 } // namespace extension_webrequest_api_helpers
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698