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

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

Issue 10825102: Protect Chrome WebStore based on process IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test Created 8 years, 4 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 | Annotate | Revision Log
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/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 rules_registries_.erase(profile); 463 rules_registries_.erase(profile);
464 } 464 }
465 465
466 int ExtensionWebRequestEventRouter::OnBeforeRequest( 466 int ExtensionWebRequestEventRouter::OnBeforeRequest(
467 void* profile, 467 void* profile,
468 ExtensionInfoMap* extension_info_map, 468 ExtensionInfoMap* extension_info_map,
469 net::URLRequest* request, 469 net::URLRequest* request,
470 const net::CompletionCallback& callback, 470 const net::CompletionCallback& callback,
471 GURL* new_url) { 471 GURL* new_url) {
472 // We hide events from the system context as well as sensitive requests. 472 // We hide events from the system context as well as sensitive requests.
473 if (!profile || WebRequestPermissions::HideRequest(request)) 473 if (!profile ||
474 WebRequestPermissions::HideRequest(extension_info_map, request))
474 return net::OK; 475 return net::OK;
475 476
476 if (IsPageLoad(request)) 477 if (IsPageLoad(request))
477 NotifyPageLoad(); 478 NotifyPageLoad();
478 479
479 request_time_tracker_->LogRequestStartTime(request->identifier(), 480 request_time_tracker_->LogRequestStartTime(request->identifier(),
480 base::Time::Now(), 481 base::Time::Now(),
481 request->url(), 482 request->url(),
482 profile); 483 profile);
483 484
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 523 }
523 } 524 }
524 525
525 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders( 526 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders(
526 void* profile, 527 void* profile,
527 ExtensionInfoMap* extension_info_map, 528 ExtensionInfoMap* extension_info_map,
528 net::URLRequest* request, 529 net::URLRequest* request,
529 const net::CompletionCallback& callback, 530 const net::CompletionCallback& callback,
530 net::HttpRequestHeaders* headers) { 531 net::HttpRequestHeaders* headers) {
531 // We hide events from the system context as well as sensitive requests. 532 // We hide events from the system context as well as sensitive requests.
532 if (!profile || WebRequestPermissions::HideRequest(request)) 533 if (!profile ||
534 WebRequestPermissions::HideRequest(extension_info_map, request))
533 return net::OK; 535 return net::OK;
534 536
535 bool initialize_blocked_requests = false; 537 bool initialize_blocked_requests = false;
536 538
537 initialize_blocked_requests |= 539 initialize_blocked_requests |=
538 ProcessDeclarativeRules(profile, extension_info_map, 540 ProcessDeclarativeRules(profile, extension_info_map,
539 keys::kOnBeforeSendHeaders, request, 541 keys::kOnBeforeSendHeaders, request,
540 extensions::ON_BEFORE_SEND_HEADERS, NULL); 542 extensions::ON_BEFORE_SEND_HEADERS, NULL);
541 543
542 int extra_info_spec = 0; 544 int extra_info_spec = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return net::ERR_IO_PENDING; 576 return net::ERR_IO_PENDING;
575 } 577 }
576 } 578 }
577 579
578 void ExtensionWebRequestEventRouter::OnSendHeaders( 580 void ExtensionWebRequestEventRouter::OnSendHeaders(
579 void* profile, 581 void* profile,
580 ExtensionInfoMap* extension_info_map, 582 ExtensionInfoMap* extension_info_map,
581 net::URLRequest* request, 583 net::URLRequest* request,
582 const net::HttpRequestHeaders& headers) { 584 const net::HttpRequestHeaders& headers) {
583 // 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.
584 if (!profile || WebRequestPermissions::HideRequest(request)) 586 if (!profile ||
587 WebRequestPermissions::HideRequest(extension_info_map, request))
585 return; 588 return;
586 589
587 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders)) 590 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders))
588 return; 591 return;
589 592
590 ClearSignaled(request->identifier(), kOnBeforeRedirect); 593 ClearSignaled(request->identifier(), kOnBeforeRedirect);
591 594
592 int extra_info_spec = 0; 595 int extra_info_spec = 0;
593 std::vector<const EventListener*> listeners = 596 std::vector<const EventListener*> listeners =
594 GetMatchingListeners(profile, extension_info_map, 597 GetMatchingListeners(profile, extension_info_map,
(...skipping 12 matching lines...) Expand all
607 } 610 }
608 611
609 int ExtensionWebRequestEventRouter::OnHeadersReceived( 612 int ExtensionWebRequestEventRouter::OnHeadersReceived(
610 void* profile, 613 void* profile,
611 ExtensionInfoMap* extension_info_map, 614 ExtensionInfoMap* extension_info_map,
612 net::URLRequest* request, 615 net::URLRequest* request,
613 const net::CompletionCallback& callback, 616 const net::CompletionCallback& callback,
614 net::HttpResponseHeaders* original_response_headers, 617 net::HttpResponseHeaders* original_response_headers,
615 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { 618 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
616 // We hide events from the system context as well as sensitive requests. 619 // We hide events from the system context as well as sensitive requests.
617 if (!profile || WebRequestPermissions::HideRequest(request)) 620 if (!profile ||
621 WebRequestPermissions::HideRequest(extension_info_map, request))
618 return net::OK; 622 return net::OK;
619 623
620 bool initialize_blocked_requests = false; 624 bool initialize_blocked_requests = false;
621 625
622 initialize_blocked_requests |= 626 initialize_blocked_requests |=
623 ProcessDeclarativeRules(profile, extension_info_map, 627 ProcessDeclarativeRules(profile, extension_info_map,
624 keys::kOnHeadersReceived, request, 628 keys::kOnHeadersReceived, request,
625 extensions::ON_HEADERS_RECEIVED, 629 extensions::ON_HEADERS_RECEIVED,
626 original_response_headers); 630 original_response_headers);
627 631
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 net::NetworkDelegate::AuthRequiredResponse 676 net::NetworkDelegate::AuthRequiredResponse
673 ExtensionWebRequestEventRouter::OnAuthRequired( 677 ExtensionWebRequestEventRouter::OnAuthRequired(
674 void* profile, 678 void* profile,
675 ExtensionInfoMap* extension_info_map, 679 ExtensionInfoMap* extension_info_map,
676 net::URLRequest* request, 680 net::URLRequest* request,
677 const net::AuthChallengeInfo& auth_info, 681 const net::AuthChallengeInfo& auth_info,
678 const net::NetworkDelegate::AuthCallback& callback, 682 const net::NetworkDelegate::AuthCallback& callback,
679 net::AuthCredentials* credentials) { 683 net::AuthCredentials* credentials) {
680 // No profile means that this is for authentication challenges in the 684 // No profile means that this is for authentication challenges in the
681 // system context. Skip in that case. Also skip sensitive requests. 685 // system context. Skip in that case. Also skip sensitive requests.
682 if (!profile || WebRequestPermissions::HideRequest(request)) 686 if (!profile ||
687 WebRequestPermissions::HideRequest(extension_info_map, request))
683 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 688 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
684 689
685 int extra_info_spec = 0; 690 int extra_info_spec = 0;
686 std::vector<const EventListener*> listeners = 691 std::vector<const EventListener*> listeners =
687 GetMatchingListeners(profile, extension_info_map, 692 GetMatchingListeners(profile, extension_info_map,
688 keys::kOnAuthRequired, request, &extra_info_spec); 693 keys::kOnAuthRequired, request, &extra_info_spec);
689 if (listeners.empty()) 694 if (listeners.empty())
690 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 695 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
691 696
692 ListValue args; 697 ListValue args;
(...skipping 24 matching lines...) Expand all
717 } 722 }
718 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 723 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
719 } 724 }
720 725
721 void ExtensionWebRequestEventRouter::OnBeforeRedirect( 726 void ExtensionWebRequestEventRouter::OnBeforeRedirect(
722 void* profile, 727 void* profile,
723 ExtensionInfoMap* extension_info_map, 728 ExtensionInfoMap* extension_info_map,
724 net::URLRequest* request, 729 net::URLRequest* request,
725 const GURL& new_location) { 730 const GURL& new_location) {
726 // We hide events from the system context as well as sensitive requests. 731 // We hide events from the system context as well as sensitive requests.
727 if (!profile || WebRequestPermissions::HideRequest(request)) 732 if (!profile ||
733 WebRequestPermissions::HideRequest(extension_info_map, request))
728 return; 734 return;
729 735
730 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect)) 736 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect))
731 return; 737 return;
732 738
733 ClearSignaled(request->identifier(), kOnBeforeRequest); 739 ClearSignaled(request->identifier(), kOnBeforeRequest);
734 ClearSignaled(request->identifier(), kOnBeforeSendHeaders); 740 ClearSignaled(request->identifier(), kOnBeforeSendHeaders);
735 ClearSignaled(request->identifier(), kOnSendHeaders); 741 ClearSignaled(request->identifier(), kOnSendHeaders);
736 ClearSignaled(request->identifier(), kOnHeadersReceived); 742 ClearSignaled(request->identifier(), kOnHeadersReceived);
737 743
(...skipping 24 matching lines...) Expand all
762 args.Append(dict); 768 args.Append(dict);
763 769
764 DispatchEvent(profile, request, listeners, args); 770 DispatchEvent(profile, request, listeners, args);
765 } 771 }
766 772
767 void ExtensionWebRequestEventRouter::OnResponseStarted( 773 void ExtensionWebRequestEventRouter::OnResponseStarted(
768 void* profile, 774 void* profile,
769 ExtensionInfoMap* extension_info_map, 775 ExtensionInfoMap* extension_info_map,
770 net::URLRequest* request) { 776 net::URLRequest* request) {
771 // We hide events from the system context as well as sensitive requests. 777 // We hide events from the system context as well as sensitive requests.
772 if (!profile || WebRequestPermissions::HideRequest(request)) 778 if (!profile ||
779 WebRequestPermissions::HideRequest(extension_info_map, request))
773 return; 780 return;
774 781
775 // OnResponseStarted is even triggered, when the request was cancelled. 782 // OnResponseStarted is even triggered, when the request was cancelled.
776 if (request->status().status() != net::URLRequestStatus::SUCCESS) 783 if (request->status().status() != net::URLRequestStatus::SUCCESS)
777 return; 784 return;
778 785
779 int extra_info_spec = 0; 786 int extra_info_spec = 0;
780 std::vector<const EventListener*> listeners = 787 std::vector<const EventListener*> listeners =
781 GetMatchingListeners(profile, extension_info_map, 788 GetMatchingListeners(profile, extension_info_map,
782 keys::kOnResponseStarted, request, &extra_info_spec); 789 keys::kOnResponseStarted, request, &extra_info_spec);
(...skipping 26 matching lines...) Expand all
809 816
810 void ExtensionWebRequestEventRouter::OnCompleted( 817 void ExtensionWebRequestEventRouter::OnCompleted(
811 void* profile, 818 void* profile,
812 ExtensionInfoMap* extension_info_map, 819 ExtensionInfoMap* extension_info_map,
813 net::URLRequest* request) { 820 net::URLRequest* request) {
814 // We hide events from the system context as well as sensitive requests. 821 // We hide events from the system context as well as sensitive requests.
815 // However, if the request first became sensitive after redirecting we have 822 // However, if the request first became sensitive after redirecting we have
816 // already signaled it and thus we have to signal the end of it. This is 823 // already signaled it and thus we have to signal the end of it. This is
817 // risk-free because the handler cannot modify the request now. 824 // risk-free because the handler cannot modify the request now.
818 if (!profile || 825 if (!profile ||
819 (WebRequestPermissions::HideRequest(request) && !WasSignaled(*request))) 826 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
827 !WasSignaled(*request)))
820 return; 828 return;
821 829
822 request_time_tracker_->LogRequestEndTime(request->identifier(), 830 request_time_tracker_->LogRequestEndTime(request->identifier(),
823 base::Time::Now()); 831 base::Time::Now());
824 832
825 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS); 833 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS);
826 834
827 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); 835 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted));
828 836
829 ClearPendingCallbacks(request); 837 ClearPendingCallbacks(request);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 void ExtensionWebRequestEventRouter::OnErrorOccurred( 870 void ExtensionWebRequestEventRouter::OnErrorOccurred(
863 void* profile, 871 void* profile,
864 ExtensionInfoMap* extension_info_map, 872 ExtensionInfoMap* extension_info_map,
865 net::URLRequest* request, 873 net::URLRequest* request,
866 bool started) { 874 bool started) {
867 // We hide events from the system context as well as sensitive requests. 875 // We hide events from the system context as well as sensitive requests.
868 // However, if the request first became sensitive after redirecting we have 876 // However, if the request first became sensitive after redirecting we have
869 // already signaled it and thus we have to signal the end of it. This is 877 // already signaled it and thus we have to signal the end of it. This is
870 // risk-free because the handler cannot modify the request now. 878 // risk-free because the handler cannot modify the request now.
871 if (!profile || 879 if (!profile ||
872 (WebRequestPermissions::HideRequest(request) && !WasSignaled(*request))) 880 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
881 !WasSignaled(*request)))
873 return; 882 return;
874 883
875 request_time_tracker_->LogRequestEndTime(request->identifier(), 884 request_time_tracker_->LogRequestEndTime(request->identifier(),
876 base::Time::Now()); 885 base::Time::Now());
877 886
878 DCHECK(request->status().status() == net::URLRequestStatus::FAILED || 887 DCHECK(request->status().status() == net::URLRequestStatus::FAILED ||
879 request->status().status() == net::URLRequestStatus::CANCELED); 888 request->status().status() == net::URLRequestStatus::CANCELED);
880 889
881 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred)); 890 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred));
882 891
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 1841 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1833 adblock = true; 1842 adblock = true;
1834 } else { 1843 } else {
1835 other = true; 1844 other = true;
1836 } 1845 }
1837 } 1846 }
1838 } 1847 }
1839 1848
1840 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 1849 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1841 } 1850 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698