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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 num_handlers_blocking(0), | 405 num_handlers_blocking(0), |
406 net_log(NULL), | 406 net_log(NULL), |
407 new_url(NULL), | 407 new_url(NULL), |
408 request_headers(NULL), | 408 request_headers(NULL), |
409 override_response_headers(NULL), | 409 override_response_headers(NULL), |
410 auth_credentials(NULL) {} | 410 auth_credentials(NULL) {} |
411 }; | 411 }; |
412 | 412 |
413 bool ExtensionWebRequestEventRouter::RequestFilter::InitFromValue( | 413 bool ExtensionWebRequestEventRouter::RequestFilter::InitFromValue( |
414 const DictionaryValue& value, std::string* error) { | 414 const DictionaryValue& value, std::string* error) { |
| 415 if (!value.HasKey("urls")) |
| 416 return false; |
| 417 |
415 for (DictionaryValue::key_iterator key = value.begin_keys(); | 418 for (DictionaryValue::key_iterator key = value.begin_keys(); |
416 key != value.end_keys(); ++key) { | 419 key != value.end_keys(); ++key) { |
417 if (*key == "urls") { | 420 if (*key == "urls") { |
418 ListValue* urls_value = NULL; | 421 ListValue* urls_value = NULL; |
419 if (!value.GetList("urls", &urls_value)) | 422 if (!value.GetList("urls", &urls_value)) |
420 return false; | 423 return false; |
421 for (size_t i = 0; i < urls_value->GetSize(); ++i) { | 424 for (size_t i = 0; i < urls_value->GetSize(); ++i) { |
422 std::string url; | 425 std::string url; |
423 URLPattern pattern(URLPattern::SCHEME_ALL); | 426 URLPattern pattern(URLPattern::SCHEME_ALL); |
424 if (!urls_value->GetString(i, &url) || | 427 if (!urls_value->GetString(i, &url) || |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 | 1485 |
1483 void ClearCacheQuotaHeuristic::OnPageLoad(Bucket* bucket) { | 1486 void ClearCacheQuotaHeuristic::OnPageLoad(Bucket* bucket) { |
1484 callback_registered_ = false; | 1487 callback_registered_ = false; |
1485 bucket->DeductToken(); | 1488 bucket->DeductToken(); |
1486 } | 1489 } |
1487 | 1490 |
1488 bool WebRequestAddEventListener::RunImpl() { | 1491 bool WebRequestAddEventListener::RunImpl() { |
1489 // Argument 0 is the callback, which we don't use here. | 1492 // Argument 0 is the callback, which we don't use here. |
1490 | 1493 |
1491 ExtensionWebRequestEventRouter::RequestFilter filter; | 1494 ExtensionWebRequestEventRouter::RequestFilter filter; |
1492 if (HasOptionalArgument(1)) { | 1495 DictionaryValue* value = NULL; |
1493 DictionaryValue* value = NULL; | 1496 error_.clear(); |
1494 error_.clear(); | 1497 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &value)); |
1495 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &value)); | 1498 // Failure + an empty error string means a fatal error. |
1496 // Failure + an empty error string means a fatal error. | 1499 EXTENSION_FUNCTION_VALIDATE(filter.InitFromValue(*value, &error_) || |
1497 EXTENSION_FUNCTION_VALIDATE(filter.InitFromValue(*value, &error_) || | 1500 !error_.empty()); |
1498 !error_.empty()); | 1501 if (!error_.empty()) |
1499 if (!error_.empty()) | 1502 return false; |
1500 return false; | |
1501 } | |
1502 | 1503 |
1503 int extra_info_spec = 0; | 1504 int extra_info_spec = 0; |
1504 if (HasOptionalArgument(2)) { | 1505 if (HasOptionalArgument(2)) { |
1505 ListValue* value = NULL; | 1506 ListValue* value = NULL; |
1506 EXTENSION_FUNCTION_VALIDATE(args_->GetList(2, &value)); | 1507 EXTENSION_FUNCTION_VALIDATE(args_->GetList(2, &value)); |
1507 EXTENSION_FUNCTION_VALIDATE( | 1508 EXTENSION_FUNCTION_VALIDATE( |
1508 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | 1509 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( |
1509 *value, &extra_info_spec)); | 1510 *value, &extra_info_spec)); |
1510 } | 1511 } |
1511 | 1512 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1708 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
1708 adblock = true; | 1709 adblock = true; |
1709 } else { | 1710 } else { |
1710 other = true; | 1711 other = true; |
1711 } | 1712 } |
1712 } | 1713 } |
1713 } | 1714 } |
1714 | 1715 |
1715 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1716 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
1716 } | 1717 } |
OLD | NEW |