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

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

Issue 568583002: Introduce WebRequestEventRouterDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename the delegate to WebRequestEventRouterDelegate. Created 6 years, 3 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 "chrome/browser/extensions/api/web_request/web_request_api.h" 5 #include "chrome/browser/extensions/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"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_content_browser_client.h"
21 #include "chrome/browser/extensions/activity_log/activity_action_constants.h"
22 #include "chrome/browser/extensions/activity_log/activity_actions.h"
23 #include "chrome/browser/extensions/activity_log/activity_log.h"
24 #include "chrome/browser/extensions/activity_log/web_request_constants.h"
25 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 19 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
26 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" 20 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h"
27 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" 21 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h"
28 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 22 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
29 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" 23 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h"
30 #include "chrome/browser/extensions/extension_renderer_state.h"
31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/common/extensions/api/web_request.h" 24 #include "chrome/common/extensions/api/web_request.h"
34 #include "chrome/common/extensions/extension_constants.h"
35 #include "chrome/common/url_constants.h"
36 #include "chrome/grit/generated_resources.h"
37 #include "content/public/browser/browser_message_filter.h" 25 #include "content/public/browser/browser_message_filter.h"
38 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/render_process_host.h" 28 #include "content/public/browser/render_process_host.h"
41 #include "content/public/browser/resource_request_info.h" 29 #include "content/public/browser/resource_request_info.h"
42 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
43 #include "extensions/browser/api/declarative_webrequest/request_stage.h" 31 #include "extensions/browser/api/declarative_webrequest/request_stage.h"
44 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 32 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
33 #include "extensions/browser/api/extensions_api_client.h"
45 #include "extensions/browser/api/web_request/web_request_api_utils.h" 34 #include "extensions/browser/api/web_request/web_request_api_utils.h"
35 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h "
46 #include "extensions/browser/event_router.h" 36 #include "extensions/browser/event_router.h"
47 #include "extensions/browser/extension_message_filter.h" 37 #include "extensions/browser/extension_message_filter.h"
48 #include "extensions/browser/extension_prefs.h" 38 #include "extensions/browser/extension_prefs.h"
49 #include "extensions/browser/extension_registry.h" 39 #include "extensions/browser/extension_registry.h"
50 #include "extensions/browser/extension_system.h" 40 #include "extensions/browser/extension_system.h"
41 #include "extensions/browser/extensions_browser_client.h"
51 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 42 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
52 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" 43 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
53 #include "extensions/browser/info_map.h" 44 #include "extensions/browser/info_map.h"
54 #include "extensions/browser/runtime_data.h" 45 #include "extensions/browser/runtime_data.h"
55 #include "extensions/browser/warning_service.h" 46 #include "extensions/browser/warning_service.h"
56 #include "extensions/browser/warning_set.h" 47 #include "extensions/browser/warning_set.h"
57 #include "extensions/common/error_utils.h" 48 #include "extensions/common/error_utils.h"
58 #include "extensions/common/event_filtering_info.h" 49 #include "extensions/common/event_filtering_info.h"
59 #include "extensions/common/extension.h" 50 #include "extensions/common/extension.h"
60 #include "extensions/common/extension_messages.h" 51 #include "extensions/common/extension_messages.h"
61 #include "extensions/common/extension_set.h" 52 #include "extensions/common/extension_set.h"
62 #include "extensions/common/features/feature.h" 53 #include "extensions/common/features/feature.h"
63 #include "extensions/common/permissions/permissions_data.h" 54 #include "extensions/common/permissions/permissions_data.h"
64 #include "extensions/common/url_pattern.h" 55 #include "extensions/common/url_pattern.h"
56 #include "extensions/strings/grit/extensions_strings.h"
65 #include "net/base/auth.h" 57 #include "net/base/auth.h"
66 #include "net/base/net_errors.h" 58 #include "net/base/net_errors.h"
67 #include "net/base/upload_data_stream.h" 59 #include "net/base/upload_data_stream.h"
68 #include "net/http/http_response_headers.h" 60 #include "net/http/http_response_headers.h"
69 #include "net/http/http_util.h" 61 #include "net/http/http_util.h"
70 #include "net/url_request/url_request.h" 62 #include "net/url_request/url_request.h"
71 #include "ui/base/l10n/l10n_util.h" 63 #include "ui/base/l10n/l10n_util.h"
72 #include "url/gurl.h" 64 #include "url/gurl.h"
73 65
74 using base::DictionaryValue; 66 using base::DictionaryValue;
(...skipping 10 matching lines...) Expand all
85 using extensions::RulesRegistryService; 77 using extensions::RulesRegistryService;
86 using extensions::Warning; 78 using extensions::Warning;
87 using extensions::WarningService; 79 using extensions::WarningService;
88 using extensions::WarningSet; 80 using extensions::WarningSet;
89 81
90 namespace helpers = extension_web_request_api_helpers; 82 namespace helpers = extension_web_request_api_helpers;
91 namespace utils = extension_web_request_api_utils; 83 namespace utils = extension_web_request_api_utils;
92 namespace keys = extension_web_request_api_constants; 84 namespace keys = extension_web_request_api_constants;
93 namespace web_request = extensions::api::web_request; 85 namespace web_request = extensions::api::web_request;
94 namespace declarative_keys = extensions::declarative_webrequest_constants; 86 namespace declarative_keys = extensions::declarative_webrequest_constants;
95 namespace activitylog = activity_log_web_request_constants;
96 87
97 namespace { 88 namespace {
98 89
99 const char kWebRequestEventPrefix[] = "webRequest."; 90 const char kWebRequestEventPrefix[] = "webRequest.";
100 91
101 // List of all the webRequest events. 92 // List of all the webRequest events.
102 const char* const kWebRequestEvents[] = { 93 const char* const kWebRequestEvents[] = {
103 keys::kOnBeforeRedirectEvent, 94 keys::kOnBeforeRedirectEvent,
104 web_request::OnBeforeRequest::kEventName, 95 web_request::OnBeforeRequest::kEventName,
105 keys::kOnBeforeSendHeadersEvent, 96 keys::kOnBeforeSendHeadersEvent,
106 keys::kOnCompletedEvent, 97 keys::kOnCompletedEvent,
107 web_request::OnErrorOccurred::kEventName, 98 web_request::OnErrorOccurred::kEventName,
108 keys::kOnSendHeadersEvent, 99 keys::kOnSendHeadersEvent,
109 keys::kOnAuthRequiredEvent, 100 keys::kOnAuthRequiredEvent,
110 keys::kOnResponseStartedEvent, 101 keys::kOnResponseStartedEvent,
111 keys::kOnHeadersReceivedEvent, 102 keys::kOnHeadersReceivedEvent,
112 }; 103 };
113 104
114 #define ARRAYEND(array) (array + arraysize(array))
115
116 const char* GetRequestStageAsString( 105 const char* GetRequestStageAsString(
117 ExtensionWebRequestEventRouter::EventTypes type) { 106 ExtensionWebRequestEventRouter::EventTypes type) {
118 switch (type) { 107 switch (type) {
119 case ExtensionWebRequestEventRouter::kInvalidEvent: 108 case ExtensionWebRequestEventRouter::kInvalidEvent:
120 return "Invalid"; 109 return "Invalid";
121 case ExtensionWebRequestEventRouter::kOnBeforeRequest: 110 case ExtensionWebRequestEventRouter::kOnBeforeRequest:
122 return keys::kOnBeforeRequest; 111 return keys::kOnBeforeRequest;
123 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders: 112 case ExtensionWebRequestEventRouter::kOnBeforeSendHeaders:
124 return keys::kOnBeforeSendHeaders; 113 return keys::kOnBeforeSendHeaders;
125 case ExtensionWebRequestEventRouter::kOnSendHeaders: 114 case ExtensionWebRequestEventRouter::kOnSendHeaders:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bool GetWebViewInfo( 180 bool GetWebViewInfo(
192 net::URLRequest* request, 181 net::URLRequest* request,
193 extensions::WebViewRendererState::WebViewInfo* web_view_info) { 182 extensions::WebViewRendererState::WebViewInfo* web_view_info) {
194 int render_process_host_id = -1; 183 int render_process_host_id = -1;
195 int routing_id = -1; 184 int routing_id = -1;
196 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); 185 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id);
197 return extensions::WebViewRendererState::GetInstance()-> 186 return extensions::WebViewRendererState::GetInstance()->
198 GetInfo(render_process_host_id, routing_id, web_view_info); 187 GetInfo(render_process_host_id, routing_id, web_view_info);
199 } 188 }
200 189
201 void ExtractRequestInfoDetails(net::URLRequest* request,
202 bool* is_main_frame,
203 int* frame_id,
204 bool* parent_is_main_frame,
205 int* parent_frame_id,
206 int* tab_id,
207 int* window_id,
208 int* render_process_host_id,
209 int* routing_id,
210 ResourceType* resource_type) {
211 if (!request->GetUserData(NULL))
212 return;
213
214 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
215 ExtensionRendererState::GetInstance()->GetTabAndWindowId(
216 info, tab_id, window_id);
217 *frame_id = info->GetRenderFrameID();
218 *is_main_frame = info->IsMainFrame();
219 *parent_frame_id = info->GetParentRenderFrameID();
220 *parent_is_main_frame = info->ParentIsMainFrame();
221 *render_process_host_id = info->GetChildID();
222 *routing_id = info->GetRouteID();
223
224 // Restrict the resource type to the values we care about.
225 if (utils::IsRelevantResourceType(info->GetResourceType()))
226 *resource_type = info->GetResourceType();
227 else
228 *resource_type = content::RESOURCE_TYPE_LAST_TYPE;
229 }
230
231 // Extracts from |request| information for the keys requestId, url, method,
232 // frameId, tabId, type, and timeStamp and writes these into |out| to be passed
233 // on to extensions.
234 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) {
235 bool is_main_frame = false;
236 int frame_id = -1;
237 bool parent_is_main_frame = false;
238 int parent_frame_id = -1;
239 int frame_id_for_extension = -1;
240 int parent_frame_id_for_extension = -1;
241 int tab_id = -1;
242 int window_id = -1;
243 int render_process_host_id = -1;
244 int routing_id = -1;
245 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
246 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
247 &parent_is_main_frame, &parent_frame_id, &tab_id,
248 &window_id, &render_process_host_id, &routing_id,
249 &resource_type);
250 frame_id_for_extension = GetFrameId(is_main_frame, frame_id);
251 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame,
252 parent_frame_id);
253
254 out->SetString(keys::kRequestIdKey,
255 base::Uint64ToString(request->identifier()));
256 out->SetString(keys::kUrlKey, request->url().spec());
257 out->SetString(keys::kMethodKey, request->method());
258 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension);
259 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension);
260 out->SetInteger(keys::kTabIdKey, tab_id);
261 out->SetString(keys::kTypeKey, utils::ResourceTypeToString(resource_type));
262 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
263 }
264
265 // Extracts the body from |request| and writes the data into |out|. 190 // Extracts the body from |request| and writes the data into |out|.
266 void ExtractRequestInfoBody(const net::URLRequest* request, 191 void ExtractRequestInfoBody(const net::URLRequest* request,
267 base::DictionaryValue* out) { 192 base::DictionaryValue* out) {
268 const net::UploadDataStream* upload_data = request->get_upload(); 193 const net::UploadDataStream* upload_data = request->get_upload();
269 if (!upload_data || 194 if (!upload_data ||
270 (request->method() != "POST" && request->method() != "PUT")) 195 (request->method() != "POST" && request->method() != "PUT"))
271 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . 196 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" .
272 197
273 base::DictionaryValue* requestBody = new base::DictionaryValue(); 198 base::DictionaryValue* requestBody = new base::DictionaryValue();
274 out->Set(keys::kRequestBodyKey, requestBody); 199 out->Set(keys::kRequestBodyKey, requestBody);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (!header_value->HasKey(keys::kHeaderBinaryValueKey)) { 249 if (!header_value->HasKey(keys::kHeaderBinaryValueKey)) {
325 *value = ""; 250 *value = "";
326 } else if (!header_value->GetList(keys::kHeaderBinaryValueKey, &list) || 251 } else if (!header_value->GetList(keys::kHeaderBinaryValueKey, &list) ||
327 !helpers::CharListToString(list, value)) { 252 !helpers::CharListToString(list, value)) {
328 return false; 253 return false;
329 } 254 }
330 } 255 }
331 return true; 256 return true;
332 } 257 }
333 258
334 // Converts the |name|, |value| pair of a http header to a HttpHeaders
335 // dictionary. Ownership is passed to the caller.
336 base::DictionaryValue* ToHeaderDictionary(const std::string& name,
337 const std::string& value) {
338 base::DictionaryValue* header = new base::DictionaryValue();
339 header->SetString(keys::kHeaderNameKey, name);
340 if (base::IsStringUTF8(value)) {
341 header->SetString(keys::kHeaderValueKey, value);
342 } else {
343 header->Set(keys::kHeaderBinaryValueKey,
344 helpers::StringToCharList(value));
345 }
346 return header;
347 }
348
349 // Creates a list of HttpHeaders (see the extension API JSON). If |headers| is 259 // Creates a list of HttpHeaders (see the extension API JSON). If |headers| is
350 // NULL, the list is empty. Ownership is passed to the caller. 260 // NULL, the list is empty. Ownership is passed to the caller.
351 base::ListValue* GetResponseHeadersList( 261 base::ListValue* GetResponseHeadersList(
352 const net::HttpResponseHeaders* headers) { 262 const net::HttpResponseHeaders* headers) {
353 base::ListValue* headers_value = new base::ListValue(); 263 base::ListValue* headers_value = new base::ListValue();
354 if (headers) { 264 if (headers) {
355 void* iter = NULL; 265 void* iter = NULL;
356 std::string name; 266 std::string name;
357 std::string value; 267 std::string value;
358 while (headers->EnumerateHeaderLines(&iter, &name, &value)) 268 while (headers->EnumerateHeaderLines(&iter, &name, &value))
359 headers_value->Append(ToHeaderDictionary(name, value)); 269 headers_value->Append(helpers::ToHeaderDictionary(name, value));
360 } 270 }
361 return headers_value; 271 return headers_value;
362 } 272 }
363 273
364 base::ListValue* GetRequestHeadersList(const net::HttpRequestHeaders& headers) { 274 base::ListValue* GetRequestHeadersList(const net::HttpRequestHeaders& headers) {
365 base::ListValue* headers_value = new base::ListValue(); 275 base::ListValue* headers_value = new base::ListValue();
366 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) 276 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); )
367 headers_value->Append(ToHeaderDictionary(it.name(), it.value())); 277 headers_value->Append(helpers::ToHeaderDictionary(it.name(), it.value()));
368 return headers_value; 278 return headers_value;
369 } 279 }
370 280
371 // Creates a base::StringValue with the status line of |headers|. If |headers| 281 // Creates a base::StringValue with the status line of |headers|. If |headers|
372 // is NULL, an empty string is returned. Ownership is passed to the caller. 282 // is NULL, an empty string is returned. Ownership is passed to the caller.
373 base::StringValue* GetStatusLine(net::HttpResponseHeaders* headers) { 283 base::StringValue* GetStatusLine(net::HttpResponseHeaders* headers) {
374 return new base::StringValue( 284 return new base::StringValue(
375 headers ? headers->GetStatusLine() : std::string()); 285 headers ? headers->GetStatusLine() : std::string());
376 } 286 }
377 287
378 void RemoveEventListenerOnUI( 288 void RemoveEventListenerOnUI(
379 void* profile_id, 289 void* profile_id,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context?
Xi Han 2014/09/18 16:24:00 Done.
380 const std::string& event_name, 290 const std::string& event_name,
381 int process_id, 291 int process_id,
382 const std::string& extension_id) { 292 const std::string& extension_id) {
383 DCHECK_CURRENTLY_ON(BrowserThread::UI); 293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
384 294
385 Profile* profile = reinterpret_cast<Profile*>(profile_id); 295 content::BrowserContext* browser_context =
386 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 296 reinterpret_cast<content::BrowserContext*>(profile_id);
297 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(
298 browser_context))
387 return; 299 return;
388 300
389 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); 301 extensions::EventRouter* event_router =
302 extensions::EventRouter::Get(browser_context);
390 if (!event_router) 303 if (!event_router)
391 return; 304 return;
392 305
393 content::RenderProcessHost* process = 306 content::RenderProcessHost* process =
394 content::RenderProcessHost::FromID(process_id); 307 content::RenderProcessHost::FromID(process_id);
395 if (!process) 308 if (!process)
396 return; 309 return;
397 310
398 event_router->RemoveEventListener(event_name, process, extension_id); 311 event_router->RemoveEventListener(event_name, process, extension_id);
399 } 312 }
400 313
401 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage or 314 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage or
402 // to subscribers of webview.onMessage if the action is being operated upon 315 // to subscribers of webview.onMessage if the action is being operated upon
403 // a <webview> guest renderer. 316 // a <webview> guest renderer.
404 // |extension_id| identifies the extension that sends and receives the event. 317 // |extension_id| identifies the extension that sends and receives the event.
405 // |is_web_view_guest| indicates whether the action is for a <webview>. 318 // |is_web_view_guest| indicates whether the action is for a <webview>.
406 // |web_view_info| is a struct containing information about the <webview> 319 // |web_view_info| is a struct containing information about the <webview>
407 // embedder. 320 // embedder.
408 // |event_argument| is passed to the event listener. 321 // |event_argument| is passed to the event listener.
409 void SendOnMessageEventOnUI( 322 void SendOnMessageEventOnUI(
410 void* profile_id, 323 void* profile_id,
Fady Samuel 2014/09/12 21:55:40 nit: Rename to browser_context?
Xi Han 2014/09/18 16:24:02 Done.
411 const std::string& extension_id, 324 const std::string& extension_id,
412 bool is_web_view_guest, 325 bool is_web_view_guest,
413 const extensions::WebViewRendererState::WebViewInfo& web_view_info, 326 const extensions::WebViewRendererState::WebViewInfo& web_view_info,
414 scoped_ptr<base::DictionaryValue> event_argument) { 327 scoped_ptr<base::DictionaryValue> event_argument) {
415 DCHECK_CURRENTLY_ON(BrowserThread::UI); 328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
416 329
417 Profile* profile = reinterpret_cast<Profile*>(profile_id); 330 content::BrowserContext* browser_context =
418 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 331 reinterpret_cast<content::BrowserContext*>(profile_id);
332 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(
333 browser_context))
419 return; 334 return;
420 335
421 scoped_ptr<base::ListValue> event_args(new base::ListValue); 336 scoped_ptr<base::ListValue> event_args(new base::ListValue);
422 event_args->Append(event_argument.release()); 337 event_args->Append(event_argument.release());
423 338
424 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); 339 extensions::EventRouter* event_router =
340 extensions::EventRouter::Get(browser_context);
425 341
426 extensions::EventFilteringInfo event_filtering_info; 342 extensions::EventFilteringInfo event_filtering_info;
427 343
428 std::string event_name; 344 std::string event_name;
429 // The instance ID uniquely identifies a <webview> instance within an embedder 345 // The instance ID uniquely identifies a <webview> instance within an embedder
430 // process. We use a filter here so that only event listeners for a particular 346 // process. We use a filter here so that only event listeners for a particular
431 // <webview> will fire. 347 // <webview> will fire.
432 if (is_web_view_guest) { 348 if (is_web_view_guest) {
433 event_filtering_info.SetInstanceID(web_view_info.instance_id); 349 event_filtering_info.SetInstanceID(web_view_info.instance_id);
434 event_name = webview::kEventMessage; 350 event_name = webview::kEventMessage;
435 } else { 351 } else {
436 event_name = declarative_keys::kOnMessage; 352 event_name = declarative_keys::kOnMessage;
437 } 353 }
438 354
439 scoped_ptr<extensions::Event> event(new extensions::Event( 355 scoped_ptr<extensions::Event> event(new extensions::Event(
440 event_name, 356 event_name,
441 event_args.Pass(), profile, GURL(), 357 event_args.Pass(), browser_context, GURL(),
442 extensions::EventRouter::USER_GESTURE_UNKNOWN, 358 extensions::EventRouter::USER_GESTURE_UNKNOWN,
443 event_filtering_info)); 359 event_filtering_info));
444 event_router->DispatchEventToExtension(extension_id, event.Pass()); 360 event_router->DispatchEventToExtension(extension_id, event.Pass());
445 } 361 }
446 362
447 void RemoveEventListenerOnIOThread( 363 void RemoveEventListenerOnIOThread(
448 content::BrowserContext* browser_context, 364 content::BrowserContext* browser_context,
449 const std::string& extension_id, 365 const std::string& extension_id,
450 const std::string& sub_event_name) { 366 const std::string& sub_event_name) {
451 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( 367 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // ExtensionWebRequestEventRouter 614 // ExtensionWebRequestEventRouter
699 // 615 //
700 616
701 // static 617 // static
702 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { 618 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() {
703 return Singleton<ExtensionWebRequestEventRouter>::get(); 619 return Singleton<ExtensionWebRequestEventRouter>::get();
704 } 620 }
705 621
706 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() 622 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
707 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { 623 : request_time_tracker_(new ExtensionWebRequestTimeTracker) {
624 web_request_event_router_delegate_.reset(
625 extensions::ExtensionsAPIClient::Get()->
626 CreateWebRequestEventRouterDelegate());
708 } 627 }
709 628
710 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { 629 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() {
711 } 630 }
712 631
713 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( 632 void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
714 void* profile, 633 void* profile,
Fady Samuel 2014/09/12 21:55:40 nit rename profile to browser_context.
Xi Han 2014/09/18 16:24:01 Done.
715 const RulesRegistryService::WebViewKey& webview_key, 634 const RulesRegistryService::WebViewKey& webview_key,
716 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { 635 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) {
717 RulesRegistryKey key(profile, webview_key); 636 RulesRegistryKey key(profile, webview_key);
718 if (rules_registry.get()) 637 if (rules_registry.get())
719 rules_registries_[key] = rules_registry; 638 rules_registries_[key] = rules_registry;
720 else 639 else
721 rules_registries_.erase(key); 640 rules_registries_.erase(key);
722 } 641 }
723 642
643 void ExtensionWebRequestEventRouter::ExtractRequestInfoDetails(
644 net::URLRequest* request,
645 bool* is_main_frame,
646 int* frame_id,
647 bool* parent_is_main_frame,
648 int* parent_frame_id,
649 int* tab_id,
650 int* window_id,
Fady Samuel 2014/09/12 21:55:40 Can we get rid of tab_id and window_id in extensio
651 int* render_process_host_id,
652 int* routing_id,
653 ResourceType* resource_type) const {
654 if (!request->GetUserData(NULL))
655 return;
656
657 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
658 if(web_request_event_router_delegate_) {
659 web_request_event_router_delegate_->ExtractRequestInfoDetails(
660 info, tab_id, window_id);
661 }
662 *frame_id = info->GetRenderFrameID();
663 *is_main_frame = info->IsMainFrame();
664 *parent_frame_id = info->GetParentRenderFrameID();
665 *parent_is_main_frame = info->ParentIsMainFrame();
666 *render_process_host_id = info->GetChildID();
667 *routing_id = info->GetRouteID();
668
669 // Restrict the resource type to the values we care about.
670 if (utils::IsRelevantResourceType(info->GetResourceType()))
671 *resource_type = info->GetResourceType();
672 else
673 *resource_type = content::RESOURCE_TYPE_LAST_TYPE;
674 }
675
676 void ExtensionWebRequestEventRouter::ExtractRequestInfo(
677 net::URLRequest* request, base::DictionaryValue* out) {
678 bool is_main_frame = false;
679 int frame_id = -1;
680 bool parent_is_main_frame = false;
681 int parent_frame_id = -1;
682 int frame_id_for_extension = -1;
683 int parent_frame_id_for_extension = -1;
684 int tab_id = -1;
685 int window_id = -1;
Fady Samuel 2014/09/12 21:55:40 The concepts of tab_id and window_id should not ex
686 int render_process_host_id = -1;
687 int routing_id = -1;
688 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
689 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
690 &parent_is_main_frame, &parent_frame_id, &tab_id,
691 &window_id, &render_process_host_id, &routing_id,
692 &resource_type);
693 frame_id_for_extension = GetFrameId(is_main_frame, frame_id);
694 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame,
695 parent_frame_id);
696
697 out->SetString(keys::kRequestIdKey,
698 base::Uint64ToString(request->identifier()));
699 out->SetString(keys::kUrlKey, request->url().spec());
700 out->SetString(keys::kMethodKey, request->method());
701 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension);
702 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension);
703 out->SetInteger(keys::kTabIdKey, tab_id);
704 out->SetString(keys::kTypeKey, utils::ResourceTypeToString(resource_type));
705 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
706 }
707
724 int ExtensionWebRequestEventRouter::OnBeforeRequest( 708 int ExtensionWebRequestEventRouter::OnBeforeRequest(
725 void* profile, 709 void* profile,
Fady Samuel 2014/09/12 21:55:40 nit: rename to browser_context
Xi Han 2014/09/18 16:24:00 Done.
726 InfoMap* extension_info_map, 710 InfoMap* extension_info_map,
727 net::URLRequest* request, 711 net::URLRequest* request,
728 const net::CompletionCallback& callback, 712 const net::CompletionCallback& callback,
729 GURL* new_url) { 713 GURL* new_url) {
730 // We hide events from the system context as well as sensitive requests. 714 // We hide events from the system context as well as sensitive requests.
731 if (!profile || 715 if (!profile ||
732 WebRequestPermissions::HideRequest(extension_info_map, request)) 716 WebRequestPermissions::HideRequest(extension_info_map, request))
733 return net::OK; 717 return net::OK;
734 718
735 if (IsPageLoad(request)) 719 if (IsPageLoad(request))
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 // If there are no blocking handlers, only the declarative rules tried 765 // If there are no blocking handlers, only the declarative rules tried
782 // to modify the request and we can respond synchronously. 766 // to modify the request and we can respond synchronously.
783 return ExecuteDeltas(profile, request->identifier(), 767 return ExecuteDeltas(profile, request->identifier(),
784 false /* call_callback*/); 768 false /* call_callback*/);
785 } else { 769 } else {
786 return net::ERR_IO_PENDING; 770 return net::ERR_IO_PENDING;
787 } 771 }
788 } 772 }
789 773
790 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders( 774 int ExtensionWebRequestEventRouter::OnBeforeSendHeaders(
791 void* profile, 775 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context
Xi Han 2014/09/18 16:24:00 Done.
792 InfoMap* extension_info_map, 776 InfoMap* extension_info_map,
793 net::URLRequest* request, 777 net::URLRequest* request,
794 const net::CompletionCallback& callback, 778 const net::CompletionCallback& callback,
795 net::HttpRequestHeaders* headers) { 779 net::HttpRequestHeaders* headers) {
796 // We hide events from the system context as well as sensitive requests. 780 // We hide events from the system context as well as sensitive requests.
797 if (!profile || 781 if (!profile ||
798 WebRequestPermissions::HideRequest(extension_info_map, request)) 782 WebRequestPermissions::HideRequest(extension_info_map, request))
799 return net::OK; 783 return net::OK;
800 784
801 bool initialize_blocked_requests = false; 785 bool initialize_blocked_requests = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 // If there are no blocking handlers, only the declarative rules tried 822 // If there are no blocking handlers, only the declarative rules tried
839 // to modify the request and we can respond synchronously. 823 // to modify the request and we can respond synchronously.
840 return ExecuteDeltas(profile, request->identifier(), 824 return ExecuteDeltas(profile, request->identifier(),
841 false /* call_callback*/); 825 false /* call_callback*/);
842 } else { 826 } else {
843 return net::ERR_IO_PENDING; 827 return net::ERR_IO_PENDING;
844 } 828 }
845 } 829 }
846 830
847 void ExtensionWebRequestEventRouter::OnSendHeaders( 831 void ExtensionWebRequestEventRouter::OnSendHeaders(
848 void* profile, 832 void* profile,
Fady Samuel 2014/09/12 21:55:40 nit: rename to browser_context
Xi Han 2014/09/18 16:24:01 Done.
849 InfoMap* extension_info_map, 833 InfoMap* extension_info_map,
850 net::URLRequest* request, 834 net::URLRequest* request,
851 const net::HttpRequestHeaders& headers) { 835 const net::HttpRequestHeaders& headers) {
852 // We hide events from the system context as well as sensitive requests. 836 // We hide events from the system context as well as sensitive requests.
853 if (!profile || 837 if (!profile ||
854 WebRequestPermissions::HideRequest(extension_info_map, request)) 838 WebRequestPermissions::HideRequest(extension_info_map, request))
855 return; 839 return;
856 840
857 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders)) 841 if (GetAndSetSignaled(request->identifier(), kOnSendHeaders))
858 return; 842 return;
(...skipping 12 matching lines...) Expand all
871 base::DictionaryValue* dict = new base::DictionaryValue(); 855 base::DictionaryValue* dict = new base::DictionaryValue();
872 ExtractRequestInfo(request, dict); 856 ExtractRequestInfo(request, dict);
873 if (extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) 857 if (extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)
874 dict->Set(keys::kRequestHeadersKey, GetRequestHeadersList(headers)); 858 dict->Set(keys::kRequestHeadersKey, GetRequestHeadersList(headers));
875 args.Append(dict); 859 args.Append(dict);
876 860
877 DispatchEvent(profile, request, listeners, args); 861 DispatchEvent(profile, request, listeners, args);
878 } 862 }
879 863
880 int ExtensionWebRequestEventRouter::OnHeadersReceived( 864 int ExtensionWebRequestEventRouter::OnHeadersReceived(
881 void* profile, 865 void* profile,
Fady Samuel 2014/09/12 21:55:38 nit: rename to browser_context
Xi Han 2014/09/18 16:23:59 Done.
882 InfoMap* extension_info_map, 866 InfoMap* extension_info_map,
883 net::URLRequest* request, 867 net::URLRequest* request,
884 const net::CompletionCallback& callback, 868 const net::CompletionCallback& callback,
885 const net::HttpResponseHeaders* original_response_headers, 869 const net::HttpResponseHeaders* original_response_headers,
886 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, 870 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
887 GURL* allowed_unsafe_redirect_url) { 871 GURL* allowed_unsafe_redirect_url) {
888 // We hide events from the system context as well as sensitive requests. 872 // We hide events from the system context as well as sensitive requests.
889 if (!profile || 873 if (!profile ||
890 WebRequestPermissions::HideRequest(extension_info_map, request)) 874 WebRequestPermissions::HideRequest(extension_info_map, request))
891 return net::OK; 875 return net::OK;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 // to modify the request and we can respond synchronously. 926 // to modify the request and we can respond synchronously.
943 return ExecuteDeltas(profile, request->identifier(), 927 return ExecuteDeltas(profile, request->identifier(),
944 false /* call_callback*/); 928 false /* call_callback*/);
945 } else { 929 } else {
946 return net::ERR_IO_PENDING; 930 return net::ERR_IO_PENDING;
947 } 931 }
948 } 932 }
949 933
950 net::NetworkDelegate::AuthRequiredResponse 934 net::NetworkDelegate::AuthRequiredResponse
951 ExtensionWebRequestEventRouter::OnAuthRequired( 935 ExtensionWebRequestEventRouter::OnAuthRequired(
952 void* profile, 936 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context
953 InfoMap* extension_info_map, 937 InfoMap* extension_info_map,
954 net::URLRequest* request, 938 net::URLRequest* request,
955 const net::AuthChallengeInfo& auth_info, 939 const net::AuthChallengeInfo& auth_info,
956 const net::NetworkDelegate::AuthCallback& callback, 940 const net::NetworkDelegate::AuthCallback& callback,
957 net::AuthCredentials* credentials) { 941 net::AuthCredentials* credentials) {
958 // No profile means that this is for authentication challenges in the 942 // No profile means that this is for authentication challenges in the
959 // system context. Skip in that case. Also skip sensitive requests. 943 // system context. Skip in that case. Also skip sensitive requests.
960 if (!profile || 944 if (!profile ||
961 WebRequestPermissions::HideRequest(extension_info_map, request)) 945 WebRequestPermissions::HideRequest(extension_info_map, request))
962 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 946 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 blocked_requests_[request->identifier()].request = request; 979 blocked_requests_[request->identifier()].request = request;
996 blocked_requests_[request->identifier()].auth_callback = callback; 980 blocked_requests_[request->identifier()].auth_callback = callback;
997 blocked_requests_[request->identifier()].auth_credentials = credentials; 981 blocked_requests_[request->identifier()].auth_credentials = credentials;
998 blocked_requests_[request->identifier()].net_log = &request->net_log(); 982 blocked_requests_[request->identifier()].net_log = &request->net_log();
999 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING; 983 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING;
1000 } 984 }
1001 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 985 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
1002 } 986 }
1003 987
1004 void ExtensionWebRequestEventRouter::OnBeforeRedirect( 988 void ExtensionWebRequestEventRouter::OnBeforeRedirect(
1005 void* profile, 989 void* profile,
Fady Samuel 2014/09/12 21:55:38 nit: Rename to browser_context
Xi Han 2014/09/18 16:23:59 Done.
1006 InfoMap* extension_info_map, 990 InfoMap* extension_info_map,
1007 net::URLRequest* request, 991 net::URLRequest* request,
1008 const GURL& new_location) { 992 const GURL& new_location) {
1009 // We hide events from the system context as well as sensitive requests. 993 // We hide events from the system context as well as sensitive requests.
1010 if (!profile || 994 if (!profile ||
1011 WebRequestPermissions::HideRequest(extension_info_map, request)) 995 WebRequestPermissions::HideRequest(extension_info_map, request))
1012 return; 996 return;
1013 997
1014 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect)) 998 if (GetAndSetSignaled(request->identifier(), kOnBeforeRedirect))
1015 return; 999 return;
(...skipping 27 matching lines...) Expand all
1043 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) { 1027 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) {
1044 dict->Set(keys::kResponseHeadersKey, 1028 dict->Set(keys::kResponseHeadersKey,
1045 GetResponseHeadersList(request->response_headers())); 1029 GetResponseHeadersList(request->response_headers()));
1046 } 1030 }
1047 args.Append(dict); 1031 args.Append(dict);
1048 1032
1049 DispatchEvent(profile, request, listeners, args); 1033 DispatchEvent(profile, request, listeners, args);
1050 } 1034 }
1051 1035
1052 void ExtensionWebRequestEventRouter::OnResponseStarted( 1036 void ExtensionWebRequestEventRouter::OnResponseStarted(
1053 void* profile, 1037 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context
Xi Han 2014/09/18 16:23:59 Done.
1054 InfoMap* extension_info_map, 1038 InfoMap* extension_info_map,
1055 net::URLRequest* request) { 1039 net::URLRequest* request) {
1056 // We hide events from the system context as well as sensitive requests. 1040 // We hide events from the system context as well as sensitive requests.
1057 if (!profile || 1041 if (!profile ||
1058 WebRequestPermissions::HideRequest(extension_info_map, request)) 1042 WebRequestPermissions::HideRequest(extension_info_map, request))
1059 return; 1043 return;
1060 1044
1061 // OnResponseStarted is even triggered, when the request was cancelled. 1045 // OnResponseStarted is even triggered, when the request was cancelled.
1062 if (request->status().status() != net::URLRequestStatus::SUCCESS) 1046 if (request->status().status() != net::URLRequestStatus::SUCCESS)
1063 return; 1047 return;
(...skipping 23 matching lines...) Expand all
1087 dict->Set(keys::kStatusLineKey, GetStatusLine(request->response_headers())); 1071 dict->Set(keys::kStatusLineKey, GetStatusLine(request->response_headers()));
1088 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) { 1072 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) {
1089 dict->Set(keys::kResponseHeadersKey, 1073 dict->Set(keys::kResponseHeadersKey,
1090 GetResponseHeadersList(request->response_headers())); 1074 GetResponseHeadersList(request->response_headers()));
1091 } 1075 }
1092 args.Append(dict); 1076 args.Append(dict);
1093 1077
1094 DispatchEvent(profile, request, listeners, args); 1078 DispatchEvent(profile, request, listeners, args);
1095 } 1079 }
1096 1080
1097 void ExtensionWebRequestEventRouter::OnCompleted(void* profile, 1081 void ExtensionWebRequestEventRouter::OnCompleted(void* profile,
Fady Samuel 2014/09/12 21:55:38 nit: rename to browser_context
Xi Han 2014/09/18 16:23:58 Done.
1098 InfoMap* extension_info_map, 1082 InfoMap* extension_info_map,
1099 net::URLRequest* request) { 1083 net::URLRequest* request) {
1100 // We hide events from the system context as well as sensitive requests. 1084 // We hide events from the system context as well as sensitive requests.
1101 // However, if the request first became sensitive after redirecting we have 1085 // However, if the request first became sensitive after redirecting we have
1102 // already signaled it and thus we have to signal the end of it. This is 1086 // already signaled it and thus we have to signal the end of it. This is
1103 // risk-free because the handler cannot modify the request now. 1087 // risk-free because the handler cannot modify the request now.
1104 if (!profile || 1088 if (!profile ||
1105 (WebRequestPermissions::HideRequest(extension_info_map, request) && 1089 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
1106 !WasSignaled(*request))) 1090 !WasSignaled(*request)))
1107 return; 1091 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) { 1124 if (extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) {
1141 dict->Set(keys::kResponseHeadersKey, 1125 dict->Set(keys::kResponseHeadersKey,
1142 GetResponseHeadersList(request->response_headers())); 1126 GetResponseHeadersList(request->response_headers()));
1143 } 1127 }
1144 args.Append(dict); 1128 args.Append(dict);
1145 1129
1146 DispatchEvent(profile, request, listeners, args); 1130 DispatchEvent(profile, request, listeners, args);
1147 } 1131 }
1148 1132
1149 void ExtensionWebRequestEventRouter::OnErrorOccurred( 1133 void ExtensionWebRequestEventRouter::OnErrorOccurred(
1150 void* profile, 1134 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context.
Xi Han 2014/09/18 16:24:00 Done.
1151 InfoMap* extension_info_map, 1135 InfoMap* extension_info_map,
1152 net::URLRequest* request, 1136 net::URLRequest* request,
1153 bool started) { 1137 bool started) {
1154 // We hide events from the system context as well as sensitive requests. 1138 // We hide events from the system context as well as sensitive requests.
1155 // However, if the request first became sensitive after redirecting we have 1139 // However, if the request first became sensitive after redirecting we have
1156 // already signaled it and thus we have to signal the end of it. This is 1140 // already signaled it and thus we have to signal the end of it. This is
1157 // risk-free because the handler cannot modify the request now. 1141 // risk-free because the handler cannot modify the request now.
1158 if (!profile || 1142 if (!profile ||
1159 (WebRequestPermissions::HideRequest(extension_info_map, request) && 1143 (WebRequestPermissions::HideRequest(extension_info_map, request) &&
1160 !WasSignaled(*request))) 1144 !WasSignaled(*request)))
(...skipping 27 matching lines...) Expand all
1188 } 1172 }
1189 dict->SetBoolean(keys::kFromCache, request->was_cached()); 1173 dict->SetBoolean(keys::kFromCache, request->was_cached());
1190 dict->SetString(keys::kErrorKey, 1174 dict->SetString(keys::kErrorKey,
1191 net::ErrorToString(request->status().error())); 1175 net::ErrorToString(request->status().error()));
1192 args.Append(dict); 1176 args.Append(dict);
1193 1177
1194 DispatchEvent(profile, request, listeners, args); 1178 DispatchEvent(profile, request, listeners, args);
1195 } 1179 }
1196 1180
1197 void ExtensionWebRequestEventRouter::OnURLRequestDestroyed( 1181 void ExtensionWebRequestEventRouter::OnURLRequestDestroyed(
1198 void* profile, net::URLRequest* request) { 1182 void* profile, net::URLRequest* request) {
Fady Samuel 2014/09/12 21:55:38 nit: rename to browser_context.
Xi Han 2014/09/18 16:24:01 Done.
1199 ClearPendingCallbacks(request); 1183 ClearPendingCallbacks(request);
1200 1184
1201 signaled_requests_.erase(request->identifier()); 1185 signaled_requests_.erase(request->identifier());
1202 1186
1203 request_time_tracker_->LogRequestEndTime(request->identifier(), 1187 request_time_tracker_->LogRequestEndTime(request->identifier(),
1204 base::Time::Now()); 1188 base::Time::Now());
1205 } 1189 }
1206 1190
1207 void ExtensionWebRequestEventRouter::ClearPendingCallbacks( 1191 void ExtensionWebRequestEventRouter::ClearPendingCallbacks(
1208 net::URLRequest* request) { 1192 net::URLRequest* request) {
1209 blocked_requests_.erase(request->identifier()); 1193 blocked_requests_.erase(request->identifier());
1210 } 1194 }
1211 1195
1212 bool ExtensionWebRequestEventRouter::DispatchEvent( 1196 bool ExtensionWebRequestEventRouter::DispatchEvent(
1213 void* profile_id, 1197 void* profile_id,
Fady Samuel 2014/09/12 21:55:40 nit: rename to browser_context
Xi Han 2014/09/18 16:24:00 Done.
1214 net::URLRequest* request, 1198 net::URLRequest* request,
1215 const std::vector<const EventListener*>& listeners, 1199 const std::vector<const EventListener*>& listeners,
1216 const base::ListValue& args) { 1200 const base::ListValue& args) {
1217 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args) 1201 // TODO(mpcomplete): Consider consolidating common (extension_id,json_args)
1218 // pairs into a single message sent to a list of sub_event_names. 1202 // pairs into a single message sent to a list of sub_event_names.
1219 int num_handlers_blocking = 0; 1203 int num_handlers_blocking = 0;
1220 for (std::vector<const EventListener*>::const_iterator it = listeners.begin(); 1204 for (std::vector<const EventListener*>::const_iterator it = listeners.begin();
1221 it != listeners.end(); ++it) { 1205 it != listeners.end(); ++it) {
1222 // Filter out the optional keys that this listener didn't request. 1206 // Filter out the optional keys that this listener didn't request.
1223 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy()); 1207 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 num_handlers_blocking; 1243 num_handlers_blocking;
1260 blocked_requests_[request->identifier()].blocking_time = base::Time::Now(); 1244 blocked_requests_[request->identifier()].blocking_time = base::Time::Now();
1261 1245
1262 return true; 1246 return true;
1263 } 1247 }
1264 1248
1265 return false; 1249 return false;
1266 } 1250 }
1267 1251
1268 void ExtensionWebRequestEventRouter::OnEventHandled( 1252 void ExtensionWebRequestEventRouter::OnEventHandled(
1269 void* profile, 1253 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context
Xi Han 2014/09/18 16:23:59 Done.
1270 const std::string& extension_id, 1254 const std::string& extension_id,
1271 const std::string& event_name, 1255 const std::string& event_name,
1272 const std::string& sub_event_name, 1256 const std::string& sub_event_name,
1273 uint64 request_id, 1257 uint64 request_id,
1274 EventResponse* response) { 1258 EventResponse* response) {
1275 EventListener listener; 1259 EventListener listener;
1276 listener.extension_id = extension_id; 1260 listener.extension_id = extension_id;
1277 listener.sub_event_name = sub_event_name; 1261 listener.sub_event_name = sub_event_name;
1278 1262
1279 // The listener may have been removed (e.g. due to the process going away) 1263 // The listener may have been removed (e.g. due to the process going away)
1280 // before we got here. 1264 // before we got here.
1281 std::set<EventListener>::iterator found = 1265 std::set<EventListener>::iterator found =
1282 listeners_[profile][event_name].find(listener); 1266 listeners_[profile][event_name].find(listener);
1283 if (found != listeners_[profile][event_name].end()) 1267 if (found != listeners_[profile][event_name].end())
1284 found->blocked_requests.erase(request_id); 1268 found->blocked_requests.erase(request_id);
1285 1269
1286 DecrementBlockCount(profile, extension_id, event_name, request_id, response); 1270 DecrementBlockCount(profile, extension_id, event_name, request_id, response);
1287 } 1271 }
1288 1272
1289 bool ExtensionWebRequestEventRouter::AddEventListener( 1273 bool ExtensionWebRequestEventRouter::AddEventListener(
1290 void* profile, 1274 void* profile,
Fady Samuel 2014/09/12 21:55:38 nit: rename to browser_context.
Xi Han 2014/09/18 16:24:01 Done.
1291 const std::string& extension_id, 1275 const std::string& extension_id,
1292 const std::string& extension_name, 1276 const std::string& extension_name,
1293 const std::string& event_name, 1277 const std::string& event_name,
1294 const std::string& sub_event_name, 1278 const std::string& sub_event_name,
1295 const RequestFilter& filter, 1279 const RequestFilter& filter,
1296 int extra_info_spec, 1280 int extra_info_spec,
1297 int embedder_process_id, 1281 int embedder_process_id,
1298 int webview_instance_id, 1282 int webview_instance_id,
1299 base::WeakPtr<IPC::Sender> ipc_sender) { 1283 base::WeakPtr<IPC::Sender> ipc_sender) {
1300 if (!IsWebRequestEvent(event_name)) 1284 if (!IsWebRequestEvent(event_name))
(...skipping 15 matching lines...) Expand all
1316 1300
1317 if (listeners_[profile][event_name].count(listener) != 0u) { 1301 if (listeners_[profile][event_name].count(listener) != 0u) {
1318 // This is likely an abuse of the API by a malicious extension. 1302 // This is likely an abuse of the API by a malicious extension.
1319 return false; 1303 return false;
1320 } 1304 }
1321 listeners_[profile][event_name].insert(listener); 1305 listeners_[profile][event_name].insert(listener);
1322 return true; 1306 return true;
1323 } 1307 }
1324 1308
1325 void ExtensionWebRequestEventRouter::RemoveEventListener( 1309 void ExtensionWebRequestEventRouter::RemoveEventListener(
1326 void* profile, 1310 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: Rename to browser_context.
Xi Han 2014/09/18 16:23:59 Done.
1327 const std::string& extension_id, 1311 const std::string& extension_id,
1328 const std::string& sub_event_name) { 1312 const std::string& sub_event_name) {
1329 std::string event_name = 1313 std::string event_name =
1330 extensions::EventRouter::GetBaseEventName(sub_event_name); 1314 extensions::EventRouter::GetBaseEventName(sub_event_name);
1331 DCHECK(IsWebRequestEvent(event_name)); 1315 DCHECK(IsWebRequestEvent(event_name));
1332 1316
1333 EventListener listener; 1317 EventListener listener;
1334 listener.extension_id = extension_id; 1318 listener.extension_id = extension_id;
1335 listener.sub_event_name = sub_event_name; 1319 listener.sub_event_name = sub_event_name;
1336 1320
(...skipping 13 matching lines...) Expand all
1350 it != found->blocked_requests.end(); ++it) { 1334 it != found->blocked_requests.end(); ++it) {
1351 DecrementBlockCount(profile, extension_id, event_name, *it, NULL); 1335 DecrementBlockCount(profile, extension_id, event_name, *it, NULL);
1352 } 1336 }
1353 1337
1354 listeners_[profile][event_name].erase(listener); 1338 listeners_[profile][event_name].erase(listener);
1355 1339
1356 helpers::ClearCacheOnNavigation(); 1340 helpers::ClearCacheOnNavigation();
1357 } 1341 }
1358 1342
1359 void ExtensionWebRequestEventRouter::RemoveWebViewEventListeners( 1343 void ExtensionWebRequestEventRouter::RemoveWebViewEventListeners(
1360 void* profile, 1344 void* profile,
Fady Samuel 2014/09/12 21:55:38 nit: rename to browser_context.
Xi Han 2014/09/18 16:24:01 Done.
1361 const std::string& extension_id, 1345 const std::string& extension_id,
1362 int embedder_process_id, 1346 int embedder_process_id,
1363 int webview_instance_id) { 1347 int webview_instance_id) {
1364 // Iterate over all listeners of all WebRequest events to delete 1348 // Iterate over all listeners of all WebRequest events to delete
1365 // any listeners that belong to the provided <webview>. 1349 // any listeners that belong to the provided <webview>.
1366 ListenerMapForProfile& map_for_profile = listeners_[profile]; 1350 ListenerMapForProfile& map_for_profile = listeners_[profile];
1367 for (ListenerMapForProfile::iterator event_iter = map_for_profile.begin(); 1351 for (ListenerMapForProfile::iterator event_iter = map_for_profile.begin();
1368 event_iter != map_for_profile.end(); ++event_iter) { 1352 event_iter != map_for_profile.end(); ++event_iter) {
1369 std::vector<EventListener> listeners_to_delete; 1353 std::vector<EventListener> listeners_to_delete;
1370 std::set<EventListener>& listeners = event_iter->second; 1354 std::set<EventListener>& listeners = event_iter->second;
(...skipping 11 matching lines...) Expand all
1382 FROM_HERE, 1366 FROM_HERE,
1383 base::Bind(&RemoveEventListenerOnUI, 1367 base::Bind(&RemoveEventListenerOnUI,
1384 profile, 1368 profile,
1385 listener.sub_event_name, 1369 listener.sub_event_name,
1386 embedder_process_id, 1370 embedder_process_id,
1387 extension_id)); 1371 extension_id));
1388 } 1372 }
1389 } 1373 }
1390 } 1374 }
1391 1375
1392 void ExtensionWebRequestEventRouter::OnOTRProfileCreated( 1376 void ExtensionWebRequestEventRouter::OnOTRProfileCreated(
Fady Samuel 2014/09/12 21:55:39 nit: replace instances of "Profile" with "BrowserC
Xi Han 2014/09/18 16:24:01 Done.
1393 void* original_profile, void* otr_profile) { 1377 void* original_profile, void* otr_profile) {
1394 cross_profile_map_[original_profile] = std::make_pair(false, otr_profile); 1378 cross_profile_map_[original_profile] = std::make_pair(false, otr_profile);
1395 cross_profile_map_[otr_profile] = std::make_pair(true, original_profile); 1379 cross_profile_map_[otr_profile] = std::make_pair(true, original_profile);
1396 } 1380 }
1397 1381
1398 void ExtensionWebRequestEventRouter::OnOTRProfileDestroyed( 1382 void ExtensionWebRequestEventRouter::OnOTRProfileDestroyed(
Fady Samuel 2014/09/12 21:55:38 nit: Replace instances of "Profile" with "BrowserC
Xi Han 2014/09/18 16:23:59 Done.
1399 void* original_profile, void* otr_profile) { 1383 void* original_profile, void* otr_profile) {
1400 cross_profile_map_.erase(otr_profile); 1384 cross_profile_map_.erase(otr_profile);
1401 cross_profile_map_.erase(original_profile); 1385 cross_profile_map_.erase(original_profile);
1402 } 1386 }
1403 1387
1404 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( 1388 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad(
1405 const base::Closure& callback) { 1389 const base::Closure& callback) {
1406 callbacks_for_page_load_.push_back(callback); 1390 callbacks_for_page_load_.push_back(callback);
1407 } 1391 }
1408 1392
(...skipping 19 matching lines...) Expand all
1428 1412
1429 void ExtensionWebRequestEventRouter::NotifyPageLoad() { 1413 void ExtensionWebRequestEventRouter::NotifyPageLoad() {
1430 for (CallbacksForPageLoad::const_iterator i = 1414 for (CallbacksForPageLoad::const_iterator i =
1431 callbacks_for_page_load_.begin(); 1415 callbacks_for_page_load_.begin();
1432 i != callbacks_for_page_load_.end(); ++i) { 1416 i != callbacks_for_page_load_.end(); ++i) {
1433 i->Run(); 1417 i->Run();
1434 } 1418 }
1435 callbacks_for_page_load_.clear(); 1419 callbacks_for_page_load_.clear();
1436 } 1420 }
1437 1421
1438 void* ExtensionWebRequestEventRouter::GetCrossProfile(void* profile) const { 1422 void* ExtensionWebRequestEventRouter::GetCrossProfile(void* profile) const {
Fady Samuel 2014/09/12 21:55:38 nit: rename "Profile" to "BrowserContext".
Xi Han 2014/09/18 16:24:01 Done.
1439 CrossProfileMap::const_iterator cross_profile = 1423 CrossProfileMap::const_iterator cross_profile =
1440 cross_profile_map_.find(profile); 1424 cross_profile_map_.find(profile);
1441 if (cross_profile == cross_profile_map_.end()) 1425 if (cross_profile == cross_profile_map_.end())
1442 return NULL; 1426 return NULL;
1443 return cross_profile->second.second; 1427 return cross_profile->second.second;
1444 } 1428 }
1445 1429
1446 bool ExtensionWebRequestEventRouter::IsIncognitoProfile(void* profile) const { 1430 bool ExtensionWebRequestEventRouter::IsIncognitoProfile(void* profile) const {
Fady Samuel 2014/09/12 21:55:39 nit: profile to browser_context
Xi Han 2014/09/18 16:23:59 Done.
1447 CrossProfileMap::const_iterator cross_profile = 1431 CrossProfileMap::const_iterator cross_profile =
1448 cross_profile_map_.find(profile); 1432 cross_profile_map_.find(profile);
1449 if (cross_profile == cross_profile_map_.end()) 1433 if (cross_profile == cross_profile_map_.end())
1450 return false; 1434 return false;
1451 return cross_profile->second.first; 1435 return cross_profile->second.first;
1452 } 1436 }
1453 1437
1454 bool ExtensionWebRequestEventRouter::WasSignaled( 1438 bool ExtensionWebRequestEventRouter::WasSignaled(
1455 const net::URLRequest& request) const { 1439 const net::URLRequest& request) const {
1456 SignaledRequestMap::const_iterator flag = 1440 SignaledRequestMap::const_iterator flag =
1457 signaled_requests_.find(request.identifier()); 1441 signaled_requests_.find(request.identifier());
1458 return (flag != signaled_requests_.end()) && (flag->second != 0); 1442 return (flag != signaled_requests_.end()) && (flag->second != 0);
1459 } 1443 }
1460 1444
1461 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( 1445 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl(
1462 void* profile, 1446 void* profile,
Fady Samuel 2014/09/12 21:55:40 nit: rename profile to browser_context.
Xi Han 2014/09/18 16:24:01 Done.
1463 InfoMap* extension_info_map, 1447 InfoMap* extension_info_map,
1464 bool crosses_incognito, 1448 bool crosses_incognito,
1465 const std::string& event_name, 1449 const std::string& event_name,
1466 const GURL& url, 1450 const GURL& url,
1467 int tab_id, 1451 int tab_id,
1468 int window_id, 1452 int window_id,
1469 int render_process_host_id, 1453 int render_process_host_id,
1470 int routing_id, 1454 int routing_id,
1471 ResourceType resource_type, 1455 ResourceType resource_type,
1472 bool is_async_request, 1456 bool is_async_request,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 if (blocking_listener && synchronous_xhr_from_extension) 1516 if (blocking_listener && synchronous_xhr_from_extension)
1533 continue; 1517 continue;
1534 1518
1535 matching_listeners->push_back(&(*it)); 1519 matching_listeners->push_back(&(*it));
1536 *extra_info_spec |= it->extra_info_spec; 1520 *extra_info_spec |= it->extra_info_spec;
1537 } 1521 }
1538 } 1522 }
1539 1523
1540 std::vector<const ExtensionWebRequestEventRouter::EventListener*> 1524 std::vector<const ExtensionWebRequestEventRouter::EventListener*>
1541 ExtensionWebRequestEventRouter::GetMatchingListeners( 1525 ExtensionWebRequestEventRouter::GetMatchingListeners(
1542 void* profile, 1526 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename profile to browser_context.
Xi Han 2014/09/18 16:24:00 Done.
1543 InfoMap* extension_info_map, 1527 InfoMap* extension_info_map,
1544 const std::string& event_name, 1528 const std::string& event_name,
1545 net::URLRequest* request, 1529 net::URLRequest* request,
1546 int* extra_info_spec) { 1530 int* extra_info_spec) {
1547 // TODO(mpcomplete): handle profile == NULL (should collect all listeners). 1531 // TODO(mpcomplete): handle profile == NULL (should collect all listeners).
1548 *extra_info_spec = 0; 1532 *extra_info_spec = 0;
1549 1533
1550 bool is_main_frame = false; 1534 bool is_main_frame = false;
1551 int frame_id = -1; 1535 int frame_id = -1;
1552 bool parent_is_main_frame = false; 1536 bool parent_is_main_frame = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 return helpers::CalculateOnAuthRequiredDelta( 1609 return helpers::CalculateOnAuthRequiredDelta(
1626 response->extension_id, response->extension_install_time, 1610 response->extension_id, response->extension_install_time,
1627 response->cancel, &response->auth_credentials); 1611 response->cancel, &response->auth_credentials);
1628 default: 1612 default:
1629 NOTREACHED(); 1613 NOTREACHED();
1630 break; 1614 break;
1631 } 1615 }
1632 return NULL; 1616 return NULL;
1633 } 1617 }
1634 1618
1635 base::Value* SerializeResponseHeaders(const helpers::ResponseHeaders& headers) {
1636 scoped_ptr<base::ListValue> serialized_headers(new base::ListValue());
1637 for (helpers::ResponseHeaders::const_iterator i = headers.begin();
1638 i != headers.end(); ++i) {
1639 serialized_headers->Append(ToHeaderDictionary(i->first, i->second));
1640 }
1641 return serialized_headers.release();
1642 }
1643
1644 // Convert a RequestCookieModifications/ResponseCookieModifications object to a
1645 // base::ListValue which summarizes the changes made. This is templated since
1646 // the two types (request/response) are different but contain essentially the
1647 // same fields.
1648 template<typename CookieType>
1649 base::ListValue* SummarizeCookieModifications(
1650 const std::vector<linked_ptr<CookieType> >& modifications) {
1651 scoped_ptr<base::ListValue> cookie_modifications(new base::ListValue());
1652 for (typename std::vector<linked_ptr<CookieType> >::const_iterator i =
1653 modifications.begin();
1654 i != modifications.end(); ++i) {
1655 scoped_ptr<base::DictionaryValue> summary(new base::DictionaryValue());
1656 const CookieType& mod = *i->get();
1657 switch (mod.type) {
1658 case helpers::ADD:
1659 summary->SetString(activitylog::kCookieModificationTypeKey,
1660 activitylog::kCookieModificationAdd);
1661 break;
1662 case helpers::EDIT:
1663 summary->SetString(activitylog::kCookieModificationTypeKey,
1664 activitylog::kCookieModificationEdit);
1665 break;
1666 case helpers::REMOVE:
1667 summary->SetString(activitylog::kCookieModificationTypeKey,
1668 activitylog::kCookieModificationRemove);
1669 break;
1670 }
1671 if (mod.filter) {
1672 if (mod.filter->name)
1673 summary->SetString(activitylog::kCookieFilterNameKey,
1674 *mod.modification->name);
1675 if (mod.filter->domain)
1676 summary->SetString(activitylog::kCookieFilterDomainKey,
1677 *mod.modification->name);
1678 }
1679 if (mod.modification) {
1680 if (mod.modification->name)
1681 summary->SetString(activitylog::kCookieModDomainKey,
1682 *mod.modification->name);
1683 if (mod.modification->domain)
1684 summary->SetString(activitylog::kCookieModDomainKey,
1685 *mod.modification->name);
1686 }
1687 cookie_modifications->Append(summary.release());
1688 }
1689 return cookie_modifications.release();
1690 }
1691
1692 // Converts an EventResponseDelta object to a dictionary value suitable for the
1693 // activity log.
1694 scoped_ptr<base::DictionaryValue> SummarizeResponseDelta(
1695 const std::string& event_name,
1696 const helpers::EventResponseDelta& delta) {
1697 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue());
1698 if (delta.cancel) {
1699 details->SetBoolean(activitylog::kCancelKey, true);
1700 }
1701 if (!delta.new_url.is_empty()) {
1702 details->SetString(activitylog::kNewUrlKey, delta.new_url.spec());
1703 }
1704
1705 scoped_ptr<base::ListValue> modified_headers(new base::ListValue());
1706 net::HttpRequestHeaders::Iterator iter(delta.modified_request_headers);
1707 while (iter.GetNext()) {
1708 modified_headers->Append(ToHeaderDictionary(iter.name(), iter.value()));
1709 }
1710 if (!modified_headers->empty()) {
1711 details->Set(activitylog::kModifiedRequestHeadersKey,
1712 modified_headers.release());
1713 }
1714
1715 scoped_ptr<base::ListValue> deleted_headers(new base::ListValue());
1716 deleted_headers->AppendStrings(delta.deleted_request_headers);
1717 if (!deleted_headers->empty()) {
1718 details->Set(activitylog::kDeletedRequestHeadersKey,
1719 deleted_headers.release());
1720 }
1721
1722 if (!delta.added_response_headers.empty()) {
1723 details->Set(activitylog::kAddedRequestHeadersKey,
1724 SerializeResponseHeaders(delta.added_response_headers));
1725 }
1726 if (!delta.deleted_response_headers.empty()) {
1727 details->Set(activitylog::kDeletedResponseHeadersKey,
1728 SerializeResponseHeaders(delta.deleted_response_headers));
1729 }
1730 if (delta.auth_credentials) {
1731 details->SetString(activitylog::kAuthCredentialsKey,
1732 base::UTF16ToUTF8(
1733 delta.auth_credentials->username()) + ":*");
1734 }
1735
1736 if (!delta.response_cookie_modifications.empty()) {
1737 details->Set(
1738 activitylog::kResponseCookieModificationsKey,
1739 SummarizeCookieModifications(delta.response_cookie_modifications));
1740 }
1741
1742 return details.Pass();
1743 }
1744
1745 void LogExtensionActivity(void* profile_id,
1746 bool is_incognito,
1747 const std::string& extension_id,
1748 const GURL& url,
1749 const std::string& api_call,
1750 scoped_ptr<base::DictionaryValue> details) {
1751 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
1752 BrowserThread::PostTask(BrowserThread::UI,
1753 FROM_HERE,
1754 base::Bind(&LogExtensionActivity,
1755 profile_id,
1756 is_incognito,
1757 extension_id,
1758 url,
1759 api_call,
1760 base::Passed(&details)));
1761 } else {
1762 Profile* profile = static_cast<Profile*>(profile_id);
1763 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
1764 return;
1765 scoped_refptr<extensions::Action> action =
1766 new extensions::Action(extension_id,
1767 base::Time::Now(),
1768 extensions::Action::ACTION_WEB_REQUEST,
1769 api_call);
1770 action->set_page_url(url);
1771 action->set_page_incognito(is_incognito);
1772 action->mutable_other()->Set(activity_log_constants::kActionWebRequest,
1773 details.release());
1774 extensions::ActivityLog::GetInstance(profile)->LogAction(action);
1775 }
1776 }
1777
1778 } // namespace 1619 } // namespace
1779 1620
1780 void ExtensionWebRequestEventRouter::DecrementBlockCount( 1621 void ExtensionWebRequestEventRouter::DecrementBlockCount(
1781 void* profile, 1622 void* profile,
Fady Samuel 2014/09/12 21:55:39 nit: rename to browser_context.
Xi Han 2014/09/18 16:24:00 Done.
1782 const std::string& extension_id, 1623 const std::string& extension_id,
1783 const std::string& event_name, 1624 const std::string& event_name,
1784 uint64 request_id, 1625 uint64 request_id,
1785 EventResponse* response) { 1626 EventResponse* response) {
1786 scoped_ptr<EventResponse> response_scoped(response); 1627 scoped_ptr<EventResponse> response_scoped(response);
1787 1628
1788 // It's possible that this request was deleted, or cancelled by a previous 1629 // It's possible that this request was deleted, or cancelled by a previous
1789 // event handler. If so, ignore this response. 1630 // event handler. If so, ignore this response.
1790 if (blocked_requests_.find(request_id) == blocked_requests_.end()) 1631 if (blocked_requests_.find(request_id) == blocked_requests_.end())
1791 return; 1632 return;
1792 1633
1793 BlockedRequest& blocked_request = blocked_requests_[request_id]; 1634 BlockedRequest& blocked_request = blocked_requests_[request_id];
1794 int num_handlers_blocking = --blocked_request.num_handlers_blocking; 1635 int num_handlers_blocking = --blocked_request.num_handlers_blocking;
1795 CHECK_GE(num_handlers_blocking, 0); 1636 CHECK_GE(num_handlers_blocking, 0);
1796 1637
1797 if (response) { 1638 if (response) {
1798 helpers::EventResponseDelta* delta = 1639 helpers::EventResponseDelta* delta =
1799 CalculateDelta(&blocked_request, response); 1640 CalculateDelta(&blocked_request, response);
1800 1641
1801 LogExtensionActivity(profile, 1642 if(web_request_event_router_delegate_) {
1802 blocked_request.is_incognito, 1643 web_request_event_router_delegate_->LogExtensionActivity(
1803 extension_id, 1644 profile,
1804 blocked_request.request->url(), 1645 blocked_request.is_incognito,
1805 event_name, 1646 extension_id,
1806 SummarizeResponseDelta(event_name, *delta)); 1647 blocked_request.request->url(),
1648 event_name,
1649 *delta);
1650 }
1807 1651
1808 blocked_request.response_deltas.push_back( 1652 blocked_request.response_deltas.push_back(
1809 linked_ptr<helpers::EventResponseDelta>(delta)); 1653 linked_ptr<helpers::EventResponseDelta>(delta));
1810 } 1654 }
1811 1655
1812 base::TimeDelta block_time = 1656 base::TimeDelta block_time =
1813 base::Time::Now() - blocked_request.blocking_time; 1657 base::Time::Now() - blocked_request.blocking_time;
1814 if (!extension_id.empty()) { 1658 if (!extension_id.empty()) {
1815 request_time_tracker_->IncrementExtensionBlockTime( 1659 request_time_tracker_->IncrementExtensionBlockTime(
1816 extension_id, request_id, block_time); 1660 extension_id, request_id, block_time);
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 // Continue gracefully. 2312 // Continue gracefully.
2469 RunSync(); 2313 RunSync();
2470 } 2314 }
2471 2315
2472 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { 2316 bool WebRequestHandlerBehaviorChangedFunction::RunSync() {
2473 helpers::ClearCacheOnNavigation(); 2317 helpers::ClearCacheOnNavigation();
2474 return true; 2318 return true;
2475 } 2319 }
2476 2320
2477 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) { 2321 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) {
2478 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 2322 content::BrowserContext* browser_context = host->GetBrowserContext();
2479 if (!profile) 2323 if (!browser_context)
2480 return; 2324 return;
2481 2325
2482 bool webrequest_used = false; 2326 bool webrequest_used = false;
2483 const extensions::ExtensionSet& extensions = 2327 const extensions::ExtensionSet& extensions =
2484 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); 2328 extensions::ExtensionRegistry::Get(browser_context)->enabled_extensions();
2485 extensions::RuntimeData* runtime_data = 2329 extensions::RuntimeData* runtime_data =
2486 extensions::ExtensionSystem::Get(profile)->runtime_data(); 2330 extensions::ExtensionSystem::Get(browser_context)->runtime_data();
2487 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); 2331 for (extensions::ExtensionSet::const_iterator it = extensions.begin();
2488 !webrequest_used && it != extensions.end(); 2332 !webrequest_used && it != extensions.end();
2489 ++it) { 2333 ++it) {
2490 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); 2334 webrequest_used |= runtime_data->HasUsedWebRequest(it->get());
2491 } 2335 }
2492 2336
2493 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); 2337 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used));
2494 } 2338 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698