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 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 std::string event_name; | 1470 std::string event_name; |
1471 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); | 1471 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); |
1472 | 1472 |
1473 std::string sub_event_name; | 1473 std::string sub_event_name; |
1474 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); | 1474 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); |
1475 | 1475 |
1476 const Extension* extension = | 1476 const Extension* extension = |
1477 extension_info_map()->extensions().GetByID(extension_id()); | 1477 extension_info_map()->extensions().GetByID(extension_id()); |
1478 std::string extension_name = extension ? extension->name() : extension_id(); | 1478 std::string extension_name = extension ? extension->name() : extension_id(); |
1479 | 1479 |
| 1480 // We check automatically whether the extension has the 'webRequest' |
| 1481 // permission. For blocking calls we require the additional permission |
| 1482 // 'webRequestBlocking'. |
| 1483 if ((extra_info_spec & |
| 1484 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | |
| 1485 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && |
| 1486 !extension->HasAPIPermission( |
| 1487 ExtensionAPIPermission::kWebRequestBlocking)) { |
| 1488 error_ = keys::kBlockingPermissionRequired; |
| 1489 return false; |
| 1490 } |
| 1491 |
1480 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 1492 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
1481 profile_id(), extension_id(), extension_name, | 1493 profile_id(), extension_id(), extension_name, |
1482 event_name, sub_event_name, filter, | 1494 event_name, sub_event_name, filter, |
1483 extra_info_spec, ipc_sender_weak()); | 1495 extra_info_spec, ipc_sender_weak()); |
1484 | 1496 |
1485 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 1497 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
1486 &NotifyWebRequestAPIUsed, | 1498 &NotifyWebRequestAPIUsed, |
1487 profile_id(), make_scoped_refptr(GetExtension()))); | 1499 profile_id(), make_scoped_refptr(GetExtension()))); |
1488 | 1500 |
1489 return true; | 1501 return true; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1662 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1651 adblock = true; | 1663 adblock = true; |
1652 } else { | 1664 } else { |
1653 other = true; | 1665 other = true; |
1654 } | 1666 } |
1655 } | 1667 } |
1656 } | 1668 } |
1657 | 1669 |
1658 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1670 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1659 } | 1671 } |
OLD | NEW |