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 scoped_ptr<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 extensions::EventRouter::DispatchEvent( | 934 extensions::EventRouter::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(), extensions::EventRouter::USER_GESTURE_UNKNOWN, | 936 args_filtered.Pass(), GURL(), |
| 937 extensions::EventRouter::USER_GESTURE_UNKNOWN, |
941 extensions::EventFilteringInfo()); | 938 extensions::EventFilteringInfo()); |
942 if ((*it)->extra_info_spec & | 939 if ((*it)->extra_info_spec & |
943 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { | 940 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { |
944 (*it)->blocked_requests.insert(request->identifier()); | 941 (*it)->blocked_requests.insert(request->identifier()); |
945 ++num_handlers_blocking; | 942 ++num_handlers_blocking; |
946 | 943 |
947 request->SetLoadStateParam( | 944 request->SetLoadStateParam( |
948 l10n_util::GetStringFUTF16(IDS_LOAD_STATE_PARAMETER_EXTENSION, | 945 l10n_util::GetStringFUTF16(IDS_LOAD_STATE_PARAMETER_EXTENSION, |
949 UTF8ToUTF16((*it)->extension_name))); | 946 UTF8ToUTF16((*it)->extension_name))); |
950 } | 947 } |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1817 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1821 adblock = true; | 1818 adblock = true; |
1822 } else { | 1819 } else { |
1823 other = true; | 1820 other = true; |
1824 } | 1821 } |
1825 } | 1822 } |
1826 } | 1823 } |
1827 | 1824 |
1828 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1825 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1829 } | 1826 } |
OLD | NEW |