| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" | 24 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" |
| 25 #include "chrome/browser/extensions/event_router.h" | 25 #include "chrome/browser/extensions/event_router.h" |
| 26 #include "chrome/browser/extensions/extension_info_map.h" | 26 #include "chrome/browser/extensions/extension_info_map.h" |
| 27 #include "chrome/browser/extensions/extension_prefs.h" | 27 #include "chrome/browser/extensions/extension_prefs.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_tab_id_map.h" | 29 #include "chrome/browser/extensions/extension_tab_id_map.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
| 32 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 32 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 33 #include "chrome/browser/renderer_host/web_cache_manager.h" | 33 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 34 #include "chrome/common/extensions/api/web_request.h" |
| 34 #include "chrome/common/extensions/event_filtering_info.h" | 35 #include "chrome/common/extensions/event_filtering_info.h" |
| 35 #include "chrome/common/extensions/extension.h" | 36 #include "chrome/common/extensions/extension.h" |
| 36 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
| 37 #include "chrome/common/extensions/extension_error_utils.h" | 38 #include "chrome/common/extensions/extension_error_utils.h" |
| 38 #include "chrome/common/extensions/extension_messages.h" | 39 #include "chrome/common/extensions/extension_messages.h" |
| 39 #include "chrome/common/extensions/url_pattern.h" | 40 #include "chrome/common/extensions/url_pattern.h" |
| 40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 41 #include "content/public/browser/browser_message_filter.h" | 42 #include "content/public/browser/browser_message_filter.h" |
| 42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/browser/resource_request_info.h" | 45 #include "content/public/browser/resource_request_info.h" |
| 45 #include "googleurl/src/gurl.h" | 46 #include "googleurl/src/gurl.h" |
| 46 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
| 47 #include "net/base/auth.h" | 48 #include "net/base/auth.h" |
| 48 #include "net/base/net_errors.h" | 49 #include "net/base/net_errors.h" |
| 49 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
| 50 #include "net/url_request/url_request.h" | 51 #include "net/url_request/url_request.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 52 | 53 |
| 53 using content::BrowserMessageFilter; | 54 using content::BrowserMessageFilter; |
| 54 using content::BrowserThread; | 55 using content::BrowserThread; |
| 55 using content::ResourceRequestInfo; | 56 using content::ResourceRequestInfo; |
| 56 using extensions::Extension; | 57 using extensions::Extension; |
| 57 | 58 |
| 58 using extensions::web_navigation_api_helpers::GetFrameId; | 59 using extensions::web_navigation_api_helpers::GetFrameId; |
| 59 | 60 |
| 60 namespace helpers = extension_web_request_api_helpers; | 61 namespace helpers = extension_web_request_api_helpers; |
| 61 namespace keys = extension_web_request_api_constants; | 62 namespace keys = extension_web_request_api_constants; |
| 63 namespace web_request = extensions::api::web_request; |
| 62 | 64 |
| 63 namespace { | 65 namespace { |
| 64 | 66 |
| 65 // List of all the webRequest events. | 67 // List of all the webRequest events. |
| 66 static const char* const kWebRequestEvents[] = { | 68 static const char* const kWebRequestEvents[] = { |
| 67 keys::kOnBeforeRedirect, | 69 keys::kOnBeforeRedirect, |
| 68 keys::kOnBeforeRequest, | 70 keys::kOnBeforeRequest, |
| 69 keys::kOnBeforeSendHeaders, | 71 keys::kOnBeforeSendHeaders, |
| 70 keys::kOnCompleted, | 72 keys::kOnCompleted, |
| 71 keys::kOnErrorOccurred, | 73 keys::kOnErrorOccurred, |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 // | 1552 // |
| 1551 // As we want to account for the number of times the cache is really cleared | 1553 // As we want to account for the number of times the cache is really cleared |
| 1552 // (opposed to the number of times webRequest.handlerBehaviorChanged() is | 1554 // (opposed to the number of times webRequest.handlerBehaviorChanged() is |
| 1553 // called), we cannot decide whether a call of | 1555 // called), we cannot decide whether a call of |
| 1554 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the | 1556 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the |
| 1555 // time it is called. Instead we only decrement the bucket counter at the time | 1557 // time it is called. Instead we only decrement the bucket counter at the time |
| 1556 // when the cache is cleared (when page loads happen). | 1558 // when the cache is cleared (when page loads happen). |
| 1557 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic { | 1559 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic { |
| 1558 public: | 1560 public: |
| 1559 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map) | 1561 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map) |
| 1560 : QuotaLimitHeuristic(config, map), | 1562 : QuotaLimitHeuristic( |
| 1563 config, |
| 1564 map, |
| 1565 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"), |
| 1561 callback_registered_(false), | 1566 callback_registered_(false), |
| 1562 weak_ptr_factory_(this) {} | 1567 weak_ptr_factory_(this) {} |
| 1563 virtual ~ClearCacheQuotaHeuristic() {} | 1568 virtual ~ClearCacheQuotaHeuristic() {} |
| 1564 virtual bool Apply(Bucket* bucket, | 1569 virtual bool Apply(Bucket* bucket, |
| 1565 const base::TimeTicks& event_time) OVERRIDE; | 1570 const base::TimeTicks& event_time) OVERRIDE; |
| 1566 | 1571 |
| 1567 private: | 1572 private: |
| 1568 // Callback that is triggered by the ExtensionWebRequestEventRouter on a page | 1573 // Callback that is triggered by the ExtensionWebRequestEventRouter on a page |
| 1569 // load. | 1574 // load. |
| 1570 // | 1575 // |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( | 1789 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( |
| 1785 profile_id(), extension_id(), event_name, sub_event_name, request_id, | 1790 profile_id(), extension_id(), event_name, sub_event_name, request_id, |
| 1786 response.release()); | 1791 response.release()); |
| 1787 | 1792 |
| 1788 return true; | 1793 return true; |
| 1789 } | 1794 } |
| 1790 | 1795 |
| 1791 void WebRequestHandlerBehaviorChanged::GetQuotaLimitHeuristics( | 1796 void WebRequestHandlerBehaviorChanged::GetQuotaLimitHeuristics( |
| 1792 QuotaLimitHeuristics* heuristics) const { | 1797 QuotaLimitHeuristics* heuristics) const { |
| 1793 QuotaLimitHeuristic::Config config = { | 1798 QuotaLimitHeuristic::Config config = { |
| 1794 20, // Refill 20 tokens per interval. | 1799 // See web_request.json for current value. |
| 1795 base::TimeDelta::FromMinutes(10) // 10 minutes refill interval. | 1800 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES, |
| 1801 base::TimeDelta::FromMinutes(10) |
| 1796 }; | 1802 }; |
| 1797 QuotaLimitHeuristic::BucketMapper* bucket_mapper = | 1803 QuotaLimitHeuristic::BucketMapper* bucket_mapper = |
| 1798 new QuotaLimitHeuristic::SingletonBucketMapper(); | 1804 new QuotaLimitHeuristic::SingletonBucketMapper(); |
| 1799 ClearCacheQuotaHeuristic* heuristic = | 1805 ClearCacheQuotaHeuristic* heuristic = |
| 1800 new ClearCacheQuotaHeuristic(config, bucket_mapper); | 1806 new ClearCacheQuotaHeuristic(config, bucket_mapper); |
| 1801 heuristics->push_back(heuristic); | 1807 heuristics->push_back(heuristic); |
| 1802 } | 1808 } |
| 1803 | 1809 |
| 1804 void WebRequestHandlerBehaviorChanged::OnQuotaExceeded() { | 1810 void WebRequestHandlerBehaviorChanged::OnQuotaExceeded( |
| 1811 const std::string& violation_error) { |
| 1805 // Post warning message. | 1812 // Post warning message. |
| 1806 std::set<std::string> extension_ids; | 1813 std::set<std::string> extension_ids; |
| 1807 extension_ids.insert(extension_id()); | 1814 extension_ids.insert(extension_id()); |
| 1808 BrowserThread::PostTask( | 1815 BrowserThread::PostTask( |
| 1809 BrowserThread::UI, | 1816 BrowserThread::UI, |
| 1810 FROM_HERE, | 1817 FROM_HERE, |
| 1811 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI, | 1818 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI, |
| 1812 profile_id(), | 1819 profile_id(), |
| 1813 extension_ids, | 1820 extension_ids, |
| 1814 ExtensionWarningSet::kRepeatedCacheFlushes)); | 1821 ExtensionWarningSet::kRepeatedCacheFlushes)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1841 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1848 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 1842 adblock = true; | 1849 adblock = true; |
| 1843 } else { | 1850 } else { |
| 1844 other = true; | 1851 other = true; |
| 1845 } | 1852 } |
| 1846 } | 1853 } |
| 1847 } | 1854 } |
| 1848 | 1855 |
| 1849 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1856 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 1850 } | 1857 } |
| OLD | NEW |