Untitled diff

Created Diff never expires
202 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
814 lines
167 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
766 lines
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// GENERATED FROM THE API DEFINITION IN
// GENERATED FROM THE API DEFINITION IN
// extensions/common/api/declarative_net_request.idl
// extensions/common/api/declarative_net_request.idl
// DO NOT EDIT.
// DO NOT EDIT.
#include "tools/json_schema_compiler/util.h"
#include "tools/json_schema_compiler/util.h"
#include "base/logging.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "base/values.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/api/declarative_net_request.h"
#include <set>
#include <set>
#include <utility>
#include <utility>
using base::UTF8ToUTF16;
using base::UTF8ToUTF16;
namespace extensions {
namespace extensions {
namespace api {
namespace api {
namespace declarative_net_request {
namespace declarative_net_request {
//
//
// Properties
// Properties
//
//
const int MAX_NUMBER_OF_ALLOWED_PAGES = 100;
const int MAX_NUMBER_OF_ALLOWED_PAGES = 100;
const int MAX_NUMBER_OF_RULES = 30000;
const int MAX_NUMBER_OF_RULES = 30000;
//
//
// Types
// Types
//
//
const char* ToString(ResourceType enum_param) {
const char* ToString(ResourceType enum_param) {
switch (enum_param) {
switch (enum_param) {
case RESOURCE_TYPE_MAIN_FRAME:
case RESOURCE_TYPE_MAIN_FRAME:
return "main_frame";
return "main_frame";
case RESOURCE_TYPE_SUB_FRAME:
case RESOURCE_TYPE_SUB_FRAME:
return "sub_frame";
return "sub_frame";
case RESOURCE_TYPE_STYLESHEET:
case RESOURCE_TYPE_STYLESHEET:
return "stylesheet";
return "stylesheet";
case RESOURCE_TYPE_SCRIPT:
case RESOURCE_TYPE_SCRIPT:
return "script";
return "script";
case RESOURCE_TYPE_IMAGE:
case RESOURCE_TYPE_IMAGE:
return "image";
return "image";
case RESOURCE_TYPE_FONT:
case RESOURCE_TYPE_FONT:
return "font";
return "font";
case RESOURCE_TYPE_OBJECT:
case RESOURCE_TYPE_OBJECT:
return "object";
return "object";
case RESOURCE_TYPE_XMLHTTPREQUEST:
case RESOURCE_TYPE_XMLHTTPREQUEST:
return "xmlhttprequest";
return "xmlhttprequest";
case RESOURCE_TYPE_PING:
case RESOURCE_TYPE_PING:
return "ping";
return "ping";
case RESOURCE_TYPE_CSP_REPORT:
case RESOURCE_TYPE_CSP_REPORT:
return "csp_report";
return "csp_report";
case RESOURCE_TYPE_MEDIA:
case RESOURCE_TYPE_MEDIA:
return "media";
return "media";
case RESOURCE_TYPE_WEBSOCKET:
case RESOURCE_TYPE_WEBSOCKET:
return "websocket";
return "websocket";
case RESOURCE_TYPE_OTHER:
case RESOURCE_TYPE_OTHER:
return "other";
return "other";
case RESOURCE_TYPE_NONE:
case RESOURCE_TYPE_NONE:
return "";
return "";
}
}
NOTREACHED();
NOTREACHED();
return "";
return "";
}
}
ResourceType ParseResourceType(const std::string& enum_string) {
ResourceType ParseResourceType(const std::string& enum_string) {
if (enum_string == "main_frame")
if (enum_string == "main_frame")
return RESOURCE_TYPE_MAIN_FRAME;
return RESOURCE_TYPE_MAIN_FRAME;
if (enum_string == "sub_frame")
if (enum_string == "sub_frame")
return RESOURCE_TYPE_SUB_FRAME;
return RESOURCE_TYPE_SUB_FRAME;
if (enum_string == "stylesheet")
if (enum_string == "stylesheet")
return RESOURCE_TYPE_STYLESHEET;
return RESOURCE_TYPE_STYLESHEET;
if (enum_string == "script")
if (enum_string == "script")
return RESOURCE_TYPE_SCRIPT;
return RESOURCE_TYPE_SCRIPT;
if (enum_string == "image")
if (enum_string == "image")
return RESOURCE_TYPE_IMAGE;
return RESOURCE_TYPE_IMAGE;
if (enum_string == "font")
if (enum_string == "font")
return RESOURCE_TYPE_FONT;
return RESOURCE_TYPE_FONT;
if (enum_string == "object")
if (enum_string == "object")
return RESOURCE_TYPE_OBJECT;
return RESOURCE_TYPE_OBJECT;
if (enum_string == "xmlhttprequest")
if (enum_string == "xmlhttprequest")
return RESOURCE_TYPE_XMLHTTPREQUEST;
return RESOURCE_TYPE_XMLHTTPREQUEST;
if (enum_string == "ping")
if (enum_string == "ping")
return RESOURCE_TYPE_PING;
return RESOURCE_TYPE_PING;
if (enum_string == "csp_report")
if (enum_string == "csp_report")
return RESOURCE_TYPE_CSP_REPORT;
return RESOURCE_TYPE_CSP_REPORT;
if (enum_string == "media")
if (enum_string == "media")
return RESOURCE_TYPE_MEDIA;
return RESOURCE_TYPE_MEDIA;
if (enum_string == "websocket")
if (enum_string == "websocket")
return RESOURCE_TYPE_WEBSOCKET;
return RESOURCE_TYPE_WEBSOCKET;
if (enum_string == "other")
if (enum_string == "other")
return RESOURCE_TYPE_OTHER;
return RESOURCE_TYPE_OTHER;
return RESOURCE_TYPE_NONE;
return RESOURCE_TYPE_NONE;
}
}
const char* ToString(DomainType enum_param) {
const char* ToString(DomainType enum_param) {
switch (enum_param) {
switch (enum_param) {
case DOMAIN_TYPE_FIRSTPARTY:
case DOMAIN_TYPE_FIRSTPARTY:
return "firstParty";
return "firstParty";
case DOMAIN_TYPE_THIRDPARTY:
case DOMAIN_TYPE_THIRDPARTY:
return "thirdParty";
return "thirdParty";
case DOMAIN_TYPE_NONE:
case DOMAIN_TYPE_NONE:
return "";
return "";
}
}
NOTREACHED();
NOTREACHED();
return "";
return "";
}
}
DomainType ParseDomainType(const std::string& enum_string) {
DomainType ParseDomainType(const std::string& enum_string) {
if (enum_string == "firstParty")
if (enum_string == "firstParty")
return DOMAIN_TYPE_FIRSTPARTY;
return DOMAIN_TYPE_FIRSTPARTY;
if (enum_string == "thirdParty")
if (enum_string == "thirdParty")
return DOMAIN_TYPE_THIRDPARTY;
return DOMAIN_TYPE_THIRDPARTY;
return DOMAIN_TYPE_NONE;
return DOMAIN_TYPE_NONE;
}
}
const char* ToString(RuleActionType enum_param) {
const char* ToString(RuleActionType enum_param) {
switch (enum_param) {
switch (enum_param) {
case RULE_ACTION_TYPE_BLOCK:
case RULE_ACTION_TYPE_BLOCK:
return "block";
return "block";
case RULE_ACTION_TYPE_REDIRECT:
case RULE_ACTION_TYPE_REDIRECT:
return "redirect";
return "redirect";
case RULE_ACTION_TYPE_ALLOW:
case RULE_ACTION_TYPE_ALLOW:
return "allow";
return "allow";
case RULE_ACTION_TYPE_NONE:
case RULE_ACTION_TYPE_NONE:
return "";
return "";
}
}
NOTREACHED();
NOTREACHED();
return "";
return "";
}
}
RuleActionType ParseRuleActionType(const std::string& enum_string) {
RuleActionType ParseRuleActionType(const std::string& enum_string) {
if (enum_string == "block")
if (enum_string == "block")
return RULE_ACTION_TYPE_BLOCK;
return RULE_ACTION_TYPE_BLOCK;
if (enum_string == "redirect")
if (enum_string == "redirect")
return RULE_ACTION_TYPE_REDIRECT;
return RULE_ACTION_TYPE_REDIRECT;
if (enum_string == "allow")
if (enum_string == "allow")
return RULE_ACTION_TYPE_ALLOW;
return RULE_ACTION_TYPE_ALLOW;
return RULE_ACTION_TYPE_NONE;
return RULE_ACTION_TYPE_NONE;
}
}
RuleCondition::RuleCondition()
RuleCondition::RuleCondition()
: domain_type(DOMAIN_TYPE_NONE) {}
: domain_type(DOMAIN_TYPE_NONE) {}
RuleCondition::~RuleCondition() {}
RuleCondition::~RuleCondition() {}
RuleCondition::RuleCondition(RuleCondition&& rhs)
RuleCondition::RuleCondition(RuleCondition&& rhs)
: url_filter(std::move(rhs.url_filter)),
: url_filter(std::move(rhs.url_filter)),
is_url_filter_case_sensitive(std::move(rhs.is_url_filter_case_sensitive)),
is_url_filter_case_sensitive(std::move(rhs.is_url_filter_case_sensitive)),
domains(std::move(rhs.domains)),
domains(std::move(rhs.domains)),
excluded_domains(std::move(rhs.excluded_domains)),
excluded_domains(std::move(rhs.excluded_domains)),
resource_types(std::move(rhs.resource_types)),
resource_types(std::move(rhs.resource_types)),
excluded_resource_types(std::move(rhs.excluded_resource_types)),
excluded_resource_types(std::move(rhs.excluded_resource_types)),
domain_type(rhs.domain_type){
domain_type(rhs.domain_type){
}
}
RuleCondition& RuleCondition::operator=(RuleCondition&& rhs)
RuleCondition& RuleCondition::operator=(RuleCondition&& rhs)
{
{
url_filter = std::move(rhs.url_filter);
url_filter = std::move(rhs.url_filter);
is_url_filter_case_sensitive = std::move(rhs.is_url_filter_case_sensitive);
is_url_filter_case_sensitive = std::move(rhs.is_url_filter_case_sensitive);
domains = std::move(rhs.domains);
domains = std::move(rhs.domains);
excluded_domains = std::move(rhs.excluded_domains);
excluded_domains = std::move(rhs.excluded_domains);
resource_types = std::move(rhs.resource_types);
resource_types = std::move(rhs.resource_types);
excluded_resource_types = std::move(rhs.excluded_resource_types);
excluded_resource_types = std::move(rhs.excluded_resource_types);
domain_type = rhs.domain_type;
domain_type = rhs.domain_type;
return *this;
return *this;
}
}
// static
// static
bool RuleCondition::Populate(
bool RuleCondition::Populate(
const base::Value& value, RuleCondition* out) {
const base::Value& value, RuleCondition* out, base::string16* error) {
DCHECK(error);
if (!value.is_dict()) {
if (!value.is_dict()) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("expected dictionary, got " + std::string(base::Value::GetTypeName(value.type()))));
return false;
return false;
}
}
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
std::set<std::string> keys;
out->domain_type = DOMAIN_TYPE_NONE;
out->domain_type = DOMAIN_TYPE_NONE;
keys.insert("urlFilter");
const base::Value* url_filter_value = NULL;
const base::Value* url_filter_value = NULL;
if (dict->GetWithoutPathExpansion("urlFilter", &url_filter_value)) {
if (dict->GetWithoutPathExpansion("urlFilter", &url_filter_value)) {
{
{
std::string temp;
std::string temp;
if (!url_filter_value->GetAsString(&temp)) {
if (!url_filter_value->GetAsString(&temp)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'urlFilter': expected urlFilter, got " + std::string(base::Value::GetTypeName(url_filter_value->type()))));
out->url_filter.reset();
out->url_filter.reset();
return false;
}
}
else
else
out->url_filter.reset(new std::string(temp));
out->url_filter.reset(new std::string(temp));
}
}
}
}
keys.insert("isUrlFilterCaseSensitive");
const base::Value* is_url_filter_case_sensitive_value = NULL;
const base::Value* is_url_filter_case_sensitive_value = NULL;
if (dict->GetWithoutPathExpansion("isUrlFilterCaseSensitive", &is_url_filter_case_sensitive_value)) {
if (dict->GetWithoutPathExpansion("isUrlFilterCaseSensitive", &is_url_filter_case_sensitive_value)) {
{
{
bool temp;
bool temp;
if (!is_url_filter_case_sensitive_value->GetAsBoolean(&temp)) {
if (!is_url_filter_case_sensitive_value->GetAsBoolean(&temp)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'isUrlFilterCaseSensitive': expected isUrlFilterCaseSensitive, got " + std::string(base::Value::GetTypeName(is_url_filter_case_sensitive_value->type()))));
out->is_url_filter_case_sensitive.reset();
out->is_url_filter_case_sensitive.reset();
return false;
}
}
else
else
out->is_url_filter_case_sensitive.reset(new bool(temp));
out->is_url_filter_case_sensitive.reset(new bool(temp));
}
}
}
}
keys.insert("domains");
const base::Value* domains_value = NULL;
const base::Value* domains_value = NULL;
if (dict->GetWithoutPathExpansion("domains", &domains_value)) {
if (dict->GetWithoutPathExpansion("domains", &domains_value)) {
{
{
const base::ListValue* list = NULL;
const base::ListValue* list = NULL;
if (!domains_value->GetAsList(&list)) {
if (!domains_value->GetAsList(&list)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'domains': expected list, got " + std::string(base::Value::GetTypeName(domains_value->type()))));
out->domains.reset();
}
}
else {
else {
if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &out->domains)) {
if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &out->domains, error)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("unable to populate array 'RuleCondition'"));
out->domains.reset();
}
}
}
}
}
}
}
}
keys.insert("excludedDomains");
const base::Value* excluded_domains_value = NULL;
const base::Value* excluded_domains_value = NULL;
if (dict->GetWithoutPathExpansion("excludedDomains", &excluded_domains_value)) {
if (dict->GetWithoutPathExpansion("excludedDomains", &excluded_domains_value)) {
{
{
const base::ListValue* list = NULL;
const base::ListValue* list = NULL;
if (!excluded_domains_value->GetAsList(&list)) {
if (!excluded_domains_value->GetAsList(&list)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'excludedDomains': expected list, got " + std::string(base::Value::GetTypeName(excluded_domains_value->type()))));
out->excluded_domains.reset();
}
}
else {
else {
if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &out->excluded_domains)) {
if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &out->excluded_domains, error)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("unable to populate array 'RuleCondition'"));
out->excluded_domains.reset();
}
}
}
}
}
}
}
}
keys.insert("resourceTypes");
const base::Value* resource_types_value = NULL;
const base::Value* resource_types_value = NULL;
if (dict->GetWithoutPathExpansion("resourceTypes", &resource_types_value)) {
if (dict->GetWithoutPathExpansion("resourceTypes", &resource_types_value)) {
{
{
const base::ListValue* list = NULL;
const base::ListValue* list = NULL;
if (!resource_types_value->GetAsList(&list)) {
if (!resource_types_value->GetAsList(&list)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'resourceTypes': expected list, got " + std::string(base::Value::GetTypeName(resource_types_value->type()))));
out->resource_types.reset();
}
}
else {
else {
out->resource_types.reset(new std::vector<ResourceType>);
out->resource_types.reset(new std::vector<ResourceType>);
for (const auto& it : *(list)) {
for (const auto& it : *(list)) {
ResourceType tmp;
ResourceType tmp;
std::string resource_type_as_string;
std::string resource_type_as_string;
if (!(it).GetAsString(&resource_type_as_string)) {
if (!(it).GetAsString(&resource_type_as_string)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'ResourceType': expected string, got " + std::string(base::Value::GetTypeName((it).type()))));
return false;
return false;
}
}
tmp = ParseResourceType(resource_type_as_string);
tmp = ParseResourceType(resource_type_as_string);
if (tmp == RESOURCE_TYPE_NONE) {
if (tmp == RESOURCE_TYPE_NONE) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'ResourceType': expected \"main_frame\" or \"sub_frame\" or \"stylesheet\" or \"script\" or \"image\" or \"font\" or \"object\" or \"xmlhttprequest\" or \"ping\" or \"csp_report\" or \"media\" or \"websocket\" or \"other\", got \"" + resource_type_as_string + "\""));
return false;
return false;
}
}
out->resource_types->push_back(tmp);
out->resource_types->push_back(tmp);
}
}
}
}
}
}
}
}
keys.insert("excludedResourceTypes");
const base::Value* excluded_resource_types_value = NULL;
const base::Value* excluded_resource_types_value = NULL;
if (dict->GetWithoutPathExpansion("excludedResourceTypes", &excluded_resource_types_value)) {
if (dict->GetWithoutPathExpansion("excludedResourceTypes", &excluded_resource_types_value)) {
{
{
const base::ListValue* list = NULL;
const base::ListValue* list = NULL;
if (!excluded_resource_types_value->GetAsList(&list)) {
if (!excluded_resource_types_value->GetAsList(&list)) {
return false;
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'excludedResourceTypes': expected list, got " + std::string(base::Value::GetTypeName(excluded_resource_types_value->type()))));
out->excluded_resource_types.reset();
}
}
else {
else {
out->excluded_resource_types.reset(new std::vector<ResourceType>);
out->excluded_resource_types.reset(new std::vector<ResourceType>);
for (const auto& it : *(list)) {
for (const auto& it : *(list)) {
ResourceType tmp;
ResourceType tmp;
std::string resource_type_as_string;
std::string resource_type_as_string;
if (!(it).GetAsString(&resource_type_as_string)) {
if (!(it).GetAsString(&resource_type_as_string)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'ResourceType': expected string, got " + std::string(base::Value::GetTypeName((it).type()))));
return false;
return false;
}
}
tmp = ParseResourceType(resource_type_as_string);
tmp = ParseResourceType(resource_type_as_string);
if (tmp == RESOURCE_TYPE_NONE) {
if (tmp == RESOURCE_TYPE_NONE) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'ResourceType': expected \"main_frame\" or \"sub_frame\" or \"stylesheet\" or \"script\" or \"image\" or \"font\" or \"object\" or \"xmlhttprequest\" or \"ping\" or \"csp_report\" or \"media\" or \"websocket\" or \"other\", got \"" + resource_type_as_string + "\""));
return false;
return false;
}
}
out->excluded_resource_types->push_back(tmp);
out->excluded_resource_types->push_back(tmp);
}
}
}
}
}
}
}
}
keys.insert("domainType");
const base::Value* domain_type_value = NULL;
const base::Value* domain_type_value = NULL;
if (dict->GetWithoutPathExpansion("domainType", &domain_type_value)) {
if (dict->GetWithoutPathExpansion("domainType", &domain_type_value)) {
{
{
std::string domain_type_as_string;
std::string domain_type_as_string;
if (!domain_type_value->GetAsString(&domain_type_as_string)) {
if (!domain_type_value->GetAsString(&domain_type_as_string)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'DomainType': expected string, got " + std::string(base::Value::GetTypeName(domain_type_value->type()))));
return false;
return false;
}
}
out->domain_type = ParseDomainType(domain_type_as_string);
out->domain_type = ParseDomainType(domain_type_as_string);
if (out->domain_type == DOMAIN_TYPE_NONE) {
if (out->domain_type == DOMAIN_TYPE_NONE) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'DomainType': expected \"firstParty\" or \"thirdParty\", got \"" + domain_type_as_string + "\""));
return false;
return false;
}
}
}
}
} else {
} else {
out->domain_type = DOMAIN_TYPE_NONE;
out->domain_type = DOMAIN_TYPE_NONE;
}
}
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
if (!keys.count(it.key())) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("found unexpected key '" + it.key() + "'"));
}
}
return true;
return true;
}
}
// static
// static
std::unique_ptr<RuleCondition> RuleCondition::FromValue(const base::Value& value) {
std::unique_ptr<RuleCondition> RuleCondition::FromValue(const base::Value& value, base::string16* error) {
DCHECK(error);
std::unique_ptr<RuleCondition> out(new RuleCondition());
std::unique_ptr<RuleCondition> out(new RuleCondition());
if (!Populate(value, out.get()))
if (!Populate(value, out.get(), error))
return nullptr;
return nullptr;
return out;
return out;
}
}
std::unique_ptr<base::DictionaryValue> RuleCondition::ToValue() const {
std::unique_ptr<base::DictionaryValue> RuleCondition::ToValue() const {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
if (this->url_filter.get()) {
if (this->url_filter.get()) {
value->SetWithoutPathExpansion("urlFilter", std::make_unique<base::Value>(*this->url_filter));
value->SetWithoutPathExpansion("urlFilter", std::make_unique<base::Value>(*this->url_filter));
}
}
if (this->is_url_filter_case_sensitive.get()) {
if (this->is_url_filter_case_sensitive.get()) {
value->SetWithoutPathExpansion("isUrlFilterCaseSensitive", std::make_unique<base::Value>(*this->is_url_filter_case_sensitive));
value->SetWithoutPathExpansion("isUrlFilterCaseSensitive", std::make_unique<base::Value>(*this->is_url_filter_case_sensitive));
}
}
if (this->domains.get()) {
if (this->domains.get()) {
value->SetWithoutPathExpansion("domains", json_schema_compiler::util::CreateValueFromOptionalArray(this->domains));
value->SetWithoutPathExpansion("domains", json_schema_compiler::util::CreateValueFromOptionalArray(this->domains));
}
}
if (this->excluded_domains.get()) {
if (this->excluded_domains.get()) {
value->SetWithoutPathExpansion("excludedDomains", json_schema_compiler::util::CreateValueFromOptionalArray(this->excluded_domains));
value->SetWithoutPathExpansion("excludedDomains", json_schema_compiler::util::CreateValueFromOptionalArray(this->excluded_domains));
}
}
if (this->resource_types.get()) {
if (this->resource_types.get()) {
{
{
std::vector<std::string> resourceTypes_list;
std::vector<std::string> resourceTypes_list;
for (const auto& it : *(this->resource_types)) {
for (const auto& it : *(this->resource_types)) {
resourceTypes_list.push_back(declarative_net_request::ToString(it));
resourceTypes_list.push_back(declarative_net_request::ToString(it));
}
}
value->SetWithoutPathExpansion("resourceTypes", json_schema_compiler::util::CreateValueFromArray(resourceTypes_list));
value->SetWithoutPathExpansion("resourceTypes", json_schema_compiler::util::CreateValueFromArray(resourceTypes_list));
}
}
}
}
if (this->excluded_resource_types.get()) {
if (this->excluded_resource_types.get()) {
{
{
std::vector<std::string> excludedResourceTypes_list;
std::vector<std::string> excludedResourceTypes_list;
for (const auto& it : *(this->excluded_resource_types)) {
for (const auto& it : *(this->excluded_resource_types)) {
excludedResourceTypes_list.push_back(declarative_net_request::ToString(it));
excludedResourceTypes_list.push_back(declarative_net_request::ToString(it));
}
}
value->SetWithoutPathExpansion("excludedResourceTypes", json_schema_compiler::util::CreateValueFromArray(excludedResourceTypes_list));
value->SetWithoutPathExpansion("excludedResourceTypes", json_schema_compiler::util::CreateValueFromArray(excludedResourceTypes_list));
}
}
}
}
if (this->domain_type != DOMAIN_TYPE_NONE) {
if (this->domain_type != DOMAIN_TYPE_NONE) {
value->SetWithoutPathExpansion("domainType", std::make_unique<base::Value>(declarative_net_request::ToString(this->domain_type)));
value->SetWithoutPathExpansion("domainType", std::make_unique<base::Value>(declarative_net_request::ToString(this->domain_type)));
}
}
return value;
return value;
}
}
RuleAction::RuleAction()
RuleAction::RuleAction()
: type(RULE_ACTION_TYPE_NONE) {}
: type(RULE_ACTION_TYPE_NONE) {}
RuleAction::~RuleAction() {}
RuleAction::~RuleAction() {}
RuleAction::RuleAction(RuleAction&& rhs)
RuleAction::RuleAction(RuleAction&& rhs)
: type(rhs.type),
: type(rhs.type),
redirect_url(std::move(rhs.redirect_url)){
redirect_url(std::move(rhs.redirect_url)){
}
}
RuleAction& RuleAction::operator=(RuleAction&& rhs)
RuleAction& RuleAction::operator=(RuleAction&& rhs)
{
{
type = rhs.type;
type = rhs.type;
redirect_url = std::move(rhs.redirect_url);
redirect_url = std::move(rhs.redirect_url);
return *this;
return *this;
}
}
// static
// static
bool RuleAction::Populate(
bool RuleAction::Populate(
const base::Value& value, RuleAction* out) {
const base::Value& value, RuleAction* out, base::string16* error) {
DCHECK(error);
if (!value.is_dict()) {
if (!value.is_dict()) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("expected dictionary, got " + std::string(base::Value::GetTypeName(value.type()))));
return false;
return false;
}
}
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
std::set<std::string> keys;
keys.insert("type");
const base::Value* type_value = NULL;
const base::Value* type_value = NULL;
if (!dict->GetWithoutPathExpansion("type", &type_value)) {
if (!dict->GetWithoutPathExpansion("type", &type_value)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'type' is required"));
return false;
return false;
}
}
{
{
std::string rule_action_type_as_string;
std::string rule_action_type_as_string;
if (!type_value->GetAsString(&rule_action_type_as_string)) {
if (!type_value->GetAsString(&rule_action_type_as_string)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'RuleActionType': expected string, got " + std::string(base::Value::GetTypeName(type_value->type()))));
return false;
return false;
}
}
out->type = ParseRuleActionType(rule_action_type_as_string);
out->type = ParseRuleActionType(rule_action_type_as_string);
if (out->type == RULE_ACTION_TYPE_NONE) {
if (out->type == RULE_ACTION_TYPE_NONE) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'RuleActionType': expected \"block\" or \"redirect\" or \"allow\", got \"" + rule_action_type_as_string + "\""));
return false;
return false;
}
}
}
}
keys.insert("redirectUrl");
const base::Value* redirect_url_value = NULL;
const base::Value* redirect_url_value = NULL;
if (dict->GetWithoutPathExpansion("redirectUrl", &redirect_url_value)) {
if (dict->GetWithoutPathExpansion("redirectUrl", &redirect_url_value)) {
{
{
std::string temp;
std::string temp;
if (!redirect_url_value->GetAsString(&temp)) {
if (!redirect_url_value->GetAsString(&temp)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'redirectUrl': expected redirectUrl, got " + std::string(base::Value::GetTypeName(redirect_url_value->type()))));
out->redirect_url.reset();
out->redirect_url.reset();
return false;
}
}
else
else
out->redirect_url.reset(new std::string(temp));
out->redirect_url.reset(new std::string(temp));
}
}
}
}
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
if (!keys.count(it.key())) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("found unexpected key '" + it.key() + "'"));
}
}
return true;
return true;
}
}
// static
// static
std::unique_ptr<RuleAction> RuleAction::FromValue(const base::Value& value) {
std::unique_ptr<RuleAction> RuleAction::FromValue(const base::Value& value, base::string16* error) {
DCHECK(error);
std::unique_ptr<RuleAction> out(new RuleAction());
std::unique_ptr<RuleAction> out(new RuleAction());
if (!Populate(value, out.get()))
if (!Populate(value, out.get(), error))
return nullptr;
return nullptr;
return out;
return out;
}
}
std::unique_ptr<base::DictionaryValue> RuleAction::ToValue() const {
std::unique_ptr<base::DictionaryValue> RuleAction::ToValue() const {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
value->SetWithoutPathExpansion("type", std::make_unique<base::Value>(declarative_net_request::ToString(this->type)));
value->SetWithoutPathExpansion("type", std::make_unique<base::Value>(declarative_net_request::ToString(this->type)));
if (this->redirect_url.get()) {
if (this->redirect_url.get()) {
value->SetWithoutPathExpansion("redirectUrl", std::make_unique<base::Value>(*this->redirect_url));
value->SetWithoutPathExpansion("redirectUrl", std::make_unique<base::Value>(*this->redirect_url));
}
}
return value;
return value;
}
}
Rule::Rule()
Rule::Rule()
: id(0) {}
: id(0) {}
Rule::~Rule() {}
Rule::~Rule() {}
Rule::Rule(Rule&& rhs)
Rule::Rule(Rule&& rhs)
: id(rhs.id),
: id(rhs.id),
priority(std::move(rhs.priority)),
priority(std::move(rhs.priority)),
condition(std::move(rhs.condition)),
condition(std::move(rhs.condition)),
action(std::move(rhs.action)){
action(std::move(rhs.action)){
}
}
Rule& Rule::operator=(Rule&& rhs)
Rule& Rule::operator=(Rule&& rhs)
{
{
id = rhs.id;
id = rhs.id;
priority = std::move(rhs.priority);
priority = std::move(rhs.priority);
condition = std::move(rhs.condition);
condition = std::move(rhs.condition);
action = std::move(rhs.action);
action = std::move(rhs.action);
return *this;
return *this;
}
}
// static
// static
bool Rule::Populate(
bool Rule::Populate(
const base::Value& value, Rule* out) {
const base::Value& value, Rule* out, base::string16* error) {
DCHECK(error);
if (!value.is_dict()) {
if (!value.is_dict()) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("expected dictionary, got " + std::string(base::Value::GetTypeName(value.type()))));
return false;
return false;
}
}
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
const base::DictionaryValue* dict = static_cast<const base::DictionaryValue*>(&value);
std::set<std::string> keys;
keys.insert("id");
const base::Value* id_value = NULL;
const base::Value* id_value = NULL;
if (!dict->GetWithoutPathExpansion("id", &id_value)) {
if (!dict->GetWithoutPathExpansion("id", &id_value)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'id' is required"));
return false;
return false;
}
}
{
{
if (!id_value->GetAsInteger(&out->id)) {
if (!id_value->GetAsInteger(&out->id)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'id': expected id, got " + std::string(base::Value::GetTypeName(id_value->type()))));
return false;
return false;
}
}
}
}
keys.insert("priority");
const base::Value* priority_value = NULL;
const base::Value* priority_value = NULL;
if (dict->GetWithoutPathExpansion("priority", &priority_value)) {
if (dict->GetWithoutPathExpansion("priority", &priority_value)) {
{
{
int temp;
int temp;
if (!priority_value->GetAsInteger(&temp)) {
if (!priority_value->GetAsInteger(&temp)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'priority': expected priority, got " + std::string(base::Value::GetTypeName(priority_value->type()))));
out->priority.reset();
out->priority.reset();
return false;
}
}
else
else
out->priority.reset(new int(temp));
out->priority.reset(new int(temp));
}
}
}
}
keys.insert("condition");
const base::Value* condition_value = NULL;
const base::Value* condition_value = NULL;
if (!dict->GetWithoutPathExpansion("condition", &condition_value)) {
if (!dict->GetWithoutPathExpansion("condition", &condition_value)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'condition' is required"));
return false;
return false;
}
}
{
{
const base::DictionaryValue* dictionary = NULL;
const base::DictionaryValue* dictionary = NULL;
if (!condition_value->GetAsDictionary(&dictionary)) {
if (!condition_value->GetAsDictionary(&dictionary)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'condition': expected dictionary, got " + std::string(base::Value::GetTypeName(condition_value->type()))));
return false;
return false;
}
}
if (!RuleCondition::Populate(*dictionary, &out->condition)) {
if (!RuleCondition::Populate(*dictionary, &out->condition, error)) {
return false;
return false;
}
}
}
}
keys.insert("action");
const base::Value* action_value = NULL;
const base::Value* action_value = NULL;
if (!dict->GetWithoutPathExpansion("action", &action_value)) {
if (!dict->GetWithoutPathExpansion("action", &action_value)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'action' is required"));
return false;
return false;
}
}
{
{
const base::DictionaryValue* dictionary = NULL;
const base::DictionaryValue* dictionary = NULL;
if (!action_value->GetAsDictionary(&dictionary)) {
if (!action_value->GetAsDictionary(&dictionary)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'action': expected dictionary, got " + std::string(base::Value::GetTypeName(action_value->type()))));
return false;
return false;
}
}
if (!RuleAction::Populate(*dictionary, &out->action)) {
if (!RuleAction::Populate(*dictionary, &out->action, error)) {
return false;
return false;
}
}
}
}
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
if (!keys.count(it.key())) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("found unexpected key '" + it.key() + "'"));
}
}
return true;
return true;
}
}
// static
// static
std::unique_ptr<Rule> Rule::FromValue(const base::Value& value) {
std::unique_ptr<Rule> Rule::FromValue(const base::Value& value, base::string16* error) {
DCHECK(error);
std::unique_ptr<Rule> out(new Rule());
std::unique_ptr<Rule> out(new Rule());
if (!Populate(value, out.get()))
if (!Populate(value, out.get(), error))
return nullptr;
return nullptr;
return out;
return out;
}
}
std::unique_ptr<base::DictionaryValue> Rule::ToValue() const {
std::unique_ptr<base::DictionaryValue> Rule::ToValue() const {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
value->SetWithoutPathExpansion("id", std::make_unique<base::Value>(this->id));
value->SetWithoutPathExpansion("id", std::make_unique<base::Value>(this->id));
if (this->priority.get()) {
if (this->priority.get()) {
value->SetWithoutPathExpansion("priority", std::make_unique<base::Value>(*this->priority));
value->SetWithoutPathExpansion("priority", std::make_unique<base::Value>(*this->priority));
}
}
value->SetWithoutPathExpansion("condition", (this->condition).ToValue());
value->SetWithoutPathExpansion("condition", (this->condition).ToValue());
value->SetWithoutPathExpansion("action", (this->action).ToValue());
value->SetWithoutPathExpansion("action", (this->action).ToValue());
return value;
return value;
}
}
//
//
// Functions
// Functions
//
//
namespace AddAllowedPages {
namespace AddAllowedPages {
Params::Params() {}
Params::Params() {}
Params::~Params() {}
Params::~Params() {}
// static
// static
std::unique_ptr<Params> Params::Create(const base::ListValue& args) {
std::unique_ptr<Params> Params::Create(const base::ListValue& args, base::string16* error) {
DCHECK(error);
if (args.GetSize() != 1) {
if (args.GetSize() != 1) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("expected 1 arguments, got " + base::IntToString(args.GetSize())));
return nullptr;
return nullptr;
}
}
std::unique_ptr<Params> params(new Params());
std::unique_ptr<Params> params(new Params());
const base::Value* page_patterns_value = NULL;
const base::Value* page_patterns_value = NULL;
if (args.Get(0, &page_patterns_value) &&
if (args.Get(0, &page_patterns_value) &&
!page_patterns_value->is_none()) {
!page_patterns_value->is_none()) {
{
{
const base::ListValue* list = NULL;
const base::ListValue* list = NULL;
if (!page_patterns_value->GetAsList(&list)) {
if (!page_patterns_value->GetAsList(&list)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'page_patterns': expected list, got " + std::string(base::Value::GetTypeName(page_patterns_value->type()))));
return std::unique_ptr<Params>();
return std::unique_ptr<Params>();
}
}
else {
else {
if (!json_schema_compiler::util::PopulateArrayFromList(*list, &params->page_patterns)) {
if (!json_schema_compiler::util::PopulateArrayFromList(*list, &params->page_patterns, error)) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("unable to populate array 'addAllowedPages'"));
return std::unique_ptr<Params>();
return std::unique_ptr<Params>();
}
}
}
}
}
}
}
}
else {
else {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("'page_patterns' is required"));
return std::unique_ptr<Params>();
return std::unique_ptr<Params>();
}
}
return params;
return params;
}
}
std::unique_ptr<base::ListValue> Results::Create() {
std::unique_ptr<base::ListValue> Results::Create() {
std::unique_ptr<base::ListValue> create_results(new base::ListValue());
std::unique_ptr<base::ListValue> create_results(new base::ListValue());
return create_results;
return create_results;
}
}
} // namespace AddAllowedPages
} // namespace AddAllowedPages
namespace RemoveAllowedPages {
namespace RemoveAllowedPages {
Params::Params() {}
Params::Params() {}
Params::~Params() {}
Params::~Params() {}
// static
// static
std::unique_ptr<Params> Params::Create(const base::ListValue& args) {
std::unique_ptr<Params> Params::Create(const base::ListValue& args, base::string16* error) {
DCHECK(error);
if (args.GetSize() != 1) {
if (args.GetSize() != 1) {
if (error->length())
error->append(UTF8ToUTF16("; "));
error->append(UTF8ToUTF16("expected 1 arguments, got " + base::IntToString(args.GetSize())));
return nullptr;
return nullptr;
}
}
std::unique_ptr<Params> params(new Params());
std::unique_ptr<Params> params(new Params());
const base::Value* page_patterns_value = NULL;
const base::Value* page_patterns_value = NULL;
if (args.Get(0, &page_patterns_value) &&
if (args.Get(0, &page_patterns_value) &&
!page_patterns_value->is_none()) {
!page_patterns_value->is_none()) {
{
{
const base::ListValue* list = NULL;
const base
if (!page_patterns_value->GetAsList(&list)) {
return std::unique_ptr<Params>();
}
else {
if (!json_schema_compiler::util::PopulateArrayFromList(*list, &params->page_patterns)) {
return std::unique_ptr<Params>();
}
}
}
}
else {
return std::unique_ptr<Params>();
}
return params;
}
std::unique_ptr<base::ListValue> Results::Create() {
std::unique_ptr<base::ListValue> create_results(new base::ListValue());
return create_results;
}
} // namespace RemoveAllowedPages
namespace GetAllowedPages {
std::unique_ptr<base::ListValue> Results::Create(const std::vector<std::string>& result) {
std::unique_ptr<base::ListValue> create_results(new base::ListValue());
create_results->Append(json_schema_compiler::util::CreateValueFromArray(result));
return create_results;
}
} // namespace GetAllowedPages
} // namespace declarative_net_request
} // namespace api
} // namespace extensions