| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 23 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
| 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" | |
| 34 #include "chrome/common/extensions/api/web_request.h" | 33 #include "chrome/common/extensions/api/web_request.h" |
| 35 #include "chrome/common/extensions/event_filtering_info.h" | 34 #include "chrome/common/extensions/event_filtering_info.h" |
| 36 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| 37 #include "chrome/common/extensions/extension_constants.h" | 36 #include "chrome/common/extensions/extension_constants.h" |
| 38 #include "chrome/common/extensions/extension_error_utils.h" | 37 #include "chrome/common/extensions/extension_error_utils.h" |
| 39 #include "chrome/common/extensions/extension_messages.h" | 38 #include "chrome/common/extensions/extension_messages.h" |
| 40 #include "chrome/common/extensions/url_pattern.h" | 39 #include "chrome/common/extensions/url_pattern.h" |
| 41 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 42 #include "content/public/browser/browser_message_filter.h" | 41 #include "content/public/browser/browser_message_filter.h" |
| 43 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 content::BrowserContext* browser_context = profile; | 239 content::BrowserContext* browser_context = profile; |
| 241 for (content::RenderProcessHost::iterator it = | 240 for (content::RenderProcessHost::iterator it = |
| 242 content::RenderProcessHost::AllHostsIterator(); | 241 content::RenderProcessHost::AllHostsIterator(); |
| 243 !it.IsAtEnd(); it.Advance()) { | 242 !it.IsAtEnd(); it.Advance()) { |
| 244 content::RenderProcessHost* host = it.GetCurrentValue(); | 243 content::RenderProcessHost* host = it.GetCurrentValue(); |
| 245 if (host->GetBrowserContext() == browser_context) | 244 if (host->GetBrowserContext() == browser_context) |
| 246 SendExtensionWebRequestStatusToHost(host); | 245 SendExtensionWebRequestStatusToHost(host); |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 | 248 |
| 250 void ClearCacheOnNavigationOnUI() { | |
| 251 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | |
| 252 } | |
| 253 | |
| 254 } // namespace | 249 } // namespace |
| 255 | 250 |
| 256 // Represents a single unique listener to an event, along with whatever filter | 251 // Represents a single unique listener to an event, along with whatever filter |
| 257 // parameters and extra_info_spec were specified at the time the listener was | 252 // parameters and extra_info_spec were specified at the time the listener was |
| 258 // added. | 253 // added. |
| 259 struct ExtensionWebRequestEventRouter::EventListener { | 254 struct ExtensionWebRequestEventRouter::EventListener { |
| 260 std::string extension_id; | 255 std::string extension_id; |
| 261 std::string extension_name; | 256 std::string extension_name; |
| 262 std::string sub_event_name; | 257 std::string sub_event_name; |
| 263 RequestFilter filter; | 258 RequestFilter filter; |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 "extension=" << extension_id << " event=" << event_name; | 1048 "extension=" << extension_id << " event=" << event_name; |
| 1054 | 1049 |
| 1055 // Unblock any request that this event listener may have been blocking. | 1050 // Unblock any request that this event listener may have been blocking. |
| 1056 for (std::set<uint64>::iterator it = found->blocked_requests.begin(); | 1051 for (std::set<uint64>::iterator it = found->blocked_requests.begin(); |
| 1057 it != found->blocked_requests.end(); ++it) { | 1052 it != found->blocked_requests.end(); ++it) { |
| 1058 DecrementBlockCount(profile, extension_id, event_name, *it, NULL); | 1053 DecrementBlockCount(profile, extension_id, event_name, *it, NULL); |
| 1059 } | 1054 } |
| 1060 | 1055 |
| 1061 listeners_[profile][event_name].erase(listener); | 1056 listeners_[profile][event_name].erase(listener); |
| 1062 | 1057 |
| 1063 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1058 helpers::ClearCacheOnNavigation(); |
| 1064 base::Bind(&ClearCacheOnNavigationOnUI)); | |
| 1065 } | 1059 } |
| 1066 | 1060 |
| 1067 void ExtensionWebRequestEventRouter::OnOTRProfileCreated( | 1061 void ExtensionWebRequestEventRouter::OnOTRProfileCreated( |
| 1068 void* original_profile, void* otr_profile) { | 1062 void* original_profile, void* otr_profile) { |
| 1069 cross_profile_map_[original_profile] = otr_profile; | 1063 cross_profile_map_[original_profile] = otr_profile; |
| 1070 cross_profile_map_[otr_profile] = original_profile; | 1064 cross_profile_map_[otr_profile] = original_profile; |
| 1071 } | 1065 } |
| 1072 | 1066 |
| 1073 void ExtensionWebRequestEventRouter::OnOTRProfileDestroyed( | 1067 void ExtensionWebRequestEventRouter::OnOTRProfileDestroyed( |
| 1074 void* original_profile, void* otr_profile) { | 1068 void* original_profile, void* otr_profile) { |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 return false; | 1662 return false; |
| 1669 } | 1663 } |
| 1670 | 1664 |
| 1671 bool success = | 1665 bool success = |
| 1672 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 1666 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 1673 profile_id(), extension_id(), extension_name, | 1667 profile_id(), extension_id(), extension_name, |
| 1674 event_name, sub_event_name, filter, | 1668 event_name, sub_event_name, filter, |
| 1675 extra_info_spec, ipc_sender_weak()); | 1669 extra_info_spec, ipc_sender_weak()); |
| 1676 EXTENSION_FUNCTION_VALIDATE(success); | 1670 EXTENSION_FUNCTION_VALIDATE(success); |
| 1677 | 1671 |
| 1678 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1672 helpers::ClearCacheOnNavigation(); |
| 1679 base::Bind(&ClearCacheOnNavigationOnUI)); | |
| 1680 | 1673 |
| 1681 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 1674 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 1682 &NotifyWebRequestAPIUsed, | 1675 &NotifyWebRequestAPIUsed, |
| 1683 profile_id(), make_scoped_refptr(GetExtension()))); | 1676 profile_id(), make_scoped_refptr(GetExtension()))); |
| 1684 | 1677 |
| 1685 return true; | 1678 return true; |
| 1686 } | 1679 } |
| 1687 | 1680 |
| 1688 bool WebRequestEventHandled::RunImpl() { | 1681 bool WebRequestEventHandled::RunImpl() { |
| 1689 std::string event_name; | 1682 std::string event_name; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI, | 1811 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI, |
| 1819 profile_id(), | 1812 profile_id(), |
| 1820 extension_ids, | 1813 extension_ids, |
| 1821 ExtensionWarningSet::kRepeatedCacheFlushes)); | 1814 ExtensionWarningSet::kRepeatedCacheFlushes)); |
| 1822 | 1815 |
| 1823 // Continue gracefully. | 1816 // Continue gracefully. |
| 1824 Run(); | 1817 Run(); |
| 1825 } | 1818 } |
| 1826 | 1819 |
| 1827 bool WebRequestHandlerBehaviorChanged::RunImpl() { | 1820 bool WebRequestHandlerBehaviorChanged::RunImpl() { |
| 1828 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1821 helpers::ClearCacheOnNavigation(); |
| 1829 base::Bind(&ClearCacheOnNavigationOnUI)); | |
| 1830 return true; | 1822 return true; |
| 1831 } | 1823 } |
| 1832 | 1824 |
| 1833 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) { | 1825 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) { |
| 1834 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 1826 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 1835 if (!profile || !profile->GetExtensionService()) | 1827 if (!profile || !profile->GetExtensionService()) |
| 1836 return; | 1828 return; |
| 1837 | 1829 |
| 1838 bool adblock = false; | 1830 bool adblock = false; |
| 1839 bool adblock_plus = false; | 1831 bool adblock_plus = false; |
| 1840 bool other = false; | 1832 bool other = false; |
| 1841 const ExtensionSet* extensions = | 1833 const ExtensionSet* extensions = |
| 1842 profile->GetExtensionService()->extensions(); | 1834 profile->GetExtensionService()->extensions(); |
| 1843 for (ExtensionSet::const_iterator it = extensions->begin(); | 1835 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 1844 it != extensions->end(); ++it) { | 1836 it != extensions->end(); ++it) { |
| 1845 if (profile->GetExtensionService()->HasUsedWebRequest(*it)) { | 1837 if (profile->GetExtensionService()->HasUsedWebRequest(*it)) { |
| 1846 if ((*it)->name().find("Adblock Plus") != std::string::npos) { | 1838 if ((*it)->name().find("Adblock Plus") != std::string::npos) { |
| 1847 adblock_plus = true; | 1839 adblock_plus = true; |
| 1848 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1840 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 1849 adblock = true; | 1841 adblock = true; |
| 1850 } else { | 1842 } else { |
| 1851 other = true; | 1843 other = true; |
| 1852 } | 1844 } |
| 1853 } | 1845 } |
| 1854 } | 1846 } |
| 1855 | 1847 |
| 1856 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1848 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 1857 } | 1849 } |
| OLD | NEW |