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

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

Issue 1236493004: Final batch adding real histogram values for extension events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android compile Created 5 years, 5 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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "ui/base/l10n/l10n_util.h" 62 #include "ui/base/l10n/l10n_util.h"
63 #include "url/gurl.h" 63 #include "url/gurl.h"
64 64
65 using base::DictionaryValue; 65 using base::DictionaryValue;
66 using base::ListValue; 66 using base::ListValue;
67 using base::StringValue; 67 using base::StringValue;
68 using content::BrowserMessageFilter; 68 using content::BrowserMessageFilter;
69 using content::BrowserThread; 69 using content::BrowserThread;
70 using content::ResourceRequestInfo; 70 using content::ResourceRequestInfo;
71 using content::ResourceType; 71 using content::ResourceType;
72 using extensions::ErrorUtils;
73 using extensions::Extension;
74 using extensions::InfoMap;
75 using extensions::Feature;
76 using extensions::RulesRegistryService;
77 using extensions::Warning;
78 using extensions::WarningService;
79 using extensions::WarningSet;
80 72
81 namespace activitylog = activity_log_web_request_constants; 73 namespace activity_log = activity_log_web_request_constants;
82 namespace helpers = extension_web_request_api_helpers; 74 namespace helpers = extension_web_request_api_helpers;
83 namespace keys = extension_web_request_api_constants; 75 namespace keys = extension_web_request_api_constants;
84 namespace web_request = extensions::core_api::web_request; 76
85 namespace declarative_keys = extensions::declarative_webrequest_constants; 77 namespace extensions {
78
79 namespace declarative_keys = declarative_webrequest_constants;
80 namespace web_request = core_api::web_request;
86 81
87 namespace { 82 namespace {
88 83
89 const char kWebRequestEventPrefix[] = "webRequest."; 84 const char kWebRequestEventPrefix[] = "webRequest.";
90 85
91 // List of all the webRequest events. 86 // List of all the webRequest events.
92 const char* const kWebRequestEvents[] = { 87 const char* const kWebRequestEvents[] = {
93 keys::kOnBeforeRedirectEvent, 88 keys::kOnBeforeRedirectEvent,
94 web_request::OnBeforeRequest::kEventName, 89 web_request::OnBeforeRequest::kEventName,
95 keys::kOnBeforeSendHeadersEvent, 90 keys::kOnBeforeSendHeadersEvent,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return; 169 return;
175 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 170 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
176 *render_process_host_id = info->GetChildID(); 171 *render_process_host_id = info->GetChildID();
177 *routing_id = info->GetRouteID(); 172 *routing_id = info->GetRouteID();
178 } 173 }
179 174
180 // Given a |request|, this function determines whether it originated from 175 // Given a |request|, this function determines whether it originated from
181 // a <webview> guest process or not. If it is from a <webview> guest process, 176 // a <webview> guest process or not. If it is from a <webview> guest process,
182 // then |web_view_info| is returned with information about the instance ID 177 // then |web_view_info| is returned with information about the instance ID
183 // that uniquely identifies the <webview> and its embedder. 178 // that uniquely identifies the <webview> and its embedder.
184 bool GetWebViewInfo( 179 bool GetWebViewInfo(net::URLRequest* request,
185 net::URLRequest* request, 180 WebViewRendererState::WebViewInfo* web_view_info) {
186 extensions::WebViewRendererState::WebViewInfo* web_view_info) {
187 int render_process_host_id = -1; 181 int render_process_host_id = -1;
188 int routing_id = -1; 182 int routing_id = -1;
189 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); 183 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id);
190 return extensions::WebViewRendererState::GetInstance()-> 184 return WebViewRendererState::GetInstance()->GetInfo(
191 GetInfo(render_process_host_id, routing_id, web_view_info); 185 render_process_host_id, routing_id, web_view_info);
192 } 186 }
193 187
194 void ExtractRequestInfoDetails(net::URLRequest* request, 188 void ExtractRequestInfoDetails(net::URLRequest* request,
195 bool* is_main_frame, 189 bool* is_main_frame,
196 int* frame_id, 190 int* frame_id,
197 bool* parent_is_main_frame, 191 bool* parent_is_main_frame,
198 int* parent_frame_id, 192 int* parent_frame_id,
199 int* render_process_host_id, 193 int* render_process_host_id,
200 int* routing_id, 194 int* routing_id,
201 ResourceType* resource_type) { 195 ResourceType* resource_type) {
(...skipping 20 matching lines...) Expand all
222 base::DictionaryValue* out) { 216 base::DictionaryValue* out) {
223 const net::UploadDataStream* upload_data = request->get_upload(); 217 const net::UploadDataStream* upload_data = request->get_upload();
224 if (!upload_data || 218 if (!upload_data ||
225 (request->method() != "POST" && request->method() != "PUT")) 219 (request->method() != "POST" && request->method() != "PUT"))
226 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . 220 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" .
227 221
228 base::DictionaryValue* request_body = new base::DictionaryValue(); 222 base::DictionaryValue* request_body = new base::DictionaryValue();
229 out->Set(keys::kRequestBodyKey, request_body); 223 out->Set(keys::kRequestBodyKey, request_body);
230 224
231 // Get the data presenters, ordered by how specific they are. 225 // Get the data presenters, ordered by how specific they are.
232 extensions::ParsedDataPresenter parsed_data_presenter(*request); 226 ParsedDataPresenter parsed_data_presenter(*request);
233 extensions::RawDataPresenter raw_data_presenter; 227 RawDataPresenter raw_data_presenter;
234 extensions::UploadDataPresenter* const presenters[] = { 228 UploadDataPresenter* const presenters[] = {
235 &parsed_data_presenter, // 1: any parseable forms? (Specific to forms.) 229 &parsed_data_presenter, // 1: any parseable forms? (Specific to forms.)
236 &raw_data_presenter // 2: any data at all? (Non-specific.) 230 &raw_data_presenter // 2: any data at all? (Non-specific.)
237 }; 231 };
238 // Keys for the results of the corresponding presenters. 232 // Keys for the results of the corresponding presenters.
239 static const char* const kKeys[] = { 233 static const char* const kKeys[] = {
240 keys::kRequestBodyFormDataKey, 234 keys::kRequestBodyFormDataKey,
241 keys::kRequestBodyRawKey 235 keys::kRequestBodyRawKey
242 }; 236 };
243 237
244 const ScopedVector<net::UploadElementReader>* readers = 238 const ScopedVector<net::UploadElementReader>* readers =
245 upload_data->GetElementReaders(); 239 upload_data->GetElementReaders();
246 bool some_succeeded = false; 240 bool some_succeeded = false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // a <webview> guest renderer. 317 // a <webview> guest renderer.
324 // |extension_id| identifies the extension that sends and receives the event. 318 // |extension_id| identifies the extension that sends and receives the event.
325 // |is_web_view_guest| indicates whether the action is for a <webview>. 319 // |is_web_view_guest| indicates whether the action is for a <webview>.
326 // |web_view_info| is a struct containing information about the <webview> 320 // |web_view_info| is a struct containing information about the <webview>
327 // embedder. 321 // embedder.
328 // |event_argument| is passed to the event listener. 322 // |event_argument| is passed to the event listener.
329 void SendOnMessageEventOnUI( 323 void SendOnMessageEventOnUI(
330 void* browser_context_id, 324 void* browser_context_id,
331 const std::string& extension_id, 325 const std::string& extension_id,
332 bool is_web_view_guest, 326 bool is_web_view_guest,
333 const extensions::WebViewRendererState::WebViewInfo& web_view_info, 327 const WebViewRendererState::WebViewInfo& web_view_info,
334 scoped_ptr<base::DictionaryValue> event_argument) { 328 scoped_ptr<base::DictionaryValue> event_argument) {
335 DCHECK_CURRENTLY_ON(BrowserThread::UI); 329 DCHECK_CURRENTLY_ON(BrowserThread::UI);
336 330
337 content::BrowserContext* browser_context = 331 content::BrowserContext* browser_context =
338 reinterpret_cast<content::BrowserContext*>(browser_context_id); 332 reinterpret_cast<content::BrowserContext*>(browser_context_id);
339 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext( 333 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
340 browser_context))
341 return; 334 return;
342 335
343 scoped_ptr<base::ListValue> event_args(new base::ListValue); 336 scoped_ptr<base::ListValue> event_args(new base::ListValue);
344 event_args->Append(event_argument.release()); 337 event_args->Append(event_argument.release());
345 338
346 extensions::EventRouter* event_router = 339 EventRouter* event_router = EventRouter::Get(browser_context);
347 extensions::EventRouter::Get(browser_context);
348 340
349 extensions::EventFilteringInfo event_filtering_info; 341 EventFilteringInfo event_filtering_info;
350 342
343 events::HistogramValue histogram_value = events::UNKNOWN;
351 std::string event_name; 344 std::string event_name;
352 // The instance ID uniquely identifies a <webview> instance within an embedder 345 // The instance ID uniquely identifies a <webview> instance within an embedder
353 // 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
354 // <webview> will fire. 347 // <webview> will fire.
355 if (is_web_view_guest) { 348 if (is_web_view_guest) {
356 event_filtering_info.SetInstanceID(web_view_info.instance_id); 349 event_filtering_info.SetInstanceID(web_view_info.instance_id);
350 histogram_value = events::WEB_VIEW_INTERNAL_ON_MESSAGE;
357 event_name = webview::kEventMessage; 351 event_name = webview::kEventMessage;
358 } else { 352 } else {
353 histogram_value = events::DECLARATIVE_WEB_REQUEST_ON_MESSAGE;
359 event_name = declarative_keys::kOnMessage; 354 event_name = declarative_keys::kOnMessage;
360 } 355 }
361 356
362 scoped_ptr<extensions::Event> event(new extensions::Event( 357 scoped_ptr<Event> event(new Event(
363 extensions::events::UNKNOWN, event_name, event_args.Pass(), 358 histogram_value, event_name, event_args.Pass(), browser_context, GURL(),
364 browser_context, GURL(), extensions::EventRouter::USER_GESTURE_UNKNOWN, 359 EventRouter::USER_GESTURE_UNKNOWN, event_filtering_info));
365 event_filtering_info));
366 event_router->DispatchEventToExtension(extension_id, event.Pass()); 360 event_router->DispatchEventToExtension(extension_id, event.Pass());
367 } 361 }
368 362
369 void RemoveEventListenerOnIOThread( 363 void RemoveEventListenerOnIOThread(
370 void* browser_context, 364 void* browser_context,
371 const std::string& extension_id, 365 const std::string& extension_id,
372 const std::string& sub_event_name, 366 const std::string& sub_event_name,
373 int embedder_process_id, 367 int embedder_process_id,
374 int web_view_instance_id) { 368 int web_view_instance_id) {
375 DCHECK_CURRENTLY_ON(BrowserThread::IO); 369 DCHECK_CURRENTLY_ON(BrowserThread::IO);
376 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( 370 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
377 browser_context, extension_id, sub_event_name, 371 browser_context, extension_id, sub_event_name,
378 embedder_process_id, web_view_instance_id); 372 embedder_process_id, web_view_instance_id);
379 } 373 }
380 374
381 } // namespace 375 } // namespace
382 376
383 namespace extensions {
384
385 WebRequestAPI::WebRequestAPI(content::BrowserContext* context) 377 WebRequestAPI::WebRequestAPI(content::BrowserContext* context)
386 : browser_context_(context) { 378 : browser_context_(context) {
387 EventRouter* event_router = EventRouter::Get(browser_context_); 379 EventRouter* event_router = EventRouter::Get(browser_context_);
388 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) { 380 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) {
389 // Observe the webRequest event. 381 // Observe the webRequest event.
390 std::string event_name = kWebRequestEvents[i]; 382 std::string event_name = kWebRequestEvents[i];
391 event_router->RegisterObserver(this, event_name); 383 event_router->RegisterObserver(this, event_name);
392 384
393 // Also observe the corresponding webview event. 385 // Also observe the corresponding webview event.
394 event_name.replace( 386 event_name.replace(
(...skipping 26 matching lines...) Expand all
421 BrowserThread::PostTask(BrowserThread::IO, 413 BrowserThread::PostTask(BrowserThread::IO,
422 FROM_HERE, 414 FROM_HERE,
423 base::Bind(&RemoveEventListenerOnIOThread, 415 base::Bind(&RemoveEventListenerOnIOThread,
424 details.browser_context, 416 details.browser_context,
425 details.extension_id, 417 details.extension_id,
426 details.event_name, 418 details.event_name,
427 0 /* embedder_process_id */, 419 0 /* embedder_process_id */,
428 0 /* web_view_instance_id */)); 420 0 /* web_view_instance_id */));
429 } 421 }
430 422
431 } // namespace extensions
432
433 // Represents a single unique listener to an event, along with whatever filter 423 // Represents a single unique listener to an event, along with whatever filter
434 // parameters and extra_info_spec were specified at the time the listener was 424 // parameters and extra_info_spec were specified at the time the listener was
435 // added. 425 // added.
436 // NOTE(benjhayden) New APIs should not use this sub_event_name trick! It does 426 // NOTE(benjhayden) New APIs should not use this sub_event_name trick! It does
437 // not play well with event pages. See downloads.onDeterminingFilename and 427 // not play well with event pages. See downloads.onDeterminingFilename and
438 // ExtensionDownloadsEventRouter for an alternative approach. 428 // ExtensionDownloadsEventRouter for an alternative approach.
439 struct ExtensionWebRequestEventRouter::EventListener { 429 struct ExtensionWebRequestEventRouter::EventListener {
440 std::string extension_id; 430 std::string extension_id;
441 std::string extension_name; 431 std::string extension_name;
442 std::string sub_event_name; 432 std::string sub_event_name;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // 631 //
642 632
643 // static 633 // static
644 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { 634 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() {
645 return Singleton<ExtensionWebRequestEventRouter>::get(); 635 return Singleton<ExtensionWebRequestEventRouter>::get();
646 } 636 }
647 637
648 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() 638 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
649 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { 639 : request_time_tracker_(new ExtensionWebRequestTimeTracker) {
650 web_request_event_router_delegate_.reset( 640 web_request_event_router_delegate_.reset(
651 extensions::ExtensionsAPIClient::Get()-> 641 ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate());
652 CreateWebRequestEventRouterDelegate());
653 } 642 }
654 643
655 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { 644 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() {
656 } 645 }
657 646
658 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( 647 void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
659 void* browser_context, 648 void* browser_context,
660 int rules_registry_id, 649 int rules_registry_id,
661 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { 650 scoped_refptr<WebRequestRulesRegistry> rules_registry) {
662 RulesRegistryKey key(browser_context, rules_registry_id); 651 RulesRegistryKey key(browser_context, rules_registry_id);
663 if (rules_registry.get()) 652 if (rules_registry.get())
664 rules_registries_[key] = rules_registry; 653 rules_registries_[key] = rules_registry;
665 else 654 else
666 rules_registries_.erase(key); 655 rules_registries_.erase(key);
667 } 656 }
668 657
669 void ExtensionWebRequestEventRouter::ExtractRequestInfo( 658 void ExtensionWebRequestEventRouter::ExtractRequestInfo(
670 net::URLRequest* request, base::DictionaryValue* out) { 659 net::URLRequest* request, base::DictionaryValue* out) {
671 bool is_main_frame = false; 660 bool is_main_frame = false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 base::Time::Now(), 706 base::Time::Now(),
718 request->url(), 707 request->url(),
719 browser_context); 708 browser_context);
720 709
721 // Whether to initialized blocked_requests_. 710 // Whether to initialized blocked_requests_.
722 bool initialize_blocked_requests = false; 711 bool initialize_blocked_requests = false;
723 712
724 initialize_blocked_requests |= 713 initialize_blocked_requests |=
725 ProcessDeclarativeRules(browser_context, extension_info_map, 714 ProcessDeclarativeRules(browser_context, extension_info_map,
726 web_request::OnBeforeRequest::kEventName, request, 715 web_request::OnBeforeRequest::kEventName, request,
727 extensions::ON_BEFORE_REQUEST, NULL); 716 ON_BEFORE_REQUEST, NULL);
728 717
729 int extra_info_spec = 0; 718 int extra_info_spec = 0;
730 std::vector<const EventListener*> listeners = 719 std::vector<const EventListener*> listeners =
731 GetMatchingListeners(browser_context, extension_info_map, 720 GetMatchingListeners(browser_context, extension_info_map,
732 web_request::OnBeforeRequest::kEventName, request, 721 web_request::OnBeforeRequest::kEventName, request,
733 &extra_info_spec); 722 &extra_info_spec);
734 if (!listeners.empty() && 723 if (!listeners.empty() &&
735 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) { 724 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) {
736 base::ListValue args; 725 base::ListValue args;
737 base::DictionaryValue* dict = new base::DictionaryValue(); 726 base::DictionaryValue* dict = new base::DictionaryValue();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 net::URLRequest* request, 760 net::URLRequest* request,
772 const net::CompletionCallback& callback, 761 const net::CompletionCallback& callback,
773 net::HttpRequestHeaders* headers) { 762 net::HttpRequestHeaders* headers) {
774 // We hide events from the system context as well as sensitive requests. 763 // We hide events from the system context as well as sensitive requests.
775 if (!browser_context || 764 if (!browser_context ||
776 WebRequestPermissions::HideRequest(extension_info_map, request)) 765 WebRequestPermissions::HideRequest(extension_info_map, request))
777 return net::OK; 766 return net::OK;
778 767
779 bool initialize_blocked_requests = false; 768 bool initialize_blocked_requests = false;
780 769
781 initialize_blocked_requests |= 770 initialize_blocked_requests |= ProcessDeclarativeRules(
782 ProcessDeclarativeRules(browser_context, extension_info_map, 771 browser_context, extension_info_map, keys::kOnBeforeSendHeadersEvent,
783 keys::kOnBeforeSendHeadersEvent, request, 772 request, ON_BEFORE_SEND_HEADERS, NULL);
784 extensions::ON_BEFORE_SEND_HEADERS, NULL);
785 773
786 int extra_info_spec = 0; 774 int extra_info_spec = 0;
787 std::vector<const EventListener*> listeners = 775 std::vector<const EventListener*> listeners =
788 GetMatchingListeners(browser_context, extension_info_map, 776 GetMatchingListeners(browser_context, extension_info_map,
789 keys::kOnBeforeSendHeadersEvent, request, 777 keys::kOnBeforeSendHeadersEvent, request,
790 &extra_info_spec); 778 &extra_info_spec);
791 if (!listeners.empty() && 779 if (!listeners.empty() &&
792 !GetAndSetSignaled(request->identifier(), kOnBeforeSendHeaders)) { 780 !GetAndSetSignaled(request->identifier(), kOnBeforeSendHeaders)) {
793 base::ListValue args; 781 base::ListValue args;
794 base::DictionaryValue* dict = new base::DictionaryValue(); 782 base::DictionaryValue* dict = new base::DictionaryValue();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 const net::HttpResponseHeaders* original_response_headers, 851 const net::HttpResponseHeaders* original_response_headers,
864 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, 852 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
865 GURL* allowed_unsafe_redirect_url) { 853 GURL* allowed_unsafe_redirect_url) {
866 // We hide events from the system context as well as sensitive requests. 854 // We hide events from the system context as well as sensitive requests.
867 if (!browser_context || 855 if (!browser_context ||
868 WebRequestPermissions::HideRequest(extension_info_map, request)) 856 WebRequestPermissions::HideRequest(extension_info_map, request))
869 return net::OK; 857 return net::OK;
870 858
871 bool initialize_blocked_requests = false; 859 bool initialize_blocked_requests = false;
872 860
873 initialize_blocked_requests |= 861 initialize_blocked_requests |= ProcessDeclarativeRules(
874 ProcessDeclarativeRules(browser_context, extension_info_map, 862 browser_context, extension_info_map, keys::kOnHeadersReceivedEvent,
875 keys::kOnHeadersReceivedEvent, request, 863 request, ON_HEADERS_RECEIVED, original_response_headers);
876 extensions::ON_HEADERS_RECEIVED,
877 original_response_headers);
878 864
879 int extra_info_spec = 0; 865 int extra_info_spec = 0;
880 std::vector<const EventListener*> listeners = 866 std::vector<const EventListener*> listeners =
881 GetMatchingListeners(browser_context, extension_info_map, 867 GetMatchingListeners(browser_context, extension_info_map,
882 keys::kOnHeadersReceivedEvent, request, 868 keys::kOnHeadersReceivedEvent, request,
883 &extra_info_spec); 869 &extra_info_spec);
884 870
885 if (!listeners.empty() && 871 if (!listeners.empty() &&
886 !GetAndSetSignaled(request->identifier(), kOnHeadersReceived)) { 872 !GetAndSetSignaled(request->identifier(), kOnHeadersReceived)) {
887 base::ListValue args; 873 base::ListValue args;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 it != listeners.end(); ++it) { 1189 it != listeners.end(); ++it) {
1204 // Filter out the optional keys that this listener didn't request. 1190 // Filter out the optional keys that this listener didn't request.
1205 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy()); 1191 scoped_ptr<base::ListValue> args_filtered(args.DeepCopy());
1206 base::DictionaryValue* dict = NULL; 1192 base::DictionaryValue* dict = NULL;
1207 CHECK(args_filtered->GetDictionary(0, &dict) && dict); 1193 CHECK(args_filtered->GetDictionary(0, &dict) && dict);
1208 if (!((*it)->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS)) 1194 if (!((*it)->extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS))
1209 dict->Remove(keys::kRequestHeadersKey, NULL); 1195 dict->Remove(keys::kRequestHeadersKey, NULL);
1210 if (!((*it)->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS)) 1196 if (!((*it)->extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS))
1211 dict->Remove(keys::kResponseHeadersKey, NULL); 1197 dict->Remove(keys::kResponseHeadersKey, NULL);
1212 1198
1213 extensions::EventRouter::DispatchEvent( 1199 EventRouter::DispatchEvent(
1214 (*it)->ipc_sender.get(), browser_context, 1200 (*it)->ipc_sender.get(), browser_context, (*it)->extension_id,
1215 (*it)->extension_id, (*it)->sub_event_name, 1201 (*it)->sub_event_name, args_filtered.Pass(),
1216 args_filtered.Pass(), 1202 EventRouter::USER_GESTURE_UNKNOWN, EventFilteringInfo());
1217 extensions::EventRouter::USER_GESTURE_UNKNOWN,
1218 extensions::EventFilteringInfo());
1219 if ((*it)->extra_info_spec & 1203 if ((*it)->extra_info_spec &
1220 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) { 1204 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) {
1221 (*it)->blocked_requests.insert(request->identifier()); 1205 (*it)->blocked_requests.insert(request->identifier());
1222 // If this is the first delegate blocking the request, go ahead and log 1206 // If this is the first delegate blocking the request, go ahead and log
1223 // it. 1207 // it.
1224 if (num_handlers_blocking == 0) { 1208 if (num_handlers_blocking == 0) {
1225 std::string delegate_info = 1209 std::string delegate_info =
1226 l10n_util::GetStringFUTF8(IDS_LOAD_STATE_PARAMETER_EXTENSION, 1210 l10n_util::GetStringFUTF8(IDS_LOAD_STATE_PARAMETER_EXTENSION,
1227 base::UTF8ToUTF16((*it)->extension_name)); 1211 base::UTF8ToUTF16((*it)->extension_name));
1228 // LobAndReport allows extensions that block requests to be displayed in 1212 // LobAndReport allows extensions that block requests to be displayed in
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 listeners_[browser_context][event_name].insert(listener); 1288 listeners_[browser_context][event_name].insert(listener);
1305 return true; 1289 return true;
1306 } 1290 }
1307 1291
1308 void ExtensionWebRequestEventRouter::RemoveEventListener( 1292 void ExtensionWebRequestEventRouter::RemoveEventListener(
1309 void* browser_context, 1293 void* browser_context,
1310 const std::string& extension_id, 1294 const std::string& extension_id,
1311 const std::string& sub_event_name, 1295 const std::string& sub_event_name,
1312 int embedder_process_id, 1296 int embedder_process_id,
1313 int web_view_instance_id) { 1297 int web_view_instance_id) {
1314 std::string event_name = 1298 std::string event_name = EventRouter::GetBaseEventName(sub_event_name);
1315 extensions::EventRouter::GetBaseEventName(sub_event_name);
1316 DCHECK(IsWebRequestEvent(event_name)); 1299 DCHECK(IsWebRequestEvent(event_name));
1317 1300
1318 EventListener listener; 1301 EventListener listener;
1319 listener.extension_id = extension_id; 1302 listener.extension_id = extension_id;
1320 listener.sub_event_name = sub_event_name; 1303 listener.sub_event_name = sub_event_name;
1321 listener.embedder_process_id = embedder_process_id; 1304 listener.embedder_process_id = embedder_process_id;
1322 listener.web_view_instance_id = web_view_instance_id; 1305 listener.web_view_instance_id = web_view_instance_id;
1323 1306
1324 std::set<EventListener>& event_listeners = 1307 std::set<EventListener>& event_listeners =
1325 listeners_[browser_context][event_name]; 1308 listeners_[browser_context][event_name];
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 const GURL& url, 1440 const GURL& url,
1458 int render_process_host_id, 1441 int render_process_host_id,
1459 int routing_id, 1442 int routing_id,
1460 ResourceType resource_type, 1443 ResourceType resource_type,
1461 bool is_async_request, 1444 bool is_async_request,
1462 bool is_request_from_extension, 1445 bool is_request_from_extension,
1463 int* extra_info_spec, 1446 int* extra_info_spec,
1464 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* 1447 std::vector<const ExtensionWebRequestEventRouter::EventListener*>*
1465 matching_listeners) { 1448 matching_listeners) {
1466 std::string web_request_event_name(event_name); 1449 std::string web_request_event_name(event_name);
1467 extensions::WebViewRendererState::WebViewInfo web_view_info; 1450 WebViewRendererState::WebViewInfo web_view_info;
1468 bool is_web_view_guest = extensions::WebViewRendererState::GetInstance()-> 1451 bool is_web_view_guest = WebViewRendererState::GetInstance()->GetInfo(
1469 GetInfo(render_process_host_id, routing_id, &web_view_info); 1452 render_process_host_id, routing_id, &web_view_info);
1470 if (is_web_view_guest) { 1453 if (is_web_view_guest) {
1471 web_request_event_name.replace( 1454 web_request_event_name.replace(
1472 0, sizeof(kWebRequestEventPrefix) - 1, webview::kWebViewEventPrefix); 1455 0, sizeof(kWebRequestEventPrefix) - 1, webview::kWebViewEventPrefix);
1473 } 1456 }
1474 1457
1475 std::set<EventListener>& listeners = 1458 std::set<EventListener>& listeners =
1476 listeners_[browser_context][web_request_event_name]; 1459 listeners_[browser_context][web_request_event_name];
1477 for (std::set<EventListener>::iterator it = listeners.begin(); 1460 for (std::set<EventListener>::iterator it = listeners.begin();
1478 it != listeners.end(); ++it) { 1461 it != listeners.end(); ++it) {
1479 if (!it->ipc_sender.get()) { 1462 if (!it->ipc_sender.get()) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 base::ListValue* SummarizeCookieModifications( 1621 base::ListValue* SummarizeCookieModifications(
1639 const std::vector<linked_ptr<CookieType> >& modifications) { 1622 const std::vector<linked_ptr<CookieType> >& modifications) {
1640 scoped_ptr<base::ListValue> cookie_modifications(new base::ListValue()); 1623 scoped_ptr<base::ListValue> cookie_modifications(new base::ListValue());
1641 for (typename std::vector<linked_ptr<CookieType> >::const_iterator i = 1624 for (typename std::vector<linked_ptr<CookieType> >::const_iterator i =
1642 modifications.begin(); 1625 modifications.begin();
1643 i != modifications.end(); ++i) { 1626 i != modifications.end(); ++i) {
1644 scoped_ptr<base::DictionaryValue> summary(new base::DictionaryValue()); 1627 scoped_ptr<base::DictionaryValue> summary(new base::DictionaryValue());
1645 const CookieType& mod = *i->get(); 1628 const CookieType& mod = *i->get();
1646 switch (mod.type) { 1629 switch (mod.type) {
1647 case helpers::ADD: 1630 case helpers::ADD:
1648 summary->SetString(activitylog::kCookieModificationTypeKey, 1631 summary->SetString(activity_log::kCookieModificationTypeKey,
1649 activitylog::kCookieModificationAdd); 1632 activity_log::kCookieModificationAdd);
1650 break; 1633 break;
1651 case helpers::EDIT: 1634 case helpers::EDIT:
1652 summary->SetString(activitylog::kCookieModificationTypeKey, 1635 summary->SetString(activity_log::kCookieModificationTypeKey,
1653 activitylog::kCookieModificationEdit); 1636 activity_log::kCookieModificationEdit);
1654 break; 1637 break;
1655 case helpers::REMOVE: 1638 case helpers::REMOVE:
1656 summary->SetString(activitylog::kCookieModificationTypeKey, 1639 summary->SetString(activity_log::kCookieModificationTypeKey,
1657 activitylog::kCookieModificationRemove); 1640 activity_log::kCookieModificationRemove);
1658 break; 1641 break;
1659 } 1642 }
1660 if (mod.filter) { 1643 if (mod.filter) {
1661 if (mod.filter->name) 1644 if (mod.filter->name)
1662 summary->SetString(activitylog::kCookieFilterNameKey, 1645 summary->SetString(activity_log::kCookieFilterNameKey,
1663 *mod.modification->name); 1646 *mod.modification->name);
1664 if (mod.filter->domain) 1647 if (mod.filter->domain)
1665 summary->SetString(activitylog::kCookieFilterDomainKey, 1648 summary->SetString(activity_log::kCookieFilterDomainKey,
1666 *mod.modification->name); 1649 *mod.modification->name);
1667 } 1650 }
1668 if (mod.modification) { 1651 if (mod.modification) {
1669 if (mod.modification->name) 1652 if (mod.modification->name)
1670 summary->SetString(activitylog::kCookieModDomainKey, 1653 summary->SetString(activity_log::kCookieModDomainKey,
1671 *mod.modification->name); 1654 *mod.modification->name);
1672 if (mod.modification->domain) 1655 if (mod.modification->domain)
1673 summary->SetString(activitylog::kCookieModDomainKey, 1656 summary->SetString(activity_log::kCookieModDomainKey,
1674 *mod.modification->name); 1657 *mod.modification->name);
1675 } 1658 }
1676 cookie_modifications->Append(summary.release()); 1659 cookie_modifications->Append(summary.release());
1677 } 1660 }
1678 return cookie_modifications.release(); 1661 return cookie_modifications.release();
1679 } 1662 }
1680 1663
1681 // Converts an EventResponseDelta object to a dictionary value suitable for the 1664 // Converts an EventResponseDelta object to a dictionary value suitable for the
1682 // activity log. 1665 // activity log.
1683 scoped_ptr<base::DictionaryValue> SummarizeResponseDelta( 1666 scoped_ptr<base::DictionaryValue> SummarizeResponseDelta(
1684 const std::string& event_name, 1667 const std::string& event_name,
1685 const helpers::EventResponseDelta& delta) { 1668 const helpers::EventResponseDelta& delta) {
1686 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue()); 1669 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue());
1687 if (delta.cancel) { 1670 if (delta.cancel) {
1688 details->SetBoolean(activitylog::kCancelKey, true); 1671 details->SetBoolean(activity_log::kCancelKey, true);
1689 } 1672 }
1690 if (!delta.new_url.is_empty()) { 1673 if (!delta.new_url.is_empty()) {
1691 details->SetString(activitylog::kNewUrlKey, delta.new_url.spec()); 1674 details->SetString(activity_log::kNewUrlKey, delta.new_url.spec());
1692 } 1675 }
1693 1676
1694 scoped_ptr<base::ListValue> modified_headers(new base::ListValue()); 1677 scoped_ptr<base::ListValue> modified_headers(new base::ListValue());
1695 net::HttpRequestHeaders::Iterator iter(delta.modified_request_headers); 1678 net::HttpRequestHeaders::Iterator iter(delta.modified_request_headers);
1696 while (iter.GetNext()) { 1679 while (iter.GetNext()) {
1697 modified_headers->Append( 1680 modified_headers->Append(
1698 helpers::CreateHeaderDictionary(iter.name(), iter.value())); 1681 helpers::CreateHeaderDictionary(iter.name(), iter.value()));
1699 } 1682 }
1700 if (!modified_headers->empty()) { 1683 if (!modified_headers->empty()) {
1701 details->Set(activitylog::kModifiedRequestHeadersKey, 1684 details->Set(activity_log::kModifiedRequestHeadersKey,
1702 modified_headers.release()); 1685 modified_headers.release());
1703 } 1686 }
1704 1687
1705 scoped_ptr<base::ListValue> deleted_headers(new base::ListValue()); 1688 scoped_ptr<base::ListValue> deleted_headers(new base::ListValue());
1706 deleted_headers->AppendStrings(delta.deleted_request_headers); 1689 deleted_headers->AppendStrings(delta.deleted_request_headers);
1707 if (!deleted_headers->empty()) { 1690 if (!deleted_headers->empty()) {
1708 details->Set(activitylog::kDeletedRequestHeadersKey, 1691 details->Set(activity_log::kDeletedRequestHeadersKey,
1709 deleted_headers.release()); 1692 deleted_headers.release());
1710 } 1693 }
1711 1694
1712 if (!delta.added_response_headers.empty()) { 1695 if (!delta.added_response_headers.empty()) {
1713 details->Set(activitylog::kAddedRequestHeadersKey, 1696 details->Set(activity_log::kAddedRequestHeadersKey,
1714 SerializeResponseHeaders(delta.added_response_headers)); 1697 SerializeResponseHeaders(delta.added_response_headers));
1715 } 1698 }
1716 if (!delta.deleted_response_headers.empty()) { 1699 if (!delta.deleted_response_headers.empty()) {
1717 details->Set(activitylog::kDeletedResponseHeadersKey, 1700 details->Set(activity_log::kDeletedResponseHeadersKey,
1718 SerializeResponseHeaders(delta.deleted_response_headers)); 1701 SerializeResponseHeaders(delta.deleted_response_headers));
1719 } 1702 }
1720 if (delta.auth_credentials) { 1703 if (delta.auth_credentials) {
1721 details->SetString(activitylog::kAuthCredentialsKey, 1704 details->SetString(
1722 base::UTF16ToUTF8( 1705 activity_log::kAuthCredentialsKey,
1723 delta.auth_credentials->username()) + ":*"); 1706 base::UTF16ToUTF8(delta.auth_credentials->username()) + ":*");
1724 } 1707 }
1725 1708
1726 if (!delta.response_cookie_modifications.empty()) { 1709 if (!delta.response_cookie_modifications.empty()) {
1727 details->Set( 1710 details->Set(
1728 activitylog::kResponseCookieModificationsKey, 1711 activity_log::kResponseCookieModificationsKey,
1729 SummarizeCookieModifications(delta.response_cookie_modifications)); 1712 SummarizeCookieModifications(delta.response_cookie_modifications));
1730 } 1713 }
1731 1714
1732 return details.Pass(); 1715 return details.Pass();
1733 } 1716 }
1734 1717
1735 } // namespace 1718 } // namespace
1736 1719
1737 void ExtensionWebRequestEventRouter::LogExtensionActivity( 1720 void ExtensionWebRequestEventRouter::LogExtensionActivity(
1738 void* browser_context_id, 1721 void* browser_context_id,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 void* browser_context, 1814 void* browser_context,
1832 const BlockedRequest& blocked_request) { 1815 const BlockedRequest& blocked_request) {
1833 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas; 1816 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas;
1834 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin(); 1817 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin();
1835 delta != deltas.end(); ++delta) { 1818 delta != deltas.end(); ++delta) {
1836 const std::set<std::string>& messages = (*delta)->messages_to_extension; 1819 const std::set<std::string>& messages = (*delta)->messages_to_extension;
1837 for (std::set<std::string>::const_iterator message = messages.begin(); 1820 for (std::set<std::string>::const_iterator message = messages.begin();
1838 message != messages.end(); ++message) { 1821 message != messages.end(); ++message) {
1839 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue); 1822 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue);
1840 ExtractRequestInfo(blocked_request.request, argument.get()); 1823 ExtractRequestInfo(blocked_request.request, argument.get());
1841 extensions::WebViewRendererState::WebViewInfo web_view_info; 1824 WebViewRendererState::WebViewInfo web_view_info;
1842 bool is_web_view_guest = GetWebViewInfo(blocked_request.request, 1825 bool is_web_view_guest = GetWebViewInfo(blocked_request.request,
1843 &web_view_info); 1826 &web_view_info);
1844 argument->SetString(keys::kMessageKey, *message); 1827 argument->SetString(keys::kMessageKey, *message);
1845 argument->SetString(keys::kStageKey, 1828 argument->SetString(keys::kStageKey,
1846 GetRequestStageAsString(blocked_request.event)); 1829 GetRequestStageAsString(blocked_request.event));
1847 1830
1848 BrowserThread::PostTask( 1831 BrowserThread::PostTask(
1849 BrowserThread::UI, 1832 BrowserThread::UI,
1850 FROM_HERE, 1833 FROM_HERE,
1851 base::Bind(&SendOnMessageEventOnUI, 1834 base::Bind(&SendOnMessageEventOnUI,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 blocked_requests_.erase(request_id); 1941 blocked_requests_.erase(request_id);
1959 } 1942 }
1960 return rv; 1943 return rv;
1961 } 1944 }
1962 1945
1963 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( 1946 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules(
1964 void* browser_context, 1947 void* browser_context,
1965 InfoMap* extension_info_map, 1948 InfoMap* extension_info_map,
1966 const std::string& event_name, 1949 const std::string& event_name,
1967 net::URLRequest* request, 1950 net::URLRequest* request,
1968 extensions::RequestStage request_stage, 1951 RequestStage request_stage,
1969 const net::HttpResponseHeaders* original_response_headers) { 1952 const net::HttpResponseHeaders* original_response_headers) {
1970 extensions::WebViewRendererState::WebViewInfo web_view_info; 1953 WebViewRendererState::WebViewInfo web_view_info;
1971 bool is_web_view_guest = GetWebViewInfo(request, &web_view_info); 1954 bool is_web_view_guest = GetWebViewInfo(request, &web_view_info);
1972 int rules_registry_id = is_web_view_guest 1955 int rules_registry_id = is_web_view_guest
1973 ? web_view_info.rules_registry_id 1956 ? web_view_info.rules_registry_id
1974 : RulesRegistryService::kDefaultRulesRegistryID; 1957 : RulesRegistryService::kDefaultRulesRegistryID;
1975 1958
1976 RulesRegistryKey rules_key(browser_context, rules_registry_id); 1959 RulesRegistryKey rules_key(browser_context, rules_registry_id);
1977 // If this check fails, check that the active stages are up-to-date in 1960 // If this check fails, check that the active stages are up-to-date in
1978 // extensions/browser/api/declarative_webrequest/request_stage.h . 1961 // extensions/browser/api/declarative_webrequest/request_stage.h .
1979 DCHECK(request_stage & extensions::kActiveStages); 1962 DCHECK(request_stage & kActiveStages);
1980 1963
1981 // Rules of the current |browser_context| may apply but we need to check also 1964 // Rules of the current |browser_context| may apply but we need to check also
1982 // whether there are applicable rules from extensions whose background page 1965 // whether there are applicable rules from extensions whose background page
1983 // spans from regular to incognito mode. 1966 // spans from regular to incognito mode.
1984 1967
1985 // First parameter identifies the registry, the second indicates whether the 1968 // First parameter identifies the registry, the second indicates whether the
1986 // registry belongs to the cross browser_context. 1969 // registry belongs to the cross browser_context.
1987 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> 1970 typedef std::pair<WebRequestRulesRegistry*, bool> RelevantRegistry;
1988 RelevantRegistry;
1989 typedef std::vector<RelevantRegistry> RelevantRegistries; 1971 typedef std::vector<RelevantRegistry> RelevantRegistries;
1990 RelevantRegistries relevant_registries; 1972 RelevantRegistries relevant_registries;
1991 1973
1992 if (rules_registries_.find(rules_key) != rules_registries_.end()) { 1974 if (rules_registries_.find(rules_key) != rules_registries_.end()) {
1993 relevant_registries.push_back( 1975 relevant_registries.push_back(
1994 std::make_pair(rules_registries_[rules_key].get(), false)); 1976 std::make_pair(rules_registries_[rules_key].get(), false));
1995 } 1977 }
1996 1978
1997 void* cross_browser_context = GetCrossBrowserContext(browser_context); 1979 void* cross_browser_context = GetCrossBrowserContext(browser_context);
1998 RulesRegistryKey cross_browser_context_rules_key(cross_browser_context, 1980 RulesRegistryKey cross_browser_context_rules_key(cross_browser_context,
1999 rules_registry_id); 1981 rules_registry_id);
2000 if (cross_browser_context && 1982 if (cross_browser_context &&
2001 rules_registries_.find(cross_browser_context_rules_key) != 1983 rules_registries_.find(cross_browser_context_rules_key) !=
2002 rules_registries_.end()) { 1984 rules_registries_.end()) {
2003 relevant_registries.push_back( 1985 relevant_registries.push_back(
2004 std::make_pair( 1986 std::make_pair(
2005 rules_registries_[cross_browser_context_rules_key].get(), true)); 1987 rules_registries_[cross_browser_context_rules_key].get(), true));
2006 } 1988 }
2007 1989
2008 // The following block is experimentally enabled and its impact on load time 1990 // The following block is experimentally enabled and its impact on load time
2009 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 1991 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961
2010 for (RelevantRegistries::iterator i = relevant_registries.begin(); 1992 for (RelevantRegistries::iterator i = relevant_registries.begin();
2011 i != relevant_registries.end(); ++i) { 1993 i != relevant_registries.end(); ++i) {
2012 extensions::WebRequestRulesRegistry* rules_registry = i->first; 1994 WebRequestRulesRegistry* rules_registry = i->first;
2013 if (!rules_registry->ready().is_signaled()) { 1995 if (!rules_registry->ready().is_signaled()) {
2014 // The rules registry is still loading. Block this request until it 1996 // The rules registry is still loading. Block this request until it
2015 // finishes. 1997 // finishes.
2016 rules_registry->ready().Post( 1998 rules_registry->ready().Post(
2017 FROM_HERE, 1999 FROM_HERE,
2018 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady, 2000 base::Bind(&ExtensionWebRequestEventRouter::OnRulesRegistryReady,
2019 AsWeakPtr(), 2001 AsWeakPtr(),
2020 browser_context, 2002 browser_context,
2021 event_name, 2003 event_name,
2022 request->identifier(), 2004 request->identifier(),
(...skipping 10 matching lines...) Expand all
2033 extension_info_map; 2015 extension_info_map;
2034 return true; 2016 return true;
2035 } 2017 }
2036 } 2018 }
2037 2019
2038 base::Time start = base::Time::Now(); 2020 base::Time start = base::Time::Now();
2039 2021
2040 bool deltas_created = false; 2022 bool deltas_created = false;
2041 for (RelevantRegistries::iterator i = relevant_registries.begin(); 2023 for (RelevantRegistries::iterator i = relevant_registries.begin();
2042 i != relevant_registries.end(); ++i) { 2024 i != relevant_registries.end(); ++i) {
2043 extensions::WebRequestRulesRegistry* rules_registry = 2025 WebRequestRulesRegistry* rules_registry = i->first;
2044 i->first; 2026 helpers::EventResponseDeltas result = rules_registry->CreateDeltas(
2045 helpers::EventResponseDeltas result = 2027 extension_info_map,
2046 rules_registry->CreateDeltas( 2028 WebRequestData(request, request_stage, original_response_headers),
2047 extension_info_map, 2029 i->second);
2048 extensions::WebRequestData(
2049 request, request_stage, original_response_headers),
2050 i->second);
2051 2030
2052 if (!result.empty()) { 2031 if (!result.empty()) {
2053 helpers::EventResponseDeltas& deltas = 2032 helpers::EventResponseDeltas& deltas =
2054 blocked_requests_[request->identifier()].response_deltas; 2033 blocked_requests_[request->identifier()].response_deltas;
2055 deltas.insert(deltas.end(), result.begin(), result.end()); 2034 deltas.insert(deltas.end(), result.begin(), result.end());
2056 deltas_created = true; 2035 deltas_created = true;
2057 } 2036 }
2058 } 2037 }
2059 2038
2060 base::TimeDelta elapsed_time = start - base::Time::Now(); 2039 base::TimeDelta elapsed_time = start - base::Time::Now();
2061 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeWebRequestNetworkDelay", 2040 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeWebRequestNetworkDelay",
2062 elapsed_time); 2041 elapsed_time);
2063 2042
2064 return deltas_created; 2043 return deltas_created;
2065 } 2044 }
2066 2045
2067 void ExtensionWebRequestEventRouter::OnRulesRegistryReady( 2046 void ExtensionWebRequestEventRouter::OnRulesRegistryReady(
2068 void* browser_context, 2047 void* browser_context,
2069 const std::string& event_name, 2048 const std::string& event_name,
2070 uint64 request_id, 2049 uint64 request_id,
2071 extensions::RequestStage request_stage) { 2050 RequestStage request_stage) {
2072 // It's possible that this request was deleted, or cancelled by a previous 2051 // It's possible that this request was deleted, or cancelled by a previous
2073 // event handler. If so, ignore this response. 2052 // event handler. If so, ignore this response.
2074 if (blocked_requests_.find(request_id) == blocked_requests_.end()) 2053 if (blocked_requests_.find(request_id) == blocked_requests_.end())
2075 return; 2054 return;
2076 2055
2077 BlockedRequest& blocked_request = blocked_requests_[request_id]; 2056 BlockedRequest& blocked_request = blocked_requests_[request_id];
2078 base::TimeDelta block_time = 2057 base::TimeDelta block_time =
2079 base::Time::Now() - blocked_request.blocking_time; 2058 base::Time::Now() - blocked_request.blocking_time;
2080 UMA_HISTOGRAM_TIMES("Extensions.NetworkDelayRegistryLoad", block_time); 2059 UMA_HISTOGRAM_TIMES("Extensions.NetworkDelayRegistryLoad", block_time);
2081 2060
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 // of WebKit at the time of the next page load (top level navigation event). 2096 // of WebKit at the time of the next page load (top level navigation event).
2118 // This quota heuristic is intended to limit the number of times the cache is 2097 // This quota heuristic is intended to limit the number of times the cache is
2119 // cleared by an extension. 2098 // cleared by an extension.
2120 // 2099 //
2121 // As we want to account for the number of times the cache is really cleared 2100 // As we want to account for the number of times the cache is really cleared
2122 // (opposed to the number of times webRequest.handlerBehaviorChanged() is 2101 // (opposed to the number of times webRequest.handlerBehaviorChanged() is
2123 // called), we cannot decide whether a call of 2102 // called), we cannot decide whether a call of
2124 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the 2103 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the
2125 // time it is called. Instead we only decrement the bucket counter at the time 2104 // time it is called. Instead we only decrement the bucket counter at the time
2126 // when the cache is cleared (when page loads happen). 2105 // when the cache is cleared (when page loads happen).
2127 class ClearCacheQuotaHeuristic : public extensions::QuotaLimitHeuristic { 2106 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic {
2128 public: 2107 public:
2129 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map) 2108 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map)
2130 : QuotaLimitHeuristic( 2109 : QuotaLimitHeuristic(
2131 config, 2110 config,
2132 map, 2111 map,
2133 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"), 2112 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"),
2134 callback_registered_(false), 2113 callback_registered_(false),
2135 weak_ptr_factory_(this) {} 2114 weak_ptr_factory_(this) {}
2136 ~ClearCacheQuotaHeuristic() override {} 2115 ~ClearCacheQuotaHeuristic() override {}
2137 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override; 2116 bool Apply(Bucket* bucket, const base::TimeTicks& event_time) override;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 2182
2204 std::string event_name; 2183 std::string event_name;
2205 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); 2184 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name));
2206 2185
2207 std::string sub_event_name; 2186 std::string sub_event_name;
2208 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); 2187 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name));
2209 2188
2210 int web_view_instance_id = 0; 2189 int web_view_instance_id = 0;
2211 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id)); 2190 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id));
2212 2191
2213 base::WeakPtr<extensions::IOThreadExtensionMessageFilter> ipc_sender = 2192 base::WeakPtr<IOThreadExtensionMessageFilter> ipc_sender = ipc_sender_weak();
2214 ipc_sender_weak();
2215 int embedder_process_id = 2193 int embedder_process_id =
2216 ipc_sender.get() && web_view_instance_id > 0 ? 2194 ipc_sender.get() && web_view_instance_id > 0 ?
2217 ipc_sender->render_process_id() : 0; 2195 ipc_sender->render_process_id() : 0;
2218 2196
2219 const Extension* extension = 2197 const Extension* extension =
2220 extension_info_map()->extensions().GetByID(extension_id_safe()); 2198 extension_info_map()->extensions().GetByID(extension_id_safe());
2221 std::string extension_name = 2199 std::string extension_name =
2222 extension ? extension->name() : extension_id_safe(); 2200 extension ? extension->name() : extension_id_safe();
2223 2201
2224 if (!web_view_instance_id) { 2202 if (!web_view_instance_id) {
2225 // We check automatically whether the extension has the 'webRequest' 2203 // We check automatically whether the extension has the 'webRequest'
2226 // permission. For blocking calls we require the additional permission 2204 // permission. For blocking calls we require the additional permission
2227 // 'webRequestBlocking'. 2205 // 'webRequestBlocking'.
2228 if ((extra_info_spec & 2206 if ((extra_info_spec &
2229 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | 2207 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING |
2230 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && 2208 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) &&
2231 !extension->permissions_data()->HasAPIPermission( 2209 !extension->permissions_data()->HasAPIPermission(
2232 extensions::APIPermission::kWebRequestBlocking)) { 2210 APIPermission::kWebRequestBlocking)) {
2233 error_ = keys::kBlockingPermissionRequired; 2211 error_ = keys::kBlockingPermissionRequired;
2234 return false; 2212 return false;
2235 } 2213 }
2236 2214
2237 // We allow to subscribe to patterns that are broader than the host 2215 // We allow to subscribe to patterns that are broader than the host
2238 // permissions. E.g., we could subscribe to http://www.example.com/* 2216 // permissions. E.g., we could subscribe to http://www.example.com/*
2239 // while having host permissions for http://www.example.com/foo/* and 2217 // while having host permissions for http://www.example.com/foo/* and
2240 // http://www.example.com/bar/*. 2218 // http://www.example.com/bar/*.
2241 // For this reason we do only a coarse check here to warn the extension 2219 // For this reason we do only a coarse check here to warn the extension
2242 // developer if he does something obviously wrong. 2220 // developer if he does something obviously wrong.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 } 2405 }
2428 2406
2429 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( 2407 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled(
2430 profile_id(), extension_id_safe(), event_name, sub_event_name, request_id, 2408 profile_id(), extension_id_safe(), event_name, sub_event_name, request_id,
2431 response.release()); 2409 response.release());
2432 2410
2433 return true; 2411 return true;
2434 } 2412 }
2435 2413
2436 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics( 2414 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics(
2437 extensions::QuotaLimitHeuristics* heuristics) const { 2415 QuotaLimitHeuristics* heuristics) const {
2438 extensions::QuotaLimitHeuristic::Config config = { 2416 QuotaLimitHeuristic::Config config = {
2439 // See web_request.json for current value. 2417 // See web_request.json for current value.
2440 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES, 2418 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES,
2441 base::TimeDelta::FromMinutes(10)}; 2419 base::TimeDelta::FromMinutes(10)};
2442 extensions::QuotaLimitHeuristic::BucketMapper* bucket_mapper = 2420 QuotaLimitHeuristic::BucketMapper* bucket_mapper =
2443 new extensions::QuotaLimitHeuristic::SingletonBucketMapper(); 2421 new QuotaLimitHeuristic::SingletonBucketMapper();
2444 ClearCacheQuotaHeuristic* heuristic = 2422 ClearCacheQuotaHeuristic* heuristic =
2445 new ClearCacheQuotaHeuristic(config, bucket_mapper); 2423 new ClearCacheQuotaHeuristic(config, bucket_mapper);
2446 heuristics->push_back(heuristic); 2424 heuristics->push_back(heuristic);
2447 } 2425 }
2448 2426
2449 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded( 2427 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded(
2450 const std::string& violation_error) { 2428 const std::string& violation_error) {
2451 // Post warning message. 2429 // Post warning message.
2452 WarningSet warnings; 2430 WarningSet warnings;
2453 warnings.insert( 2431 warnings.insert(
2454 Warning::CreateRepeatedCacheFlushesWarning(extension_id_safe())); 2432 Warning::CreateRepeatedCacheFlushesWarning(extension_id_safe()));
2455 BrowserThread::PostTask( 2433 BrowserThread::PostTask(
2456 BrowserThread::UI, 2434 BrowserThread::UI,
2457 FROM_HERE, 2435 FROM_HERE,
2458 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings)); 2436 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings));
2459 2437
2460 // Continue gracefully. 2438 // Continue gracefully.
2461 RunSync(); 2439 RunSync();
2462 } 2440 }
2463 2441
2464 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { 2442 bool WebRequestHandlerBehaviorChangedFunction::RunSync() {
2465 helpers::ClearCacheOnNavigation(); 2443 helpers::ClearCacheOnNavigation();
2466 return true; 2444 return true;
2467 } 2445 }
2446
2447 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.h ('k') | extensions/browser/event_listener_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698