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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 void ExtensionWebRequestEventRouter::ClearPendingCallbacks( | 910 void ExtensionWebRequestEventRouter::ClearPendingCallbacks( |
911 net::URLRequest* request) { | 911 net::URLRequest* request) { |
912 blocked_requests_.erase(request->identifier()); | 912 blocked_requests_.erase(request->identifier()); |
913 } | 913 } |
914 | 914 |
915 bool ExtensionWebRequestEventRouter::DispatchEvent( | 915 bool ExtensionWebRequestEventRouter::DispatchEvent( |
916 void* profile, | 916 void* profile, |
917 net::URLRequest* request, | 917 net::URLRequest* request, |
918 const std::vector<const EventListener*>& listeners, | 918 const std::vector<const EventListener*>& listeners, |
919 const ListValue& args) { | 919 const ListValue& args) { |
920 std::string json_args; | |
921 | |
922 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) | 920 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) |
923 // pairs into a single message sent to a list of sub_event_names. | 921 // pairs into a single message sent to a list of sub_event_names. |
924 int num_handlers_blocking = 0; | 922 int num_handlers_blocking = 0; |
925 for (std::vector<const EventListener*>::const_iterator it = listeners.begin(); | 923 for (std::vector<const EventListener*>::const_iterator it = listeners.begin(); |
926 it != listeners.end(); ++it) { | 924 it != listeners.end(); ++it) { |
927 // Filter out the optional keys that this listener didn't request. | 925 // Filter out the optional keys that this listener didn't request. |
928 scoped_ptr<ListValue> args_filtered(args.DeepCopy()); | 926 ListValue* args_filtered = args.DeepCopy(); |
929 DictionaryValue* dict = NULL; | 927 DictionaryValue* dict = NULL; |
930 CHECK(args_filtered->GetDictionary(0, &dict) && dict); | 928 CHECK(args_filtered->GetDictionary(0, &dict) && dict); |
931 if (!((*it)->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) | 929 if (!((*it)->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) |
932 dict->Remove(keys::kRequestHeadersKey, NULL); | 930 dict->Remove(keys::kRequestHeadersKey, NULL); |
933 if (!((*it)->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) | 931 if (!((*it)->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) |
934 dict->Remove(keys::kResponseHeadersKey, NULL); | 932 dict->Remove(keys::kResponseHeadersKey, NULL); |
935 | 933 |
936 base::JSONWriter::Write(args_filtered.get(), &json_args); | |
937 | |
938 ExtensionEventRouter::DispatchEvent( | 934 ExtensionEventRouter::DispatchEvent( |
939 (*it)->ipc_sender.get(), (*it)->extension_id, (*it)->sub_event_name, | 935 (*it)->ipc_sender.get(), (*it)->extension_id, (*it)->sub_event_name, |
940 json_args, GURL(), ExtensionEventRouter::USER_GESTURE_UNKNOWN, | 936 args_filtered, GURL(), ExtensionEventRouter::USER_GESTURE_UNKNOWN, |
941 EventFilteringInfo()); | 937 EventFilteringInfo()); |
942 if ((*it)->extra_info_spec & | 938 if ((*it)->extra_info_spec & |
943 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { | 939 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { |
944 (*it)->blocked_requests.insert(request->identifier()); | 940 (*it)->blocked_requests.insert(request->identifier()); |
945 ++num_handlers_blocking; | 941 ++num_handlers_blocking; |
946 | 942 |
947 request->SetLoadStateParam( | 943 request->SetLoadStateParam( |
948 l10n_util::GetStringFUTF16(IDS_LOAD_STATE_PARAMETER_EXTENSION, | 944 l10n_util::GetStringFUTF16(IDS_LOAD_STATE_PARAMETER_EXTENSION, |
949 UTF8ToUTF16((*it)->extension_name))); | 945 UTF8ToUTF16((*it)->extension_name))); |
950 } | 946 } |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1768 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1773 adblock = true; | 1769 adblock = true; |
1774 } else { | 1770 } else { |
1775 other = true; | 1771 other = true; |
1776 } | 1772 } |
1777 } | 1773 } |
1778 } | 1774 } |
1779 | 1775 |
1780 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1776 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1781 } | 1777 } |
OLD | NEW |