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

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

Issue 154473002: Support redirectUrl at onHeadersReceived in WebRequest / DWR API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass allowed_unsafe_redirect_url via delegate parameter instead of HttpResponseHeaders + fragment t… Created 6 years, 9 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.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
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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const net::HttpResponseHeaders* original_response_headers, 830 const net::HttpResponseHeaders* original_response_headers,
831 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { 831 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
832 GURL* allowed_unsafe_redirect_url) {
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 |=
840 ProcessDeclarativeRules(profile, extension_info_map, 841 ProcessDeclarativeRules(profile, extension_info_map,
841 keys::kOnHeadersReceivedEvent, request, 842 keys::kOnHeadersReceivedEvent, request,
(...skipping 29 matching lines...) Expand all
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();
877 blocked_requests_[request->identifier()].override_response_headers = 878 blocked_requests_[request->identifier()].override_response_headers =
878 override_response_headers; 879 override_response_headers;
879 blocked_requests_[request->identifier()].original_response_headers = 880 blocked_requests_[request->identifier()].original_response_headers =
880 original_response_headers; 881 original_response_headers;
882 blocked_requests_[request->identifier()].new_url =
883 allowed_unsafe_redirect_url;
881 884
882 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) { 885 if (blocked_requests_[request->identifier()].num_handlers_blocking == 0) {
883 // If there are no blocking handlers, only the declarative rules tried 886 // If there are no blocking handlers, only the declarative rules tried
884 // to modify the request and we can respond synchronously. 887 // to modify the request and we can respond synchronously.
885 return ExecuteDeltas(profile, request->identifier(), 888 return ExecuteDeltas(profile, request->identifier(),
886 false /* call_callback*/); 889 false /* call_callback*/);
887 } else { 890 } else {
888 return net::ERR_IO_PENDING; 891 return net::ERR_IO_PENDING;
889 } 892 }
890 } 893 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 response->extension_id, response->extension_install_time, 1551 response->extension_id, response->extension_install_time,
1549 response->cancel, old_headers, new_headers); 1552 response->cancel, old_headers, new_headers);
1550 } 1553 }
1551 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { 1554 case ExtensionWebRequestEventRouter::kOnHeadersReceived: {
1552 const net::HttpResponseHeaders* old_headers = 1555 const net::HttpResponseHeaders* old_headers =
1553 blocked_request->original_response_headers.get(); 1556 blocked_request->original_response_headers.get();
1554 helpers::ResponseHeaders* new_headers = 1557 helpers::ResponseHeaders* new_headers =
1555 response->response_headers.get(); 1558 response->response_headers.get();
1556 return helpers::CalculateOnHeadersReceivedDelta( 1559 return helpers::CalculateOnHeadersReceivedDelta(
1557 response->extension_id, response->extension_install_time, 1560 response->extension_id, response->extension_install_time,
1558 response->cancel, old_headers, new_headers); 1561 response->cancel, response->new_url, old_headers, new_headers);
1559 } 1562 }
1560 case ExtensionWebRequestEventRouter::kOnAuthRequired: 1563 case ExtensionWebRequestEventRouter::kOnAuthRequired:
1561 return helpers::CalculateOnAuthRequiredDelta( 1564 return helpers::CalculateOnAuthRequiredDelta(
1562 response->extension_id, response->extension_install_time, 1565 response->extension_id, response->extension_install_time,
1563 response->cancel, &response->auth_credentials); 1566 response->cancel, &response->auth_credentials);
1564 default: 1567 default:
1565 NOTREACHED(); 1568 NOTREACHED();
1566 break; 1569 break;
1567 } 1570 }
1568 return NULL; 1571 return NULL;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 blocked_request.response_deltas, 1841 blocked_request.response_deltas,
1839 blocked_request.request_headers, 1842 blocked_request.request_headers,
1840 &warnings, 1843 &warnings,
1841 blocked_request.net_log); 1844 blocked_request.net_log);
1842 } else if (blocked_request.event == kOnHeadersReceived) { 1845 } else if (blocked_request.event == kOnHeadersReceived) {
1843 CHECK(!blocked_request.callback.is_null()); 1846 CHECK(!blocked_request.callback.is_null());
1844 helpers::MergeOnHeadersReceivedResponses( 1847 helpers::MergeOnHeadersReceivedResponses(
1845 blocked_request.response_deltas, 1848 blocked_request.response_deltas,
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,
1851 blocked_request.new_url,
1848 &warnings, 1852 &warnings,
1849 blocked_request.net_log); 1853 blocked_request.net_log);
1850 } else if (blocked_request.event == kOnAuthRequired) { 1854 } else if (blocked_request.event == kOnAuthRequired) {
1851 CHECK(blocked_request.callback.is_null()); 1855 CHECK(blocked_request.callback.is_null());
1852 CHECK(!blocked_request.auth_callback.is_null()); 1856 CHECK(!blocked_request.auth_callback.is_null());
1853 credentials_set = helpers::MergeOnAuthRequiredResponses( 1857 credentials_set = helpers::MergeOnAuthRequiredResponses(
1854 blocked_request.response_deltas, 1858 blocked_request.response_deltas,
1855 blocked_request.auth_credentials, 1859 blocked_request.auth_credentials,
1856 &warnings, 1860 &warnings,
1857 blocked_request.net_log); 1861 blocked_request.net_log);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2384 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
2381 adblock = true; 2385 adblock = true;
2382 } else { 2386 } else {
2383 other = true; 2387 other = true;
2384 } 2388 }
2385 } 2389 }
2386 } 2390 }
2387 2391
2388 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2392 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
2389 } 2393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698