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

Side by Side Diff: extensions/browser/api/web_request/web_request_api_helpers.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extensions/browser/api/web_request/web_request_api_helpers.h" 5 #include "extensions/browser/api/web_request/web_request_api_helpers.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 EventResponseDelta* result = 295 EventResponseDelta* result =
296 new EventResponseDelta(extension_id, extension_install_time); 296 new EventResponseDelta(extension_id, extension_install_time);
297 result->cancel = cancel; 297 result->cancel = cancel;
298 result->new_url = new_url; 298 result->new_url = new_url;
299 299
300 if (!new_response_headers) 300 if (!new_response_headers)
301 return result; 301 return result;
302 302
303 // Find deleted headers (header keys are treated case insensitively). 303 // Find deleted headers (header keys are treated case insensitively).
304 { 304 {
305 void* iter = NULL; 305 void* iter = nullptr;
306 std::string name; 306 std::string name;
307 std::string value; 307 std::string value;
308 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) { 308 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) {
309 std::string name_lowercase(name); 309 std::string name_lowercase(name);
310 base::StringToLowerASCII(&name_lowercase); 310 base::StringToLowerASCII(&name_lowercase);
311 311
312 bool header_found = false; 312 bool header_found = false;
313 for (ResponseHeaders::const_iterator i = new_response_headers->begin(); 313 for (ResponseHeaders::const_iterator i = new_response_headers->begin();
314 i != new_response_headers->end(); ++i) { 314 i != new_response_headers->end(); ++i) {
315 if (LowerCaseEqualsASCII(i->first, name_lowercase.c_str()) && 315 if (LowerCaseEqualsASCII(i->first, name_lowercase.c_str()) &&
316 value == i->second) { 316 value == i->second) {
317 header_found = true; 317 header_found = true;
318 break; 318 break;
319 } 319 }
320 } 320 }
321 if (!header_found) 321 if (!header_found)
322 result->deleted_response_headers.push_back(ResponseHeader(name, value)); 322 result->deleted_response_headers.push_back(ResponseHeader(name, value));
323 } 323 }
324 } 324 }
325 325
326 // Find added headers (header keys are treated case insensitively). 326 // Find added headers (header keys are treated case insensitively).
327 { 327 {
328 for (ResponseHeaders::const_iterator i = new_response_headers->begin(); 328 for (ResponseHeaders::const_iterator i = new_response_headers->begin();
329 i != new_response_headers->end(); ++i) { 329 i != new_response_headers->end(); ++i) {
330 void* iter = NULL; 330 void* iter = nullptr;
331 std::string value; 331 std::string value;
332 bool header_found = false; 332 bool header_found = false;
333 while (old_response_headers->EnumerateHeader(&iter, i->first, &value) && 333 while (old_response_headers->EnumerateHeader(&iter, i->first, &value) &&
334 !header_found) { 334 !header_found) {
335 header_found = (value == i->second); 335 header_found = (value == i->second);
336 } 336 }
337 if (!header_found) 337 if (!header_found)
338 result->added_response_headers.push_back(*i); 338 result->added_response_headers.push_back(*i);
339 } 339 }
340 } 340 }
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 752
753 MergeCookiesInOnBeforeSendHeadersResponses(deltas, request_headers, 753 MergeCookiesInOnBeforeSendHeadersResponses(deltas, request_headers,
754 conflicting_extensions, net_log); 754 conflicting_extensions, net_log);
755 } 755 }
756 756
757 // Retrives all cookies from |override_response_headers|. 757 // Retrives all cookies from |override_response_headers|.
758 static ParsedResponseCookies GetResponseCookies( 758 static ParsedResponseCookies GetResponseCookies(
759 scoped_refptr<net::HttpResponseHeaders> override_response_headers) { 759 scoped_refptr<net::HttpResponseHeaders> override_response_headers) {
760 ParsedResponseCookies result; 760 ParsedResponseCookies result;
761 761
762 void* iter = NULL; 762 void* iter = nullptr;
763 std::string value; 763 std::string value;
764 while (override_response_headers->EnumerateHeader(&iter, "Set-Cookie", 764 while (override_response_headers->EnumerateHeader(&iter, "Set-Cookie",
765 &value)) { 765 &value)) {
766 result.push_back(make_linked_ptr(new net::ParsedCookie(value))); 766 result.push_back(make_linked_ptr(new net::ParsedCookie(value)));
767 } 767 }
768 return result; 768 return result;
769 } 769 }
770 770
771 // Stores all |cookies| in |override_response_headers| deleting previously 771 // Stores all |cookies| in |override_response_headers| deleting previously
772 // existing cookie definitions. 772 // existing cookie definitions.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 bool cookie_modifications_exist = false; 954 bool cookie_modifications_exist = false;
955 EventResponseDeltas::const_reverse_iterator delta; 955 EventResponseDeltas::const_reverse_iterator delta;
956 for (delta = deltas.rbegin(); delta != deltas.rend(); ++delta) { 956 for (delta = deltas.rbegin(); delta != deltas.rend(); ++delta) {
957 cookie_modifications_exist |= 957 cookie_modifications_exist |=
958 !(*delta)->response_cookie_modifications.empty(); 958 !(*delta)->response_cookie_modifications.empty();
959 } 959 }
960 if (!cookie_modifications_exist) 960 if (!cookie_modifications_exist)
961 return; 961 return;
962 962
963 // Only create a copy if we really want to modify the response headers. 963 // Only create a copy if we really want to modify the response headers.
964 if (override_response_headers->get() == NULL) { 964 if (override_response_headers->get() == nullptr) {
965 *override_response_headers = new net::HttpResponseHeaders( 965 *override_response_headers = new net::HttpResponseHeaders(
966 original_response_headers->raw_headers()); 966 original_response_headers->raw_headers());
967 } 967 }
968 968
969 ParsedResponseCookies cookies = 969 ParsedResponseCookies cookies =
970 GetResponseCookies(*override_response_headers); 970 GetResponseCookies(*override_response_headers);
971 971
972 bool modified = false; 972 bool modified = false;
973 modified |= MergeAddResponseCookieModifications(deltas, &cookies); 973 modified |= MergeAddResponseCookieModifications(deltas, &cookies);
974 modified |= MergeEditResponseCookieModifications(deltas, &cookies); 974 modified |= MergeEditResponseCookieModifications(deltas, &cookies);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1021
1022 // We assume here that the deltas are sorted in decreasing extension 1022 // We assume here that the deltas are sorted in decreasing extension
1023 // precedence (i.e. decreasing extension installation time). 1023 // precedence (i.e. decreasing extension installation time).
1024 for (delta = deltas.begin(); delta != deltas.end(); ++delta) { 1024 for (delta = deltas.begin(); delta != deltas.end(); ++delta) {
1025 if ((*delta)->added_response_headers.empty() && 1025 if ((*delta)->added_response_headers.empty() &&
1026 (*delta)->deleted_response_headers.empty()) { 1026 (*delta)->deleted_response_headers.empty()) {
1027 continue; 1027 continue;
1028 } 1028 }
1029 1029
1030 // Only create a copy if we really want to modify the response headers. 1030 // Only create a copy if we really want to modify the response headers.
1031 if (override_response_headers->get() == NULL) { 1031 if (override_response_headers->get() == nullptr) {
1032 *override_response_headers = new net::HttpResponseHeaders( 1032 *override_response_headers = new net::HttpResponseHeaders(
1033 original_response_headers->raw_headers()); 1033 original_response_headers->raw_headers());
1034 } 1034 }
1035 1035
1036 // We consider modifications as pairs of (delete, add) operations. 1036 // We consider modifications as pairs of (delete, add) operations.
1037 // If a header is deleted twice by different extensions we assume that the 1037 // If a header is deleted twice by different extensions we assume that the
1038 // intention was to modify it to different values and consider this a 1038 // intention was to modify it to different values and consider this a
1039 // conflict. As deltas is sorted by decreasing extension installation order, 1039 // conflict. As deltas is sorted by decreasing extension installation order,
1040 // this takes care of precedence. 1040 // this takes care of precedence.
1041 bool extension_conflicts = false; 1041 bool extension_conflicts = false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1089 }
1090 1090
1091 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers, 1091 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers,
1092 override_response_headers, conflicting_extensions, net_log); 1092 override_response_headers, conflicting_extensions, net_log);
1093 1093
1094 GURL new_url; 1094 GURL new_url;
1095 MergeRedirectUrlOfResponses( 1095 MergeRedirectUrlOfResponses(
1096 deltas, &new_url, conflicting_extensions, net_log); 1096 deltas, &new_url, conflicting_extensions, net_log);
1097 if (new_url.is_valid()) { 1097 if (new_url.is_valid()) {
1098 // Only create a copy if we really want to modify the response headers. 1098 // Only create a copy if we really want to modify the response headers.
1099 if (override_response_headers->get() == NULL) { 1099 if (override_response_headers->get() == nullptr) {
1100 *override_response_headers = new net::HttpResponseHeaders( 1100 *override_response_headers = new net::HttpResponseHeaders(
1101 original_response_headers->raw_headers()); 1101 original_response_headers->raw_headers());
1102 } 1102 }
1103 (*override_response_headers)->ReplaceStatusLine("HTTP/1.1 302 Found"); 1103 (*override_response_headers)->ReplaceStatusLine("HTTP/1.1 302 Found");
1104 (*override_response_headers)->RemoveHeader("location"); 1104 (*override_response_headers)->RemoveHeader("location");
1105 (*override_response_headers)->AddHeader("Location: " + new_url.spec()); 1105 (*override_response_headers)->AddHeader("Location: " + new_url.spec());
1106 // Explicitly mark the URL as safe for redirection, to prevent the request 1106 // Explicitly mark the URL as safe for redirection, to prevent the request
1107 // from being blocked because of net::ERR_UNSAFE_REDIRECT. 1107 // from being blocked because of net::ERR_UNSAFE_REDIRECT.
1108 *allowed_unsafe_redirect_url = new_url; 1108 *allowed_unsafe_redirect_url = new_url;
1109 } 1109 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); 1193 for (extensions::ExtensionSet::const_iterator it = extensions.begin();
1194 !webrequest_used && it != extensions.end(); 1194 !webrequest_used && it != extensions.end();
1195 ++it) { 1195 ++it) {
1196 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); 1196 webrequest_used |= runtime_data->HasUsedWebRequest(it->get());
1197 } 1197 }
1198 1198
1199 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); 1199 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used));
1200 } 1200 }
1201 1201
1202 } // namespace extension_web_request_api_helpers 1202 } // namespace extension_web_request_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698