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

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

Issue 10560013: Persist declarative rules to the extension state store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RegisterKey Created 8 years, 6 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 | Annotate | Revision Log
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/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 request_time_tracker_->LogRequestStartTime(request->identifier(), 483 request_time_tracker_->LogRequestStartTime(request->identifier(),
484 base::Time::Now(), 484 base::Time::Now(),
485 request->url(), 485 request->url(),
486 profile); 486 profile);
487 487
488 // Whether to initialized blocked_requests_. 488 // Whether to initialized blocked_requests_.
489 bool initialize_blocked_requests = false; 489 bool initialize_blocked_requests = false;
490 490
491 initialize_blocked_requests |= 491 initialize_blocked_requests |=
492 ProcessDeclarativeRules(request, extensions::ON_BEFORE_REQUEST, NULL); 492 ProcessDeclarativeRules(profile, keys::kOnBeforeRequest, request,
493 extensions::ON_BEFORE_REQUEST, NULL);
493 494
494 int extra_info_spec = 0; 495 int extra_info_spec = 0;
495 std::vector<const EventListener*> listeners = 496 std::vector<const EventListener*> listeners =
496 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest, 497 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest,
497 request, &extra_info_spec); 498 request, &extra_info_spec);
498 if (!listeners.empty() && 499 if (!listeners.empty() &&
499 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) { 500 !GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) {
500 ListValue args; 501 ListValue args;
501 DictionaryValue* dict = new DictionaryValue(); 502 DictionaryValue* dict = new DictionaryValue();
502 ExtractRequestInfo(request, dict); 503 ExtractRequestInfo(request, dict);
(...skipping 27 matching lines...) Expand all
530 net::URLRequest* request, 531 net::URLRequest* request,
531 const net::CompletionCallback& callback, 532 const net::CompletionCallback& callback,
532 net::HttpRequestHeaders* headers) { 533 net::HttpRequestHeaders* headers) {
533 // We hide events from the system context as well as sensitive requests. 534 // We hide events from the system context as well as sensitive requests.
534 if (!profile || helpers::HideRequestForURL(request->url())) 535 if (!profile || helpers::HideRequestForURL(request->url()))
535 return net::OK; 536 return net::OK;
536 537
537 bool initialize_blocked_requests = false; 538 bool initialize_blocked_requests = false;
538 539
539 initialize_blocked_requests |= 540 initialize_blocked_requests |=
540 ProcessDeclarativeRules(request, extensions::ON_BEFORE_SEND_HEADERS, 541 ProcessDeclarativeRules(profile, keys::kOnBeforeSendHeaders, request,
541 NULL); 542 extensions::ON_BEFORE_SEND_HEADERS, NULL);
542 543
543 int extra_info_spec = 0; 544 int extra_info_spec = 0;
544 std::vector<const EventListener*> listeners = 545 std::vector<const EventListener*> listeners =
545 GetMatchingListeners(profile, extension_info_map, 546 GetMatchingListeners(profile, extension_info_map,
546 keys::kOnBeforeSendHeaders, request, 547 keys::kOnBeforeSendHeaders, request,
547 &extra_info_spec); 548 &extra_info_spec);
548 if (!listeners.empty() && 549 if (!listeners.empty() &&
549 !GetAndSetSignaled(request->identifier(), kOnBeforeSendHeaders)) { 550 !GetAndSetSignaled(request->identifier(), kOnBeforeSendHeaders)) {
550 ListValue args; 551 ListValue args;
551 DictionaryValue* dict = new DictionaryValue(); 552 DictionaryValue* dict = new DictionaryValue();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 const net::CompletionCallback& callback, 615 const net::CompletionCallback& callback,
615 net::HttpResponseHeaders* original_response_headers, 616 net::HttpResponseHeaders* original_response_headers,
616 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { 617 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
617 // We hide events from the system context as well as sensitive requests. 618 // We hide events from the system context as well as sensitive requests.
618 if (!profile || helpers::HideRequestForURL(request->url())) 619 if (!profile || helpers::HideRequestForURL(request->url()))
619 return net::OK; 620 return net::OK;
620 621
621 bool initialize_blocked_requests = false; 622 bool initialize_blocked_requests = false;
622 623
623 initialize_blocked_requests |= 624 initialize_blocked_requests |=
624 ProcessDeclarativeRules(request, extensions::ON_HEADERS_RECEIVED, 625 ProcessDeclarativeRules(profile, keys::kOnHeadersReceived, request,
626 extensions::ON_HEADERS_RECEIVED,
625 original_response_headers); 627 original_response_headers);
626 628
627 int extra_info_spec = 0; 629 int extra_info_spec = 0;
628 std::vector<const EventListener*> listeners = 630 std::vector<const EventListener*> listeners =
629 GetMatchingListeners(profile, extension_info_map, 631 GetMatchingListeners(profile, extension_info_map,
630 keys::kOnHeadersReceived, request, 632 keys::kOnHeadersReceived, request,
631 &extra_info_spec); 633 &extra_info_spec);
632 634
633 if (!listeners.empty() && 635 if (!listeners.empty() &&
634 !GetAndSetSignaled(request->identifier(), kOnHeadersReceived)) { 636 !GetAndSetSignaled(request->identifier(), kOnHeadersReceived)) {
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 CHECK_GE(num_handlers_blocking, 0); 1264 CHECK_GE(num_handlers_blocking, 0);
1263 1265
1264 if (response) { 1266 if (response) {
1265 blocked_request.response_deltas.push_back( 1267 blocked_request.response_deltas.push_back(
1266 linked_ptr<helpers::EventResponseDelta>( 1268 linked_ptr<helpers::EventResponseDelta>(
1267 CalculateDelta(&blocked_request, response))); 1269 CalculateDelta(&blocked_request, response)));
1268 } 1270 }
1269 1271
1270 base::TimeDelta block_time = 1272 base::TimeDelta block_time =
1271 base::Time::Now() - blocked_request.blocking_time; 1273 base::Time::Now() - blocked_request.blocking_time;
1272 request_time_tracker_->IncrementExtensionBlockTime( 1274 if (!extension_id.empty()) {
1273 extension_id, request_id, block_time); 1275 request_time_tracker_->IncrementExtensionBlockTime(
1276 extension_id, request_id, block_time);
1277 } else {
1278 // |extension_id| is empty for requests blocked on startup waiting for the
1279 // declarative rules to be read from disk.
1280 UMA_HISTOGRAM_TIMES("Extensions.NetworkDelayStartup", block_time);
1281 }
1274 1282
1275 if (num_handlers_blocking == 0) { 1283 if (num_handlers_blocking == 0) {
1276 ExecuteDeltas(profile, request_id, true); 1284 ExecuteDeltas(profile, request_id, true);
1277 } else { 1285 } else {
1278 // Update the URLRequest to indicate it is now blocked on a different 1286 // Update the URLRequest to indicate it is now blocked on a different
1279 // extension. 1287 // extension.
1280 std::set<EventListener>& listeners = listeners_[profile][event_name]; 1288 std::set<EventListener>& listeners = listeners_[profile][event_name];
1281 1289
1282 for (std::set<EventListener>::iterator it = listeners.begin(); 1290 for (std::set<EventListener>::iterator it = listeners.begin();
1283 it != listeners.end(); ++it) { 1291 it != listeners.end(); ++it) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 blocked_requests_.erase(request_id); 1400 blocked_requests_.erase(request_id);
1393 if (call_callback) 1401 if (call_callback)
1394 callback.Run(response); 1402 callback.Run(response);
1395 } else { 1403 } else {
1396 blocked_requests_.erase(request_id); 1404 blocked_requests_.erase(request_id);
1397 } 1405 }
1398 return rv; 1406 return rv;
1399 } 1407 }
1400 1408
1401 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( 1409 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules(
1410 void* profile,
1411 const std::string& event_name,
1402 net::URLRequest* request, 1412 net::URLRequest* request,
1403 extensions::RequestStages request_stage, 1413 extensions::RequestStages request_stage,
1404 net::HttpResponseHeaders* original_response_headers) { 1414 net::HttpResponseHeaders* original_response_headers) {
1405 if (!rules_registry_.get()) 1415 if (!rules_registry_.get())
1406 return false; 1416 return false;
1407 1417
1418 if (!rules_registry_->IsReady()) {
1419 // The rules registry is still loading. Block this request until it
1420 // finishes.
1421 EventResponse* response = NULL;
1422 rules_registry_->AddReadyCallback(
1423 base::Bind(&ExtensionWebRequestEventRouter::DecrementBlockCount,
1424 AsWeakPtr(), profile, std::string(), event_name,
1425 request->identifier(), response));
battre 2012/06/26 07:59:55 I think this is actually incorrect. We need to dec
1426 blocked_requests_[request->identifier()].num_handlers_blocking++;
1427 blocked_requests_[request->identifier()].request = request;
1428 blocked_requests_[request->identifier()].blocking_time = base::Time::Now();
1429 return true;
1430 }
1431
1408 base::Time start = base::Time::Now(); 1432 base::Time start = base::Time::Now();
1409 1433
1410 // TODO(battre): Annotate deltas with extension IDs, so that we can 1434 // TODO(battre): Annotate deltas with extension IDs, so that we can
1411 // - Sort deltas by precedence 1435 // - Sort deltas by precedence
1412 // - Check whether extensions have host permissions. 1436 // - Check whether extensions have host permissions.
1413 extensions::WebRequestRule::OptionalRequestData optional_request_data; 1437 extensions::WebRequestRule::OptionalRequestData optional_request_data;
1414 optional_request_data.original_response_headers = 1438 optional_request_data.original_response_headers =
1415 original_response_headers; 1439 original_response_headers;
1416 std::list<linked_ptr<helpers::EventResponseDelta> > result = 1440 std::list<linked_ptr<helpers::EventResponseDelta> > result =
1417 rules_registry_->CreateDeltas(request, request_stage, 1441 rules_registry_->CreateDeltas(request, request_stage,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 1775 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1752 adblock = true; 1776 adblock = true;
1753 } else { 1777 } else {
1754 other = true; 1778 other = true;
1755 } 1779 }
1756 } 1780 }
1757 } 1781 }
1758 1782
1759 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 1783 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1760 } 1784 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api.h ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698