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/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 // 'webRequestBlocking'. | 1528 // 'webRequestBlocking'. |
1529 if ((extra_info_spec & | 1529 if ((extra_info_spec & |
1530 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | | 1530 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | |
1531 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && | 1531 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && |
1532 !extension->HasAPIPermission( | 1532 !extension->HasAPIPermission( |
1533 ExtensionAPIPermission::kWebRequestBlocking)) { | 1533 ExtensionAPIPermission::kWebRequestBlocking)) { |
1534 error_ = keys::kBlockingPermissionRequired; | 1534 error_ = keys::kBlockingPermissionRequired; |
1535 return false; | 1535 return false; |
1536 } | 1536 } |
1537 | 1537 |
| 1538 // We allow to subscribe to patterns that are broader than the host |
| 1539 // permissions. E.g., we could subscribe to http://www.example.com/* |
| 1540 // while having host permissions for http://www.example.com/foo/* and |
| 1541 // http://www.example.com/bar/*. |
| 1542 // For this reason we do only a coarse check here to warn the extension |
| 1543 // developer if he does something obviously wrong. |
| 1544 if (extension->GetEffectiveHostPermissions().is_empty()) { |
| 1545 error_ = keys::kHostPermissionsRequired; |
| 1546 return false; |
| 1547 } |
| 1548 |
1538 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 1549 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
1539 profile_id(), extension_id(), extension_name, | 1550 profile_id(), extension_id(), extension_name, |
1540 event_name, sub_event_name, filter, | 1551 event_name, sub_event_name, filter, |
1541 extra_info_spec, ipc_sender_weak()); | 1552 extra_info_spec, ipc_sender_weak()); |
1542 | 1553 |
1543 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1554 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1544 base::Bind(&ClearCacheOnNavigationOnUI)); | 1555 base::Bind(&ClearCacheOnNavigationOnUI)); |
1545 | 1556 |
1546 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 1557 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
1547 &NotifyWebRequestAPIUsed, | 1558 &NotifyWebRequestAPIUsed, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1722 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1712 adblock = true; | 1723 adblock = true; |
1713 } else { | 1724 } else { |
1714 other = true; | 1725 other = true; |
1715 } | 1726 } |
1716 } | 1727 } |
1717 } | 1728 } |
1718 | 1729 |
1719 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1730 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1720 } | 1731 } |
OLD | NEW |