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

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

Issue 154473002: Support redirectUrl at onHeadersReceived in WebRequest / DWR API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 10 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 "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 5 #include "chrome/browser/extensions/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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 316 }
317 } 317 }
318 } 318 }
319 return result; 319 return result;
320 } 320 }
321 321
322 EventResponseDelta* CalculateOnHeadersReceivedDelta( 322 EventResponseDelta* CalculateOnHeadersReceivedDelta(
323 const std::string& extension_id, 323 const std::string& extension_id,
324 const base::Time& extension_install_time, 324 const base::Time& extension_install_time,
325 bool cancel, 325 bool cancel,
326 const GURL& new_url,
326 const net::HttpResponseHeaders* old_response_headers, 327 const net::HttpResponseHeaders* old_response_headers,
327 ResponseHeaders* new_response_headers) { 328 ResponseHeaders* new_response_headers) {
328 EventResponseDelta* result = 329 EventResponseDelta* result =
329 new EventResponseDelta(extension_id, extension_install_time); 330 new EventResponseDelta(extension_id, extension_install_time);
330 result->cancel = cancel; 331 result->cancel = cancel;
332 result->new_url = new_url;
331 333
332 if (!new_response_headers) 334 if (!new_response_headers)
333 return result; 335 return result;
334 336
335 // Find deleted headers (header keys are treated case insensitively). 337 // Find deleted headers (header keys are treated case insensitively).
336 { 338 {
337 void* iter = NULL; 339 void* iter = NULL;
338 std::string name; 340 std::string name;
339 std::string value; 341 std::string value;
340 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) { 342 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if ((*i)->cancel) { 397 if ((*i)->cancel) {
396 *canceled = true; 398 *canceled = true;
397 net_log->AddEvent( 399 net_log->AddEvent(
398 net::NetLog::TYPE_CHROME_EXTENSION_ABORTED_REQUEST, 400 net::NetLog::TYPE_CHROME_EXTENSION_ABORTED_REQUEST,
399 CreateNetLogExtensionIdCallback(i->get())); 401 CreateNetLogExtensionIdCallback(i->get()));
400 break; 402 break;
401 } 403 }
402 } 404 }
403 } 405 }
404 406
405 // Helper function for MergeOnBeforeRequestResponses() that allows ignoring 407 // Helper function for MergeRedirectUrlOfResponses() that allows ignoring
406 // all redirects but those to data:// urls and about:blank. This is important 408 // all redirects but those to data:// urls and about:blank. This is important
407 // to treat these URLs as "cancel urls", i.e. URLs that extensions redirect 409 // to treat these URLs as "cancel urls", i.e. URLs that extensions redirect
408 // to if they want to express that they want to cancel a request. This reduces 410 // to if they want to express that they want to cancel a request. This reduces
409 // the number of conflicts that we need to flag, as canceling is considered 411 // the number of conflicts that we need to flag, as canceling is considered
410 // a higher precedence operation that redirects. 412 // a higher precedence operation that redirects.
411 // Returns whether a redirect occurred. 413 // Returns whether a redirect occurred.
412 static bool MergeOnBeforeRequestResponsesHelper( 414 static bool MergeRedirectUrlOfResponsesHelper(
413 const EventResponseDeltas& deltas, 415 const EventResponseDeltas& deltas,
414 GURL* new_url, 416 GURL* new_url,
415 extensions::ExtensionWarningSet* conflicting_extensions, 417 extensions::ExtensionWarningSet* conflicting_extensions,
416 const net::BoundNetLog* net_log, 418 const net::BoundNetLog* net_log,
417 bool consider_only_cancel_scheme_urls) { 419 bool consider_only_cancel_scheme_urls) {
418 bool redirected = false; 420 bool redirected = false;
419 421
420 // Extension that determines the |new_url|. 422 // Extension that determines the |new_url|.
421 std::string winning_extension_id; 423 std::string winning_extension_id;
422 EventResponseDeltas::const_iterator delta; 424 EventResponseDeltas::const_iterator delta;
(...skipping 21 matching lines...) Expand all
444 (*delta)->new_url, 446 (*delta)->new_url,
445 *new_url)); 447 *new_url));
446 net_log->AddEvent( 448 net_log->AddEvent(
447 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, 449 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT,
448 CreateNetLogExtensionIdCallback(delta->get())); 450 CreateNetLogExtensionIdCallback(delta->get()));
449 } 451 }
450 } 452 }
451 return redirected; 453 return redirected;
452 } 454 }
453 455
454 void MergeOnBeforeRequestResponses( 456 void MergeRedirectUrlOfResponses(
455 const EventResponseDeltas& deltas, 457 const EventResponseDeltas& deltas,
456 GURL* new_url, 458 GURL* new_url,
457 extensions::ExtensionWarningSet* conflicting_extensions, 459 extensions::ExtensionWarningSet* conflicting_extensions,
458 const net::BoundNetLog* net_log) { 460 const net::BoundNetLog* net_log) {
459 461
460 // First handle only redirects to data:// URLs and about:blank. These are a 462 // First handle only redirects to data:// URLs and about:blank. These are a
461 // special case as they represent a way of cancelling a request. 463 // special case as they represent a way of cancelling a request.
462 if (MergeOnBeforeRequestResponsesHelper( 464 if (MergeRedirectUrlOfResponsesHelper(
463 deltas, new_url, conflicting_extensions, net_log, true)) { 465 deltas, new_url, conflicting_extensions, net_log, true)) {
464 // If any extension cancelled a request by redirecting to a data:// URL or 466 // If any extension cancelled a request by redirecting to a data:// URL or
465 // about:blank, we don't consider the other redirects. 467 // about:blank, we don't consider the other redirects.
466 return; 468 return;
467 } 469 }
468 470
469 // Handle all other redirects. 471 // Handle all other redirects.
470 MergeOnBeforeRequestResponsesHelper( 472 MergeRedirectUrlOfResponsesHelper(
471 deltas, new_url, conflicting_extensions, net_log, false); 473 deltas, new_url, conflicting_extensions, net_log, false);
472 } 474 }
473 475
476 void MergeOnBeforeRequestResponses(
477 const EventResponseDeltas& deltas,
478 GURL* new_url,
479 extensions::ExtensionWarningSet* conflicting_extensions,
480 const net::BoundNetLog* net_log) {
481 MergeRedirectUrlOfResponses(deltas, new_url, conflicting_extensions, net_log);
482 }
483
474 // Assumes that |header_value| is the cookie header value of a HTTP Request 484 // Assumes that |header_value| is the cookie header value of a HTTP Request
475 // following the cookie-string schema of RFC 6265, section 4.2.1, and returns 485 // following the cookie-string schema of RFC 6265, section 4.2.1, and returns
476 // cookie name/value pairs. If cookie values are presented in double quotes, 486 // cookie name/value pairs. If cookie values are presented in double quotes,
477 // these will appear in |parsed| as well. We can assume that the cookie header 487 // these will appear in |parsed| as well. We can assume that the cookie header
478 // is written by Chromium and therefore, well-formed. 488 // is written by Chromium and therefore, well-formed.
479 static void ParseRequestCookieLine( 489 static void ParseRequestCookieLine(
480 const std::string& header_value, 490 const std::string& header_value,
481 ParsedRequestCookies* parsed_cookies) { 491 ParsedRequestCookies* parsed_cookies) {
482 std::string::const_iterator i = header_value.begin(); 492 std::string::const_iterator i = header_value.begin();
483 while (i != header_value.end()) { 493 while (i != header_value.end()) {
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 i != (*delta)->deleted_response_headers.end(); ++i) { 1100 i != (*delta)->deleted_response_headers.end(); ++i) {
1091 if (StringToLowerASCII(i->first) == lower_key) 1101 if (StringToLowerASCII(i->first) == lower_key)
1092 return (*delta)->extension_id; 1102 return (*delta)->extension_id;
1093 } 1103 }
1094 } 1104 }
1095 return std::string(); 1105 return std::string();
1096 } 1106 }
1097 1107
1098 void MergeOnHeadersReceivedResponses( 1108 void MergeOnHeadersReceivedResponses(
1099 const EventResponseDeltas& deltas, 1109 const EventResponseDeltas& deltas,
1110 GURL* new_url,
1100 const net::HttpResponseHeaders* original_response_headers, 1111 const net::HttpResponseHeaders* original_response_headers,
1101 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, 1112 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
1102 extensions::ExtensionWarningSet* conflicting_extensions, 1113 extensions::ExtensionWarningSet* conflicting_extensions,
1103 const net::BoundNetLog* net_log) { 1114 const net::BoundNetLog* net_log) {
1104 EventResponseDeltas::const_iterator delta; 1115 EventResponseDeltas::const_iterator delta;
1105 1116
1106 // Here we collect which headers we have removed or added so far due to 1117 // Here we collect which headers we have removed or added so far due to
1107 // extensions of higher precedence. Header keys are always stored as 1118 // extensions of higher precedence. Header keys are always stored as
1108 // lower case. 1119 // lower case.
1109 std::set<ResponseHeader> removed_headers; 1120 std::set<ResponseHeader> removed_headers;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 (*delta)->extension_id, winning_extension_id, 1184 (*delta)->extension_id, winning_extension_id,
1174 conflicting_header)); 1185 conflicting_header));
1175 net_log->AddEvent( 1186 net_log->AddEvent(
1176 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, 1187 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT,
1177 CreateNetLogExtensionIdCallback(delta->get())); 1188 CreateNetLogExtensionIdCallback(delta->get()));
1178 } 1189 }
1179 } 1190 }
1180 1191
1181 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers, 1192 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers,
1182 override_response_headers, conflicting_extensions, net_log); 1193 override_response_headers, conflicting_extensions, net_log);
1194
1195 MergeRedirectUrlOfResponses(deltas, new_url, conflicting_extensions, net_log);
1183 } 1196 }
1184 1197
1185 bool MergeOnAuthRequiredResponses( 1198 bool MergeOnAuthRequiredResponses(
1186 const EventResponseDeltas& deltas, 1199 const EventResponseDeltas& deltas,
1187 net::AuthCredentials* auth_credentials, 1200 net::AuthCredentials* auth_credentials,
1188 extensions::ExtensionWarningSet* conflicting_extensions, 1201 extensions::ExtensionWarningSet* conflicting_extensions,
1189 const net::BoundNetLog* net_log) { 1202 const net::BoundNetLog* net_log) {
1190 CHECK(auth_credentials); 1203 CHECK(auth_credentials);
1191 bool credentials_set = false; 1204 bool credentials_set = false;
1192 std::string winning_extension_id; 1205 std::string winning_extension_id;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 for (content::RenderProcessHost::iterator it = 1287 for (content::RenderProcessHost::iterator it =
1275 content::RenderProcessHost::AllHostsIterator(); 1288 content::RenderProcessHost::AllHostsIterator();
1276 !it.IsAtEnd(); it.Advance()) { 1289 !it.IsAtEnd(); it.Advance()) {
1277 content::RenderProcessHost* host = it.GetCurrentValue(); 1290 content::RenderProcessHost* host = it.GetCurrentValue();
1278 if (host->GetBrowserContext() == browser_context) 1291 if (host->GetBrowserContext() == browser_context)
1279 SendExtensionWebRequestStatusToHost(host); 1292 SendExtensionWebRequestStatusToHost(host);
1280 } 1293 }
1281 } 1294 }
1282 1295
1283 } // namespace extension_web_request_api_helpers 1296 } // namespace extension_web_request_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698