Index: chrome/browser/extensions/extension_webrequest_api.cc |
diff --git a/chrome/browser/extensions/extension_webrequest_api.cc b/chrome/browser/extensions/extension_webrequest_api.cc |
index 46d14c10312903f17a03460208d9a35f07c5d786..f07c7b297ef119cf68813ee9fab739b7f8dd780f 100644 |
--- a/chrome/browser/extensions/extension_webrequest_api.cc |
+++ b/chrome/browser/extensions/extension_webrequest_api.cc |
@@ -16,6 +16,7 @@ |
#include "chrome/common/extensions/extension.h" |
#include "chrome/common/extensions/extension_extent.h" |
#include "chrome/common/extensions/url_pattern.h" |
+#include "chrome/common/url_constants.h" |
#include "content/browser/browser_thread.h" |
#include "net/base/net_errors.h" |
#include "net/url_request/url_request.h" |
@@ -243,6 +244,60 @@ bool ExtensionWebRequestEventRouter::OnBeforeRequest( |
if (listeners.empty()) |
return false; |
+ // Don't handle HTTP requests yet. We want to wait until we have headers |
+ // available. Then we can dispatch the event. Remember the request, because |
+ // we only have access to the ID at that point. |
+ if (request->url().SchemeIs(chrome::kHttpScheme) || |
+ request->url().SchemeIs(chrome::kHttpsScheme)) { |
+ http_requests_[request->identifier()] = request; |
willchan no longer on Chromium
2011/03/17 15:55:54
You insert into this map here. What happens if OnB
Matt Perry
2011/03/22 21:11:43
Yep... I added a tracking object so they're remove
|
+ return false; |
+ } |
+ |
+ return OnBeforeRequestCommon(profile_id, event_router, request, callback, |
+ tab_id, window_id, resource_type, listeners); |
willchan no longer on Chromium
2011/03/17 15:55:54
where are these variables coming from? looks like
Matt Perry
2011/03/22 21:11:43
oops. bad base revision messed this up.
|
+} |
+ |
+bool ExtensionWebRequestEventRouter::OnBeforeHttpRequest( |
+ ProfileId profile_id, |
+ ExtensionEventRouterForwarder* event_router, |
+ uint64 request_id, |
+ net::HttpRequestHeaders* headers, |
willchan no longer on Chromium
2011/03/17 15:55:54
Don't you need to pass this variable through to On
Matt Perry
2011/03/22 21:11:43
Yeah, I'm leaving that as a TODO for now. There's
|
+ net::CompletionCallback* callback) { |
+ // TODO(jochen): Figure out what to do with events from the system context. |
+ if (profile_id == Profile::kInvalidProfileId) |
+ return false; |
+ |
+ HttpRequestMap::iterator iter = http_requests_.find(request_id); |
+ if (iter == http_requests_.end()) |
willchan no longer on Chromium
2011/03/17 15:55:54
Isn't this a bug? Should this be LOG(DFATAL)?
|
+ return false; |
+ |
+ net::URLRequest* request = iter->second; |
+ http_requests_.erase(iter); |
+ |
+ int tab_id = -1; |
+ int window_id = -1; |
+ ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
+ ExtractRequestInfo(request, &tab_id, &window_id, &resource_type); |
+ |
+ std::vector<const EventListener*> listeners = |
+ GetMatchingListeners(profile_id, keys::kOnBeforeRequest, request->url(), |
+ tab_id, window_id, resource_type); |
+ if (listeners.empty()) |
+ return false; |
+ |
+ return OnBeforeRequestCommon(profile_id, event_router, request, callback, |
+ tab_id, window_id, resource_type, listeners); |
+} |
+ |
+bool ExtensionWebRequestEventRouter::OnBeforeRequestCommon( |
+ ProfileId profile_id, |
+ ExtensionEventRouterForwarder* event_router, |
+ net::URLRequest* request, |
+ net::CompletionCallback* callback, |
+ int tab_id, |
+ int window_id, |
+ ResourceType::Type resource_type, |
+ const std::vector<const EventListener*>& listeners) { |
ListValue args; |
DictionaryValue* dict = new DictionaryValue(); |
dict->SetString(keys::kUrlKey, request->url().spec()); |
@@ -261,12 +316,12 @@ bool ExtensionWebRequestEventRouter::OnBeforeRequest( |
// TODO(mpcomplete): Consider consolidating common (extension_id,json_args) |
// pairs into a single message sent to a list of sub_event_names. |
int num_handlers_blocking = 0; |
- for (std::vector<const EventListener*>::iterator it = listeners.begin(); |
+ for (std::vector<const EventListener*>::const_iterator it = listeners.begin(); |
it != listeners.end(); ++it) { |
event_router->DispatchEventToExtension( |
(*it)->extension_id, (*it)->sub_event_name, json_args, |
profile_id, true, GURL()); |
- if ((*it)->extra_info_spec & ExtraInfoSpec::BLOCKING) { |
+ if (callback && (*it)->extra_info_spec & ExtraInfoSpec::BLOCKING) { |
(*it)->blocked_requests.insert(request->identifier()); |
++num_handlers_blocking; |
} |