Commit a4909ad3 authored by hanxi's avatar hanxi Committed by Commit bot

Clean up of plumbing HostID in declarative content API.

BUG=437566

Review URL: https://codereview.chromium.org/900203003

Cr-Commit-Position: refs/heads/master@{#315296}
parent ce6a9e9d
......@@ -168,7 +168,6 @@ std::string ChromeContentRulesRegistry::AddRulesImpl(
scoped_ptr<ContentRule> content_rule(
ContentRule::Create(url_matcher_.condition_factory(), browser_context(),
HostID(HostID::EXTENSIONS, extension->id()),
extension, extension_installation_time, *rule,
ContentRule::ConsistencyChecker(), &error));
if (!error.empty()) {
......
......@@ -62,7 +62,6 @@ class ShowPageAction : public ContentAction {
static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::DictionaryValue* dict,
std::string* error,
......@@ -126,7 +125,6 @@ class SetIcon : public ContentAction {
static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::DictionaryValue* dict,
std::string* error,
......@@ -220,7 +218,6 @@ struct ContentActionFactory {
// not confirm to the validated JSON specification.
typedef scoped_refptr<ContentAction>(*FactoryMethod)(
content::BrowserContext* /* browser_context */,
const HostID& host_id /* host id */,
const Extension* /* extension */,
const base::DictionaryValue* /* dict */,
std::string* /* error */,
......@@ -266,7 +263,6 @@ RequestContentScript::ScriptData::~ScriptData() {}
// static
scoped_refptr<ContentAction> RequestContentScript::Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::DictionaryValue* dict,
std::string* error,
......@@ -277,7 +273,6 @@ scoped_refptr<ContentAction> RequestContentScript::Create(
return scoped_refptr<ContentAction>(new RequestContentScript(
browser_context,
host_id,
extension,
script_data));
}
......@@ -285,7 +280,6 @@ scoped_refptr<ContentAction> RequestContentScript::Create(
// static
scoped_refptr<ContentAction> RequestContentScript::CreateForTest(
DeclarativeUserScriptMaster* master,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......@@ -313,7 +307,6 @@ scoped_refptr<ContentAction> RequestContentScript::CreateForTest(
// using a BrowserContext.
return scoped_refptr<ContentAction>(new RequestContentScript(
master,
host_id,
extension,
script_data));
}
......@@ -355,9 +348,9 @@ bool RequestContentScript::InitScriptData(const base::DictionaryValue* dict,
RequestContentScript::RequestContentScript(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const ScriptData& script_data) {
HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data);
master_ = ExtensionSystem::Get(browser_context)
......@@ -368,9 +361,9 @@ RequestContentScript::RequestContentScript(
RequestContentScript::RequestContentScript(
DeclarativeUserScriptMaster* master,
const HostID& host_id,
const Extension* extension,
const ScriptData& script_data) {
HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data);
master_ = master;
......@@ -443,7 +436,6 @@ void RequestContentScript::InstructRenderProcessToInject(
// static
scoped_refptr<ContentAction> SetIcon::Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::DictionaryValue* dict,
std::string* error,
......@@ -481,7 +473,6 @@ ContentAction::~ContentAction() {}
// static
scoped_refptr<ContentAction> ContentAction::Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......@@ -497,7 +488,7 @@ scoped_refptr<ContentAction> ContentAction::Create(
factory_method_iter = factory.factory_methods.find(instance_type);
if (factory_method_iter != factory.factory_methods.end())
return (*factory_method_iter->second)(
browser_context, host_id, extension, action_dict, error, bad_message);
browser_context, extension, action_dict, error, bad_message);
*error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str());
return scoped_refptr<ContentAction>();
......
......@@ -67,7 +67,6 @@ class ContentAction : public base::RefCounted<ContentAction> {
// in case the input is syntactically unexpected.
static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......@@ -96,21 +95,15 @@ class RequestContentScript : public ContentAction {
public:
struct ScriptData;
// TODO(hanxi): remove the plumbing of |host_id| when introducing class
// Host/Consumer to de-couple extension from the ContentAction.
// |host_id| will be a part of Host/Consumer class.
RequestContentScript(content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const ScriptData& script_data);
RequestContentScript(DeclarativeUserScriptMaster* master,
const HostID& host_id,
const Extension* extension,
const ScriptData& script_data);
static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::DictionaryValue* dict,
std::string* error,
......@@ -118,7 +111,6 @@ class RequestContentScript : public ContentAction {
static scoped_refptr<ContentAction> CreateForTest(
DeclarativeUserScriptMaster* master,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......
......@@ -74,7 +74,7 @@ TEST(DeclarativeContentActionTest, InvalidCreation) {
// Test wrong data type passed.
error.clear();
result = ContentAction::Create(
NULL, HostID(), NULL, *ParseJson("[]"), &error, &bad_message);
NULL, NULL, *ParseJson("[]"), &error, &bad_message);
EXPECT_TRUE(bad_message);
EXPECT_EQ("", error);
EXPECT_FALSE(result.get());
......@@ -82,14 +82,14 @@ TEST(DeclarativeContentActionTest, InvalidCreation) {
// Test missing instanceType element.
error.clear();
result = ContentAction::Create(
NULL, HostID(), NULL, *ParseJson("{}"), &error, &bad_message);
NULL, NULL, *ParseJson("{}"), &error, &bad_message);
EXPECT_TRUE(bad_message);
EXPECT_EQ("", error);
EXPECT_FALSE(result.get());
// Test wrong instanceType element.
error.clear();
result = ContentAction::Create(NULL, HostID(), NULL, *ParseJson(
result = ContentAction::Create(NULL, NULL, *ParseJson(
"{\n"
" \"instanceType\": \"declarativeContent.UnknownType\",\n"
"}"),
......@@ -106,7 +106,6 @@ TEST(DeclarativeContentActionTest, ShowPageActionWithoutPageAction) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL,
HostID(HostID::EXTENSIONS, extension->id()),
extension,
*ParseJson(
"{\n"
......@@ -128,7 +127,6 @@ TEST(DeclarativeContentActionTest, ShowPageAction) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL,
HostID(HostID::EXTENSIONS, extension->id()),
extension,
*ParseJson(
"{\n"
......@@ -187,7 +185,6 @@ TEST(DeclarativeContentActionTest, SetIcon) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL,
HostID(HostID::EXTENSIONS, extension->id()),
extension,
*dict,
&error,
......@@ -220,7 +217,6 @@ TEST_F(RequestContentScriptTest, MissingScripts) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -241,7 +237,6 @@ TEST_F(RequestContentScriptTest, CSS) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -262,7 +257,6 @@ TEST_F(RequestContentScriptTest, JS) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -283,7 +277,6 @@ TEST_F(RequestContentScriptTest, CSSBadType) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -302,7 +295,6 @@ TEST_F(RequestContentScriptTest, JSBadType) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -321,7 +313,6 @@ TEST_F(RequestContentScriptTest, AllFrames) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -343,7 +334,6 @@ TEST_F(RequestContentScriptTest, MatchAboutBlank) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -365,7 +355,6 @@ TEST_F(RequestContentScriptTest, AllFramesBadType) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......@@ -385,7 +374,6 @@ TEST_F(RequestContentScriptTest, MatchAboutBlankBadType) {
bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create(
profile(),
HostID(HostID::EXTENSIONS, extension()->id()),
extension(),
*ParseJson(
"{\n"
......
......@@ -58,8 +58,7 @@ scoped_ptr<WebRequestActionSet> CreateSetOfActions(const char* json) {
bool bad_message = false;
scoped_ptr<WebRequestActionSet> action_set(
WebRequestActionSet::Create(NULL, HostID(), NULL,
actions, &error, &bad_message));
WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
EXPECT_EQ("", error);
EXPECT_FALSE(bad_message);
CHECK(action_set);
......@@ -188,31 +187,28 @@ TEST(WebRequestActionTest, CreateAction) {
error.clear();
base::ListValue empty_list;
result = WebRequestAction::Create(
NULL, HostID(), NULL, empty_list, &error, &bad_message);
NULL, NULL, empty_list, &error, &bad_message);
EXPECT_TRUE(bad_message);
EXPECT_FALSE(result.get());
// Test missing instanceType element.
base::DictionaryValue input;
error.clear();
result = WebRequestAction::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(bad_message);
EXPECT_FALSE(result.get());
// Test wrong instanceType element.
input.SetString(keys::kInstanceTypeKey, kUnknownActionType);
error.clear();
result = WebRequestAction::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_NE("", error);
EXPECT_FALSE(result.get());
// Test success
input.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
error.clear();
result = WebRequestAction::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_EQ("", error);
EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get());
......@@ -228,8 +224,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test empty input.
error.clear();
result = WebRequestActionSet::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(error.empty()) << error;
EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get());
......@@ -245,8 +240,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test success.
input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy()));
error.clear();
result = WebRequestActionSet::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(error.empty()) << error;
EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get());
......@@ -258,8 +252,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test failure.
input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy()));
error.clear();
result = WebRequestActionSet::Create(
NULL, HostID(), NULL, input, &error, &bad_message);
result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_NE("", error);
EXPECT_FALSE(result.get());
}
......
......@@ -712,7 +712,7 @@ TEST(WebRequestRulesRegistrySimpleTest, StageChecker) {
bool bad_message = false;
scoped_ptr<WebRequestActionSet> actions =
WebRequestActionSet::Create(
NULL, HostID(), NULL, rule.actions, &error, &bad_message);
NULL, NULL, rule.actions, &error, &bad_message);
ASSERT_TRUE(error.empty()) << error;
ASSERT_FALSE(bad_message);
ASSERT_TRUE(actions);
......@@ -739,8 +739,7 @@ TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) {
std::string error;
bool bad_message = false;
scoped_ptr<WebRequestActionSet> action_set(
WebRequestActionSet::Create(
NULL, HostID(), NULL, actions, &error, &bad_message));
WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
ASSERT_TRUE(error.empty()) << error;
ASSERT_FALSE(bad_message);
ASSERT_TRUE(action_set);
......
......@@ -23,7 +23,6 @@
#include "components/url_matcher/url_matcher.h"
#include "extensions/common/api/events.h"
#include "extensions/common/extension.h"
#include "extensions/common/host_id.h"
namespace base {
class Time;
......@@ -153,7 +152,6 @@ class DeclarativeActionSet {
// the extension API.
static scoped_ptr<DeclarativeActionSet> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const AnyVector& actions,
std::string* error,
......@@ -232,7 +230,6 @@ class DeclarativeRule {
static scoped_ptr<DeclarativeRule> Create(
url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
base::Time extension_installation_time,
linked_ptr<JsonRule> rule,
......@@ -369,7 +366,6 @@ template<typename ActionT>
scoped_ptr<DeclarativeActionSet<ActionT> >
DeclarativeActionSet<ActionT>::Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const AnyVector& actions,
std::string* error,
......@@ -382,8 +378,7 @@ DeclarativeActionSet<ActionT>::Create(
i != actions.end(); ++i) {
CHECK(i->get());
scoped_refptr<const ActionT> action =
ActionT::Create(
browser_context, host_id, extension, **i, error, bad_message);
ActionT::Create(browser_context, extension, **i, error, bad_message);
if (!error->empty() || *bad_message)
return scoped_ptr<DeclarativeActionSet>();
result.push_back(action);
......@@ -460,7 +455,6 @@ scoped_ptr<DeclarativeRule<ConditionT, ActionT> >
DeclarativeRule<ConditionT, ActionT>::Create(
url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
base::Time extension_installation_time,
linked_ptr<JsonRule> rule,
......@@ -476,8 +470,8 @@ DeclarativeRule<ConditionT, ActionT>::Create(
bool bad_message = false;
scoped_ptr<ActionSet> actions =
ActionSet::Create(browser_context, host_id, extension,
rule->actions, error, &bad_message);
ActionSet::Create(
browser_context, extension, rule->actions, error, &bad_message);
if (bad_message) {
// TODO(battre) Export concept of bad_message to caller, the extension
// should be killed in case it is true.
......
......@@ -219,7 +219,6 @@ class SummingAction : public base::RefCounted<SummingAction> {
static scoped_refptr<const SummingAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::Value& action,
std::string* error,
......@@ -271,7 +270,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) {
std::string error;
bool bad = false;
scoped_ptr<SummingActionSet> result =
SummingActionSet::Create(NULL, HostID(), NULL, actions, &error, &bad);
SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("the error", error);
EXPECT_FALSE(bad);
EXPECT_FALSE(result);
......@@ -279,8 +278,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) {
actions.clear();
actions.push_back(ScopedToLinkedPtr(ParseJson("{\"value\": 1}")));
actions.push_back(ScopedToLinkedPtr(ParseJson("{\"bad\": 3}")));
result = SummingActionSet::Create(
NULL, HostID(), NULL, actions, &error, &bad);
result = SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("", error);
EXPECT_TRUE(bad);
EXPECT_FALSE(result);
......@@ -297,7 +295,7 @@ TEST(DeclarativeActionTest, ApplyActionSet) {
std::string error;
bool bad = false;
scoped_ptr<SummingActionSet> result =
SummingActionSet::Create(NULL, HostID(), NULL, actions, &error, &bad);
SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("", error);
EXPECT_FALSE(bad);
ASSERT_TRUE(result);
......@@ -338,10 +336,8 @@ TEST(DeclarativeRuleTest, Create) {
URLMatcher matcher;
std::string error;
scoped_ptr<Rule> rule(
Rule::Create(matcher.condition_factory(),
scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(),
NULL,
HostID(HostID::EXTENSIONS, extension.get()->id()),
extension.get(),
install_time,
json_rule,
......@@ -409,10 +405,8 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
" \"priority\": 200 \n"
"}"),
json_rule.get()));
scoped_ptr<Rule> rule(
Rule::Create(matcher.condition_factory(),
scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(),
NULL,
HostID(HostID::EXTENSIONS, extension.get()->id()),
extension.get(),
base::Time(),
json_rule,
......@@ -436,7 +430,6 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
json_rule.get()));
rule = Rule::Create(matcher.condition_factory(),
NULL,
HostID(HostID::EXTENSIONS, extension.get()->id()),
extension.get(),
base::Time(),
json_rule,
......
......@@ -514,7 +514,6 @@ bool WebRequestAction::HasPermission(const InfoMap* extension_info_map,
// static
scoped_refptr<const WebRequestAction> WebRequestAction::Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......
......@@ -135,7 +135,6 @@ class WebRequestAction : public base::RefCounted<WebRequestAction> {
// in case the input is syntactically unexpected.
static scoped_refptr<const WebRequestAction> Create(
content::BrowserContext* browser_context,
const HostID& host_id,
const Extension* extension,
const base::Value& json_action,
std::string* error,
......
......@@ -180,8 +180,7 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
DCHECK(registered_rules.find(rule_id) == registered_rules.end());
scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create(
url_matcher_.condition_factory(), browser_context(),
HostID(HostID::EXTENSIONS, extension->id()), extension,
url_matcher_.condition_factory(), browser_context(), extension,
extension_installation_time, *rule,
base::Bind(&Checker, base::Unretained(extension)), &error));
if (!error.empty()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment