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

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

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

Powered by Google App Engine
This is Rietveld 408576698