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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // If non-empty, this contains the new URL that the request will redirect to. | 348 // If non-empty, this contains the new URL that the request will redirect to. |
349 // Only valid for OnBeforeRequest. | 349 // Only valid for OnBeforeRequest. |
350 GURL* new_url; | 350 GURL* new_url; |
351 | 351 |
352 // The request headers that will be issued along with this request. Only valid | 352 // The request headers that will be issued along with this request. Only valid |
353 // for OnBeforeSendHeaders. | 353 // for OnBeforeSendHeaders. |
354 net::HttpRequestHeaders* request_headers; | 354 net::HttpRequestHeaders* request_headers; |
355 | 355 |
356 // The response headers that were received from the server. Only valid for | 356 // The response headers that were received from the server. Only valid for |
357 // OnHeadersReceived. | 357 // OnHeadersReceived. |
358 scoped_refptr<net::HttpResponseHeaders> original_response_headers; | 358 scoped_refptr<const net::HttpResponseHeaders> original_response_headers; |
359 | 359 |
360 // Location where to override response headers. Only valid for | 360 // Location where to override response headers. Only valid for |
361 // OnHeadersReceived. | 361 // OnHeadersReceived. |
362 scoped_refptr<net::HttpResponseHeaders>* override_response_headers; | 362 scoped_refptr<net::HttpResponseHeaders>* override_response_headers; |
363 | 363 |
364 // If non-empty, this contains the auth credentials that may be filled in. | 364 // If non-empty, this contains the auth credentials that may be filled in. |
365 // Only valid for OnAuthRequired. | 365 // Only valid for OnAuthRequired. |
366 net::AuthCredentials* auth_credentials; | 366 net::AuthCredentials* auth_credentials; |
367 | 367 |
368 // The callback to invoke for auth. If |auth_callback.is_null()| is false, | 368 // The callback to invoke for auth. If |auth_callback.is_null()| is false, |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 args.Append(dict); | 662 args.Append(dict); |
663 | 663 |
664 DispatchEvent(profile, request, listeners, args); | 664 DispatchEvent(profile, request, listeners, args); |
665 } | 665 } |
666 | 666 |
667 int ExtensionWebRequestEventRouter::OnHeadersReceived( | 667 int ExtensionWebRequestEventRouter::OnHeadersReceived( |
668 void* profile, | 668 void* profile, |
669 ExtensionInfoMap* extension_info_map, | 669 ExtensionInfoMap* extension_info_map, |
670 net::URLRequest* request, | 670 net::URLRequest* request, |
671 const net::CompletionCallback& callback, | 671 const net::CompletionCallback& callback, |
672 net::HttpResponseHeaders* original_response_headers, | 672 const net::HttpResponseHeaders* original_response_headers, |
673 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 673 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { |
674 // We hide events from the system context as well as sensitive requests. | 674 // We hide events from the system context as well as sensitive requests. |
675 if (!profile || | 675 if (!profile || |
676 WebRequestPermissions::HideRequest(extension_info_map, request)) | 676 WebRequestPermissions::HideRequest(extension_info_map, request)) |
677 return net::OK; | 677 return net::OK; |
678 | 678 |
679 bool initialize_blocked_requests = false; | 679 bool initialize_blocked_requests = false; |
680 | 680 |
681 initialize_blocked_requests |= | 681 initialize_blocked_requests |= |
682 ProcessDeclarativeRules(profile, extension_info_map, | 682 ProcessDeclarativeRules(profile, extension_info_map, |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 response->extension_id, response->extension_install_time, | 1288 response->extension_id, response->extension_install_time, |
1289 response->cancel, response->new_url); | 1289 response->cancel, response->new_url); |
1290 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders: { | 1290 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders: { |
1291 net::HttpRequestHeaders* old_headers = blocked_request->request_headers; | 1291 net::HttpRequestHeaders* old_headers = blocked_request->request_headers; |
1292 net::HttpRequestHeaders* new_headers = response->request_headers.get(); | 1292 net::HttpRequestHeaders* new_headers = response->request_headers.get(); |
1293 return helpers::CalculateOnBeforeSendHeadersDelta( | 1293 return helpers::CalculateOnBeforeSendHeadersDelta( |
1294 response->extension_id, response->extension_install_time, | 1294 response->extension_id, response->extension_install_time, |
1295 response->cancel, old_headers, new_headers); | 1295 response->cancel, old_headers, new_headers); |
1296 } | 1296 } |
1297 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { | 1297 case ExtensionWebRequestEventRouter::kOnHeadersReceived: { |
1298 net::HttpResponseHeaders* old_headers = | 1298 const net::HttpResponseHeaders* old_headers = |
1299 blocked_request->original_response_headers.get(); | 1299 blocked_request->original_response_headers.get(); |
1300 helpers::ResponseHeaders* new_headers = | 1300 helpers::ResponseHeaders* new_headers = |
1301 response->response_headers.get(); | 1301 response->response_headers.get(); |
1302 return helpers::CalculateOnHeadersReceivedDelta( | 1302 return helpers::CalculateOnHeadersReceivedDelta( |
1303 response->extension_id, response->extension_install_time, | 1303 response->extension_id, response->extension_install_time, |
1304 response->cancel, old_headers, new_headers); | 1304 response->cancel, old_headers, new_headers); |
1305 } | 1305 } |
1306 case ExtensionWebRequestEventRouter::kOnAuthRequired: | 1306 case ExtensionWebRequestEventRouter::kOnAuthRequired: |
1307 return helpers::CalculateOnAuthRequiredDelta( | 1307 return helpers::CalculateOnAuthRequiredDelta( |
1308 response->extension_id, response->extension_install_time, | 1308 response->extension_id, response->extension_install_time, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 } | 1469 } |
1470 return rv; | 1470 return rv; |
1471 } | 1471 } |
1472 | 1472 |
1473 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( | 1473 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
1474 void* profile, | 1474 void* profile, |
1475 ExtensionInfoMap* extension_info_map, | 1475 ExtensionInfoMap* extension_info_map, |
1476 const std::string& event_name, | 1476 const std::string& event_name, |
1477 net::URLRequest* request, | 1477 net::URLRequest* request, |
1478 extensions::RequestStage request_stage, | 1478 extensions::RequestStage request_stage, |
1479 net::HttpResponseHeaders* original_response_headers) { | 1479 const net::HttpResponseHeaders* original_response_headers) { |
1480 // Rules of the current |profile| may apply but we need to check also whether | 1480 // Rules of the current |profile| may apply but we need to check also whether |
1481 // there are applicable rules from extensions whose background page | 1481 // there are applicable rules from extensions whose background page |
1482 // spans from regular to incognito mode. | 1482 // spans from regular to incognito mode. |
1483 | 1483 |
1484 // First parameter identifies the registry, the second indicates whether the | 1484 // First parameter identifies the registry, the second indicates whether the |
1485 // registry belongs to the cross profile. | 1485 // registry belongs to the cross profile. |
1486 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> | 1486 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> |
1487 RelevantRegistry; | 1487 RelevantRegistry; |
1488 typedef std::vector<RelevantRegistry> RelevantRegistries; | 1488 typedef std::vector<RelevantRegistry> RelevantRegistries; |
1489 RelevantRegistries relevant_registries; | 1489 RelevantRegistries relevant_registries; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1898 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1899 adblock = true; | 1899 adblock = true; |
1900 } else { | 1900 } else { |
1901 other = true; | 1901 other = true; |
1902 } | 1902 } |
1903 } | 1903 } |
1904 } | 1904 } |
1905 | 1905 |
1906 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1906 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1907 } | 1907 } |
OLD | NEW |