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 void ExtractRequestInfoOnUI(base::DictionaryValue* dict) { | |
| 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 225 DCHECK(dict); | |
| 226 | |
| 227 // Update frameId / parentFrameId. | |
| 228 // -1 if unknown | |
| 229 // 0 if top-level frame | |
| 230 // >0 otherwise. | |
| 231 int render_process_id = -1; | |
| 232 int render_frame_id = -1; | |
|
nasko
2015/11/06 23:28:27
What type of id is this? The FTN or the routing id
| |
| 233 int frame_tree_node_id = -1; | |
| 234 int parent_frame_tree_node_id = -1; | |
| 235 if (dict->GetInteger(keys::kFrameIdKey, &render_frame_id) && | |
| 236 dict->GetInteger(keys::kProcessIdKey, &render_process_id)) { | |
| 237 content::RenderFrameHost* rfh = | |
| 238 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
|
nasko
2015/11/06 23:28:27
If this comes from caller of the extension API, wo
robwu
2015/11/07 00:23:40
Heh. This ID is correct. I'm abusing kFrameIdKey a
| |
| 239 if (rfh) { | |
| 240 if (content::RenderFrameHost* parent = rfh->GetParent()) { | |
|
nasko
2015/11/06 23:28:27
Assignment should not be done inside an if clause.
| |
| 241 frame_tree_node_id = rfh->GetFrameTreeNodeID(); | |
| 242 parent_frame_tree_node_id = | |
| 243 parent->GetParent() ? parent->GetFrameTreeNodeID() : 0; | |
| 244 } else { | |
| 245 frame_tree_node_id = 0; | |
| 246 } | |
| 247 } | |
| 248 } | |
| 249 dict->SetInteger(keys::kFrameIdKey, frame_tree_node_id); | |
| 250 dict->SetInteger(keys::kParentFrameIdKey, parent_frame_tree_node_id); | |
| 251 dict->Remove(keys::kProcessIdKey, nullptr); | |
|
nasko
2015/11/06 23:28:27
Why are we removing this? I feel strongly about ke
robwu
2015/11/07 00:23:40
This is the webRequest API. processId was never in
| |
| 252 } | |
| 253 | |
| 228 // Extracts the body from |request| and writes the data into |out|. | 254 // Extracts the body from |request| and writes the data into |out|. |
| 229 void ExtractRequestInfoBody(const net::URLRequest* request, | 255 void ExtractRequestInfoBody(const net::URLRequest* request, |
| 230 base::DictionaryValue* out) { | 256 base::DictionaryValue* out) { |
| 231 const net::UploadDataStream* upload_data = request->get_upload(); | 257 const net::UploadDataStream* upload_data = request->get_upload(); |
| 232 if (!upload_data || | 258 if (!upload_data || |
| 233 (request->method() != "POST" && request->method() != "PUT")) { | 259 (request->method() != "POST" && request->method() != "PUT")) { |
| 234 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . | 260 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . |
| 235 } | 261 } |
| 236 | 262 |
| 237 base::DictionaryValue* request_body = new base::DictionaryValue(); | 263 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, | 376 const WebViewRendererState::WebViewInfo& web_view_info, |
| 351 scoped_ptr<base::DictionaryValue> event_argument) { | 377 scoped_ptr<base::DictionaryValue> event_argument) { |
| 352 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 378 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 353 | 379 |
| 354 content::BrowserContext* browser_context = | 380 content::BrowserContext* browser_context = |
| 355 reinterpret_cast<content::BrowserContext*>(browser_context_id); | 381 reinterpret_cast<content::BrowserContext*>(browser_context_id); |
| 356 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) | 382 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) |
| 357 return; | 383 return; |
| 358 | 384 |
| 359 scoped_ptr<base::ListValue> event_args(new base::ListValue); | 385 scoped_ptr<base::ListValue> event_args(new base::ListValue); |
| 386 ExtractRequestInfoOnUI(event_argument.get()); | |
| 360 event_args->Append(event_argument.release()); | 387 event_args->Append(event_argument.release()); |
| 361 | 388 |
| 362 EventRouter* event_router = EventRouter::Get(browser_context); | 389 EventRouter* event_router = EventRouter::Get(browser_context); |
| 363 | 390 |
| 364 EventFilteringInfo event_filtering_info; | 391 EventFilteringInfo event_filtering_info; |
| 365 | 392 |
| 366 events::HistogramValue histogram_value = events::UNKNOWN; | 393 events::HistogramValue histogram_value = events::UNKNOWN; |
| 367 std::string event_name; | 394 std::string event_name; |
| 368 // The instance ID uniquely identifies a <webview> instance within an embedder | 395 // 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 | 396 // process. We use a filter here so that only event listeners for a particular |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 return sub_event_name < that.sub_event_name; | 543 return sub_event_name < that.sub_event_name; |
| 517 | 544 |
| 518 if (web_view_instance_id != that.web_view_instance_id) | 545 if (web_view_instance_id != that.web_view_instance_id) |
| 519 return web_view_instance_id < that.web_view_instance_id; | 546 return web_view_instance_id < that.web_view_instance_id; |
| 520 | 547 |
| 521 if (web_view_instance_id == 0) { | 548 if (web_view_instance_id == 0) { |
| 522 // Do not filter by process ID for non-webviews, because this comparator | 549 // 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 | 550 // 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 | 551 // 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. | 552 // the original process, so 0 is used instead of the actual process ID. |
| 526 DCHECK(embedder_process_id == 0 || that.embedder_process_id == 0); | 553 if (embedder_process_id == 0 || that.embedder_process_id == 0) { |
| 527 return false; | 554 return false; |
| 555 } | |
| 528 } | 556 } |
| 529 | 557 |
| 530 if (embedder_process_id != that.embedder_process_id) | 558 if (embedder_process_id != that.embedder_process_id) |
| 531 return embedder_process_id < that.embedder_process_id; | 559 return embedder_process_id < that.embedder_process_id; |
| 532 | 560 |
| 533 return false; | 561 return false; |
| 534 } | 562 } |
| 535 | 563 |
| 536 EventListener() | 564 EventListener() |
| 537 : histogram_value(events::UNKNOWN), | 565 : histogram_value(events::UNKNOWN), |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 if (rules_registry.get()) | 761 if (rules_registry.get()) |
| 734 rules_registries_[key] = rules_registry; | 762 rules_registries_[key] = rules_registry; |
| 735 else | 763 else |
| 736 rules_registries_.erase(key); | 764 rules_registries_.erase(key); |
| 737 } | 765 } |
| 738 | 766 |
| 739 void ExtensionWebRequestEventRouter::ExtractRequestInfo( | 767 void ExtensionWebRequestEventRouter::ExtractRequestInfo( |
| 740 const net::URLRequest* request, | 768 const net::URLRequest* request, |
| 741 base::DictionaryValue* out) { | 769 base::DictionaryValue* out) { |
| 742 bool is_main_frame = false; | 770 bool is_main_frame = false; |
| 743 int frame_id = -1; | 771 int frame_id = -1; |
|
nasko
2015/11/06 23:28:27
I think this is the frame routing id, correct? If
robwu
2015/12/07 23:44:22
Done.
| |
| 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; | 772 int render_process_host_id = -1; |
| 749 int routing_id = -1; | 773 int routing_id = -1; |
| 750 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 774 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 751 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 775 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 752 &parent_is_main_frame, &parent_frame_id, | |
| 753 &render_process_host_id, &routing_id, | 776 &render_process_host_id, &routing_id, |
| 754 &resource_type); | 777 &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 | 778 |
| 759 out->SetString(keys::kRequestIdKey, | 779 out->SetString(keys::kRequestIdKey, |
| 760 base::Uint64ToString(request->identifier())); | 780 base::Uint64ToString(request->identifier())); |
| 761 out->SetString(keys::kUrlKey, request->url().spec()); | 781 out->SetString(keys::kUrlKey, request->url().spec()); |
| 762 out->SetString(keys::kMethodKey, request->method()); | 782 out->SetString(keys::kMethodKey, request->method()); |
| 763 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); | 783 // Note: This (frameId, processId) pair is used by ExtractRequestInfoOnUI to |
| 764 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); | 784 // find a RenderFrameHost, which provides the final frameId. |
| 785 out->SetInteger(keys::kFrameIdKey, frame_id); | |
| 786 out->SetInteger(keys::kProcessIdKey, render_process_host_id); | |
| 765 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); | 787 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); |
| 766 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); | 788 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); |
| 767 if (web_request_event_router_delegate_) { | 789 if (web_request_event_router_delegate_) { |
| 768 web_request_event_router_delegate_->ExtractExtraRequestDetails( | 790 web_request_event_router_delegate_->ExtractExtraRequestDetails( |
| 769 request, out); | 791 request, out); |
| 770 } | 792 } |
| 771 } | 793 } |
| 772 | 794 |
| 773 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 795 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
| 774 void* browser_context, | 796 void* browser_context, |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1247 } | 1269 } |
| 1248 | 1270 |
| 1249 bool ExtensionWebRequestEventRouter::DispatchEvent( | 1271 bool ExtensionWebRequestEventRouter::DispatchEvent( |
| 1250 void* browser_context, | 1272 void* browser_context, |
| 1251 net::URLRequest* request, | 1273 net::URLRequest* request, |
| 1252 const std::vector<const EventListener*>& listeners, | 1274 const std::vector<const EventListener*>& listeners, |
| 1253 const base::ListValue& args) { | 1275 const base::ListValue& args) { |
| 1254 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) | 1276 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) |
| 1255 // pairs into a single message sent to a list of sub_event_names. | 1277 // pairs into a single message sent to a list of sub_event_names. |
| 1256 int num_handlers_blocking = 0; | 1278 int num_handlers_blocking = 0; |
| 1279 | |
| 1280 scoped_ptr<std::vector<EventListener>> listeners_to_dispatch( | |
| 1281 new std::vector<EventListener>()); | |
| 1282 listeners_to_dispatch->reserve(listeners.size()); | |
| 1257 for (const EventListener* listener : listeners) { | 1283 for (const EventListener* listener : listeners) { |
| 1258 // Filter out the optional keys that this listener didn't request. | 1284 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 & | 1285 if (listener->extra_info_spec & |
| 1273 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { | 1286 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { |
| 1274 listener->blocked_requests.insert(request->identifier()); | 1287 listener->blocked_requests.insert(request->identifier()); |
| 1275 // If this is the first delegate blocking the request, go ahead and log | 1288 // If this is the first delegate blocking the request, go ahead and log |
| 1276 // it. | 1289 // it. |
| 1277 if (num_handlers_blocking == 0) { | 1290 if (num_handlers_blocking == 0) { |
| 1278 std::string delegate_info = l10n_util::GetStringFUTF8( | 1291 std::string delegate_info = l10n_util::GetStringFUTF8( |
| 1279 IDS_LOAD_STATE_PARAMETER_EXTENSION, | 1292 IDS_LOAD_STATE_PARAMETER_EXTENSION, |
| 1280 base::UTF8ToUTF16(listener->extension_name)); | 1293 base::UTF8ToUTF16(listener->extension_name)); |
| 1281 // LobAndReport allows extensions that block requests to be displayed in | 1294 // LobAndReport allows extensions that block requests to be displayed in |
| 1282 // the load status bar. | 1295 // the load status bar. |
| 1283 request->LogAndReportBlockedBy(delegate_info.c_str()); | 1296 request->LogAndReportBlockedBy(delegate_info.c_str()); |
| 1284 } | 1297 } |
| 1285 ++num_handlers_blocking; | 1298 ++num_handlers_blocking; |
| 1286 } | 1299 } |
| 1287 } | 1300 } |
| 1288 | 1301 |
| 1302 // TODO(robwu): Avoid unnecessary copy, by changing |args| to be a | |
| 1303 // scoped_ptr<base::DictionaryValue> and transferring the ownership. | |
| 1304 const base::DictionaryValue* dict = nullptr; | |
| 1305 CHECK(args.GetDictionary(0, &dict) && dict); | |
| 1306 base::DictionaryValue* args_copy = dict->DeepCopy(); | |
| 1307 BrowserThread::PostTaskAndReply( | |
| 1308 BrowserThread::UI, FROM_HERE, | |
| 1309 base::Bind(&ExtractRequestInfoOnUI, base::Unretained(args_copy)), | |
| 1310 base::Bind(&ExtensionWebRequestEventRouter::DispatchEventOnIO, | |
| 1311 base::Unretained(this), browser_context, | |
| 1312 base::Passed(&listeners_to_dispatch), base::Owned(args_copy))); | |
| 1313 | |
| 1289 if (num_handlers_blocking > 0) { | 1314 if (num_handlers_blocking > 0) { |
| 1290 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; | 1315 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; |
| 1291 blocked_request.request = request; | 1316 blocked_request.request = request; |
| 1292 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); | 1317 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); |
| 1293 blocked_request.num_handlers_blocking += num_handlers_blocking; | 1318 blocked_request.num_handlers_blocking += num_handlers_blocking; |
| 1294 blocked_request.blocking_time = base::Time::Now(); | 1319 blocked_request.blocking_time = base::Time::Now(); |
| 1295 return true; | 1320 return true; |
| 1296 } | 1321 } |
| 1297 | 1322 |
| 1298 return false; | 1323 return false; |
| 1299 } | 1324 } |
| 1300 | 1325 |
| 1326 void ExtensionWebRequestEventRouter::DispatchEventOnIO( | |
| 1327 void* browser_context, | |
| 1328 scoped_ptr<std::vector<EventListener>> listeners, | |
| 1329 base::DictionaryValue* dict) { | |
| 1330 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 1331 DCHECK(listeners.get()); | |
| 1332 DCHECK_GT(listeners->size(), 0UL); | |
| 1333 DCHECK(dict); | |
| 1334 | |
| 1335 std::string event_name = | |
| 1336 EventRouter::GetBaseEventName((*listeners)[0].sub_event_name); | |
| 1337 DCHECK(IsWebRequestEvent(event_name)); | |
| 1338 | |
| 1339 const std::set<EventListener>& event_listeners = | |
| 1340 listeners_[browser_context][event_name]; | |
| 1341 void* cross_browser_context = GetCrossBrowserContext(browser_context); | |
| 1342 const std::set<EventListener>* cross_event_listeners = | |
| 1343 cross_browser_context ? &listeners_[cross_browser_context][event_name] | |
| 1344 : nullptr; | |
| 1345 | |
| 1346 for (const EventListener& target : *listeners) { | |
| 1347 std::set<EventListener>::const_iterator listener = | |
| 1348 event_listeners.find(target); | |
| 1349 // Ignore listener if it was removed between the thread hops. | |
| 1350 if (listener == event_listeners.end()) { | |
| 1351 if (!cross_event_listeners) | |
| 1352 continue; | |
| 1353 listener = cross_event_listeners->find(target); | |
| 1354 if (listener == cross_event_listeners->end()) | |
| 1355 continue; | |
| 1356 } | |
| 1357 | |
| 1358 // Filter out the optional keys that this listener didn't request. | |
| 1359 scoped_ptr<base::ListValue> args_filtered(new base::ListValue); | |
| 1360 args_filtered->Append(dict->DeepCopy()); | |
| 1361 if (!(listener->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) | |
| 1362 dict->Remove(keys::kRequestHeadersKey, nullptr); | |
| 1363 if (!(listener->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) | |
| 1364 dict->Remove(keys::kResponseHeadersKey, nullptr); | |
| 1365 | |
| 1366 EventRouter::DispatchEventToSender( | |
| 1367 listener->ipc_sender.get(), browser_context, listener->extension_id, | |
| 1368 listener->histogram_value, listener->sub_event_name, | |
| 1369 args_filtered.Pass(), EventRouter::USER_GESTURE_UNKNOWN, | |
| 1370 EventFilteringInfo()); | |
| 1371 } | |
| 1372 } | |
| 1373 | |
| 1301 void ExtensionWebRequestEventRouter::OnEventHandled( | 1374 void ExtensionWebRequestEventRouter::OnEventHandled( |
| 1302 void* browser_context, | 1375 void* browser_context, |
| 1303 const std::string& extension_id, | 1376 const std::string& extension_id, |
| 1304 const std::string& event_name, | 1377 const std::string& event_name, |
| 1305 const std::string& sub_event_name, | 1378 const std::string& sub_event_name, |
| 1306 uint64_t request_id, | 1379 uint64_t request_id, |
| 1307 EventResponse* response) { | 1380 EventResponse* response) { |
| 1308 // TODO(robwu): Does this also work with webviews? operator< (used by find) | 1381 // 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|. | 1382 // takes the webview ID into account, which is not set on |listener|. |
| 1310 EventListener listener; | 1383 EventListener listener; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1445 | 1518 |
| 1446 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( | 1519 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( |
| 1447 const base::Closure& callback) { | 1520 const base::Closure& callback) { |
| 1448 callbacks_for_page_load_.push_back(callback); | 1521 callbacks_for_page_load_.push_back(callback); |
| 1449 } | 1522 } |
| 1450 | 1523 |
| 1451 bool ExtensionWebRequestEventRouter::IsPageLoad( | 1524 bool ExtensionWebRequestEventRouter::IsPageLoad( |
| 1452 const net::URLRequest* request) const { | 1525 const net::URLRequest* request) const { |
| 1453 bool is_main_frame = false; | 1526 bool is_main_frame = false; |
| 1454 int frame_id = -1; | 1527 int frame_id = -1; |
| 1455 bool parent_is_main_frame = false; | |
| 1456 int parent_frame_id = -1; | |
| 1457 int render_process_host_id = -1; | 1528 int render_process_host_id = -1; |
| 1458 int routing_id = -1; | 1529 int routing_id = -1; |
| 1459 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1530 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 1460 | 1531 |
| 1461 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1532 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1462 &parent_is_main_frame, &parent_frame_id, | |
| 1463 &render_process_host_id, | 1533 &render_process_host_id, |
| 1464 &routing_id, &resource_type); | 1534 &routing_id, &resource_type); |
| 1465 | 1535 |
| 1466 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME; | 1536 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME; |
| 1467 } | 1537 } |
| 1468 | 1538 |
| 1469 void ExtensionWebRequestEventRouter::NotifyPageLoad() { | 1539 void ExtensionWebRequestEventRouter::NotifyPageLoad() { |
| 1470 for (const auto& callback : callbacks_for_page_load_) | 1540 for (const auto& callback : callbacks_for_page_load_) |
| 1471 callback.Run(); | 1541 callback.Run(); |
| 1472 callbacks_for_page_load_.clear(); | 1542 callbacks_for_page_load_.clear(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 const InfoMap* extension_info_map, | 1665 const InfoMap* extension_info_map, |
| 1596 const std::string& event_name, | 1666 const std::string& event_name, |
| 1597 const net::URLRequest* request, | 1667 const net::URLRequest* request, |
| 1598 int* extra_info_spec) { | 1668 int* extra_info_spec) { |
| 1599 // TODO(mpcomplete): handle browser_context == NULL (should collect all | 1669 // TODO(mpcomplete): handle browser_context == NULL (should collect all |
| 1600 // listeners). | 1670 // listeners). |
| 1601 *extra_info_spec = 0; | 1671 *extra_info_spec = 0; |
| 1602 | 1672 |
| 1603 bool is_main_frame = false; | 1673 bool is_main_frame = false; |
| 1604 int frame_id = -1; | 1674 int frame_id = -1; |
| 1605 bool parent_is_main_frame = false; | |
| 1606 int parent_frame_id = -1; | |
| 1607 int render_process_host_id = -1; | 1675 int render_process_host_id = -1; |
| 1608 int routing_id = -1; | 1676 int routing_id = -1; |
| 1609 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1677 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
| 1610 const GURL& url = request->url(); | 1678 const GURL& url = request->url(); |
| 1611 | 1679 |
| 1612 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1680 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1613 &parent_is_main_frame, &parent_frame_id, | |
| 1614 &render_process_host_id, | 1681 &render_process_host_id, |
| 1615 &routing_id, &resource_type); | 1682 &routing_id, &resource_type); |
| 1616 | 1683 |
| 1617 bool is_request_from_extension = | 1684 bool is_request_from_extension = |
| 1618 IsRequestFromExtension(request, extension_info_map); | 1685 IsRequestFromExtension(request, extension_info_map); |
| 1619 | 1686 |
| 1620 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 1687 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 1621 // We are conservative here and assume requests are asynchronous in case | 1688 // 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. | 1689 // we don't have an info object. We don't want to risk a deadlock. |
| 1623 bool is_async_request = !info || info->IsAsync(); | 1690 bool is_async_request = !info || info->IsAsync(); |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2497 // Continue gracefully. | 2564 // Continue gracefully. |
| 2498 RunSync(); | 2565 RunSync(); |
| 2499 } | 2566 } |
| 2500 | 2567 |
| 2501 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2568 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { |
| 2502 helpers::ClearCacheOnNavigation(); | 2569 helpers::ClearCacheOnNavigation(); |
| 2503 return true; | 2570 return true; |
| 2504 } | 2571 } |
| 2505 | 2572 |
| 2506 } // namespace extensions | 2573 } // namespace extensions |
| OLD | NEW |