Chromium Code Reviews| 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 "extensions/browser/api/web_request/web_request_api.h" | 5 #include "extensions/browser/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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return keys::kOnResponseStarted; | 120 return keys::kOnResponseStarted; |
| 121 case ExtensionWebRequestEventRouter::kOnErrorOccurred: | 121 case ExtensionWebRequestEventRouter::kOnErrorOccurred: |
| 122 return keys::kOnErrorOccurred; | 122 return keys::kOnErrorOccurred; |
| 123 case ExtensionWebRequestEventRouter::kOnCompleted: | 123 case ExtensionWebRequestEventRouter::kOnCompleted: |
| 124 return keys::kOnCompleted; | 124 return keys::kOnCompleted; |
| 125 } | 125 } |
| 126 NOTREACHED(); | 126 NOTREACHED(); |
| 127 return "Not reached"; | 127 return "Not reached"; |
| 128 } | 128 } |
| 129 | 129 |
| 130 int GetFrameId(bool is_main_frame, int frame_id) { | |
| 131 return is_main_frame ? 0 : frame_id; | |
| 132 } | |
| 133 | |
| 134 bool IsWebRequestEvent(const std::string& event_name) { | 130 bool IsWebRequestEvent(const std::string& event_name) { |
| 135 std::string web_request_event_name(event_name); | 131 std::string web_request_event_name(event_name); |
| 136 if (base::StartsWith(web_request_event_name, | 132 if (base::StartsWith(web_request_event_name, |
| 137 webview::kWebViewEventPrefix, | 133 webview::kWebViewEventPrefix, |
| 138 base::CompareCase::SENSITIVE)) { | 134 base::CompareCase::SENSITIVE)) { |
| 139 web_request_event_name.replace( | 135 web_request_event_name.replace( |
| 140 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix); | 136 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix); |
| 141 } | 137 } |
| 142 const auto web_request_events_end = | 138 const auto web_request_events_end = |
| 143 kWebRequestEvents + arraysize(kWebRequestEvents); | 139 kWebRequestEvents + arraysize(kWebRequestEvents); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 int render_process_host_id = -1; | 191 int render_process_host_id = -1; |
| 196 int routing_id = -1; | 192 int routing_id = -1; |
| 197 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); | 193 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); |
| 198 return WebViewRendererState::GetInstance()->GetInfo( | 194 return WebViewRendererState::GetInstance()->GetInfo( |
| 199 render_process_host_id, routing_id, web_view_info); | 195 render_process_host_id, routing_id, web_view_info); |
| 200 } | 196 } |
| 201 | 197 |
| 202 void ExtractRequestInfoDetails(const net::URLRequest* request, | 198 void ExtractRequestInfoDetails(const net::URLRequest* request, |
| 203 bool* is_main_frame, | 199 bool* is_main_frame, |
| 204 int* frame_id, | 200 int* frame_id, |
| 205 bool* parent_is_main_frame, | |
| 206 int* parent_frame_id, | |
| 207 int* render_process_host_id, | 201 int* render_process_host_id, |
| 208 int* routing_id, | 202 int* routing_id, |
| 209 ResourceType* resource_type) { | 203 ResourceType* resource_type) { |
| 210 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 204 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 211 if (!info) | 205 if (!info) |
| 212 return; | 206 return; |
| 213 | 207 |
| 214 *frame_id = info->GetRenderFrameID(); | 208 *frame_id = info->GetRenderFrameID(); |
| 215 *is_main_frame = info->IsMainFrame(); | 209 *is_main_frame = info->IsMainFrame(); |
| 216 *parent_frame_id = info->GetParentRenderFrameID(); | |
| 217 *parent_is_main_frame = info->ParentIsMainFrame(); | |
| 218 *render_process_host_id = info->GetChildID(); | 210 *render_process_host_id = info->GetChildID(); |
| 219 *routing_id = info->GetRouteID(); | 211 *routing_id = info->GetRouteID(); |
| 220 | 212 |
| 221 // Restrict the resource type to the values we care about. | 213 // Restrict the resource type to the values we care about. |
| 222 if (helpers::IsRelevantResourceType(info->GetResourceType())) | 214 if (helpers::IsRelevantResourceType(info->GetResourceType())) |
| 223 *resource_type = info->GetResourceType(); | 215 *resource_type = info->GetResourceType(); |
| 224 else | 216 else |
| 225 *resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 217 *resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 226 } | 218 } |
| 227 | 219 |
| 220 // Enriches |dict| with information that can only be determined on the UI | |
| 221 // thread, such as frameId. |dict| must be populated by ExtractRequestInfo | |
| 222 // before calling this method. | |
| 223 scoped_ptr<base::DictionaryValue> ExtractRequestInfoOnUI( | |
| 224 scoped_ptr<base::DictionaryValue> dict) { | |
|
Devlin
2015/10/30 01:49:39
Seems like this should be a void method that takes
robwu
2015/11/02 19:08:34
Done.
| |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 226 DCHECK(dict.get()); | |
|
Devlin
2015/10/30 01:49:39
nit: s/.get()//
robwu
2015/11/02 19:08:34
Done.
| |
| 227 | |
| 228 // Update frameId / parentFrameId. | |
| 229 // -1 if unknown | |
| 230 // 0 if top-level frame | |
| 231 // >0 otherwise. | |
| 232 int render_process_id = -1; | |
| 233 int render_frame_id = -1; | |
| 234 int frame_tree_node_id = -1; | |
| 235 int parent_frame_tree_node_id = -1; | |
| 236 if (dict->GetInteger(keys::kFrameIdKey, &render_frame_id) && | |
| 237 dict->GetInteger(keys::kProcessIdKey, &render_process_id)) { | |
| 238 content::RenderFrameHost* rfh = | |
| 239 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
| 240 if (rfh) { | |
| 241 if (content::RenderFrameHost* parent = rfh->GetParent()) { | |
| 242 frame_tree_node_id = rfh->GetFrameTreeNodeID(); | |
| 243 parent_frame_tree_node_id = | |
| 244 parent->GetParent() ? parent->GetFrameTreeNodeID() : 0; | |
| 245 } else { | |
| 246 frame_tree_node_id = 0; | |
| 247 } | |
| 248 } | |
| 249 } | |
| 250 dict->SetInteger(keys::kFrameIdKey, frame_tree_node_id); | |
| 251 dict->SetInteger(keys::kParentFrameIdKey, parent_frame_tree_node_id); | |
| 252 dict->Remove(keys::kProcessIdKey, nullptr); | |
| 253 | |
| 254 return dict.Pass(); | |
| 255 } | |
| 256 | |
| 228 // Extracts the body from |request| and writes the data into |out|. | 257 // Extracts the body from |request| and writes the data into |out|. |
| 229 void ExtractRequestInfoBody(const net::URLRequest* request, | 258 void ExtractRequestInfoBody(const net::URLRequest* request, |
| 230 base::DictionaryValue* out) { | 259 base::DictionaryValue* out) { |
| 231 const net::UploadDataStream* upload_data = request->get_upload(); | 260 const net::UploadDataStream* upload_data = request->get_upload(); |
| 232 if (!upload_data || | 261 if (!upload_data || |
| 233 (request->method() != "POST" && request->method() != "PUT")) { | 262 (request->method() != "POST" && request->method() != "PUT")) { |
| 234 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . | 263 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . |
| 235 } | 264 } |
| 236 | 265 |
| 237 base::DictionaryValue* request_body = new base::DictionaryValue(); | 266 base::DictionaryValue* request_body = new base::DictionaryValue(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 const WebViewRendererState::WebViewInfo& web_view_info, | 379 const WebViewRendererState::WebViewInfo& web_view_info, |
| 351 scoped_ptr<base::DictionaryValue> event_argument) { | 380 scoped_ptr<base::DictionaryValue> event_argument) { |
| 352 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 381 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 353 | 382 |
| 354 content::BrowserContext* browser_context = | 383 content::BrowserContext* browser_context = |
| 355 reinterpret_cast<content::BrowserContext*>(browser_context_id); | 384 reinterpret_cast<content::BrowserContext*>(browser_context_id); |
| 356 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) | 385 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) |
| 357 return; | 386 return; |
| 358 | 387 |
| 359 scoped_ptr<base::ListValue> event_args(new base::ListValue); | 388 scoped_ptr<base::ListValue> event_args(new base::ListValue); |
| 360 event_args->Append(event_argument.release()); | 389 event_args->Append(ExtractRequestInfoOnUI(event_argument.Pass()).release()); |
| 361 | 390 |
| 362 EventRouter* event_router = EventRouter::Get(browser_context); | 391 EventRouter* event_router = EventRouter::Get(browser_context); |
| 363 | 392 |
| 364 EventFilteringInfo event_filtering_info; | 393 EventFilteringInfo event_filtering_info; |
| 365 | 394 |
| 366 events::HistogramValue histogram_value = events::UNKNOWN; | 395 events::HistogramValue histogram_value = events::UNKNOWN; |
| 367 std::string event_name; | 396 std::string event_name; |
| 368 // The instance ID uniquely identifies a <webview> instance within an embedder | 397 // The instance ID uniquely identifies a <webview> instance within an embedder |
| 369 // process. We use a filter here so that only event listeners for a particular | 398 // process. We use a filter here so that only event listeners for a particular |
| 370 // <webview> will fire. | 399 // <webview> will fire. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 return sub_event_name < that.sub_event_name; | 545 return sub_event_name < that.sub_event_name; |
| 517 | 546 |
| 518 if (web_view_instance_id != that.web_view_instance_id) | 547 if (web_view_instance_id != that.web_view_instance_id) |
| 519 return web_view_instance_id < that.web_view_instance_id; | 548 return web_view_instance_id < that.web_view_instance_id; |
| 520 | 549 |
| 521 if (web_view_instance_id == 0) { | 550 if (web_view_instance_id == 0) { |
| 522 // Do not filter by process ID for non-webviews, because this comparator | 551 // Do not filter by process ID for non-webviews, because this comparator |
| 523 // is also used to find and remove an event listener when an extension is | 552 // is also used to find and remove an event listener when an extension is |
| 524 // unloaded. At this point, the event listener cannot be mapped back to | 553 // unloaded. At this point, the event listener cannot be mapped back to |
| 525 // the original process, so 0 is used instead of the actual process ID. | 554 // the original process, so 0 is used instead of the actual process ID. |
| 526 DCHECK(embedder_process_id == 0 || that.embedder_process_id == 0); | 555 if (embedder_process_id == 0 || that.embedder_process_id == 0) { |
| 527 return false; | 556 return false; |
| 557 } | |
| 528 } | 558 } |
| 529 | 559 |
| 530 if (embedder_process_id != that.embedder_process_id) | 560 if (embedder_process_id != that.embedder_process_id) |
| 531 return embedder_process_id < that.embedder_process_id; | 561 return embedder_process_id < that.embedder_process_id; |
| 532 | 562 |
| 533 return false; | 563 return false; |
| 534 } | 564 } |
| 535 | 565 |
| 536 EventListener() | 566 EventListener() |
| 537 : histogram_value(events::UNKNOWN), | 567 : histogram_value(events::UNKNOWN), |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 rules_registries_[key] = rules_registry; | 764 rules_registries_[key] = rules_registry; |
| 735 else | 765 else |
| 736 rules_registries_.erase(key); | 766 rules_registries_.erase(key); |
| 737 } | 767 } |
| 738 | 768 |
| 739 void ExtensionWebRequestEventRouter::ExtractRequestInfo( | 769 void ExtensionWebRequestEventRouter::ExtractRequestInfo( |
| 740 const net::URLRequest* request, | 770 const net::URLRequest* request, |
| 741 base::DictionaryValue* out) { | 771 base::DictionaryValue* out) { |
| 742 bool is_main_frame = false; | 772 bool is_main_frame = false; |
| 743 int frame_id = -1; | 773 int frame_id = -1; |
| 744 bool parent_is_main_frame = false; | |
| 745 int parent_frame_id = -1; | |
| 746 int frame_id_for_extension = -1; | |
| 747 int parent_frame_id_for_extension = -1; | |
| 748 int render_process_host_id = -1; | 774 int render_process_host_id = -1; |
| 749 int routing_id = -1; | 775 int routing_id = -1; |
| 750 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 776 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 751 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 777 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 752 &parent_is_main_frame, &parent_frame_id, | |
| 753 &render_process_host_id, &routing_id, | 778 &render_process_host_id, &routing_id, |
| 754 &resource_type); | 779 &resource_type); |
| 755 frame_id_for_extension = GetFrameId(is_main_frame, frame_id); | |
| 756 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame, | |
| 757 parent_frame_id); | |
| 758 | 780 |
| 759 out->SetString(keys::kRequestIdKey, | 781 out->SetString(keys::kRequestIdKey, |
| 760 base::Uint64ToString(request->identifier())); | 782 base::Uint64ToString(request->identifier())); |
| 761 out->SetString(keys::kUrlKey, request->url().spec()); | 783 out->SetString(keys::kUrlKey, request->url().spec()); |
| 762 out->SetString(keys::kMethodKey, request->method()); | 784 out->SetString(keys::kMethodKey, request->method()); |
| 763 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); | 785 // Note: This frameId is not final. The (frameId, processId) pair is used to |
| 764 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); | 786 // find a RFH in ExtractRequestInfoOnUI, which sets the final frameId. |
|
battre
2015/11/02 13:54:57
Can you expand the abbreviation?
robwu
2015/11/02 19:08:34
Done.
| |
| 787 out->SetInteger(keys::kFrameIdKey, frame_id); | |
| 788 out->SetInteger(keys::kProcessIdKey, render_process_host_id); | |
| 765 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); | 789 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); |
| 766 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); | 790 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); |
| 767 if (web_request_event_router_delegate_) { | 791 if (web_request_event_router_delegate_) { |
| 768 web_request_event_router_delegate_->ExtractExtraRequestDetails( | 792 web_request_event_router_delegate_->ExtractExtraRequestDetails( |
| 769 request, out); | 793 request, out); |
| 770 } | 794 } |
| 771 } | 795 } |
| 772 | 796 |
| 773 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 797 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
| 774 void* browser_context, | 798 void* browser_context, |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1247 } | 1271 } |
| 1248 | 1272 |
| 1249 bool ExtensionWebRequestEventRouter::DispatchEvent( | 1273 bool ExtensionWebRequestEventRouter::DispatchEvent( |
| 1250 void* browser_context, | 1274 void* browser_context, |
| 1251 net::URLRequest* request, | 1275 net::URLRequest* request, |
| 1252 const std::vector<const EventListener*>& listeners, | 1276 const std::vector<const EventListener*>& listeners, |
| 1253 const base::ListValue& args) { | 1277 const base::ListValue& args) { |
| 1254 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) | 1278 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) |
| 1255 // pairs into a single message sent to a list of sub_event_names. | 1279 // pairs into a single message sent to a list of sub_event_names. |
| 1256 int num_handlers_blocking = 0; | 1280 int num_handlers_blocking = 0; |
| 1281 | |
| 1282 scoped_ptr<std::vector<EventListener>> listeners_to_dispatch( | |
| 1283 new std::vector<EventListener>()); | |
| 1284 listeners_to_dispatch->reserve(listeners.size()); | |
| 1257 for (const EventListener* listener : listeners) { | 1285 for (const EventListener* listener : listeners) { |
| 1258 // Filter out the optional keys that this listener didn't request. | 1286 listeners_to_dispatch->push_back(*listener); |
| 1259 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy()); | |
| 1260 base::DictionaryValue* dict = NULL; | |
| 1261 CHECK(args_filtered->GetDictionary(0, &dict) && dict); | |
| 1262 if (!(listener->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) | |
| 1263 dict->Remove(keys::kRequestHeadersKey, NULL); | |
| 1264 if (!(listener->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) | |
| 1265 dict->Remove(keys::kResponseHeadersKey, NULL); | |
| 1266 | |
| 1267 EventRouter::DispatchEventToSender( | |
| 1268 listener->ipc_sender.get(), browser_context, listener->extension_id, | |
| 1269 listener->histogram_value, listener->sub_event_name, | |
| 1270 args_filtered.Pass(), EventRouter::USER_GESTURE_UNKNOWN, | |
| 1271 EventFilteringInfo()); | |
| 1272 if (listener->extra_info_spec & | 1287 if (listener->extra_info_spec & |
| 1273 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { | 1288 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { |
| 1274 listener->blocked_requests.insert(request->identifier()); | 1289 listener->blocked_requests.insert(request->identifier()); |
| 1275 // If this is the first delegate blocking the request, go ahead and log | 1290 // If this is the first delegate blocking the request, go ahead and log |
| 1276 // it. | 1291 // it. |
| 1277 if (num_handlers_blocking == 0) { | 1292 if (num_handlers_blocking == 0) { |
| 1278 std::string delegate_info = l10n_util::GetStringFUTF8( | 1293 std::string delegate_info = l10n_util::GetStringFUTF8( |
| 1279 IDS_LOAD_STATE_PARAMETER_EXTENSION, | 1294 IDS_LOAD_STATE_PARAMETER_EXTENSION, |
| 1280 base::UTF8ToUTF16(listener->extension_name)); | 1295 base::UTF8ToUTF16(listener->extension_name)); |
| 1281 // LobAndReport allows extensions that block requests to be displayed in | 1296 // LobAndReport allows extensions that block requests to be displayed in |
| 1282 // the load status bar. | 1297 // the load status bar. |
| 1283 request->LogAndReportBlockedBy(delegate_info.c_str()); | 1298 request->LogAndReportBlockedBy(delegate_info.c_str()); |
| 1284 } | 1299 } |
| 1285 ++num_handlers_blocking; | 1300 ++num_handlers_blocking; |
| 1286 } | 1301 } |
| 1287 } | 1302 } |
| 1288 | 1303 |
| 1304 // TODO(robwu): Avoid unnecessary copy, by changing |args| to be a | |
| 1305 // scoped_ptr<base::DictionaryValue> and transferring the ownership. | |
| 1306 const base::DictionaryValue* dict = nullptr; | |
| 1307 CHECK(args.GetDictionary(0, &dict) && dict); | |
| 1308 scoped_ptr<base::DictionaryValue> args_copy = dict->CreateDeepCopy(); | |
| 1309 BrowserThread::PostTaskAndReplyWithResult( | |
| 1310 BrowserThread::UI, FROM_HERE, | |
| 1311 base::Bind(&ExtractRequestInfoOnUI, base::Passed(&args_copy)), | |
| 1312 base::Bind(&ExtensionWebRequestEventRouter::DispatchEventOnIO, | |
| 1313 base::Unretained(this), browser_context, | |
| 1314 base::Passed(&listeners_to_dispatch))); | |
|
battre
2015/11/02 13:54:57
I am a little bit concerned about this thread hopp
robwu
2015/11/02 19:08:34
Unfortunately not, the conclusion of the discussio
Matt Perry
2015/11/02 21:06:59
Your last statement doesn't seem to be true. It's
robwu
2015/11/02 21:33:32
By blocking callback, I mean the handling of the w
| |
| 1315 | |
| 1289 if (num_handlers_blocking > 0) { | 1316 if (num_handlers_blocking > 0) { |
| 1290 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; | 1317 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; |
| 1291 blocked_request.request = request; | 1318 blocked_request.request = request; |
| 1292 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); | 1319 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); |
| 1293 blocked_request.num_handlers_blocking += num_handlers_blocking; | 1320 blocked_request.num_handlers_blocking += num_handlers_blocking; |
| 1294 blocked_request.blocking_time = base::Time::Now(); | 1321 blocked_request.blocking_time = base::Time::Now(); |
| 1295 return true; | 1322 return true; |
| 1296 } | 1323 } |
| 1297 | 1324 |
| 1298 return false; | 1325 return false; |
| 1299 } | 1326 } |
| 1300 | 1327 |
| 1328 void ExtensionWebRequestEventRouter::DispatchEventOnIO( | |
| 1329 void* browser_context, | |
| 1330 scoped_ptr<std::vector<EventListener>> listeners, | |
| 1331 scoped_ptr<base::DictionaryValue> dict) { | |
| 1332 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 1333 DCHECK(listeners.get()); | |
| 1334 DCHECK_GT(listeners->size(), 0UL); | |
| 1335 DCHECK(dict.get()); | |
| 1336 | |
| 1337 std::string event_name = | |
| 1338 EventRouter::GetBaseEventName((*listeners)[0].sub_event_name); | |
| 1339 DCHECK(IsWebRequestEvent(event_name)); | |
| 1340 | |
| 1341 const std::set<EventListener>& event_listeners = | |
| 1342 listeners_[browser_context][event_name]; | |
| 1343 void* cross_browser_context = GetCrossBrowserContext(browser_context); | |
| 1344 const std::set<EventListener>* cross_event_listeners = | |
| 1345 cross_browser_context ? &listeners_[cross_browser_context][event_name] | |
| 1346 : nullptr; | |
| 1347 | |
| 1348 for (const EventListener& target : *listeners) { | |
| 1349 std::set<EventListener>::const_iterator listener = | |
| 1350 event_listeners.find(target); | |
| 1351 // Ignore listener if it was removed between the thread hops. | |
| 1352 if (listener == event_listeners.end()) { | |
| 1353 if (!cross_event_listeners) | |
| 1354 continue; | |
| 1355 listener = cross_event_listeners->find(target); | |
| 1356 if (listener == cross_event_listeners->end()) | |
| 1357 continue; | |
| 1358 } | |
| 1359 | |
| 1360 // Filter out the optional keys that this listener didn't request. | |
| 1361 scoped_ptr<base::ListValue> args_filtered(new base::ListValue); | |
| 1362 args_filtered->Append(dict->DeepCopy()); | |
| 1363 if (!(listener->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) | |
| 1364 dict->Remove(keys::kRequestHeadersKey, nullptr); | |
| 1365 if (!(listener->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) | |
| 1366 dict->Remove(keys::kResponseHeadersKey, nullptr); | |
| 1367 | |
| 1368 EventRouter::DispatchEventToSender( | |
| 1369 listener->ipc_sender.get(), browser_context, listener->extension_id, | |
| 1370 listener->histogram_value, listener->sub_event_name, | |
| 1371 args_filtered.Pass(), EventRouter::USER_GESTURE_UNKNOWN, | |
| 1372 EventFilteringInfo()); | |
| 1373 } | |
| 1374 } | |
| 1375 | |
| 1301 void ExtensionWebRequestEventRouter::OnEventHandled( | 1376 void ExtensionWebRequestEventRouter::OnEventHandled( |
| 1302 void* browser_context, | 1377 void* browser_context, |
| 1303 const std::string& extension_id, | 1378 const std::string& extension_id, |
| 1304 const std::string& event_name, | 1379 const std::string& event_name, |
| 1305 const std::string& sub_event_name, | 1380 const std::string& sub_event_name, |
| 1306 uint64_t request_id, | 1381 uint64_t request_id, |
| 1307 EventResponse* response) { | 1382 EventResponse* response) { |
| 1308 // TODO(robwu): Does this also work with webviews? operator< (used by find) | 1383 // TODO(robwu): Does this also work with webviews? operator< (used by find) |
| 1309 // takes the webview ID into account, which is not set on |listener|. | 1384 // takes the webview ID into account, which is not set on |listener|. |
| 1310 EventListener listener; | 1385 EventListener listener; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1445 | 1520 |
| 1446 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( | 1521 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( |
| 1447 const base::Closure& callback) { | 1522 const base::Closure& callback) { |
| 1448 callbacks_for_page_load_.push_back(callback); | 1523 callbacks_for_page_load_.push_back(callback); |
| 1449 } | 1524 } |
| 1450 | 1525 |
| 1451 bool ExtensionWebRequestEventRouter::IsPageLoad( | 1526 bool ExtensionWebRequestEventRouter::IsPageLoad( |
| 1452 const net::URLRequest* request) const { | 1527 const net::URLRequest* request) const { |
| 1453 bool is_main_frame = false; | 1528 bool is_main_frame = false; |
| 1454 int frame_id = -1; | 1529 int frame_id = -1; |
| 1455 bool parent_is_main_frame = false; | |
| 1456 int parent_frame_id = -1; | |
| 1457 int render_process_host_id = -1; | 1530 int render_process_host_id = -1; |
| 1458 int routing_id = -1; | 1531 int routing_id = -1; |
| 1459 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1532 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 1460 | 1533 |
| 1461 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1534 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1462 &parent_is_main_frame, &parent_frame_id, | |
| 1463 &render_process_host_id, | 1535 &render_process_host_id, |
| 1464 &routing_id, &resource_type); | 1536 &routing_id, &resource_type); |
| 1465 | 1537 |
| 1466 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME; | 1538 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME; |
| 1467 } | 1539 } |
| 1468 | 1540 |
| 1469 void ExtensionWebRequestEventRouter::NotifyPageLoad() { | 1541 void ExtensionWebRequestEventRouter::NotifyPageLoad() { |
| 1470 for (const auto& callback : callbacks_for_page_load_) | 1542 for (const auto& callback : callbacks_for_page_load_) |
| 1471 callback.Run(); | 1543 callback.Run(); |
| 1472 callbacks_for_page_load_.clear(); | 1544 callbacks_for_page_load_.clear(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 const InfoMap* extension_info_map, | 1667 const InfoMap* extension_info_map, |
| 1596 const std::string& event_name, | 1668 const std::string& event_name, |
| 1597 const net::URLRequest* request, | 1669 const net::URLRequest* request, |
| 1598 int* extra_info_spec) { | 1670 int* extra_info_spec) { |
| 1599 // TODO(mpcomplete): handle browser_context == NULL (should collect all | 1671 // TODO(mpcomplete): handle browser_context == NULL (should collect all |
| 1600 // listeners). | 1672 // listeners). |
| 1601 *extra_info_spec = 0; | 1673 *extra_info_spec = 0; |
| 1602 | 1674 |
| 1603 bool is_main_frame = false; | 1675 bool is_main_frame = false; |
| 1604 int frame_id = -1; | 1676 int frame_id = -1; |
| 1605 bool parent_is_main_frame = false; | |
| 1606 int parent_frame_id = -1; | |
| 1607 int render_process_host_id = -1; | 1677 int render_process_host_id = -1; |
| 1608 int routing_id = -1; | 1678 int routing_id = -1; |
| 1609 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1679 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 1610 const GURL& url = request->url(); | 1680 const GURL& url = request->url(); |
| 1611 | 1681 |
| 1612 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1682 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1613 &parent_is_main_frame, &parent_frame_id, | |
| 1614 &render_process_host_id, | 1683 &render_process_host_id, |
| 1615 &routing_id, &resource_type); | 1684 &routing_id, &resource_type); |
| 1616 | 1685 |
| 1617 bool is_request_from_extension = | 1686 bool is_request_from_extension = |
| 1618 IsRequestFromExtension(request, extension_info_map); | 1687 IsRequestFromExtension(request, extension_info_map); |
| 1619 | 1688 |
| 1620 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 1689 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 1621 // We are conservative here and assume requests are asynchronous in case | 1690 // We are conservative here and assume requests are asynchronous in case |
| 1622 // we don't have an info object. We don't want to risk a deadlock. | 1691 // we don't have an info object. We don't want to risk a deadlock. |
| 1623 bool is_async_request = !info || info->IsAsync(); | 1692 bool is_async_request = !info || info->IsAsync(); |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2497 // Continue gracefully. | 2566 // Continue gracefully. |
| 2498 RunSync(); | 2567 RunSync(); |
| 2499 } | 2568 } |
| 2500 | 2569 |
| 2501 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2570 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { |
| 2502 helpers::ClearCacheOnNavigation(); | 2571 helpers::ClearCacheOnNavigation(); |
| 2503 return true; | 2572 return true; |
| 2504 } | 2573 } |
| 2505 | 2574 |
| 2506 } // namespace extensions | 2575 } // namespace extensions |
| OLD | NEW |