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

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

Issue 63933003: Moved ExtensionInfoMap and ExtensionsQuotaService to extensions/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix Created 7 years, 1 month 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/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/extensions/activity_log/web_request_constants.h" 23 #include "chrome/browser/extensions/activity_log/web_request_constants.h"
24 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" 24 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h"
25 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" 25 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
27 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" 27 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h"
28 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" 28 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h"
29 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" 29 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h"
30 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 30 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
31 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" 31 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h"
32 #include "chrome/browser/extensions/event_router.h" 32 #include "chrome/browser/extensions/event_router.h"
33 #include "chrome/browser/extensions/extension_info_map.h"
34 #include "chrome/browser/extensions/extension_prefs.h" 33 #include "chrome/browser/extensions/extension_prefs.h"
35 #include "chrome/browser/extensions/extension_renderer_state.h" 34 #include "chrome/browser/extensions/extension_renderer_state.h"
36 #include "chrome/browser/extensions/extension_service.h" 35 #include "chrome/browser/extensions/extension_service.h"
37 #include "chrome/browser/extensions/extension_system.h" 36 #include "chrome/browser/extensions/extension_system.h"
38 #include "chrome/browser/extensions/extension_warning_service.h" 37 #include "chrome/browser/extensions/extension_warning_service.h"
39 #include "chrome/browser/extensions/extension_warning_set.h" 38 #include "chrome/browser/extensions/extension_warning_set.h"
40 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/profiles/profile_manager.h" 40 #include "chrome/browser/profiles/profile_manager.h"
42 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 41 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
43 #include "chrome/common/extensions/api/web_request.h" 42 #include "chrome/common/extensions/api/web_request.h"
44 #include "chrome/common/extensions/extension.h" 43 #include "chrome/common/extensions/extension.h"
45 #include "chrome/common/extensions/extension_constants.h" 44 #include "chrome/common/extensions/extension_constants.h"
46 #include "chrome/common/extensions/extension_messages.h" 45 #include "chrome/common/extensions/extension_messages.h"
47 #include "chrome/common/extensions/permissions/permissions_data.h" 46 #include "chrome/common/extensions/permissions/permissions_data.h"
48 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
49 #include "content/public/browser/browser_message_filter.h" 48 #include "content/public/browser/browser_message_filter.h"
50 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
51 #include "content/public/browser/render_process_host.h" 50 #include "content/public/browser/render_process_host.h"
52 #include "content/public/browser/resource_request_info.h" 51 #include "content/public/browser/resource_request_info.h"
53 #include "content/public/browser/user_metrics.h" 52 #include "content/public/browser/user_metrics.h"
53 #include "extensions/browser/info_map.h"
54 #include "extensions/common/error_utils.h" 54 #include "extensions/common/error_utils.h"
55 #include "extensions/common/event_filtering_info.h" 55 #include "extensions/common/event_filtering_info.h"
56 #include "extensions/common/features/feature.h" 56 #include "extensions/common/features/feature.h"
57 #include "extensions/common/url_pattern.h" 57 #include "extensions/common/url_pattern.h"
58 #include "grit/generated_resources.h" 58 #include "grit/generated_resources.h"
59 #include "net/base/auth.h" 59 #include "net/base/auth.h"
60 #include "net/base/net_errors.h" 60 #include "net/base/net_errors.h"
61 #include "net/base/upload_data_stream.h" 61 #include "net/base/upload_data_stream.h"
62 #include "net/http/http_response_headers.h" 62 #include "net/http/http_response_headers.h"
63 #include "net/url_request/url_request.h" 63 #include "net/url_request/url_request.h"
64 #include "ui/base/l10n/l10n_util.h" 64 #include "ui/base/l10n/l10n_util.h"
65 #include "url/gurl.h" 65 #include "url/gurl.h"
66 66
67 using base::DictionaryValue; 67 using base::DictionaryValue;
68 using base::ListValue; 68 using base::ListValue;
69 using base::StringValue; 69 using base::StringValue;
70 using chrome::VersionInfo; 70 using chrome::VersionInfo;
71 using content::BrowserMessageFilter; 71 using content::BrowserMessageFilter;
72 using content::BrowserThread; 72 using content::BrowserThread;
73 using content::ResourceRequestInfo; 73 using content::ResourceRequestInfo;
74 using extensions::ErrorUtils; 74 using extensions::ErrorUtils;
75 using extensions::Extension; 75 using extensions::Extension;
76 using extensions::ExtensionWarning; 76 using extensions::ExtensionWarning;
77 using extensions::ExtensionWarningService; 77 using extensions::ExtensionWarningService;
78 using extensions::ExtensionWarningSet; 78 using extensions::ExtensionWarningSet;
79 using extensions::InfoMap;
79 using extensions::Feature; 80 using extensions::Feature;
80 using extensions::web_navigation_api_helpers::GetFrameId; 81 using extensions::web_navigation_api_helpers::GetFrameId;
81 82
82 namespace helpers = extension_web_request_api_helpers; 83 namespace helpers = extension_web_request_api_helpers;
83 namespace keys = extension_web_request_api_constants; 84 namespace keys = extension_web_request_api_constants;
84 namespace web_request = extensions::api::web_request; 85 namespace web_request = extensions::api::web_request;
85 namespace declarative_keys = extensions::declarative_webrequest_constants; 86 namespace declarative_keys = extensions::declarative_webrequest_constants;
86 namespace activitylog = activity_log_web_request_constants; 87 namespace activitylog = activity_log_web_request_constants;
87 88
88 namespace { 89 namespace {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 std::string web_request_event_name(event_name); 138 std::string web_request_event_name(event_name);
138 if (web_request_event_name.find(kWebView) != std::string::npos) 139 if (web_request_event_name.find(kWebView) != std::string::npos)
139 web_request_event_name.replace(0, sizeof(kWebView) - 1, kWebRequest); 140 web_request_event_name.replace(0, sizeof(kWebView) - 1, kWebRequest);
140 return std::find(kWebRequestEvents, ARRAYEND(kWebRequestEvents), 141 return std::find(kWebRequestEvents, ARRAYEND(kWebRequestEvents),
141 web_request_event_name) != ARRAYEND(kWebRequestEvents); 142 web_request_event_name) != ARRAYEND(kWebRequestEvents);
142 } 143 }
143 144
144 // Returns whether |request| has been triggered by an extension in 145 // Returns whether |request| has been triggered by an extension in
145 // |extension_info_map|. 146 // |extension_info_map|.
146 bool IsRequestFromExtension(const net::URLRequest* request, 147 bool IsRequestFromExtension(const net::URLRequest* request,
147 const ExtensionInfoMap* extension_info_map) { 148 const InfoMap* extension_info_map) {
148 // |extension_info_map| is NULL for system-level requests. 149 // |extension_info_map| is NULL for system-level requests.
149 if (!extension_info_map) 150 if (!extension_info_map)
150 return false; 151 return false;
151 152
152 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 153 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
153 154
154 // If this request was not created by the ResourceDispatcher, |info| is NULL. 155 // If this request was not created by the ResourceDispatcher, |info| is NULL.
155 // All requests from extensions are created by the ResourceDispatcher. 156 // All requests from extensions are created by the ResourceDispatcher.
156 if (!info) 157 if (!info)
157 return false; 158 return false;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 net::NetworkDelegate::AuthCallback auth_callback; 463 net::NetworkDelegate::AuthCallback auth_callback;
463 464
464 // Time the request was paused. Used for logging purposes. 465 // Time the request was paused. Used for logging purposes.
465 base::Time blocking_time; 466 base::Time blocking_time;
466 467
467 // Changes requested by extensions. 468 // Changes requested by extensions.
468 helpers::EventResponseDeltas response_deltas; 469 helpers::EventResponseDeltas response_deltas;
469 470
470 // Provider of meta data about extensions, only used and non-NULL for events 471 // Provider of meta data about extensions, only used and non-NULL for events
471 // that are delayed until the rules registry is ready. 472 // that are delayed until the rules registry is ready.
472 ExtensionInfoMap* extension_info_map; 473 InfoMap* extension_info_map;
473 474
474 BlockedRequest() 475 BlockedRequest()
475 : request(NULL), 476 : request(NULL),
476 is_incognito(false), 477 is_incognito(false),
477 event(kInvalidEvent), 478 event(kInvalidEvent),
478 num_handlers_blocking(0), 479 num_handlers_blocking(0),
479 net_log(NULL), 480 net_log(NULL),
480 new_url(NULL), 481 new_url(NULL),
481 request_headers(NULL), 482 request_headers(NULL),
482 override_response_headers(NULL), 483 override_response_headers(NULL),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 void* profile, 602 void* profile,
602 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { 603 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) {
603 if (rules_registry.get()) 604 if (rules_registry.get())
604 rules_registries_[profile] = rules_registry; 605 rules_registries_[profile] = rules_registry;
605 else 606 else
606 rules_registries_.erase(profile); 607 rules_registries_.erase(profile);
607 } 608 }
608 609
609 int ExtensionWebRequestEventRouter::OnBeforeRequest( 610 int ExtensionWebRequestEventRouter::OnBeforeRequest(
610 void* profile, 611 void* profile,
611 ExtensionInfoMap* extension_info_map, 612 InfoMap* extension_info_map,
612 net::URLRequest* request, 613 net::URLRequest* request,
613 const net::CompletionCallback& callback, 614 const net::CompletionCallback& callback,
614 GURL* new_url) { 615 GURL* new_url) {
615 // We hide events from the system context as well as sensitive requests. 616 // We hide events from the system context as well as sensitive requests.
616 if (!profile || 617 if (!profile ||
617 WebRequestPermissions::HideRequest(extension_info_map, request)) 618 WebRequestPermissions::HideRequest(extension_info_map, request))
618 return net::OK; 619 return net::OK;
619 620
620 if (IsPageLoad(request)) 621 if (IsPageLoad(request))
621 NotifyPageLoad(); 622 NotifyPageLoad();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 // to modify the request and we can respond synchronously. 668 // to modify the request and we can respond synchronously.
668 return ExecuteDeltas(profile, request->identifier(), 669 return ExecuteDeltas(profile, request->identifier(),
669 false /* call_callback*/); 670 false /* call_callback*/);
670 } else { 671 } else {
671 return net::ERR_IO_PENDING; 672 return net::ERR_IO_PENDING;
672 } 673 }
673 } 674 }
674 675
675 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders( 676 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders(
676 void* profile, 677 void* profile,
677 ExtensionInfoMap* extension_info_map, 678 InfoMap* extension_info_map,
678 net::URLRequest* request, 679 net::URLRequest* request,
679 const net::CompletionCallback& callback, 680 const net::CompletionCallback& callback,
680 net::HttpRequestHeaders* headers) { 681 net::HttpRequestHeaders* headers) {
681 // We hide events from the system context as well as sensitive requests. 682 // We hide events from the system context as well as sensitive requests.
682 if (!profile || 683 if (!profile ||
683 WebRequestPermissions::HideRequest(extension_info_map, request)) 684 WebRequestPermissions::HideRequest(extension_info_map, request))
684 return net::OK; 685 return net::OK;
685 686
686 bool initialize_blocked_requests = false; 687 bool initialize_blocked_requests = false;
687 688
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // to modify the request and we can respond synchronously. 725 // to modify the request and we can respond synchronously.
725 return ExecuteDeltas(profile, request->identifier(), 726 return ExecuteDeltas(profile, request->identifier(),
726 false /* call_callback*/); 727 false /* call_callback*/);
727 } else { 728 } else {
728 return net::ERR_IO_PENDING; 729 return net::ERR_IO_PENDING;
729 } 730 }
730 } 731 }
731 732
732 void ExtensionWebRequestEventRouter::OnSendHeaders( 733 void ExtensionWebRequestEventRouter::OnSendHeaders(
733 void* profile, 734 void* profile,
734 ExtensionInfoMap* extension_info_map, 735 InfoMap* extension_info_map,
735 net::URLRequest* request, 736 net::URLRequest* request,
736 const net::HttpRequestHeaders& headers) { 737 const net::HttpRequestHeaders& headers) {
737 // We hide events from the system context as well as sensitive requests. 738 // We hide events from the system context as well as sensitive requests.
738 if (!profile || 739 if (!profile ||
739 WebRequestPermissions::HideRequest(extension_info_map, request)) 740 WebRequestPermissions::HideRequest(extension_info_map, request))
740 return; 741 return;
741 742
742 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders)) 743 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders))
743 return; 744 return;
744 745
(...skipping 12 matching lines...) Expand all
757 ExtractRequestInfo(request, dict); 758 ExtractRequestInfo(request, dict);
758 if (extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) 759 if (extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)
759 dict->Set(keys::kRequestHeadersKey, GetRequestHeadersList(headers)); 760 dict->Set(keys::kRequestHeadersKey, GetRequestHeadersList(headers));
760 args.Append(dict); 761 args.Append(dict);
761 762
762 DispatchEvent(profile, request, listeners, args); 763 DispatchEvent(profile, request, listeners, args);
763 } 764 }
764 765
765 int ExtensionWebRequestEventRouter::OnHeadersReceived( 766 int ExtensionWebRequestEventRouter::OnHeadersReceived(
766 void* profile, 767 void* profile,
767 ExtensionInfoMap* extension_info_map, 768 InfoMap* extension_info_map,
768 net::URLRequest* request, 769 net::URLRequest* request,
769 const net::CompletionCallback& callback, 770 const net::CompletionCallback& callback,
770 const net::HttpResponseHeaders* original_response_headers, 771 const net::HttpResponseHeaders* original_response_headers,
771 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { 772 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
772 // We hide events from the system context as well as sensitive requests. 773 // We hide events from the system context as well as sensitive requests.
773 if (!profile || 774 if (!profile ||
774 WebRequestPermissions::HideRequest(extension_info_map, request)) 775 WebRequestPermissions::HideRequest(extension_info_map, request))
775 return net::OK; 776 return net::OK;
776 777
777 bool initialize_blocked_requests = false; 778 bool initialize_blocked_requests = false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 return ExecuteDeltas(profile, request->identifier(), 826 return ExecuteDeltas(profile, request->identifier(),
826 false /* call_callback*/); 827 false /* call_callback*/);
827 } else { 828 } else {
828 return net::ERR_IO_PENDING; 829 return net::ERR_IO_PENDING;
829 } 830 }
830 } 831 }
831 832
832 net::NetworkDelegate::AuthRequiredResponse 833 net::NetworkDelegate::AuthRequiredResponse
833 ExtensionWebRequestEventRouter::OnAuthRequired( 834 ExtensionWebRequestEventRouter::OnAuthRequired(
834 void* profile, 835 void* profile,
835 ExtensionInfoMap* extension_info_map, 836 InfoMap* extension_info_map,
836 net::URLRequest* request, 837 net::URLRequest* request,
837 const net::AuthChallengeInfo& auth_info, 838 const net::AuthChallengeInfo& auth_info,
838 const net::NetworkDelegate::AuthCallback& callback, 839 const net::NetworkDelegate::AuthCallback& callback,
839 net::AuthCredentials* credentials) { 840 net::AuthCredentials* credentials) {
840 // No profile means that this is for authentication challenges in the 841 // No profile means that this is for authentication challenges in the
841 // system context. Skip in that case. Also skip sensitive requests. 842 // system context. Skip in that case. Also skip sensitive requests.
842 if (!profile || 843 if (!profile ||
843 WebRequestPermissions::HideRequest(extension_info_map, request)) 844 WebRequestPermissions::HideRequest(extension_info_map, request))
844 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 845 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
845 846
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 blocked_requests_[request->identifier()].auth_callback = callback; 879 blocked_requests_[request->identifier()].auth_callback = callback;
879 blocked_requests_[request->identifier()].auth_credentials = credentials; 880 blocked_requests_[request->identifier()].auth_credentials = credentials;
880 blocked_requests_[request->identifier()].net_log = &request->net_log(); 881 blocked_requests_[request->identifier()].net_log = &request->net_log();
881 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING; 882 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING;
882 } 883 }
883 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 884 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
884 } 885 }
885 886
886 void ExtensionWebRequestEventRouter::OnBeforeRedirect( 887 void ExtensionWebRequestEventRouter::OnBeforeRedirect(
887 void* profile, 888 void* profile,
888 ExtensionInfoMap* extension_info_map, 889 InfoMap* extension_info_map,
889 net::URLRequest* request, 890 net::URLRequest* request,
890 const GURL& new_location) { 891 const GURL& new_location) {
891 // We hide events from the system context as well as sensitive requests. 892 // We hide events from the system context as well as sensitive requests.
892 if (!profile || 893 if (!profile ||
893 WebRequestPermissions::HideRequest(extension_info_map, request)) 894 WebRequestPermissions::HideRequest(extension_info_map, request))
894 return; 895 return;
895 896
896 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect)) 897 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect))
897 return; 898 return;
898 899
(...skipping 27 matching lines...) Expand all
926 dict->Set(keys::kResponseHeadersKey, 927 dict->Set(keys::kResponseHeadersKey,
927 GetResponseHeadersList(request->response_headers())); 928 GetResponseHeadersList(request->response_headers()));
928 } 929 }
929 args.Append(dict); 930 args.Append(dict);
930 931
931 DispatchEvent(profile, request, listeners, args); 932 DispatchEvent(profile, request, listeners, args);
932 } 933 }
933 934
934 void ExtensionWebRequestEventRouter::OnResponseStarted( 935 void ExtensionWebRequestEventRouter::OnResponseStarted(
935 void* profile, 936 void* profile,
936 ExtensionInfoMap* extension_info_map, 937 InfoMap* extension_info_map,
937 net::URLRequest* request) { 938 net::URLRequest* request) {
938 // We hide events from the system context as well as sensitive requests. 939 // We hide events from the system context as well as sensitive requests.
939 if (!profile || 940 if (!profile ||
940 WebRequestPermissions::HideRequest(extension_info_map, request)) 941 WebRequestPermissions::HideRequest(extension_info_map, request))
941 return; 942 return;
942 943
943 // OnResponseStarted is even triggered, when the request was cancelled. 944 // OnResponseStarted is even triggered, when the request was cancelled.
944 if (request->status().status() != net::URLRequestStatus::SUCCESS) 945 if (request->status().status() != net::URLRequestStatus::SUCCESS)
945 return; 946 return;
946 947
(...skipping 22 matching lines...) Expand all
969 dict->Set(keys::kStatusLineKey, GetStatusLine(request->response_headers())); 970 dict->Set(keys::kStatusLineKey, GetStatusLine(request->response_headers()));
970 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) { 971 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) {
971 dict->Set(keys::kResponseHeadersKey, 972 dict->Set(keys::kResponseHeadersKey,
972 GetResponseHeadersList(request->response_headers())); 973 GetResponseHeadersList(request->response_headers()));
973 } 974 }
974 args.Append(dict); 975 args.Append(dict);
975 976
976 DispatchEvent(profile, request, listeners, args); 977 DispatchEvent(profile, request, listeners, args);
977 } 978 }
978 979
979 void ExtensionWebRequestEventRouter::OnCompleted( 980 void ExtensionWebRequestEventRouter::OnCompleted(void* profile,
980 void* profile, 981 InfoMap* extension_info_map,
981 ExtensionInfoMap* extension_info_map, 982 net::URLRequest* request) {
982 net::URLRequest* request) {
983 // We hide events from the system context as well as sensitive requests. 983 // We hide events from the system context as well as sensitive requests.
984 // However, if the request first became sensitive after redirecting we have 984 // However, if the request first became sensitive after redirecting we have
985 // already signaled it and thus we have to signal the end of it. This is 985 // already signaled it and thus we have to signal the end of it. This is
986 // risk-free because the handler cannot modify the request now. 986 // risk-free because the handler cannot modify the request now.
987 if (!profile || 987 if (!profile ||
988 (WebRequestPermissions::HideRequest(extension_info_map, request) && 988 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
989 !WasSignaled(*request))) 989 !WasSignaled(*request)))
990 return; 990 return;
991 991
992 request_time_tracker_->LogRequestEndTime(request->identifier(), 992 request_time_tracker_->LogRequestEndTime(request->identifier(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 dict->Set(keys::kResponseHeadersKey, 1024 dict->Set(keys::kResponseHeadersKey,
1025 GetResponseHeadersList(request->response_headers())); 1025 GetResponseHeadersList(request->response_headers()));
1026 } 1026 }
1027 args.Append(dict); 1027 args.Append(dict);
1028 1028
1029 DispatchEvent(profile, request, listeners, args); 1029 DispatchEvent(profile, request, listeners, args);
1030 } 1030 }
1031 1031
1032 void ExtensionWebRequestEventRouter::OnErrorOccurred( 1032 void ExtensionWebRequestEventRouter::OnErrorOccurred(
1033 void* profile, 1033 void* profile,
1034 ExtensionInfoMap* extension_info_map, 1034 InfoMap* extension_info_map,
1035 net::URLRequest* request, 1035 net::URLRequest* request,
1036 bool started) { 1036 bool started) {
1037 // We hide events from the system context as well as sensitive requests. 1037 // We hide events from the system context as well as sensitive requests.
1038 // However, if the request first became sensitive after redirecting we have 1038 // However, if the request first became sensitive after redirecting we have
1039 // already signaled it and thus we have to signal the end of it. This is 1039 // already signaled it and thus we have to signal the end of it. This is
1040 // risk-free because the handler cannot modify the request now. 1040 // risk-free because the handler cannot modify the request now.
1041 if (!profile || 1041 if (!profile ||
1042 (WebRequestPermissions::HideRequest(extension_info_map, request) && 1042 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
1043 !WasSignaled(*request))) 1043 !WasSignaled(*request)))
1044 return; 1044 return;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 1337
1338 bool ExtensionWebRequestEventRouter::WasSignaled( 1338 bool ExtensionWebRequestEventRouter::WasSignaled(
1339 const net::URLRequest& request) const { 1339 const net::URLRequest& request) const {
1340 SignaledRequestMap::const_iterator flag = 1340 SignaledRequestMap::const_iterator flag =
1341 signaled_requests_.find(request.identifier()); 1341 signaled_requests_.find(request.identifier());
1342 return (flag != signaled_requests_.end()) && (flag->second != 0); 1342 return (flag != signaled_requests_.end()) && (flag->second != 0);
1343 } 1343 }
1344 1344
1345 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( 1345 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl(
1346 void* profile, 1346 void* profile,
1347 ExtensionInfoMap* extension_info_map, 1347 InfoMap* extension_info_map,
1348 bool crosses_incognito, 1348 bool crosses_incognito,
1349 const std::string& event_name, 1349 const std::string& event_name,
1350 const GURL& url, 1350 const GURL& url,
1351 int tab_id, 1351 int tab_id,
1352 int window_id, 1352 int window_id,
1353 int render_process_host_id, 1353 int render_process_host_id,
1354 int routing_id, 1354 int routing_id,
1355 ResourceType::Type resource_type, 1355 ResourceType::Type resource_type,
1356 bool is_async_request, 1356 bool is_async_request,
1357 bool is_request_from_extension, 1357 bool is_request_from_extension,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 continue; 1414 continue;
1415 1415
1416 matching_listeners->push_back(&(*it)); 1416 matching_listeners->push_back(&(*it));
1417 *extra_info_spec |= it->extra_info_spec; 1417 *extra_info_spec |= it->extra_info_spec;
1418 } 1418 }
1419 } 1419 }
1420 1420
1421 std::vector<const ExtensionWebRequestEventRouter::EventListener*> 1421 std::vector<const ExtensionWebRequestEventRouter::EventListener*>
1422 ExtensionWebRequestEventRouter::GetMatchingListeners( 1422 ExtensionWebRequestEventRouter::GetMatchingListeners(
1423 void* profile, 1423 void* profile,
1424 ExtensionInfoMap* extension_info_map, 1424 InfoMap* extension_info_map,
1425 const std::string& event_name, 1425 const std::string& event_name,
1426 net::URLRequest* request, 1426 net::URLRequest* request,
1427 int* extra_info_spec) { 1427 int* extra_info_spec) {
1428 // TODO(mpcomplete): handle profile == NULL (should collect all listeners). 1428 // TODO(mpcomplete): handle profile == NULL (should collect all listeners).
1429 *extra_info_spec = 0; 1429 *extra_info_spec = 0;
1430 1430
1431 bool is_main_frame = false; 1431 bool is_main_frame = false;
1432 int64 frame_id = -1; 1432 int64 frame_id = -1;
1433 bool parent_is_main_frame = false; 1433 bool parent_is_main_frame = false;
1434 int64 parent_frame_id = -1; 1434 int64 parent_frame_id = -1;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 if (call_callback) 1842 if (call_callback)
1843 callback.Run(response); 1843 callback.Run(response);
1844 } else { 1844 } else {
1845 blocked_requests_.erase(request_id); 1845 blocked_requests_.erase(request_id);
1846 } 1846 }
1847 return rv; 1847 return rv;
1848 } 1848 }
1849 1849
1850 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( 1850 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules(
1851 void* profile, 1851 void* profile,
1852 ExtensionInfoMap* extension_info_map, 1852 InfoMap* extension_info_map,
1853 const std::string& event_name, 1853 const std::string& event_name,
1854 net::URLRequest* request, 1854 net::URLRequest* request,
1855 extensions::RequestStage request_stage, 1855 extensions::RequestStage request_stage,
1856 const net::HttpResponseHeaders* original_response_headers) { 1856 const net::HttpResponseHeaders* original_response_headers) {
1857 // If this check fails, check that the active stages are up-to-date in 1857 // If this check fails, check that the active stages are up-to-date in
1858 // browser/extensions/api/declarative_webrequest/request_stage.h . 1858 // browser/extensions/api/declarative_webrequest/request_stage.h .
1859 DCHECK(request_stage & extensions::kActiveStages); 1859 DCHECK(request_stage & extensions::kActiveStages);
1860 1860
1861 // Rules of the current |profile| may apply but we need to check also whether 1861 // Rules of the current |profile| may apply but we need to check also whether
1862 // there are applicable rules from extensions whose background page 1862 // there are applicable rules from extensions whose background page
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 // of WebKit at the time of the next page load (top level navigation event). 1992 // of WebKit at the time of the next page load (top level navigation event).
1993 // This quota heuristic is intended to limit the number of times the cache is 1993 // This quota heuristic is intended to limit the number of times the cache is
1994 // cleared by an extension. 1994 // cleared by an extension.
1995 // 1995 //
1996 // As we want to account for the number of times the cache is really cleared 1996 // As we want to account for the number of times the cache is really cleared
1997 // (opposed to the number of times webRequest.handlerBehaviorChanged() is 1997 // (opposed to the number of times webRequest.handlerBehaviorChanged() is
1998 // called), we cannot decide whether a call of 1998 // called), we cannot decide whether a call of
1999 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the 1999 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the
2000 // time it is called. Instead we only decrement the bucket counter at the time 2000 // time it is called. Instead we only decrement the bucket counter at the time
2001 // when the cache is cleared (when page loads happen). 2001 // when the cache is cleared (when page loads happen).
2002 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic { 2002 class ClearCacheQuotaHeuristic : public extensions::QuotaLimitHeuristic {
2003 public: 2003 public:
2004 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map) 2004 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map)
2005 : QuotaLimitHeuristic( 2005 : QuotaLimitHeuristic(
2006 config, 2006 config,
2007 map, 2007 map,
2008 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"), 2008 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"),
2009 callback_registered_(false), 2009 callback_registered_(false),
2010 weak_ptr_factory_(this) {} 2010 weak_ptr_factory_(this) {}
2011 virtual ~ClearCacheQuotaHeuristic() {} 2011 virtual ~ClearCacheQuotaHeuristic() {}
2012 virtual bool Apply(Bucket* bucket, 2012 virtual bool Apply(Bucket* bucket,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 } 2238 }
2239 2239
2240 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( 2240 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled(
2241 profile_id(), extension_id(), event_name, sub_event_name, request_id, 2241 profile_id(), extension_id(), event_name, sub_event_name, request_id,
2242 response.release()); 2242 response.release());
2243 2243
2244 return true; 2244 return true;
2245 } 2245 }
2246 2246
2247 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics( 2247 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics(
2248 QuotaLimitHeuristics* heuristics) const { 2248 extensions::QuotaLimitHeuristics* heuristics) const {
2249 QuotaLimitHeuristic::Config config = { 2249 extensions::QuotaLimitHeuristic::Config config = {
2250 // See web_request.json for current value. 2250 // See web_request.json for current value.
2251 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES, 2251 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES,
2252 base::TimeDelta::FromMinutes(10) 2252 base::TimeDelta::FromMinutes(10)};
2253 }; 2253 extensions::QuotaLimitHeuristic::BucketMapper* bucket_mapper =
2254 QuotaLimitHeuristic::BucketMapper* bucket_mapper = 2254 new extensions::QuotaLimitHeuristic::SingletonBucketMapper();
2255 new QuotaLimitHeuristic::SingletonBucketMapper();
2256 ClearCacheQuotaHeuristic* heuristic = 2255 ClearCacheQuotaHeuristic* heuristic =
2257 new ClearCacheQuotaHeuristic(config, bucket_mapper); 2256 new ClearCacheQuotaHeuristic(config, bucket_mapper);
2258 heuristics->push_back(heuristic); 2257 heuristics->push_back(heuristic);
2259 } 2258 }
2260 2259
2261 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded( 2260 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded(
2262 const std::string& violation_error) { 2261 const std::string& violation_error) {
2263 // Post warning message. 2262 // Post warning message.
2264 ExtensionWarningSet warnings; 2263 ExtensionWarningSet warnings;
2265 warnings.insert( 2264 warnings.insert(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2296 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
2298 adblock = true; 2297 adblock = true;
2299 } else { 2298 } else {
2300 other = true; 2299 other = true;
2301 } 2300 }
2302 } 2301 }
2303 } 2302 }
2304 2303
2305 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2304 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
2306 } 2305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698