| 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 int num_handlers_blocking; | 488 int num_handlers_blocking; |
| 489 | 489 |
| 490 // Pointer to NetLog to report significant changes to the request for | 490 // Pointer to NetLog to report significant changes to the request for |
| 491 // debugging. | 491 // debugging. |
| 492 const net::BoundNetLog* net_log; | 492 const net::BoundNetLog* net_log; |
| 493 | 493 |
| 494 // The callback to call when we get a response from all event handlers. | 494 // The callback to call when we get a response from all event handlers. |
| 495 net::CompletionCallback callback; | 495 net::CompletionCallback callback; |
| 496 | 496 |
| 497 // If non-empty, this contains the new URL that the request will redirect to. | 497 // If non-empty, this contains the new URL that the request will redirect to. |
| 498 // Only valid for OnBeforeRequest. | 498 // Only valid for OnBeforeRequest and OnHeadersReceived. |
| 499 GURL* new_url; | 499 GURL* new_url; |
| 500 | 500 |
| 501 // The request headers that will be issued along with this request. Only valid | 501 // The request headers that will be issued along with this request. Only valid |
| 502 // for OnBeforeSendHeaders. | 502 // for OnBeforeSendHeaders. |
| 503 net::HttpRequestHeaders* request_headers; | 503 net::HttpRequestHeaders* request_headers; |
| 504 | 504 |
| 505 // The response headers that were received from the server. Only valid for | 505 // The response headers that were received from the server. Only valid for |
| 506 // OnHeadersReceived. | 506 // OnHeadersReceived. |
| 507 scoped_refptr<const net::HttpResponseHeaders> original_response_headers; | 507 scoped_refptr<const net::HttpResponseHeaders> original_response_headers; |
| 508 | 508 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 args.Append(dict); | 820 args.Append(dict); |
| 821 | 821 |
| 822 DispatchEvent(profile, request, listeners, args); | 822 DispatchEvent(profile, request, listeners, args); |
| 823 } | 823 } |
| 824 | 824 |
| 825 int ExtensionWebRequestEventRouter::OnHeadersReceived( | 825 int ExtensionWebRequestEventRouter::OnHeadersReceived( |
| 826 void* profile, | 826 void* profile, |
| 827 InfoMap* extension_info_map, | 827 InfoMap* extension_info_map, |
| 828 net::URLRequest* request, | 828 net::URLRequest* request, |
| 829 const net::CompletionCallback& callback, | 829 const net::CompletionCallback& callback, |
| 830 GURL* new_url, |
| 830 const net::HttpResponseHeaders* original_response_headers, | 831 const net::HttpResponseHeaders* original_response_headers, |
| 831 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 832 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { |
| 832 // We hide events from the system context as well as sensitive requests. | 833 // We hide events from the system context as well as sensitive requests. |
| 833 if (!profile || | 834 if (!profile || |
| 834 WebRequestPermissions::HideRequest(extension_info_map, request)) | 835 WebRequestPermissions::HideRequest(extension_info_map, request)) |
| 835 return net::OK; | 836 return net::OK; |
| 836 | 837 |
| 837 bool initialize_blocked_requests = false; | 838 bool initialize_blocked_requests = false; |
| 838 | 839 |
| 839 initialize_blocked_requests |= | 840 initialize_blocked_requests |= |
| (...skipping 27 matching lines...) Expand all Loading... |
| 867 | 868 |
| 868 if (!initialize_blocked_requests) | 869 if (!initialize_blocked_requests) |
| 869 return net::OK; // Nobody saw a reason for modifying the request. | 870 return net::OK; // Nobody saw a reason for modifying the request. |
| 870 | 871 |
| 871 blocked_requests_[request->identifier()].event = kOnHeadersReceived; | 872 blocked_requests_[request->identifier()].event = kOnHeadersReceived; |
| 872 blocked_requests_[request->identifier()].is_incognito |= | 873 blocked_requests_[request->identifier()].is_incognito |= |
| 873 IsIncognitoProfile(profile); | 874 IsIncognitoProfile(profile); |
| 874 blocked_requests_[request->identifier()].request = request; | 875 blocked_requests_[request->identifier()].request = request; |
| 875 blocked_requests_[request->identifier()].callback = callback; | 876 blocked_requests_[request->identifier()].callback = callback; |
| 876 blocked_requests_[request->identifier()].net_log = &request->net_log(); | 877 blocked_requests_[request->identifier()].net_log = &request->net_log(); |
| 878 blocked_requests_[request->identifier()].new_url = new_url; |
| 877 blocked_requests_[request->identifier()].override_response_headers = | 879 blocked_requests_[request->identifier()].override_response_headers = |
| 878 override_response_headers; | 880 override_response_headers; |
| 879 blocked_requests_[request->identifier()].original_response_headers = | 881 blocked_requests_[request->identifier()].original_response_headers = |
| 880 original_response_headers; | 882 original_response_headers; |
| 881 | 883 |
| 882 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) { | 884 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) { |
| 883 // If there are no blocking handlers, only the declarative rules tried | 885 // If there are no blocking handlers, only the declarative rules tried |
| 884 // to modify the request and we can respond synchronously. | 886 // to modify the request and we can respond synchronously. |
| 885 return ExecuteDeltas(profile, request->identifier(), | 887 return ExecuteDeltas(profile, request->identifier(), |
| 886 false /* call_callback*/); | 888 false /* call_callback*/); |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 response->extension_id, response->extension_install_time, | 1550 response->extension_id, response->extension_install_time, |
| 1549 response->cancel, old_headers, new_headers); | 1551 response->cancel, old_headers, new_headers); |
| 1550 } | 1552 } |
| 1551 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { | 1553 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { |
| 1552 const net::HttpResponseHeaders* old_headers = | 1554 const net::HttpResponseHeaders* old_headers = |
| 1553 blocked_request->original_response_headers.get(); | 1555 blocked_request->original_response_headers.get(); |
| 1554 helpers::ResponseHeaders* new_headers = | 1556 helpers::ResponseHeaders* new_headers = |
| 1555 response->response_headers.get(); | 1557 response->response_headers.get(); |
| 1556 return helpers::CalculateOnHeadersReceivedDelta( | 1558 return helpers::CalculateOnHeadersReceivedDelta( |
| 1557 response->extension_id, response->extension_install_time, | 1559 response->extension_id, response->extension_install_time, |
| 1558 response->cancel, old_headers, new_headers); | 1560 response->cancel, response->new_url, old_headers, new_headers); |
| 1559 } | 1561 } |
| 1560 case ExtensionWebRequestEventRouter::kOnAuthRequired: | 1562 case ExtensionWebRequestEventRouter::kOnAuthRequired: |
| 1561 return helpers::CalculateOnAuthRequiredDelta( | 1563 return helpers::CalculateOnAuthRequiredDelta( |
| 1562 response->extension_id, response->extension_install_time, | 1564 response->extension_id, response->extension_install_time, |
| 1563 response->cancel, &response->auth_credentials); | 1565 response->cancel, &response->auth_credentials); |
| 1564 default: | 1566 default: |
| 1565 NOTREACHED(); | 1567 NOTREACHED(); |
| 1566 break; | 1568 break; |
| 1567 } | 1569 } |
| 1568 return NULL; | 1570 return NULL; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 CHECK(!blocked_request.callback.is_null()); | 1838 CHECK(!blocked_request.callback.is_null()); |
| 1837 helpers::MergeOnBeforeSendHeadersResponses( | 1839 helpers::MergeOnBeforeSendHeadersResponses( |
| 1838 blocked_request.response_deltas, | 1840 blocked_request.response_deltas, |
| 1839 blocked_request.request_headers, | 1841 blocked_request.request_headers, |
| 1840 &warnings, | 1842 &warnings, |
| 1841 blocked_request.net_log); | 1843 blocked_request.net_log); |
| 1842 } else if (blocked_request.event == kOnHeadersReceived) { | 1844 } else if (blocked_request.event == kOnHeadersReceived) { |
| 1843 CHECK(!blocked_request.callback.is_null()); | 1845 CHECK(!blocked_request.callback.is_null()); |
| 1844 helpers::MergeOnHeadersReceivedResponses( | 1846 helpers::MergeOnHeadersReceivedResponses( |
| 1845 blocked_request.response_deltas, | 1847 blocked_request.response_deltas, |
| 1848 blocked_request.new_url, |
| 1846 blocked_request.original_response_headers.get(), | 1849 blocked_request.original_response_headers.get(), |
| 1847 blocked_request.override_response_headers, | 1850 blocked_request.override_response_headers, |
| 1848 &warnings, | 1851 &warnings, |
| 1849 blocked_request.net_log); | 1852 blocked_request.net_log); |
| 1850 } else if (blocked_request.event == kOnAuthRequired) { | 1853 } else if (blocked_request.event == kOnAuthRequired) { |
| 1851 CHECK(blocked_request.callback.is_null()); | 1854 CHECK(blocked_request.callback.is_null()); |
| 1852 CHECK(!blocked_request.auth_callback.is_null()); | 1855 CHECK(!blocked_request.auth_callback.is_null()); |
| 1853 credentials_set = helpers::MergeOnAuthRequiredResponses( | 1856 credentials_set = helpers::MergeOnAuthRequiredResponses( |
| 1854 blocked_request.response_deltas, | 1857 blocked_request.response_deltas, |
| 1855 blocked_request.auth_credentials, | 1858 blocked_request.auth_credentials, |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2383 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 2381 adblock = true; | 2384 adblock = true; |
| 2382 } else { | 2385 } else { |
| 2383 other = true; | 2386 other = true; |
| 2384 } | 2387 } |
| 2385 } | 2388 } |
| 2386 } | 2389 } |
| 2387 | 2390 |
| 2388 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2391 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 2389 } | 2392 } |
| OLD | NEW |