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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 rules_registry_ = rules_registry; | 467 rules_registry_ = rules_registry; |
468 } | 468 } |
469 | 469 |
470 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 470 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
471 void* profile, | 471 void* profile, |
472 ExtensionInfoMap* extension_info_map, | 472 ExtensionInfoMap* extension_info_map, |
473 net::URLRequest* request, | 473 net::URLRequest* request, |
474 const net::CompletionCallback& callback, | 474 const net::CompletionCallback& callback, |
475 GURL* new_url) { | 475 GURL* new_url) { |
476 // We hide events from the system context as well as sensitive requests. | 476 // We hide events from the system context as well as sensitive requests. |
477 if (!profile || helpers::HideRequest(request)) | 477 if (!profile || helpers::HideRequestForURL(request->url())) |
478 return net::OK; | 478 return net::OK; |
479 | 479 |
480 if (IsPageLoad(request)) | 480 if (IsPageLoad(request)) |
481 NotifyPageLoad(); | 481 NotifyPageLoad(); |
482 | 482 |
483 request_time_tracker_->LogRequestStartTime(request->identifier(), | 483 request_time_tracker_->LogRequestStartTime(request->identifier(), |
484 base::Time::Now(), | 484 base::Time::Now(), |
485 request->url(), | 485 request->url(), |
486 profile); | 486 profile); |
487 | 487 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 525 } |
526 } | 526 } |
527 | 527 |
528 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders( | 528 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders( |
529 void* profile, | 529 void* profile, |
530 ExtensionInfoMap* extension_info_map, | 530 ExtensionInfoMap* extension_info_map, |
531 net::URLRequest* request, | 531 net::URLRequest* request, |
532 const net::CompletionCallback& callback, | 532 const net::CompletionCallback& callback, |
533 net::HttpRequestHeaders* headers) { | 533 net::HttpRequestHeaders* headers) { |
534 // We hide events from the system context as well as sensitive requests. | 534 // We hide events from the system context as well as sensitive requests. |
535 if (!profile || helpers::HideRequest(request)) | 535 if (!profile || helpers::HideRequestForURL(request->url())) |
536 return net::OK; | 536 return net::OK; |
537 | 537 |
538 bool initialize_blocked_requests = false; | 538 bool initialize_blocked_requests = false; |
539 | 539 |
540 initialize_blocked_requests |= | 540 initialize_blocked_requests |= |
541 ProcessDeclarativeRules(profile, keys::kOnBeforeSendHeaders, request, | 541 ProcessDeclarativeRules(profile, keys::kOnBeforeSendHeaders, request, |
542 extensions::ON_BEFORE_SEND_HEADERS, NULL); | 542 extensions::ON_BEFORE_SEND_HEADERS, NULL); |
543 | 543 |
544 int extra_info_spec = 0; | 544 int extra_info_spec = 0; |
545 std::vector<const EventListener*> listeners = | 545 std::vector<const EventListener*> listeners = |
(...skipping 30 matching lines...) Expand all Loading... |
576 return net::ERR_IO_PENDING; | 576 return net::ERR_IO_PENDING; |
577 } | 577 } |
578 } | 578 } |
579 | 579 |
580 void ExtensionWebRequestEventRouter::OnSendHeaders( | 580 void ExtensionWebRequestEventRouter::OnSendHeaders( |
581 void* profile, | 581 void* profile, |
582 ExtensionInfoMap* extension_info_map, | 582 ExtensionInfoMap* extension_info_map, |
583 net::URLRequest* request, | 583 net::URLRequest* request, |
584 const net::HttpRequestHeaders& headers) { | 584 const net::HttpRequestHeaders& headers) { |
585 // We hide events from the system context as well as sensitive requests. | 585 // We hide events from the system context as well as sensitive requests. |
586 if (!profile || helpers::HideRequest(request)) | 586 if (!profile || helpers::HideRequestForURL(request->url())) |
587 return; | 587 return; |
588 | 588 |
589 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders)) | 589 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders)) |
590 return; | 590 return; |
591 | 591 |
592 ClearSignaled(request->identifier(), kOnBeforeRedirect); | 592 ClearSignaled(request->identifier(), kOnBeforeRedirect); |
593 | 593 |
594 int extra_info_spec = 0; | 594 int extra_info_spec = 0; |
595 std::vector<const EventListener*> listeners = | 595 std::vector<const EventListener*> listeners = |
596 GetMatchingListeners(profile, extension_info_map, | 596 GetMatchingListeners(profile, extension_info_map, |
(...skipping 12 matching lines...) Expand all Loading... |
609 } | 609 } |
610 | 610 |
611 int ExtensionWebRequestEventRouter::OnHeadersReceived( | 611 int ExtensionWebRequestEventRouter::OnHeadersReceived( |
612 void* profile, | 612 void* profile, |
613 ExtensionInfoMap* extension_info_map, | 613 ExtensionInfoMap* extension_info_map, |
614 net::URLRequest* request, | 614 net::URLRequest* request, |
615 const net::CompletionCallback& callback, | 615 const net::CompletionCallback& callback, |
616 net::HttpResponseHeaders* original_response_headers, | 616 net::HttpResponseHeaders* original_response_headers, |
617 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 617 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { |
618 // We hide events from the system context as well as sensitive requests. | 618 // We hide events from the system context as well as sensitive requests. |
619 if (!profile || helpers::HideRequest(request)) | 619 if (!profile || helpers::HideRequestForURL(request->url())) |
620 return net::OK; | 620 return net::OK; |
621 | 621 |
622 bool initialize_blocked_requests = false; | 622 bool initialize_blocked_requests = false; |
623 | 623 |
624 initialize_blocked_requests |= | 624 initialize_blocked_requests |= |
625 ProcessDeclarativeRules(profile, keys::kOnHeadersReceived, request, | 625 ProcessDeclarativeRules(profile, keys::kOnHeadersReceived, request, |
626 extensions::ON_HEADERS_RECEIVED, | 626 extensions::ON_HEADERS_RECEIVED, |
627 original_response_headers); | 627 original_response_headers); |
628 | 628 |
629 int extra_info_spec = 0; | 629 int extra_info_spec = 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 net::NetworkDelegate::AuthRequiredResponse | 673 net::NetworkDelegate::AuthRequiredResponse |
674 ExtensionWebRequestEventRouter::OnAuthRequired( | 674 ExtensionWebRequestEventRouter::OnAuthRequired( |
675 void* profile, | 675 void* profile, |
676 ExtensionInfoMap* extension_info_map, | 676 ExtensionInfoMap* extension_info_map, |
677 net::URLRequest* request, | 677 net::URLRequest* request, |
678 const net::AuthChallengeInfo& auth_info, | 678 const net::AuthChallengeInfo& auth_info, |
679 const net::NetworkDelegate::AuthCallback& callback, | 679 const net::NetworkDelegate::AuthCallback& callback, |
680 net::AuthCredentials* credentials) { | 680 net::AuthCredentials* credentials) { |
681 // No profile means that this is for authentication challenges in the | 681 // No profile means that this is for authentication challenges in the |
682 // system context. Skip in that case. Also skip sensitive requests. | 682 // system context. Skip in that case. Also skip sensitive requests. |
683 if (!profile || helpers::HideRequest(request)) | 683 if (!profile || helpers::HideRequestForURL(request->url())) |
684 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 684 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
685 | 685 |
686 int extra_info_spec = 0; | 686 int extra_info_spec = 0; |
687 std::vector<const EventListener*> listeners = | 687 std::vector<const EventListener*> listeners = |
688 GetMatchingListeners(profile, extension_info_map, | 688 GetMatchingListeners(profile, extension_info_map, |
689 keys::kOnAuthRequired, request, &extra_info_spec); | 689 keys::kOnAuthRequired, request, &extra_info_spec); |
690 if (listeners.empty()) | 690 if (listeners.empty()) |
691 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 691 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
692 | 692 |
693 ListValue args; | 693 ListValue args; |
(...skipping 24 matching lines...) Expand all Loading... |
718 } | 718 } |
719 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 719 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
720 } | 720 } |
721 | 721 |
722 void ExtensionWebRequestEventRouter::OnBeforeRedirect( | 722 void ExtensionWebRequestEventRouter::OnBeforeRedirect( |
723 void* profile, | 723 void* profile, |
724 ExtensionInfoMap* extension_info_map, | 724 ExtensionInfoMap* extension_info_map, |
725 net::URLRequest* request, | 725 net::URLRequest* request, |
726 const GURL& new_location) { | 726 const GURL& new_location) { |
727 // We hide events from the system context as well as sensitive requests. | 727 // We hide events from the system context as well as sensitive requests. |
728 if (!profile || helpers::HideRequest(request)) | 728 if (!profile || helpers::HideRequestForURL(request->url())) |
729 return; | 729 return; |
730 | 730 |
731 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect)) | 731 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect)) |
732 return; | 732 return; |
733 | 733 |
734 ClearSignaled(request->identifier(), kOnBeforeRequest); | 734 ClearSignaled(request->identifier(), kOnBeforeRequest); |
735 ClearSignaled(request->identifier(), kOnBeforeSendHeaders); | 735 ClearSignaled(request->identifier(), kOnBeforeSendHeaders); |
736 ClearSignaled(request->identifier(), kOnSendHeaders); | 736 ClearSignaled(request->identifier(), kOnSendHeaders); |
737 ClearSignaled(request->identifier(), kOnHeadersReceived); | 737 ClearSignaled(request->identifier(), kOnHeadersReceived); |
738 | 738 |
(...skipping 24 matching lines...) Expand all Loading... |
763 args.Append(dict); | 763 args.Append(dict); |
764 | 764 |
765 DispatchEvent(profile, request, listeners, args); | 765 DispatchEvent(profile, request, listeners, args); |
766 } | 766 } |
767 | 767 |
768 void ExtensionWebRequestEventRouter::OnResponseStarted( | 768 void ExtensionWebRequestEventRouter::OnResponseStarted( |
769 void* profile, | 769 void* profile, |
770 ExtensionInfoMap* extension_info_map, | 770 ExtensionInfoMap* extension_info_map, |
771 net::URLRequest* request) { | 771 net::URLRequest* request) { |
772 // We hide events from the system context as well as sensitive requests. | 772 // We hide events from the system context as well as sensitive requests. |
773 if (!profile || helpers::HideRequest(request)) | 773 if (!profile || helpers::HideRequestForURL(request->url())) |
774 return; | 774 return; |
775 | 775 |
776 // OnResponseStarted is even triggered, when the request was cancelled. | 776 // OnResponseStarted is even triggered, when the request was cancelled. |
777 if (request->status().status() != net::URLRequestStatus::SUCCESS) | 777 if (request->status().status() != net::URLRequestStatus::SUCCESS) |
778 return; | 778 return; |
779 | 779 |
780 int extra_info_spec = 0; | 780 int extra_info_spec = 0; |
781 std::vector<const EventListener*> listeners = | 781 std::vector<const EventListener*> listeners = |
782 GetMatchingListeners(profile, extension_info_map, | 782 GetMatchingListeners(profile, extension_info_map, |
783 keys::kOnResponseStarted, request, &extra_info_spec); | 783 keys::kOnResponseStarted, request, &extra_info_spec); |
(...skipping 22 matching lines...) Expand all Loading... |
806 args.Append(dict); | 806 args.Append(dict); |
807 | 807 |
808 DispatchEvent(profile, request, listeners, args); | 808 DispatchEvent(profile, request, listeners, args); |
809 } | 809 } |
810 | 810 |
811 void ExtensionWebRequestEventRouter::OnCompleted( | 811 void ExtensionWebRequestEventRouter::OnCompleted( |
812 void* profile, | 812 void* profile, |
813 ExtensionInfoMap* extension_info_map, | 813 ExtensionInfoMap* extension_info_map, |
814 net::URLRequest* request) { | 814 net::URLRequest* request) { |
815 // We hide events from the system context as well as sensitive requests. | 815 // We hide events from the system context as well as sensitive requests. |
816 if (!profile || helpers::HideRequest(request)) | 816 if (!profile || helpers::HideRequestForURL(request->url())) |
817 return; | 817 return; |
818 | 818 |
819 request_time_tracker_->LogRequestEndTime(request->identifier(), | 819 request_time_tracker_->LogRequestEndTime(request->identifier(), |
820 base::Time::Now()); | 820 base::Time::Now()); |
821 | 821 |
822 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS); | 822 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS); |
823 | 823 |
824 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); | 824 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); |
825 | 825 |
826 ClearPendingCallbacks(request); | 826 ClearPendingCallbacks(request); |
(...skipping 28 matching lines...) Expand all Loading... |
855 | 855 |
856 DispatchEvent(profile, request, listeners, args); | 856 DispatchEvent(profile, request, listeners, args); |
857 } | 857 } |
858 | 858 |
859 void ExtensionWebRequestEventRouter::OnErrorOccurred( | 859 void ExtensionWebRequestEventRouter::OnErrorOccurred( |
860 void* profile, | 860 void* profile, |
861 ExtensionInfoMap* extension_info_map, | 861 ExtensionInfoMap* extension_info_map, |
862 net::URLRequest* request, | 862 net::URLRequest* request, |
863 bool started) { | 863 bool started) { |
864 // We hide events from the system context as well as sensitive requests. | 864 // We hide events from the system context as well as sensitive requests. |
865 if (!profile || helpers::HideRequest(request)) | 865 if (!profile || helpers::HideRequestForURL(request->url())) |
866 return; | 866 return; |
867 | 867 |
868 request_time_tracker_->LogRequestEndTime(request->identifier(), | 868 request_time_tracker_->LogRequestEndTime(request->identifier(), |
869 base::Time::Now()); | 869 base::Time::Now()); |
870 | 870 |
871 DCHECK(request->status().status() == net::URLRequestStatus::FAILED || | 871 DCHECK(request->status().status() == net::URLRequestStatus::FAILED || |
872 request->status().status() == net::URLRequestStatus::CANCELED); | 872 request->status().status() == net::URLRequestStatus::CANCELED); |
873 | 873 |
874 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred)); | 874 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred)); |
875 | 875 |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1775 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1776 adblock = true; | 1776 adblock = true; |
1777 } else { | 1777 } else { |
1778 other = true; | 1778 other = true; |
1779 } | 1779 } |
1780 } | 1780 } |
1781 } | 1781 } |
1782 | 1782 |
1783 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1783 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1784 } | 1784 } |
OLD | NEW |