Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_webrequest_api.h" | 5 #include "chrome/browser/extensions/extension_webrequest_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 9 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 14 #include "chrome/browser/extensions/extension_event_router.h" | 16 #include "chrome/browser/extensions/extension_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_info_map.h" | 17 #include "chrome/browser/extensions/extension_info_map.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_tab_id_map.h" | 20 #include "chrome/browser/extensions/extension_tab_id_map.h" |
| 19 #include "chrome/browser/extensions/extension_webrequest_api_constants.h" | 21 #include "chrome/browser/extensions/extension_webrequest_api_constants.h" |
| 20 #include "chrome/browser/extensions/extension_webrequest_time_tracker.h" | |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | |
| 22 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 24 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 23 #include "chrome/browser/renderer_host/web_cache_manager.h" | 25 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 24 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_error_utils.h" | 27 #include "chrome/common/extensions/extension_error_utils.h" |
| 26 #include "chrome/common/extensions/url_pattern.h" | 28 #include "chrome/common/extensions/url_pattern.h" |
| 27 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 28 #include "content/browser/browser_message_filter.h" | 30 #include "content/browser/browser_message_filter.h" |
| 29 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
| 30 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 32 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 31 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 33 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 modified_headers_.Append(Value::CreateStringValue(key + ": " + value)); | 136 modified_headers_.Append(Value::CreateStringValue(key + ": " + value)); |
| 135 } | 137 } |
| 136 | 138 |
| 137 private: | 139 private: |
| 138 ListValue modified_headers_; | 140 ListValue modified_headers_; |
| 139 ListValue deleted_headers_; | 141 ListValue deleted_headers_; |
| 140 | 142 |
| 141 DISALLOW_COPY_AND_ASSIGN(NetLogModificationParameter); | 143 DISALLOW_COPY_AND_ASSIGN(NetLogModificationParameter); |
| 142 }; | 144 }; |
| 143 | 145 |
| 146 // Handles ExtensionWebRequestTimeTrackerDelegate calls on UI thread. | |
| 147 void NotifyExcessiveDelaysOnUI(void* profile, | |
| 148 size_t num_delayed_messages, | |
| 149 size_t total_num_messages, | |
| 150 std::set<std::string> extension_ids) { | |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 152 Profile* p = reinterpret_cast<Profile*>(profile); | |
| 153 if (!p || !g_browser_process->profile_manager()->IsValidProfile(p)) | |
| 154 return; | |
| 155 | |
| 156 ExtensionService* extension_service = p->GetExtensionService(); | |
| 157 | |
| 158 // We don't need to warn more than once. | |
| 159 if (extension_service->HasWarning(ExtensionServiceWarning::kNetworkDelay)) | |
| 160 return; | |
| 161 | |
| 162 // Override previous warning | |
| 163 extension_service->SetWarning( | |
| 164 ExtensionServiceWarning(ExtensionServiceWarning::kNetworkDelay, | |
| 165 extension_ids)); | |
| 166 } | |
| 167 | |
| 144 // Returns the frame ID as it will be passed to the extension: | 168 // Returns the frame ID as it will be passed to the extension: |
| 145 // 0 if the navigation happens in the main frame, or the frame ID | 169 // 0 if the navigation happens in the main frame, or the frame ID |
| 146 // modulo 32 bits otherwise. | 170 // modulo 32 bits otherwise. |
| 147 // Keep this in sync with the GetFrameId() function in | 171 // Keep this in sync with the GetFrameId() function in |
| 148 // extension_webnavigation_api.cc. | 172 // extension_webnavigation_api.cc. |
| 149 int GetFrameId(bool is_main_frame, int64 frame_id) { | 173 int GetFrameId(bool is_main_frame, int64 frame_id) { |
| 150 return is_main_frame ? 0 : static_cast<int>(frame_id); | 174 return is_main_frame ? 0 : static_cast<int>(frame_id); |
| 151 } | 175 } |
| 152 | 176 |
| 153 bool IsWebRequestEvent(const std::string& event_name) { | 177 bool IsWebRequestEvent(const std::string& event_name) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 allow_extension_scheme = true; | 483 allow_extension_scheme = true; |
| 460 } | 484 } |
| 461 | 485 |
| 462 // static | 486 // static |
| 463 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { | 487 ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() { |
| 464 return Singleton<ExtensionWebRequestEventRouter>::get(); | 488 return Singleton<ExtensionWebRequestEventRouter>::get(); |
| 465 } | 489 } |
| 466 | 490 |
| 467 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() | 491 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() |
| 468 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { | 492 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { |
| 493 request_time_tracker_->SetDelegate(this); | |
| 469 } | 494 } |
| 470 | 495 |
| 471 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { | 496 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { |
| 472 } | 497 } |
| 473 | 498 |
| 499 void ExtensionWebRequestEventRouter::NotifyExcessiveDelays( | |
| 500 void* profile, | |
| 501 size_t num_delayed_messages, | |
| 502 size_t total_num_messages, | |
| 503 const std::set<std::string>& extension_ids) { | |
| 504 BrowserThread::PostTask( | |
| 505 BrowserThread::UI, | |
| 506 FROM_HERE, | |
| 507 base::Bind(&NotifyExcessiveDelaysOnUI, | |
| 508 profile, num_delayed_messages, total_num_messages, | |
| 509 extension_ids)); | |
| 510 } | |
| 511 | |
| 512 void ExtensionWebRequestEventRouter::NotifyModerateDelays( | |
| 513 void* profile, | |
| 514 size_t num_delayed_messages, | |
| 515 size_t total_num_messages, | |
| 516 const std::set<std::string>& extension_ids) { | |
| 517 // We do not report these. | |
|
Matt Perry
2011/10/06 22:55:54
why not?
The goal of the 2 buckets was to catch 2
battre
2011/10/07 14:09:24
Done.
I had not understood this properly before.
| |
| 518 } | |
| 519 | |
| 474 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 520 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
| 475 void* profile, | 521 void* profile, |
| 476 ExtensionInfoMap* extension_info_map, | 522 ExtensionInfoMap* extension_info_map, |
| 477 net::URLRequest* request, | 523 net::URLRequest* request, |
| 478 net::OldCompletionCallback* callback, | 524 net::OldCompletionCallback* callback, |
| 479 GURL* new_url) { | 525 GURL* new_url) { |
| 480 // TODO(jochen): Figure out what to do with events from the system context. | 526 // TODO(jochen): Figure out what to do with events from the system context. |
| 481 if (!profile) | 527 if (!profile) |
| 482 return net::OK; | 528 return net::OK; |
| 483 | 529 |
| 484 if (!HasWebRequestScheme(request->url())) | 530 if (!HasWebRequestScheme(request->url())) |
| 485 return net::OK; | 531 return net::OK; |
| 486 | 532 |
| 487 request_time_tracker_->LogRequestStartTime(request->identifier(), | 533 request_time_tracker_->LogRequestStartTime(request->identifier(), |
| 488 base::Time::Now(), | 534 base::Time::Now(), |
| 489 request->url()); | 535 request->url(), |
| 536 profile); | |
| 490 | 537 |
| 491 int extra_info_spec = 0; | 538 int extra_info_spec = 0; |
| 492 std::vector<const EventListener*> listeners = | 539 std::vector<const EventListener*> listeners = |
| 493 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest, | 540 GetMatchingListeners(profile, extension_info_map, keys::kOnBeforeRequest, |
| 494 request, &extra_info_spec); | 541 request, &extra_info_spec); |
| 495 if (listeners.empty()) | 542 if (listeners.empty()) |
| 496 return net::OK; | 543 return net::OK; |
| 497 | 544 |
| 498 if (GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) | 545 if (GetAndSetSignaled(request->identifier(), kOnBeforeRequest)) |
| 499 return net::OK; | 546 return net::OK; |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 profile_id(), extension_id(), event_name, sub_event_name, request_id, | 1628 profile_id(), extension_id(), event_name, sub_event_name, request_id, |
| 1582 response.release()); | 1629 response.release()); |
| 1583 | 1630 |
| 1584 return true; | 1631 return true; |
| 1585 } | 1632 } |
| 1586 | 1633 |
| 1587 bool WebRequestHandlerBehaviorChanged::RunImpl() { | 1634 bool WebRequestHandlerBehaviorChanged::RunImpl() { |
| 1588 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 1635 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
| 1589 return true; | 1636 return true; |
| 1590 } | 1637 } |
| OLD | NEW |