| 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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 IsGuestProcess(render_process_host_id); | 1278 IsGuestProcess(render_process_host_id); |
| 1279 std::set<EventListener>& listeners = listeners_[profile][event_name]; | 1279 std::set<EventListener>& listeners = listeners_[profile][event_name]; |
| 1280 for (std::set<EventListener>::iterator it = listeners.begin(); | 1280 for (std::set<EventListener>::iterator it = listeners.begin(); |
| 1281 it != listeners.end(); ++it) { | 1281 it != listeners.end(); ++it) { |
| 1282 if (!it->ipc_sender.get()) { | 1282 if (!it->ipc_sender.get()) { |
| 1283 // The IPC sender has been deleted. This listener will be removed soon | 1283 // The IPC sender has been deleted. This listener will be removed soon |
| 1284 // via a call to RemoveEventListener. For now, just skip it. | 1284 // via a call to RemoveEventListener. For now, just skip it. |
| 1285 continue; | 1285 continue; |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 if (is_guest && (it->target_process_id != render_process_host_id|| | 1288 if (is_guest && (it->target_process_id != render_process_host_id || |
| 1289 it->target_route_id != routing_id)) | 1289 it->target_route_id != routing_id)) |
| 1290 continue; | 1290 continue; |
| 1291 | 1291 |
| 1292 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) | 1292 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) |
| 1293 continue; | 1293 continue; |
| 1294 if (it->filter.tab_id != -1 && tab_id != it->filter.tab_id) | 1294 if (it->filter.tab_id != -1 && tab_id != it->filter.tab_id) |
| 1295 continue; | 1295 continue; |
| 1296 if (it->filter.window_id != -1 && window_id != it->filter.window_id) | 1296 if (it->filter.window_id != -1 && window_id != it->filter.window_id) |
| 1297 continue; | 1297 continue; |
| 1298 if (!it->filter.types.empty() && | 1298 if (!it->filter.types.empty() && |
| 1299 std::find(it->filter.types.begin(), it->filter.types.end(), | 1299 std::find(it->filter.types.begin(), it->filter.types.end(), |
| 1300 resource_type) == it->filter.types.end()) | 1300 resource_type) == it->filter.types.end()) |
| 1301 continue; | 1301 continue; |
| 1302 | 1302 |
| 1303 if (!WebRequestPermissions::CanExtensionAccessURL( | 1303 if (!is_guest && !WebRequestPermissions::CanExtensionAccessURL( |
| 1304 extension_info_map, it->extension_id, url, crosses_incognito, true)) | 1304 extension_info_map, it->extension_id, url, crosses_incognito, true)) |
| 1305 continue; | 1305 continue; |
| 1306 | 1306 |
| 1307 bool blocking_listener = | 1307 bool blocking_listener = |
| 1308 (it->extra_info_spec & | 1308 (it->extra_info_spec & |
| 1309 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; | 1309 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; |
| 1310 | 1310 |
| 1311 // We do not want to notify extensions about XHR requests that are | 1311 // We do not want to notify extensions about XHR requests that are |
| 1312 // triggered by themselves. This is a workaround to prevent deadlocks | 1312 // triggered by themselves. This is a workaround to prevent deadlocks |
| 1313 // in case of synchronous XHR requests that block the extension renderer | 1313 // in case of synchronous XHR requests that block the extension renderer |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | 1818 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( |
| 1819 *value, &extra_info_spec)); | 1819 *value, &extra_info_spec)); |
| 1820 } | 1820 } |
| 1821 | 1821 |
| 1822 std::string event_name; | 1822 std::string event_name; |
| 1823 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); | 1823 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); |
| 1824 | 1824 |
| 1825 std::string sub_event_name; | 1825 std::string sub_event_name; |
| 1826 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); | 1826 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); |
| 1827 | 1827 |
| 1828 int target_process_id = -1; |
| 1829 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &target_process_id)); |
| 1830 |
| 1831 int target_route_id = -1; |
| 1832 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(6, &target_route_id)); |
| 1833 |
| 1828 const Extension* extension = | 1834 const Extension* extension = |
| 1829 extension_info_map()->extensions().GetByID(extension_id()); | 1835 extension_info_map()->extensions().GetByID(extension_id()); |
| 1830 std::string extension_name = extension ? extension->name() : extension_id(); | 1836 std::string extension_name = extension ? extension->name() : extension_id(); |
| 1831 | 1837 |
| 1832 // We check automatically whether the extension has the 'webRequest' | 1838 // We check automatically whether the extension has the 'webRequest' |
| 1833 // permission. For blocking calls we require the additional permission | 1839 // permission. For blocking calls we require the additional permission |
| 1834 // 'webRequestBlocking'. | 1840 // 'webRequestBlocking'. |
| 1835 if ((extra_info_spec & | 1841 if ((!extension->is_app() && extra_info_spec & |
| 1836 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | | 1842 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | |
| 1837 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && | 1843 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && |
| 1838 !extension->HasAPIPermission( | 1844 !extension->HasAPIPermission( |
| 1839 extensions::APIPermission::kWebRequestBlocking)) { | 1845 extensions::APIPermission::kWebRequestBlocking)) { |
| 1840 error_ = keys::kBlockingPermissionRequired; | 1846 error_ = keys::kBlockingPermissionRequired; |
| 1841 return false; | 1847 return false; |
| 1842 } | 1848 } |
| 1843 | 1849 |
| 1844 // We allow to subscribe to patterns that are broader than the host | 1850 // We allow to subscribe to patterns that are broader than the host |
| 1845 // permissions. E.g., we could subscribe to http://www.example.com/* | 1851 // permissions. E.g., we could subscribe to http://www.example.com/* |
| 1846 // while having host permissions for http://www.example.com/foo/* and | 1852 // while having host permissions for http://www.example.com/foo/* and |
| 1847 // http://www.example.com/bar/*. | 1853 // http://www.example.com/bar/*. |
| 1848 // For this reason we do only a coarse check here to warn the extension | 1854 // For this reason we do only a coarse check here to warn the extension |
| 1849 // developer if he does something obviously wrong. | 1855 // developer if he does something obviously wrong. |
| 1850 if (extension->GetEffectiveHostPermissions().is_empty()) { | 1856 if (!extension->is_app() && extension->GetEffectiveHostPermissions().is_empty(
)) { |
| 1851 error_ = keys::kHostPermissionsRequired; | 1857 error_ = keys::kHostPermissionsRequired; |
| 1852 return false; | 1858 return false; |
| 1853 } | 1859 } |
| 1854 | 1860 |
| 1855 bool success = | 1861 bool success = |
| 1856 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 1862 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 1857 profile_id(), extension_id(), extension_name, | 1863 profile_id(), extension_id(), extension_name, |
| 1858 event_name, sub_event_name, filter, | 1864 event_name, sub_event_name, filter, |
| 1859 extra_info_spec, -1, -1, ipc_sender_weak()); | 1865 extra_info_spec, target_process_id, target_route_id, |
| 1866 ipc_sender_weak()); |
| 1860 EXTENSION_FUNCTION_VALIDATE(success); | 1867 EXTENSION_FUNCTION_VALIDATE(success); |
| 1861 | 1868 |
| 1862 helpers::ClearCacheOnNavigation(); | 1869 helpers::ClearCacheOnNavigation(); |
| 1863 | 1870 |
| 1864 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 1871 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 1865 &NotifyWebRequestAPIUsed, | 1872 &NotifyWebRequestAPIUsed, |
| 1866 profile_id(), make_scoped_refptr(GetExtension()))); | 1873 profile_id(), make_scoped_refptr(GetExtension()))); |
| 1867 | 1874 |
| 1868 return true; | 1875 return true; |
| 1869 } | 1876 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2036 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 2030 adblock = true; | 2037 adblock = true; |
| 2031 } else { | 2038 } else { |
| 2032 other = true; | 2039 other = true; |
| 2033 } | 2040 } |
| 2034 } | 2041 } |
| 2035 } | 2042 } |
| 2036 | 2043 |
| 2037 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2044 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 2038 } | 2045 } |
| OLD | NEW |