OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
27 #include "extensions/browser/extensions_browser_client.h" | 27 #include "extensions/browser/extensions_browser_client.h" |
28 #include "extensions/browser/runtime_data.h" | 28 #include "extensions/browser/runtime_data.h" |
29 #include "extensions/browser/warning_set.h" | 29 #include "extensions/browser/warning_set.h" |
30 #include "extensions/common/extension_messages.h" | 30 #include "extensions/common/extension_messages.h" |
31 #include "net/cookies/cookie_util.h" | 31 #include "net/cookies/cookie_util.h" |
32 #include "net/cookies/parsed_cookie.h" | 32 #include "net/cookies/parsed_cookie.h" |
33 #include "net/http/http_util.h" | 33 #include "net/http/http_util.h" |
34 #include "net/log/net_log.h" | 34 #include "net/log/net_log.h" |
| 35 #include "net/log/net_log_event_type.h" |
35 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
36 #include "url/url_constants.h" | 37 #include "url/url_constants.h" |
37 | 38 |
38 // TODO(battre): move all static functions into an anonymous namespace at the | 39 // TODO(battre): move all static functions into an anonymous namespace at the |
39 // top of this file. | 40 // top of this file. |
40 | 41 |
41 using base::Time; | 42 using base::Time; |
42 using content::ResourceType; | 43 using content::ResourceType; |
43 using net::cookie_util::ParsedRequestCookie; | 44 using net::cookie_util::ParsedRequestCookie; |
44 using net::cookie_util::ParsedRequestCookies; | 45 using net::cookie_util::ParsedRequestCookies; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 437 } |
437 | 438 |
438 void MergeCancelOfResponses( | 439 void MergeCancelOfResponses( |
439 const EventResponseDeltas& deltas, | 440 const EventResponseDeltas& deltas, |
440 bool* canceled, | 441 bool* canceled, |
441 const net::BoundNetLog* net_log) { | 442 const net::BoundNetLog* net_log) { |
442 for (EventResponseDeltas::const_iterator i = deltas.begin(); | 443 for (EventResponseDeltas::const_iterator i = deltas.begin(); |
443 i != deltas.end(); ++i) { | 444 i != deltas.end(); ++i) { |
444 if ((*i)->cancel) { | 445 if ((*i)->cancel) { |
445 *canceled = true; | 446 *canceled = true; |
446 net_log->AddEvent( | 447 net_log->AddEvent(net::NetLogEventType::CHROME_EXTENSION_ABORTED_REQUEST, |
447 net::NetLog::TYPE_CHROME_EXTENSION_ABORTED_REQUEST, | 448 CreateNetLogExtensionIdCallback(i->get())); |
448 CreateNetLogExtensionIdCallback(i->get())); | |
449 break; | 449 break; |
450 } | 450 } |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 // Helper function for MergeRedirectUrlOfResponses() that allows ignoring | 454 // Helper function for MergeRedirectUrlOfResponses() that allows ignoring |
455 // all redirects but those to data:// urls and about:blank. This is important | 455 // all redirects but those to data:// urls and about:blank. This is important |
456 // to treat these URLs as "cancel urls", i.e. URLs that extensions redirect | 456 // to treat these URLs as "cancel urls", i.e. URLs that extensions redirect |
457 // to if they want to express that they want to cancel a request. This reduces | 457 // to if they want to express that they want to cancel a request. This reduces |
458 // the number of conflicts that we need to flag, as canceling is considered | 458 // the number of conflicts that we need to flag, as canceling is considered |
(...skipping 17 matching lines...) Expand all Loading... |
476 !(*delta)->new_url.SchemeIs(url::kDataScheme) && | 476 !(*delta)->new_url.SchemeIs(url::kDataScheme) && |
477 (*delta)->new_url.spec() != "about:blank") { | 477 (*delta)->new_url.spec() != "about:blank") { |
478 continue; | 478 continue; |
479 } | 479 } |
480 | 480 |
481 if (!redirected || *new_url == (*delta)->new_url) { | 481 if (!redirected || *new_url == (*delta)->new_url) { |
482 *new_url = (*delta)->new_url; | 482 *new_url = (*delta)->new_url; |
483 winning_extension_id = (*delta)->extension_id; | 483 winning_extension_id = (*delta)->extension_id; |
484 redirected = true; | 484 redirected = true; |
485 net_log->AddEvent( | 485 net_log->AddEvent( |
486 net::NetLog::TYPE_CHROME_EXTENSION_REDIRECTED_REQUEST, | 486 net::NetLogEventType::CHROME_EXTENSION_REDIRECTED_REQUEST, |
487 CreateNetLogExtensionIdCallback(delta->get())); | 487 CreateNetLogExtensionIdCallback(delta->get())); |
488 } else { | 488 } else { |
489 conflicting_extensions->insert( | 489 conflicting_extensions->insert( |
490 extensions::Warning::CreateRedirectConflictWarning( | 490 extensions::Warning::CreateRedirectConflictWarning( |
491 (*delta)->extension_id, | 491 (*delta)->extension_id, |
492 winning_extension_id, | 492 winning_extension_id, |
493 (*delta)->new_url, | 493 (*delta)->new_url, |
494 *new_url)); | 494 *new_url)); |
495 net_log->AddEvent( | 495 net_log->AddEvent( |
496 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, | 496 net::NetLogEventType::CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, |
497 CreateNetLogExtensionIdCallback(delta->get())); | 497 CreateNetLogExtensionIdCallback(delta->get())); |
498 } | 498 } |
499 } | 499 } |
500 return redirected; | 500 return redirected; |
501 } | 501 } |
502 | 502 |
503 void MergeRedirectUrlOfResponses( | 503 void MergeRedirectUrlOfResponses( |
504 const EventResponseDeltas& deltas, | 504 const EventResponseDeltas& deltas, |
505 GURL* new_url, | 505 GURL* new_url, |
506 extensions::WarningSet* conflicting_extensions, | 506 extensions::WarningSet* conflicting_extensions, |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 // Perform all deletions and record which keys were deleted. | 811 // Perform all deletions and record which keys were deleted. |
812 { | 812 { |
813 std::vector<std::string>::iterator key; | 813 std::vector<std::string>::iterator key; |
814 for (key = (*delta)->deleted_request_headers.begin(); | 814 for (key = (*delta)->deleted_request_headers.begin(); |
815 key != (*delta)->deleted_request_headers.end(); | 815 key != (*delta)->deleted_request_headers.end(); |
816 ++key) { | 816 ++key) { |
817 request_headers->RemoveHeader(*key); | 817 request_headers->RemoveHeader(*key); |
818 removed_headers.insert(*key); | 818 removed_headers.insert(*key); |
819 } | 819 } |
820 } | 820 } |
821 net_log->AddEvent( | 821 net_log->AddEvent(net::NetLogEventType::CHROME_EXTENSION_MODIFIED_HEADERS, |
822 net::NetLog::TYPE_CHROME_EXTENSION_MODIFIED_HEADERS, | 822 base::Bind(&NetLogModificationCallback, delta->get())); |
823 base::Bind(&NetLogModificationCallback, delta->get())); | |
824 } else { | 823 } else { |
825 conflicting_extensions->insert( | 824 conflicting_extensions->insert( |
826 extensions::Warning::CreateRequestHeaderConflictWarning( | 825 extensions::Warning::CreateRequestHeaderConflictWarning( |
827 (*delta)->extension_id, winning_extension_id, | 826 (*delta)->extension_id, winning_extension_id, |
828 conflicting_header)); | 827 conflicting_header)); |
829 net_log->AddEvent( | 828 net_log->AddEvent( |
830 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, | 829 net::NetLogEventType::CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, |
831 CreateNetLogExtensionIdCallback(delta->get())); | 830 CreateNetLogExtensionIdCallback(delta->get())); |
832 } | 831 } |
833 } | 832 } |
834 | 833 |
835 MergeCookiesInOnBeforeSendHeadersResponses(deltas, request_headers, | 834 MergeCookiesInOnBeforeSendHeadersResponses(deltas, request_headers, |
836 conflicting_extensions, net_log); | 835 conflicting_extensions, net_log); |
837 } | 836 } |
838 | 837 |
839 // Retrives all cookies from |override_response_headers|. | 838 // Retrives all cookies from |override_response_headers|. |
840 static ParsedResponseCookies GetResponseCookies( | 839 static ParsedResponseCookies GetResponseCookies( |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 { | 1143 { |
1145 for (i = (*delta)->added_response_headers.begin(); | 1144 for (i = (*delta)->added_response_headers.begin(); |
1146 i != (*delta)->added_response_headers.end(); ++i) { | 1145 i != (*delta)->added_response_headers.end(); ++i) { |
1147 ResponseHeader lowercase_header(ToLowerCase(*i)); | 1146 ResponseHeader lowercase_header(ToLowerCase(*i)); |
1148 if (added_headers.find(lowercase_header) != added_headers.end()) | 1147 if (added_headers.find(lowercase_header) != added_headers.end()) |
1149 continue; | 1148 continue; |
1150 added_headers.insert(lowercase_header); | 1149 added_headers.insert(lowercase_header); |
1151 (*override_response_headers)->AddHeader(i->first + ": " + i->second); | 1150 (*override_response_headers)->AddHeader(i->first + ": " + i->second); |
1152 } | 1151 } |
1153 } | 1152 } |
1154 net_log->AddEvent( | 1153 net_log->AddEvent(net::NetLogEventType::CHROME_EXTENSION_MODIFIED_HEADERS, |
1155 net::NetLog::TYPE_CHROME_EXTENSION_MODIFIED_HEADERS, | 1154 CreateNetLogExtensionIdCallback(delta->get())); |
1156 CreateNetLogExtensionIdCallback(delta->get())); | |
1157 } else { | 1155 } else { |
1158 conflicting_extensions->insert( | 1156 conflicting_extensions->insert( |
1159 extensions::Warning::CreateResponseHeaderConflictWarning( | 1157 extensions::Warning::CreateResponseHeaderConflictWarning( |
1160 (*delta)->extension_id, winning_extension_id, | 1158 (*delta)->extension_id, winning_extension_id, |
1161 conflicting_header)); | 1159 conflicting_header)); |
1162 net_log->AddEvent( | 1160 net_log->AddEvent( |
1163 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, | 1161 net::NetLogEventType::CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, |
1164 CreateNetLogExtensionIdCallback(delta->get())); | 1162 CreateNetLogExtensionIdCallback(delta->get())); |
1165 } | 1163 } |
1166 } | 1164 } |
1167 | 1165 |
1168 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers, | 1166 MergeCookiesInOnHeadersReceivedResponses(deltas, original_response_headers, |
1169 override_response_headers, conflicting_extensions, net_log); | 1167 override_response_headers, conflicting_extensions, net_log); |
1170 | 1168 |
1171 GURL new_url; | 1169 GURL new_url; |
1172 MergeRedirectUrlOfResponses( | 1170 MergeRedirectUrlOfResponses( |
1173 deltas, &new_url, conflicting_extensions, net_log); | 1171 deltas, &new_url, conflicting_extensions, net_log); |
(...skipping 28 matching lines...) Expand all Loading... |
1202 continue; | 1200 continue; |
1203 bool different = | 1201 bool different = |
1204 auth_credentials->username() != | 1202 auth_credentials->username() != |
1205 (*delta)->auth_credentials->username() || | 1203 (*delta)->auth_credentials->username() || |
1206 auth_credentials->password() != (*delta)->auth_credentials->password(); | 1204 auth_credentials->password() != (*delta)->auth_credentials->password(); |
1207 if (credentials_set && different) { | 1205 if (credentials_set && different) { |
1208 conflicting_extensions->insert( | 1206 conflicting_extensions->insert( |
1209 extensions::Warning::CreateCredentialsConflictWarning( | 1207 extensions::Warning::CreateCredentialsConflictWarning( |
1210 (*delta)->extension_id, winning_extension_id)); | 1208 (*delta)->extension_id, winning_extension_id)); |
1211 net_log->AddEvent( | 1209 net_log->AddEvent( |
1212 net::NetLog::TYPE_CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, | 1210 net::NetLogEventType::CHROME_EXTENSION_IGNORED_DUE_TO_CONFLICT, |
1213 CreateNetLogExtensionIdCallback(delta->get())); | 1211 CreateNetLogExtensionIdCallback(delta->get())); |
1214 } else { | 1212 } else { |
1215 net_log->AddEvent( | 1213 net_log->AddEvent( |
1216 net::NetLog::TYPE_CHROME_EXTENSION_PROVIDE_AUTH_CREDENTIALS, | 1214 net::NetLogEventType::CHROME_EXTENSION_PROVIDE_AUTH_CREDENTIALS, |
1217 CreateNetLogExtensionIdCallback(delta->get())); | 1215 CreateNetLogExtensionIdCallback(delta->get())); |
1218 *auth_credentials = *(*delta)->auth_credentials; | 1216 *auth_credentials = *(*delta)->auth_credentials; |
1219 credentials_set = true; | 1217 credentials_set = true; |
1220 winning_extension_id = (*delta)->extension_id; | 1218 winning_extension_id = (*delta)->extension_id; |
1221 } | 1219 } |
1222 } | 1220 } |
1223 return credentials_set; | 1221 return credentials_set; |
1224 } | 1222 } |
1225 | 1223 |
1226 void ClearCacheOnNavigation() { | 1224 void ClearCacheOnNavigation() { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { | 1314 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { |
1317 if (type_str == kResourceTypeStrings[i]) { | 1315 if (type_str == kResourceTypeStrings[i]) { |
1318 found = true; | 1316 found = true; |
1319 types->push_back(kResourceTypeValues[i]); | 1317 types->push_back(kResourceTypeValues[i]); |
1320 } | 1318 } |
1321 } | 1319 } |
1322 return found; | 1320 return found; |
1323 } | 1321 } |
1324 | 1322 |
1325 } // namespace extension_web_request_api_helpers | 1323 } // namespace extension_web_request_api_helpers |
OLD | NEW |