Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: extensions/browser/api/web_request/web_request_api.cc

Issue 1413543005: Use FrameTreeNode ID as frameId in extension APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/runs/that runs/ + public copy cons. to avoid compiler error Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 22 matching lines...) Expand all
33 #include "extensions/browser/api/declarative_webrequest/request_stage.h" 33 #include "extensions/browser/api/declarative_webrequest/request_stage.h"
34 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 34 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
35 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" 35 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h"
36 #include "extensions/browser/api/extensions_api_client.h" 36 #include "extensions/browser/api/extensions_api_client.h"
37 #include "extensions/browser/api/web_request/upload_data_presenter.h" 37 #include "extensions/browser/api/web_request/upload_data_presenter.h"
38 #include "extensions/browser/api/web_request/web_request_api_constants.h" 38 #include "extensions/browser/api/web_request/web_request_api_constants.h"
39 #include "extensions/browser/api/web_request/web_request_api_helpers.h" 39 #include "extensions/browser/api/web_request/web_request_api_helpers.h"
40 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h " 40 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h "
41 #include "extensions/browser/api/web_request/web_request_time_tracker.h" 41 #include "extensions/browser/api/web_request/web_request_time_tracker.h"
42 #include "extensions/browser/event_router.h" 42 #include "extensions/browser/event_router.h"
43 #include "extensions/browser/extension_api_frame_id_map.h"
43 #include "extensions/browser/extension_prefs.h" 44 #include "extensions/browser/extension_prefs.h"
44 #include "extensions/browser/extension_registry.h" 45 #include "extensions/browser/extension_registry.h"
45 #include "extensions/browser/extension_system.h" 46 #include "extensions/browser/extension_system.h"
46 #include "extensions/browser/extensions_browser_client.h" 47 #include "extensions/browser/extensions_browser_client.h"
47 #include "extensions/browser/guest_view/guest_view_events.h" 48 #include "extensions/browser/guest_view/guest_view_events.h"
48 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 49 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
49 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 50 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
50 #include "extensions/browser/info_map.h" 51 #include "extensions/browser/info_map.h"
51 #include "extensions/browser/io_thread_extension_message_filter.h" 52 #include "extensions/browser/io_thread_extension_message_filter.h"
52 #include "extensions/browser/runtime_data.h" 53 #include "extensions/browser/runtime_data.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return keys::kOnResponseStarted; 125 return keys::kOnResponseStarted;
125 case ExtensionWebRequestEventRouter::kOnErrorOccurred: 126 case ExtensionWebRequestEventRouter::kOnErrorOccurred:
126 return keys::kOnErrorOccurred; 127 return keys::kOnErrorOccurred;
127 case ExtensionWebRequestEventRouter::kOnCompleted: 128 case ExtensionWebRequestEventRouter::kOnCompleted:
128 return keys::kOnCompleted; 129 return keys::kOnCompleted;
129 } 130 }
130 NOTREACHED(); 131 NOTREACHED();
131 return "Not reached"; 132 return "Not reached";
132 } 133 }
133 134
134 int GetFrameId(bool is_main_frame, int frame_id) {
135 return is_main_frame ? 0 : frame_id;
136 }
137
138 bool IsWebRequestEvent(const std::string& event_name) { 135 bool IsWebRequestEvent(const std::string& event_name) {
139 std::string web_request_event_name(event_name); 136 std::string web_request_event_name(event_name);
140 if (base::StartsWith(web_request_event_name, 137 if (base::StartsWith(web_request_event_name,
141 webview::kWebViewEventPrefix, 138 webview::kWebViewEventPrefix,
142 base::CompareCase::SENSITIVE)) { 139 base::CompareCase::SENSITIVE)) {
143 web_request_event_name.replace( 140 web_request_event_name.replace(
144 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix); 141 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix);
145 } 142 }
146 const auto web_request_events_end = 143 const auto web_request_events_end =
147 kWebRequestEvents + arraysize(kWebRequestEvents); 144 kWebRequestEvents + arraysize(kWebRequestEvents);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 WebViewRendererState::WebViewInfo* web_view_info) { 195 WebViewRendererState::WebViewInfo* web_view_info) {
199 int render_process_host_id = -1; 196 int render_process_host_id = -1;
200 int routing_id = -1; 197 int routing_id = -1;
201 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); 198 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id);
202 return WebViewRendererState::GetInstance()->GetInfo( 199 return WebViewRendererState::GetInstance()->GetInfo(
203 render_process_host_id, routing_id, web_view_info); 200 render_process_host_id, routing_id, web_view_info);
204 } 201 }
205 202
206 void ExtractRequestInfoDetails(const net::URLRequest* request, 203 void ExtractRequestInfoDetails(const net::URLRequest* request,
207 bool* is_main_frame, 204 bool* is_main_frame,
208 int* frame_id, 205 int* render_frame_id,
209 bool* parent_is_main_frame,
210 int* parent_frame_id,
211 int* render_process_host_id, 206 int* render_process_host_id,
212 int* routing_id, 207 int* routing_id,
213 ResourceType* resource_type) { 208 ResourceType* resource_type) {
214 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 209 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
215 if (!info) 210 if (!info)
216 return; 211 return;
217 212
218 *frame_id = info->GetRenderFrameID(); 213 *render_frame_id = info->GetRenderFrameID();
219 *is_main_frame = info->IsMainFrame(); 214 *is_main_frame = info->IsMainFrame();
220 *parent_frame_id = info->GetParentRenderFrameID();
221 *parent_is_main_frame = info->ParentIsMainFrame();
222 *render_process_host_id = info->GetChildID(); 215 *render_process_host_id = info->GetChildID();
223 *routing_id = info->GetRouteID(); 216 *routing_id = info->GetRouteID();
224 217
225 // Restrict the resource type to the values we care about. 218 // Restrict the resource type to the values we care about.
226 if (helpers::IsRelevantResourceType(info->GetResourceType())) 219 if (helpers::IsRelevantResourceType(info->GetResourceType()))
227 *resource_type = info->GetResourceType(); 220 *resource_type = info->GetResourceType();
228 else 221 else
229 *resource_type = content::RESOURCE_TYPE_LAST_TYPE; 222 *resource_type = content::RESOURCE_TYPE_LAST_TYPE;
230 } 223 }
231 224
225 // Extracts a pair of IDs to identify the RenderFrameHost. These IDs are used to
226 // get the frame ID and parent frame ID from ExtensionApiFrameIdMap, and then
227 // stored in |dict| by DispatchEventToListeners or SendOnMessageEventOnUI.
228 void ExtractRenderFrameInfo(base::DictionaryValue* dict,
229 int* render_process_id,
230 int* render_frame_id) {
231 if (!dict->GetInteger(keys::kFrameIdKey, render_frame_id) ||
232 !dict->GetInteger(keys::kProcessIdKey, render_process_id)) {
233 *render_process_id = -1;
234 *render_frame_id = -1;
235 }
236 // kFrameIdKey will be overwritten later, so it's not removed here.
237 dict->Remove(keys::kProcessIdKey, nullptr);
238 }
239
232 // Extracts the body from |request| and writes the data into |out|. 240 // Extracts the body from |request| and writes the data into |out|.
233 void ExtractRequestInfoBody(const net::URLRequest* request, 241 void ExtractRequestInfoBody(const net::URLRequest* request,
234 base::DictionaryValue* out) { 242 base::DictionaryValue* out) {
235 const net::UploadDataStream* upload_data = request->get_upload(); 243 const net::UploadDataStream* upload_data = request->get_upload();
236 if (!upload_data || 244 if (!upload_data ||
237 (request->method() != "POST" && request->method() != "PUT")) { 245 (request->method() != "POST" && request->method() != "PUT")) {
238 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . 246 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" .
239 } 247 }
240 248
241 base::DictionaryValue* request_body = new base::DictionaryValue(); 249 base::DictionaryValue* request_body = new base::DictionaryValue();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 const WebViewRendererState::WebViewInfo& web_view_info, 362 const WebViewRendererState::WebViewInfo& web_view_info,
355 scoped_ptr<base::DictionaryValue> event_argument) { 363 scoped_ptr<base::DictionaryValue> event_argument) {
356 DCHECK_CURRENTLY_ON(BrowserThread::UI); 364 DCHECK_CURRENTLY_ON(BrowserThread::UI);
357 365
358 content::BrowserContext* browser_context = 366 content::BrowserContext* browser_context =
359 reinterpret_cast<content::BrowserContext*>(browser_context_id); 367 reinterpret_cast<content::BrowserContext*>(browser_context_id);
360 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) 368 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
361 return; 369 return;
362 370
363 scoped_ptr<base::ListValue> event_args(new base::ListValue); 371 scoped_ptr<base::ListValue> event_args(new base::ListValue);
372 int render_process_host_id = -1;
373 int render_frame_id = -1;
374 ExtractRenderFrameInfo(event_argument.get(), &render_process_host_id,
375 &render_frame_id);
376 content::RenderFrameHost* rfh =
377 content::RenderFrameHost::FromID(render_process_host_id, render_frame_id);
378 event_argument->SetInteger(keys::kFrameIdKey,
379 ExtensionApiFrameIdMap::GetFrameId(rfh));
380 event_argument->SetInteger(keys::kParentFrameIdKey,
381 ExtensionApiFrameIdMap::GetParentFrameId(rfh));
364 event_args->Append(event_argument.release()); 382 event_args->Append(event_argument.release());
365 383
366 EventRouter* event_router = EventRouter::Get(browser_context); 384 EventRouter* event_router = EventRouter::Get(browser_context);
367 385
368 EventFilteringInfo event_filtering_info; 386 EventFilteringInfo event_filtering_info;
369 387
370 events::HistogramValue histogram_value = events::UNKNOWN; 388 events::HistogramValue histogram_value = events::UNKNOWN;
371 std::string event_name; 389 std::string event_name;
372 // The instance ID uniquely identifies a <webview> instance within an embedder 390 // The instance ID uniquely identifies a <webview> instance within an embedder
373 // process. We use a filter here so that only event listeners for a particular 391 // 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
520 return sub_event_name < that.sub_event_name; 538 return sub_event_name < that.sub_event_name;
521 539
522 if (web_view_instance_id != that.web_view_instance_id) 540 if (web_view_instance_id != that.web_view_instance_id)
523 return web_view_instance_id < that.web_view_instance_id; 541 return web_view_instance_id < that.web_view_instance_id;
524 542
525 if (web_view_instance_id == 0) { 543 if (web_view_instance_id == 0) {
526 // Do not filter by process ID for non-webviews, because this comparator 544 // Do not filter by process ID for non-webviews, because this comparator
527 // is also used to find and remove an event listener when an extension is 545 // is also used to find and remove an event listener when an extension is
528 // unloaded. At this point, the event listener cannot be mapped back to 546 // unloaded. At this point, the event listener cannot be mapped back to
529 // the original process, so 0 is used instead of the actual process ID. 547 // the original process, so 0 is used instead of the actual process ID.
530 DCHECK(embedder_process_id == 0 || that.embedder_process_id == 0); 548 if (embedder_process_id == 0 || that.embedder_process_id == 0)
531 return false; 549 return false;
532 } 550 }
533 551
534 if (embedder_process_id != that.embedder_process_id) 552 if (embedder_process_id != that.embedder_process_id)
535 return embedder_process_id < that.embedder_process_id; 553 return embedder_process_id < that.embedder_process_id;
536 554
537 return false; 555 return false;
538 } 556 }
539 557
540 EventListener() 558 EventListener()
541 : histogram_value(events::UNKNOWN), 559 : histogram_value(events::UNKNOWN),
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 if (rules_registry.get()) 755 if (rules_registry.get())
738 rules_registries_[key] = rules_registry; 756 rules_registries_[key] = rules_registry;
739 else 757 else
740 rules_registries_.erase(key); 758 rules_registries_.erase(key);
741 } 759 }
742 760
743 void ExtensionWebRequestEventRouter::ExtractRequestInfo( 761 void ExtensionWebRequestEventRouter::ExtractRequestInfo(
744 const net::URLRequest* request, 762 const net::URLRequest* request,
745 base::DictionaryValue* out) { 763 base::DictionaryValue* out) {
746 bool is_main_frame = false; 764 bool is_main_frame = false;
747 int frame_id = -1; 765 int render_frame_id = -1;
748 bool parent_is_main_frame = false;
749 int parent_frame_id = -1;
750 int frame_id_for_extension = -1;
751 int parent_frame_id_for_extension = -1;
752 int render_process_host_id = -1; 766 int render_process_host_id = -1;
753 int routing_id = -1; 767 int routing_id = -1;
754 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; 768 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
755 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 769 ExtractRequestInfoDetails(request, &is_main_frame, &render_frame_id,
756 &parent_is_main_frame, &parent_frame_id,
757 &render_process_host_id, &routing_id, 770 &render_process_host_id, &routing_id,
758 &resource_type); 771 &resource_type);
759 frame_id_for_extension = GetFrameId(is_main_frame, frame_id);
760 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame,
761 parent_frame_id);
762 772
763 out->SetString(keys::kRequestIdKey, 773 out->SetString(keys::kRequestIdKey,
764 base::Uint64ToString(request->identifier())); 774 base::Uint64ToString(request->identifier()));
765 out->SetString(keys::kUrlKey, request->url().spec()); 775 out->SetString(keys::kUrlKey, request->url().spec());
766 out->SetString(keys::kMethodKey, request->method()); 776 out->SetString(keys::kMethodKey, request->method());
767 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); 777 // Note: This (frameId, processId) pair is removed by ExtractRenderFrameInfo,
768 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); 778 // and finally restored in DispatchEventToListeners or SendOnMessageEventOnUI.
779 // TODO(robwu): This is ugly. Create a proper data structure to separate these
780 // two IDs from the dictionary, so that kFrameIdKey has only one meaning.
781 out->SetInteger(keys::kFrameIdKey, render_frame_id);
782 out->SetInteger(keys::kProcessIdKey, render_process_host_id);
769 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); 783 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type));
770 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); 784 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
771 if (web_request_event_router_delegate_) { 785 if (web_request_event_router_delegate_) {
772 web_request_event_router_delegate_->ExtractExtraRequestDetails( 786 web_request_event_router_delegate_->ExtractExtraRequestDetails(
773 request, out); 787 request, out);
774 } 788 }
775 } 789 }
776 790
777 int ExtensionWebRequestEventRouter::OnBeforeRequest( 791 int ExtensionWebRequestEventRouter::OnBeforeRequest(
778 void* browser_context, 792 void* browser_context,
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 } 1251 }
1238 1252
1239 bool ExtensionWebRequestEventRouter::DispatchEvent( 1253 bool ExtensionWebRequestEventRouter::DispatchEvent(
1240 void* browser_context, 1254 void* browser_context,
1241 net::URLRequest* request, 1255 net::URLRequest* request,
1242 const std::vector<const EventListener*>& listeners, 1256 const std::vector<const EventListener*>& listeners,
1243 const base::ListValue& args) { 1257 const base::ListValue& args) {
1244 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) 1258 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args)
1245 // pairs into a single message sent to a list of sub_event_names. 1259 // pairs into a single message sent to a list of sub_event_names.
1246 int num_handlers_blocking = 0; 1260 int num_handlers_blocking = 0;
1261
1262 scoped_ptr<std::vector<EventListener>> listeners_to_dispatch(
1263 new std::vector<EventListener>());
1264 listeners_to_dispatch->reserve(listeners.size());
1247 for (const EventListener* listener : listeners) { 1265 for (const EventListener* listener : listeners) {
1248 // Filter out the optional keys that this listener didn't request. 1266 listeners_to_dispatch->push_back(*listener);
1249 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy());
1250 base::DictionaryValue* dict = NULL;
1251 CHECK(args_filtered->GetDictionary(0, &dict) && dict);
1252 if (!(listener->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS))
1253 dict->Remove(keys::kRequestHeadersKey, NULL);
1254 if (!(listener->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS))
1255 dict->Remove(keys::kResponseHeadersKey, NULL);
1256
1257 EventRouter::DispatchEventToSender(
1258 listener->ipc_sender.get(), browser_context, listener->extension_id,
1259 listener->histogram_value, listener->sub_event_name,
1260 std::move(args_filtered), EventRouter::USER_GESTURE_UNKNOWN,
1261 EventFilteringInfo());
1262 if (listener->extra_info_spec & 1267 if (listener->extra_info_spec &
1263 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { 1268 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) {
1264 listener->blocked_requests.insert(request->identifier()); 1269 listener->blocked_requests.insert(request->identifier());
1265 // If this is the first delegate blocking the request, go ahead and log 1270 // If this is the first delegate blocking the request, go ahead and log
1266 // it. 1271 // it.
1267 if (num_handlers_blocking == 0) { 1272 if (num_handlers_blocking == 0) {
1268 std::string delegate_info = l10n_util::GetStringFUTF8( 1273 std::string delegate_info = l10n_util::GetStringFUTF8(
1269 IDS_LOAD_STATE_PARAMETER_EXTENSION, 1274 IDS_LOAD_STATE_PARAMETER_EXTENSION,
1270 base::UTF8ToUTF16(listener->extension_name)); 1275 base::UTF8ToUTF16(listener->extension_name));
1271 // LobAndReport allows extensions that block requests to be displayed in 1276 // LobAndReport allows extensions that block requests to be displayed in
1272 // the load status bar. 1277 // the load status bar.
1273 request->LogAndReportBlockedBy(delegate_info.c_str()); 1278 request->LogAndReportBlockedBy(delegate_info.c_str());
1274 } 1279 }
1275 ++num_handlers_blocking; 1280 ++num_handlers_blocking;
1276 } 1281 }
1277 } 1282 }
1278 1283
1284 // TODO(robwu): Avoid unnecessary copy, by changing |args| to be a
1285 // scoped_ptr<base::DictionaryValue> and transferring the ownership.
1286 const base::DictionaryValue* dict = nullptr;
1287 CHECK(args.GetDictionary(0, &dict) && dict);
1288 base::DictionaryValue* args_copy = dict->DeepCopy();
1289
1290 int render_process_host_id = -1;
1291 int render_frame_id = -1;
1292 ExtractRenderFrameInfo(args_copy, &render_process_host_id, &render_frame_id);
1293
1294 ExtensionApiFrameIdMap::Get()->GetFrameIdOnIO(
1295 render_process_host_id, render_frame_id,
1296 base::Bind(&ExtensionWebRequestEventRouter::DispatchEventToListeners,
1297 AsWeakPtr(), browser_context,
1298 base::Passed(&listeners_to_dispatch), base::Owned(args_copy)));
1299
1279 if (num_handlers_blocking > 0) { 1300 if (num_handlers_blocking > 0) {
1280 BlockedRequest& blocked_request = blocked_requests_[request->identifier()]; 1301 BlockedRequest& blocked_request = blocked_requests_[request->identifier()];
1281 blocked_request.request = request; 1302 blocked_request.request = request;
1282 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context); 1303 blocked_request.is_incognito |= IsIncognitoBrowserContext(browser_context);
1283 blocked_request.num_handlers_blocking += num_handlers_blocking; 1304 blocked_request.num_handlers_blocking += num_handlers_blocking;
1284 blocked_request.blocking_time = base::Time::Now(); 1305 blocked_request.blocking_time = base::Time::Now();
1285 return true; 1306 return true;
1286 } 1307 }
1287 1308
1288 return false; 1309 return false;
1289 } 1310 }
1290 1311
1312 void ExtensionWebRequestEventRouter::DispatchEventToListeners(
1313 void* browser_context,
1314 scoped_ptr<std::vector<EventListener>> listeners,
1315 base::DictionaryValue* dict,
1316 int extension_api_frame_id,
1317 int extension_api_parent_frame_id) {
1318 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1319 DCHECK(listeners.get());
1320 DCHECK_GT(listeners->size(), 0UL);
1321 DCHECK(dict);
1322
1323 dict->SetInteger(keys::kFrameIdKey, extension_api_frame_id);
1324 dict->SetInteger(keys::kParentFrameIdKey, extension_api_parent_frame_id);
1325
1326 std::string event_name =
1327 EventRouter::GetBaseEventName((*listeners)[0].sub_event_name);
1328 DCHECK(IsWebRequestEvent(event_name));
1329
1330 const std::set<EventListener>& event_listeners =
1331 listeners_[browser_context][event_name];
1332 void* cross_browser_context = GetCrossBrowserContext(browser_context);
1333 const std::set<EventListener>* cross_event_listeners =
1334 cross_browser_context ? &listeners_[cross_browser_context][event_name]
1335 : nullptr;
1336
1337 for (const EventListener& target : *listeners) {
1338 std::set<EventListener>::const_iterator listener =
1339 event_listeners.find(target);
1340 // Ignore listener if it was removed between the thread hops.
1341 if (listener == event_listeners.end()) {
1342 if (!cross_event_listeners)
1343 continue;
1344 listener = cross_event_listeners->find(target);
1345 if (listener == cross_event_listeners->end())
1346 continue;
1347 }
1348
1349 // Filter out the optional keys that this listener didn't request.
1350 scoped_ptr<base::ListValue> args_filtered(new base::ListValue);
1351 args_filtered->Append(dict->DeepCopy());
1352 if (!(listener->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS))
1353 dict->Remove(keys::kRequestHeadersKey, nullptr);
1354 if (!(listener->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS))
1355 dict->Remove(keys::kResponseHeadersKey, nullptr);
1356
1357 EventRouter::DispatchEventToSender(
1358 listener->ipc_sender.get(), browser_context, listener->extension_id,
1359 listener->histogram_value, listener->sub_event_name,
1360 std::move(args_filtered), EventRouter::USER_GESTURE_UNKNOWN,
1361 EventFilteringInfo());
1362 }
1363 }
1364
1291 void ExtensionWebRequestEventRouter::OnEventHandled( 1365 void ExtensionWebRequestEventRouter::OnEventHandled(
1292 void* browser_context, 1366 void* browser_context,
1293 const std::string& extension_id, 1367 const std::string& extension_id,
1294 const std::string& event_name, 1368 const std::string& event_name,
1295 const std::string& sub_event_name, 1369 const std::string& sub_event_name,
1296 uint64_t request_id, 1370 uint64_t request_id,
1297 EventResponse* response) { 1371 EventResponse* response) {
1298 // TODO(robwu): Does this also work with webviews? operator< (used by find) 1372 // TODO(robwu): Does this also work with webviews? operator< (used by find)
1299 // takes the webview ID into account, which is not set on |listener|. 1373 // takes the webview ID into account, which is not set on |listener|.
1300 EventListener listener; 1374 EventListener listener;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 } 1508 }
1435 1509
1436 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( 1510 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad(
1437 const base::Closure& callback) { 1511 const base::Closure& callback) {
1438 callbacks_for_page_load_.push_back(callback); 1512 callbacks_for_page_load_.push_back(callback);
1439 } 1513 }
1440 1514
1441 bool ExtensionWebRequestEventRouter::IsPageLoad( 1515 bool ExtensionWebRequestEventRouter::IsPageLoad(
1442 const net::URLRequest* request) const { 1516 const net::URLRequest* request) const {
1443 bool is_main_frame = false; 1517 bool is_main_frame = false;
1444 int frame_id = -1; 1518 int render_frame_id = -1;
1445 bool parent_is_main_frame = false;
1446 int parent_frame_id = -1;
1447 int render_process_host_id = -1; 1519 int render_process_host_id = -1;
1448 int routing_id = -1; 1520 int routing_id = -1;
1449 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; 1521 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
1450 1522
1451 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 1523 ExtractRequestInfoDetails(request, &is_main_frame, &render_frame_id,
1452 &parent_is_main_frame, &parent_frame_id, 1524 &render_process_host_id, &routing_id,
1453 &render_process_host_id, 1525 &resource_type);
1454 &routing_id, &resource_type);
1455 1526
1456 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME; 1527 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME;
1457 } 1528 }
1458 1529
1459 void ExtensionWebRequestEventRouter::NotifyPageLoad() { 1530 void ExtensionWebRequestEventRouter::NotifyPageLoad() {
1460 for (const auto& callback : callbacks_for_page_load_) 1531 for (const auto& callback : callbacks_for_page_load_)
1461 callback.Run(); 1532 callback.Run();
1462 callbacks_for_page_load_.clear(); 1533 callbacks_for_page_load_.clear();
1463 } 1534 }
1464 1535
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 void* browser_context, 1655 void* browser_context,
1585 const InfoMap* extension_info_map, 1656 const InfoMap* extension_info_map,
1586 const std::string& event_name, 1657 const std::string& event_name,
1587 const net::URLRequest* request, 1658 const net::URLRequest* request,
1588 int* extra_info_spec) { 1659 int* extra_info_spec) {
1589 // TODO(mpcomplete): handle browser_context == NULL (should collect all 1660 // TODO(mpcomplete): handle browser_context == NULL (should collect all
1590 // listeners). 1661 // listeners).
1591 *extra_info_spec = 0; 1662 *extra_info_spec = 0;
1592 1663
1593 bool is_main_frame = false; 1664 bool is_main_frame = false;
1594 int frame_id = -1; 1665 int render_frame_id = -1;
1595 bool parent_is_main_frame = false;
1596 int parent_frame_id = -1;
1597 int render_process_host_id = -1; 1666 int render_process_host_id = -1;
1598 int routing_id = -1; 1667 int routing_id = -1;
1599 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; 1668 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
1600 const GURL& url = request->url(); 1669 const GURL& url = request->url();
1601 1670
1602 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 1671 ExtractRequestInfoDetails(request, &is_main_frame, &render_frame_id,
1603 &parent_is_main_frame, &parent_frame_id, 1672 &render_process_host_id, &routing_id,
1604 &render_process_host_id, 1673 &resource_type);
1605 &routing_id, &resource_type);
1606 1674
1607 bool is_request_from_extension = 1675 bool is_request_from_extension =
1608 IsRequestFromExtension(request, extension_info_map); 1676 IsRequestFromExtension(request, extension_info_map);
1609 1677
1610 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 1678 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
1611 // We are conservative here and assume requests are asynchronous in case 1679 // We are conservative here and assume requests are asynchronous in case
1612 // we don't have an info object. We don't want to risk a deadlock. 1680 // we don't have an info object. We don't want to risk a deadlock.
1613 bool is_async_request = !info || info->IsAsync(); 1681 bool is_async_request = !info || info->IsAsync();
1614 1682
1615 EventListeners matching_listeners; 1683 EventListeners matching_listeners;
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 // Continue gracefully. 2540 // Continue gracefully.
2473 RunSync(); 2541 RunSync();
2474 } 2542 }
2475 2543
2476 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { 2544 bool WebRequestHandlerBehaviorChangedFunction::RunSync() {
2477 helpers::ClearCacheOnNavigation(); 2545 helpers::ClearCacheOnNavigation();
2478 return true; 2546 return true;
2479 } 2547 }
2480 2548
2481 } // namespace extensions 2549 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698