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

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

Powered by Google App Engine
This is Rietveld 408576698