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 "chrome/browser/extensions/api/web_request/web_request_api.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 int num_handlers_blocking; | 491 int num_handlers_blocking; |
492 | 492 |
493 // Pointer to NetLog to report significant changes to the request for | 493 // Pointer to NetLog to report significant changes to the request for |
494 // debugging. | 494 // debugging. |
495 const net::BoundNetLog* net_log; | 495 const net::BoundNetLog* net_log; |
496 | 496 |
497 // The callback to call when we get a response from all event handlers. | 497 // The callback to call when we get a response from all event handlers. |
498 net::CompletionCallback callback; | 498 net::CompletionCallback callback; |
499 | 499 |
500 // If non-empty, this contains the new URL that the request will redirect to. | 500 // If non-empty, this contains the new URL that the request will redirect to. |
501 // Only valid for OnBeforeRequest. | 501 // Only valid for OnBeforeRequest and OnHeadersReceived. |
502 GURL* new_url; | 502 GURL* new_url; |
503 | 503 |
504 // The request headers that will be issued along with this request. Only valid | 504 // The request headers that will be issued along with this request. Only valid |
505 // for OnBeforeSendHeaders. | 505 // for OnBeforeSendHeaders. |
506 net::HttpRequestHeaders* request_headers; | 506 net::HttpRequestHeaders* request_headers; |
507 | 507 |
508 // The response headers that were received from the server. Only valid for | 508 // The response headers that were received from the server. Only valid for |
509 // OnHeadersReceived. | 509 // OnHeadersReceived. |
510 scoped_refptr<const net::HttpResponseHeaders> original_response_headers; | 510 scoped_refptr<const net::HttpResponseHeaders> original_response_headers; |
511 | 511 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 824 |
825 DispatchEvent(profile, request, listeners, args); | 825 DispatchEvent(profile, request, listeners, args); |
826 } | 826 } |
827 | 827 |
828 int ExtensionWebRequestEventRouter::OnHeadersReceived( | 828 int ExtensionWebRequestEventRouter::OnHeadersReceived( |
829 void* profile, | 829 void* profile, |
830 InfoMap* extension_info_map, | 830 InfoMap* extension_info_map, |
831 net::URLRequest* request, | 831 net::URLRequest* request, |
832 const net::CompletionCallback& callback, | 832 const net::CompletionCallback& callback, |
833 const net::HttpResponseHeaders* original_response_headers, | 833 const net::HttpResponseHeaders* original_response_headers, |
834 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 834 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 835 GURL* allowed_unsafe_redirect_url) { |
835 // We hide events from the system context as well as sensitive requests. | 836 // We hide events from the system context as well as sensitive requests. |
836 if (!profile || | 837 if (!profile || |
837 WebRequestPermissions::HideRequest(extension_info_map, request)) | 838 WebRequestPermissions::HideRequest(extension_info_map, request)) |
838 return net::OK; | 839 return net::OK; |
839 | 840 |
840 bool initialize_blocked_requests = false; | 841 bool initialize_blocked_requests = false; |
841 | 842 |
842 initialize_blocked_requests |= | 843 initialize_blocked_requests |= |
843 ProcessDeclarativeRules(profile, extension_info_map, | 844 ProcessDeclarativeRules(profile, extension_info_map, |
844 keys::kOnHeadersReceivedEvent, request, | 845 keys::kOnHeadersReceivedEvent, request, |
(...skipping 29 matching lines...) Expand all Loading... |
874 blocked_requests_[request->identifier()].event = kOnHeadersReceived; | 875 blocked_requests_[request->identifier()].event = kOnHeadersReceived; |
875 blocked_requests_[request->identifier()].is_incognito |= | 876 blocked_requests_[request->identifier()].is_incognito |= |
876 IsIncognitoProfile(profile); | 877 IsIncognitoProfile(profile); |
877 blocked_requests_[request->identifier()].request = request; | 878 blocked_requests_[request->identifier()].request = request; |
878 blocked_requests_[request->identifier()].callback = callback; | 879 blocked_requests_[request->identifier()].callback = callback; |
879 blocked_requests_[request->identifier()].net_log = &request->net_log(); | 880 blocked_requests_[request->identifier()].net_log = &request->net_log(); |
880 blocked_requests_[request->identifier()].override_response_headers = | 881 blocked_requests_[request->identifier()].override_response_headers = |
881 override_response_headers; | 882 override_response_headers; |
882 blocked_requests_[request->identifier()].original_response_headers = | 883 blocked_requests_[request->identifier()].original_response_headers = |
883 original_response_headers; | 884 original_response_headers; |
| 885 blocked_requests_[request->identifier()].new_url = |
| 886 allowed_unsafe_redirect_url; |
884 | 887 |
885 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) { | 888 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) { |
886 // If there are no blocking handlers, only the declarative rules tried | 889 // If there are no blocking handlers, only the declarative rules tried |
887 // to modify the request and we can respond synchronously. | 890 // to modify the request and we can respond synchronously. |
888 return ExecuteDeltas(profile, request->identifier(), | 891 return ExecuteDeltas(profile, request->identifier(), |
889 false /* call_callback*/); | 892 false /* call_callback*/); |
890 } else { | 893 } else { |
891 return net::ERR_IO_PENDING; | 894 return net::ERR_IO_PENDING; |
892 } | 895 } |
893 } | 896 } |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 return helpers::CalculateOnBeforeSendHeadersDelta( | 1553 return helpers::CalculateOnBeforeSendHeadersDelta( |
1551 response->extension_id, response->extension_install_time, | 1554 response->extension_id, response->extension_install_time, |
1552 response->cancel, old_headers, new_headers); | 1555 response->cancel, old_headers, new_headers); |
1553 } | 1556 } |
1554 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { | 1557 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { |
1555 const net::HttpResponseHeaders* old_headers = | 1558 const net::HttpResponseHeaders* old_headers = |
1556 blocked_request->original_response_headers.get(); | 1559 blocked_request->original_response_headers.get(); |
1557 helpers::ResponseHeaders* new_headers = | 1560 helpers::ResponseHeaders* new_headers = |
1558 response->response_headers.get(); | 1561 response->response_headers.get(); |
1559 return helpers::CalculateOnHeadersReceivedDelta( | 1562 return helpers::CalculateOnHeadersReceivedDelta( |
1560 response->extension_id, response->extension_install_time, | 1563 response->extension_id, |
1561 response->cancel, old_headers, new_headers); | 1564 response->extension_install_time, |
| 1565 response->cancel, |
| 1566 response->new_url, |
| 1567 old_headers, |
| 1568 new_headers); |
1562 } | 1569 } |
1563 case ExtensionWebRequestEventRouter::kOnAuthRequired: | 1570 case ExtensionWebRequestEventRouter::kOnAuthRequired: |
1564 return helpers::CalculateOnAuthRequiredDelta( | 1571 return helpers::CalculateOnAuthRequiredDelta( |
1565 response->extension_id, response->extension_install_time, | 1572 response->extension_id, response->extension_install_time, |
1566 response->cancel, &response->auth_credentials); | 1573 response->cancel, &response->auth_credentials); |
1567 default: | 1574 default: |
1568 NOTREACHED(); | 1575 NOTREACHED(); |
1569 break; | 1576 break; |
1570 } | 1577 } |
1571 return NULL; | 1578 return NULL; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 blocked_request.response_deltas, | 1848 blocked_request.response_deltas, |
1842 blocked_request.request_headers, | 1849 blocked_request.request_headers, |
1843 &warnings, | 1850 &warnings, |
1844 blocked_request.net_log); | 1851 blocked_request.net_log); |
1845 } else if (blocked_request.event == kOnHeadersReceived) { | 1852 } else if (blocked_request.event == kOnHeadersReceived) { |
1846 CHECK(!blocked_request.callback.is_null()); | 1853 CHECK(!blocked_request.callback.is_null()); |
1847 helpers::MergeOnHeadersReceivedResponses( | 1854 helpers::MergeOnHeadersReceivedResponses( |
1848 blocked_request.response_deltas, | 1855 blocked_request.response_deltas, |
1849 blocked_request.original_response_headers.get(), | 1856 blocked_request.original_response_headers.get(), |
1850 blocked_request.override_response_headers, | 1857 blocked_request.override_response_headers, |
| 1858 blocked_request.new_url, |
1851 &warnings, | 1859 &warnings, |
1852 blocked_request.net_log); | 1860 blocked_request.net_log); |
1853 } else if (blocked_request.event == kOnAuthRequired) { | 1861 } else if (blocked_request.event == kOnAuthRequired) { |
1854 CHECK(blocked_request.callback.is_null()); | 1862 CHECK(blocked_request.callback.is_null()); |
1855 CHECK(!blocked_request.auth_callback.is_null()); | 1863 CHECK(!blocked_request.auth_callback.is_null()); |
1856 credentials_set = helpers::MergeOnAuthRequiredResponses( | 1864 credentials_set = helpers::MergeOnAuthRequiredResponses( |
1857 blocked_request.response_deltas, | 1865 blocked_request.response_deltas, |
1858 blocked_request.auth_credentials, | 1866 blocked_request.auth_credentials, |
1859 &warnings, | 1867 &warnings, |
1860 blocked_request.net_log); | 1868 blocked_request.net_log); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2438 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2446 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
2439 adblock = true; | 2447 adblock = true; |
2440 } else { | 2448 } else { |
2441 other = true; | 2449 other = true; |
2442 } | 2450 } |
2443 } | 2451 } |
2444 } | 2452 } |
2445 | 2453 |
2446 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2454 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
2447 } | 2455 } |
OLD | NEW |