Commit 3ac20004 authored by markdittmer's avatar markdittmer Committed by Commit bot

Browser changes for wiring up RequestContentScript API to shared memory

BUG=377978

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

Cr-Commit-Position: refs/heads/master@{#292504}
parent a5081a4c
...@@ -29,6 +29,10 @@ class Time; ...@@ -29,6 +29,10 @@ class Time;
class Value; class Value;
} }
namespace content {
class BrowserContext;
}
namespace extensions { namespace extensions {
// This class stores a set of conditions that may be part of a DeclarativeRule. // This class stores a set of conditions that may be part of a DeclarativeRule.
...@@ -146,7 +150,9 @@ class DeclarativeActionSet { ...@@ -146,7 +150,9 @@ class DeclarativeActionSet {
// Factory method that instantiates a DeclarativeActionSet for |extension| // Factory method that instantiates a DeclarativeActionSet for |extension|
// according to |actions| which represents the array of actions received from // according to |actions| which represents the array of actions received from
// the extension API. // the extension API.
static scoped_ptr<DeclarativeActionSet> Create(const Extension* extension, static scoped_ptr<DeclarativeActionSet> Create(
content::BrowserContext* browser_context,
const Extension* extension,
const AnyVector& actions, const AnyVector& actions,
std::string* error, std::string* error,
bool* bad_message); bool* bad_message);
...@@ -223,6 +229,7 @@ class DeclarativeRule { ...@@ -223,6 +229,7 @@ class DeclarativeRule {
// the returned rule is internally consistent. // the returned rule is internally consistent.
static scoped_ptr<DeclarativeRule> Create( static scoped_ptr<DeclarativeRule> Create(
url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
base::Time extension_installation_time, base::Time extension_installation_time,
linked_ptr<JsonRule> rule, linked_ptr<JsonRule> rule,
...@@ -358,6 +365,7 @@ DeclarativeActionSet<ActionT>::DeclarativeActionSet(const Actions& actions) ...@@ -358,6 +365,7 @@ DeclarativeActionSet<ActionT>::DeclarativeActionSet(const Actions& actions)
template<typename ActionT> template<typename ActionT>
scoped_ptr<DeclarativeActionSet<ActionT> > scoped_ptr<DeclarativeActionSet<ActionT> >
DeclarativeActionSet<ActionT>::Create( DeclarativeActionSet<ActionT>::Create(
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const AnyVector& actions, const AnyVector& actions,
std::string* error, std::string* error,
...@@ -370,7 +378,7 @@ DeclarativeActionSet<ActionT>::Create( ...@@ -370,7 +378,7 @@ DeclarativeActionSet<ActionT>::Create(
i != actions.end(); ++i) { i != actions.end(); ++i) {
CHECK(i->get()); CHECK(i->get());
scoped_refptr<const ActionT> action = scoped_refptr<const ActionT> action =
ActionT::Create(extension, **i, error, bad_message); ActionT::Create(browser_context, extension, **i, error, bad_message);
if (!error->empty() || *bad_message) if (!error->empty() || *bad_message)
return scoped_ptr<DeclarativeActionSet>(); return scoped_ptr<DeclarativeActionSet>();
result.push_back(action); result.push_back(action);
...@@ -446,6 +454,7 @@ template<typename ConditionT, typename ActionT> ...@@ -446,6 +454,7 @@ template<typename ConditionT, typename ActionT>
scoped_ptr<DeclarativeRule<ConditionT, ActionT> > scoped_ptr<DeclarativeRule<ConditionT, ActionT> >
DeclarativeRule<ConditionT, ActionT>::Create( DeclarativeRule<ConditionT, ActionT>::Create(
url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
base::Time extension_installation_time, base::Time extension_installation_time,
linked_ptr<JsonRule> rule, linked_ptr<JsonRule> rule,
...@@ -461,7 +470,8 @@ DeclarativeRule<ConditionT, ActionT>::Create( ...@@ -461,7 +470,8 @@ DeclarativeRule<ConditionT, ActionT>::Create(
bool bad_message = false; bool bad_message = false;
scoped_ptr<ActionSet> actions = scoped_ptr<ActionSet> actions =
ActionSet::Create(extension, rule->actions, error, &bad_message); ActionSet::Create(
browser_context, extension, rule->actions, error, &bad_message);
if (bad_message) { if (bad_message) {
// TODO(battre) Export concept of bad_message to caller, the extension // TODO(battre) Export concept of bad_message to caller, the extension
// should be killed in case it is true. // should be killed in case it is true.
......
...@@ -217,7 +217,9 @@ class SummingAction : public base::RefCounted<SummingAction> { ...@@ -217,7 +217,9 @@ class SummingAction : public base::RefCounted<SummingAction> {
SummingAction(int increment, int min_priority) SummingAction(int increment, int min_priority)
: increment_(increment), min_priority_(min_priority) {} : increment_(increment), min_priority_(min_priority) {}
static scoped_refptr<const SummingAction> Create(const Extension* extension, static scoped_refptr<const SummingAction> Create(
content::BrowserContext* browser_context,
const Extension* extension,
const base::Value& action, const base::Value& action,
std::string* error, std::string* error,
bool* bad_message) { bool* bad_message) {
...@@ -268,7 +270,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) { ...@@ -268,7 +270,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) {
std::string error; std::string error;
bool bad = false; bool bad = false;
scoped_ptr<SummingActionSet> result = scoped_ptr<SummingActionSet> result =
SummingActionSet::Create(NULL, actions, &error, &bad); SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("the error", error); EXPECT_EQ("the error", error);
EXPECT_FALSE(bad); EXPECT_FALSE(bad);
EXPECT_FALSE(result); EXPECT_FALSE(result);
...@@ -276,7 +278,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) { ...@@ -276,7 +278,7 @@ TEST(DeclarativeActionTest, ErrorActionSet) {
actions.clear(); actions.clear();
actions.push_back(ScopedToLinkedPtr(ParseJson("{\"value\": 1}"))); actions.push_back(ScopedToLinkedPtr(ParseJson("{\"value\": 1}")));
actions.push_back(ScopedToLinkedPtr(ParseJson("{\"bad\": 3}"))); actions.push_back(ScopedToLinkedPtr(ParseJson("{\"bad\": 3}")));
result = SummingActionSet::Create(NULL, actions, &error, &bad); result = SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_TRUE(bad); EXPECT_TRUE(bad);
EXPECT_FALSE(result); EXPECT_FALSE(result);
...@@ -293,7 +295,7 @@ TEST(DeclarativeActionTest, ApplyActionSet) { ...@@ -293,7 +295,7 @@ TEST(DeclarativeActionTest, ApplyActionSet) {
std::string error; std::string error;
bool bad = false; bool bad = false;
scoped_ptr<SummingActionSet> result = scoped_ptr<SummingActionSet> result =
SummingActionSet::Create(NULL, actions, &error, &bad); SummingActionSet::Create(NULL, NULL, actions, &error, &bad);
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_FALSE(bad); EXPECT_FALSE(bad);
ASSERT_TRUE(result); ASSERT_TRUE(result);
...@@ -335,6 +337,7 @@ TEST(DeclarativeRuleTest, Create) { ...@@ -335,6 +337,7 @@ TEST(DeclarativeRuleTest, Create) {
URLMatcher matcher; URLMatcher matcher;
std::string error; std::string error;
scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(), scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(),
NULL,
extension.get(), extension.get(),
install_time, install_time,
json_rule, json_rule,
...@@ -403,6 +406,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) { ...@@ -403,6 +406,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
"}"), "}"),
json_rule.get())); json_rule.get()));
scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(), scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(),
NULL,
extension.get(), extension.get(),
base::Time(), base::Time(),
json_rule, json_rule,
...@@ -425,6 +429,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) { ...@@ -425,6 +429,7 @@ TEST(DeclarativeRuleTest, CheckConsistency) {
"}"), "}"),
json_rule.get())); json_rule.get()));
rule = Rule::Create(matcher.condition_factory(), rule = Rule::Create(matcher.condition_factory(),
NULL,
extension.get(), extension.get(),
base::Time(), base::Time(),
json_rule, json_rule,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/api/declarative_content/content_constants.h" #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h" #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/declarative_user_script_master.h"
#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tab_util.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "content/public/browser/invalidate_type.h" #include "content/public/browser/invalidate_type.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
namespace extensions { namespace extensions {
...@@ -48,7 +50,9 @@ class ShowPageAction : public ContentAction { ...@@ -48,7 +50,9 @@ class ShowPageAction : public ContentAction {
public: public:
ShowPageAction() {} ShowPageAction() {}
static scoped_refptr<ContentAction> Create(const Extension* extension, static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const Extension* extension,
const base::DictionaryValue* dict, const base::DictionaryValue* dict,
std::string* error, std::string* error,
bool* bad_message) { bool* bad_message) {
...@@ -103,16 +107,16 @@ class ShowPageAction : public ContentAction { ...@@ -103,16 +107,16 @@ class ShowPageAction : public ContentAction {
// Action that injects a content script. // Action that injects a content script.
class RequestContentScript : public ContentAction { class RequestContentScript : public ContentAction {
public: public:
RequestContentScript(const std::vector<std::string>& css_file_names, RequestContentScript(content::BrowserContext* browser_context,
const Extension* extension,
const std::vector<std::string>& css_file_names,
const std::vector<std::string>& js_file_names, const std::vector<std::string>& js_file_names,
bool all_frames, bool all_frames,
bool match_about_blank) bool match_about_blank);
: css_file_names_(css_file_names),
js_file_names_(js_file_names),
all_frames_(all_frames),
match_about_blank_(match_about_blank) {}
static scoped_refptr<ContentAction> Create(const Extension* extension, static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const Extension* extension,
const base::DictionaryValue* dict, const base::DictionaryValue* dict,
std::string* error, std::string* error,
bool* bad_message); bool* bad_message);
...@@ -125,31 +129,31 @@ class RequestContentScript : public ContentAction { ...@@ -125,31 +129,31 @@ class RequestContentScript : public ContentAction {
virtual void Apply(const std::string& extension_id, virtual void Apply(const std::string& extension_id,
const base::Time& extension_install_time, const base::Time& extension_install_time,
ApplyInfo* apply_info) const OVERRIDE { ApplyInfo* apply_info) const OVERRIDE {
// TODO(markdittmer): Invoke UserScriptMaster declarative script loader: InstructRenderProcessToInject(apply_info->tab, extension_id);
// load new user script.
} }
virtual void Reapply(const std::string& extension_id, virtual void Reapply(const std::string& extension_id,
const base::Time& extension_install_time, const base::Time& extension_install_time,
ApplyInfo* apply_info) const OVERRIDE { ApplyInfo* apply_info) const OVERRIDE {
// TODO(markdittmer): Invoke UserScriptMaster declarative script loader: InstructRenderProcessToInject(apply_info->tab, extension_id);
// load new user script.
} }
virtual void Revert(const std::string& extension_id, virtual void Revert(const std::string& extension_id,
const base::Time& extension_install_time, const base::Time& extension_install_time,
ApplyInfo* apply_info) const OVERRIDE { ApplyInfo* apply_info) const OVERRIDE {
// TODO(markdittmer): Invoke UserScriptMaster declarative script loader:
// do not load user script if Apply() runs again on the same page.
} }
private: private:
virtual ~RequestContentScript() {} virtual ~RequestContentScript() {
DCHECK(master_);
master_->RemoveScript(script_);
}
std::vector<std::string> css_file_names_; void InstructRenderProcessToInject(content::WebContents* contents,
std::vector<std::string> js_file_names_; const std::string& extension_id) const;
bool all_frames_;
bool match_about_blank_; UserScript script_;
DeclarativeUserScriptMaster* master_;
DISALLOW_COPY_AND_ASSIGN(RequestContentScript); DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
}; };
...@@ -173,6 +177,7 @@ static bool AppendJSStringsToCPPStrings(const base::ListValue& append_strings, ...@@ -173,6 +177,7 @@ static bool AppendJSStringsToCPPStrings(const base::ListValue& append_strings,
// static // static
scoped_refptr<ContentAction> RequestContentScript::Create( scoped_refptr<ContentAction> RequestContentScript::Create(
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const base::DictionaryValue* dict, const base::DictionaryValue* dict,
std::string* error, std::string* error,
...@@ -206,7 +211,52 @@ scoped_refptr<ContentAction> RequestContentScript::Create( ...@@ -206,7 +211,52 @@ scoped_refptr<ContentAction> RequestContentScript::Create(
} }
return scoped_refptr<ContentAction>(new RequestContentScript( return scoped_refptr<ContentAction>(new RequestContentScript(
css_file_names, js_file_names, all_frames, match_about_blank)); browser_context,
extension,
css_file_names,
js_file_names,
all_frames,
match_about_blank));
}
RequestContentScript::RequestContentScript(
content::BrowserContext* browser_context,
const Extension* extension,
const std::vector<std::string>& css_file_names,
const std::vector<std::string>& js_file_names,
bool all_frames,
bool match_about_blank) {
script_.set_id(UserScript::GenerateUserScriptID());
script_.set_extension_id(extension->id());
script_.set_run_location(UserScript::BROWSER_DRIVEN);
script_.set_match_all_frames(all_frames);
script_.set_match_about_blank(match_about_blank);
for (std::vector<std::string>::const_iterator it = css_file_names.begin();
it != css_file_names.end(); ++it) {
GURL url = extension->GetResourceURL(*it);
ExtensionResource resource = extension->GetResource(*it);
script_.css_scripts().push_back(UserScript::File(
resource.extension_root(), resource.relative_path(), url));
}
for (std::vector<std::string>::const_iterator it = js_file_names.begin();
it != js_file_names.end(); ++it) {
GURL url = extension->GetResourceURL(*it);
ExtensionResource resource = extension->GetResource(*it);
script_.js_scripts().push_back(UserScript::File(
resource.extension_root(), resource.relative_path(), url));
}
master_ =
ExtensionSystem::Get(browser_context)->
GetDeclarativeUserScriptMasterByExtension(extension->id());
DCHECK(master_);
master_->AddScript(script_);
}
void RequestContentScript::InstructRenderProcessToInject(
content::WebContents* contents,
const std::string& extension_id) const {
// TODO(markdittmer): Send ExtensionMsg to renderer.
} }
struct ContentActionFactory { struct ContentActionFactory {
...@@ -217,6 +267,7 @@ struct ContentActionFactory { ...@@ -217,6 +267,7 @@ struct ContentActionFactory {
// semantically incorrect. |bad_message| is set to true in case |dict| does // semantically incorrect. |bad_message| is set to true in case |dict| does
// not confirm to the validated JSON specification. // not confirm to the validated JSON specification.
typedef scoped_refptr<ContentAction>(*FactoryMethod)( typedef scoped_refptr<ContentAction>(*FactoryMethod)(
content::BrowserContext* /* browser_context */,
const Extension* /* extension */, const Extension* /* extension */,
const base::DictionaryValue* /* dict */, const base::DictionaryValue* /* dict */,
std::string* /* error */, std::string* /* error */,
...@@ -248,6 +299,7 @@ ContentAction::~ContentAction() {} ...@@ -248,6 +299,7 @@ ContentAction::~ContentAction() {}
// static // static
scoped_refptr<ContentAction> ContentAction::Create( scoped_refptr<ContentAction> ContentAction::Create(
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error, std::string* error,
...@@ -267,7 +319,7 @@ scoped_refptr<ContentAction> ContentAction::Create( ...@@ -267,7 +319,7 @@ scoped_refptr<ContentAction> ContentAction::Create(
factory_method_iter = factory.factory_methods.find(instance_type); factory_method_iter = factory.factory_methods.find(instance_type);
if (factory_method_iter != factory.factory_methods.end()) if (factory_method_iter != factory.factory_methods.end())
return (*factory_method_iter->second)( return (*factory_method_iter->second)(
extension, action_dict, error, bad_message); browser_context, extension, action_dict, error, bad_message);
*error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str());
return scoped_refptr<ContentAction>(); return scoped_refptr<ContentAction>();
......
...@@ -63,7 +63,9 @@ class ContentAction : public base::RefCounted<ContentAction> { ...@@ -63,7 +63,9 @@ class ContentAction : public base::RefCounted<ContentAction> {
// Sets |error| and returns NULL in case of a semantic error that cannot // Sets |error| and returns NULL in case of a semantic error that cannot
// be caught by schema validation. Sets |bad_message| and returns NULL // be caught by schema validation. Sets |bad_message| and returns NULL
// in case the input is syntactically unexpected. // in case the input is syntactically unexpected.
static scoped_refptr<ContentAction> Create(const Extension* extension, static scoped_refptr<ContentAction> Create(
content::BrowserContext* browser_context,
const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error, std::string* error,
bool* bad_message); bool* bad_message);
......
...@@ -4,13 +4,19 @@ ...@@ -4,13 +4,19 @@
#include "chrome/browser/extensions/api/declarative_content/content_action.h" #include "chrome/browser/extensions/api/declarative_content/content_action.h"
#include "base/run_loop.h"
#include "base/test/values_test_util.h" #include "base/test/values_test_util.h"
#include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/test_extension_environment.h" #include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -21,6 +27,38 @@ namespace { ...@@ -21,6 +27,38 @@ namespace {
using base::test::ParseJson; using base::test::ParseJson;
using testing::HasSubstr; using testing::HasSubstr;
scoped_ptr<base::DictionaryValue> SimpleManifest() {
return DictionaryBuilder()
.Set("name", "extension")
.Set("manifest_version", 2)
.Set("version", "1.0")
.Build();
}
class RequestContentScriptTest : public ExtensionServiceTestBase {
public:
RequestContentScriptTest()
: extension_(ExtensionBuilder().SetManifest(SimpleManifest()).Build()) {};
// TODO(rdevlin.cronin): This should be SetUp(), but an issues with invoking
// InitializeEmptyExtensionService() within SetUp() means that we have to
// call this manually within every test. This can be cleaned up once said
// issue is fixed.
virtual void Init() {
InitializeEmptyExtensionService();
static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))->
SetReady();
base::RunLoop().RunUntilIdle();
}
Profile* profile() { return profile_.get(); }
Extension* extension() { return extension_.get(); }
private:
scoped_refptr<Extension> extension_;
};
TEST(DeclarativeContentActionTest, InvalidCreation) { TEST(DeclarativeContentActionTest, InvalidCreation) {
TestExtensionEnvironment env; TestExtensionEnvironment env;
std::string error; std::string error;
...@@ -29,21 +67,23 @@ TEST(DeclarativeContentActionTest, InvalidCreation) { ...@@ -29,21 +67,23 @@ TEST(DeclarativeContentActionTest, InvalidCreation) {
// Test wrong data type passed. // Test wrong data type passed.
error.clear(); error.clear();
result = ContentAction::Create(NULL, *ParseJson("[]"), &error, &bad_message); result = ContentAction::Create(
NULL, NULL, *ParseJson("[]"), &error, &bad_message);
EXPECT_TRUE(bad_message); EXPECT_TRUE(bad_message);
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
// Test missing instanceType element. // Test missing instanceType element.
error.clear(); error.clear();
result = ContentAction::Create(NULL, *ParseJson("{}"), &error, &bad_message); result = ContentAction::Create(
NULL, NULL, *ParseJson("{}"), &error, &bad_message);
EXPECT_TRUE(bad_message); EXPECT_TRUE(bad_message);
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
// Test wrong instanceType element. // Test wrong instanceType element.
error.clear(); error.clear();
result = ContentAction::Create(NULL, *ParseJson( result = ContentAction::Create(NULL, NULL, *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.UnknownType\",\n" " \"instanceType\": \"declarativeContent.UnknownType\",\n"
"}"), "}"),
...@@ -59,6 +99,7 @@ TEST(DeclarativeContentActionTest, ShowPageActionWithoutPageAction) { ...@@ -59,6 +99,7 @@ TEST(DeclarativeContentActionTest, ShowPageActionWithoutPageAction) {
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL,
extension, extension,
*ParseJson( *ParseJson(
"{\n" "{\n"
...@@ -79,6 +120,7 @@ TEST(DeclarativeContentActionTest, ShowPageAction) { ...@@ -79,6 +120,7 @@ TEST(DeclarativeContentActionTest, ShowPageAction) {
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL,
extension, extension,
*ParseJson( *ParseJson(
"{\n" "{\n"
...@@ -109,13 +151,13 @@ TEST(DeclarativeContentActionTest, ShowPageAction) { ...@@ -109,13 +151,13 @@ TEST(DeclarativeContentActionTest, ShowPageAction) {
EXPECT_FALSE(page_action->GetIsVisible(tab_id)); EXPECT_FALSE(page_action->GetIsVisible(tab_id));
} }
TEST(DeclarativeContentActionTest, RequestContentScriptMissingScripts) { TEST_F(RequestContentScriptTest, MissingScripts) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -129,13 +171,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptMissingScripts) { ...@@ -129,13 +171,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptMissingScripts) {
ASSERT_FALSE(result.get()); ASSERT_FALSE(result.get());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptCSS) { TEST_F(RequestContentScriptTest, CSS) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -149,13 +191,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptCSS) { ...@@ -149,13 +191,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptCSS) {
EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptJS) { TEST_F(RequestContentScriptTest, JS) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -169,13 +211,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptJS) { ...@@ -169,13 +211,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptJS) {
EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptCSSBadType) { TEST_F(RequestContentScriptTest, CSSBadType) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -187,13 +229,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptCSSBadType) { ...@@ -187,13 +229,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptCSSBadType) {
ASSERT_FALSE(result.get()); ASSERT_FALSE(result.get());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) { TEST_F(RequestContentScriptTest, JSBadType) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -205,13 +247,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) { ...@@ -205,13 +247,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) {
ASSERT_FALSE(result.get()); ASSERT_FALSE(result.get());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) { TEST_F(RequestContentScriptTest, AllFrames) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -226,13 +268,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) { ...@@ -226,13 +268,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) {
EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) { TEST_F(RequestContentScriptTest, MatchAboutBlank) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -247,13 +289,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) { ...@@ -247,13 +289,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) {
EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) { TEST_F(RequestContentScriptTest, AllFramesBadType) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
...@@ -266,13 +308,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) { ...@@ -266,13 +308,13 @@ TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) {
ASSERT_FALSE(result.get()); ASSERT_FALSE(result.get());
} }
TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlankBadType) { TEST_F(RequestContentScriptTest, MatchAboutBlankBadType) {
TestExtensionEnvironment env; Init();
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_refptr<const ContentAction> result = ContentAction::Create( scoped_refptr<const ContentAction> result = ContentAction::Create(
NULL, profile(),
extension(),
*ParseJson( *ParseJson(
"{\n" "{\n"
" \"instanceType\": \"declarativeContent.RequestContentScript\",\n" " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
......
...@@ -160,6 +160,7 @@ std::string ContentRulesRegistry::AddRulesImpl( ...@@ -160,6 +160,7 @@ std::string ContentRulesRegistry::AddRulesImpl(
scoped_ptr<ContentRule> content_rule( scoped_ptr<ContentRule> content_rule(
ContentRule::Create(url_matcher_.condition_factory(), ContentRule::Create(url_matcher_.condition_factory(),
profile(),
extension, extension,
extension_installation_time, extension_installation_time,
*rule, *rule,
......
...@@ -513,6 +513,7 @@ bool WebRequestAction::HasPermission(const InfoMap* extension_info_map, ...@@ -513,6 +513,7 @@ bool WebRequestAction::HasPermission(const InfoMap* extension_info_map,
// static // static
scoped_refptr<const WebRequestAction> WebRequestAction::Create( scoped_refptr<const WebRequestAction> WebRequestAction::Create(
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error, std::string* error,
......
...@@ -134,6 +134,7 @@ class WebRequestAction : public base::RefCounted<WebRequestAction> { ...@@ -134,6 +134,7 @@ class WebRequestAction : public base::RefCounted<WebRequestAction> {
// be caught by schema validation. Sets |bad_message| and returns NULL // be caught by schema validation. Sets |bad_message| and returns NULL
// in case the input is syntactically unexpected. // in case the input is syntactically unexpected.
static scoped_refptr<const WebRequestAction> Create( static scoped_refptr<const WebRequestAction> Create(
content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error, std::string* error,
......
...@@ -58,7 +58,7 @@ scoped_ptr<WebRequestActionSet> CreateSetOfActions(const char* json) { ...@@ -58,7 +58,7 @@ scoped_ptr<WebRequestActionSet> CreateSetOfActions(const char* json) {
bool bad_message = false; bool bad_message = false;
scoped_ptr<WebRequestActionSet> action_set( scoped_ptr<WebRequestActionSet> action_set(
WebRequestActionSet::Create(NULL, actions, &error, &bad_message)); WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_FALSE(bad_message); EXPECT_FALSE(bad_message);
CHECK(action_set); CHECK(action_set);
...@@ -186,28 +186,29 @@ TEST(WebRequestActionTest, CreateAction) { ...@@ -186,28 +186,29 @@ TEST(WebRequestActionTest, CreateAction) {
// Test wrong data type passed. // Test wrong data type passed.
error.clear(); error.clear();
base::ListValue empty_list; base::ListValue empty_list;
result = WebRequestAction::Create(NULL, empty_list, &error, &bad_message); result = WebRequestAction::Create(
NULL, NULL, empty_list, &error, &bad_message);
EXPECT_TRUE(bad_message); EXPECT_TRUE(bad_message);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
// Test missing instanceType element. // Test missing instanceType element.
base::DictionaryValue input; base::DictionaryValue input;
error.clear(); error.clear();
result = WebRequestAction::Create(NULL, input, &error, &bad_message); result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(bad_message); EXPECT_TRUE(bad_message);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
// Test wrong instanceType element. // Test wrong instanceType element.
input.SetString(keys::kInstanceTypeKey, kUnknownActionType); input.SetString(keys::kInstanceTypeKey, kUnknownActionType);
error.clear(); error.clear();
result = WebRequestAction::Create(NULL, input, &error, &bad_message); result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_NE("", error); EXPECT_NE("", error);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
// Test success // Test success
input.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); input.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
error.clear(); error.clear();
result = WebRequestAction::Create(NULL, input, &error, &bad_message); result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_EQ("", error); EXPECT_EQ("", error);
EXPECT_FALSE(bad_message); EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get()); ASSERT_TRUE(result.get());
...@@ -223,7 +224,7 @@ TEST(WebRequestActionTest, CreateActionSet) { ...@@ -223,7 +224,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test empty input. // Test empty input.
error.clear(); error.clear();
result = WebRequestActionSet::Create(NULL, input, &error, &bad_message); result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(error.empty()) << error; EXPECT_TRUE(error.empty()) << error;
EXPECT_FALSE(bad_message); EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get()); ASSERT_TRUE(result.get());
...@@ -239,7 +240,7 @@ TEST(WebRequestActionTest, CreateActionSet) { ...@@ -239,7 +240,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test success. // Test success.
input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy())); input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy()));
error.clear(); error.clear();
result = WebRequestActionSet::Create(NULL, input, &error, &bad_message); result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_TRUE(error.empty()) << error; EXPECT_TRUE(error.empty()) << error;
EXPECT_FALSE(bad_message); EXPECT_FALSE(bad_message);
ASSERT_TRUE(result.get()); ASSERT_TRUE(result.get());
...@@ -251,7 +252,7 @@ TEST(WebRequestActionTest, CreateActionSet) { ...@@ -251,7 +252,7 @@ TEST(WebRequestActionTest, CreateActionSet) {
// Test failure. // Test failure.
input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy())); input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy()));
error.clear(); error.clear();
result = WebRequestActionSet::Create(NULL, input, &error, &bad_message); result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
EXPECT_NE("", error); EXPECT_NE("", error);
EXPECT_FALSE(result.get()); EXPECT_FALSE(result.get());
} }
......
...@@ -182,7 +182,7 @@ std::string WebRequestRulesRegistry::AddRulesImpl( ...@@ -182,7 +182,7 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create( scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create(
url_matcher_.condition_factory(), url_matcher_.condition_factory(),
extension, extension_installation_time, *rule, profile(), extension, extension_installation_time, *rule,
base::Bind(&Checker, base::Unretained(extension)), base::Bind(&Checker, base::Unretained(extension)),
&error)); &error));
if (!error.empty()) { if (!error.empty()) {
......
...@@ -706,7 +706,8 @@ TEST(WebRequestRulesRegistrySimpleTest, StageChecker) { ...@@ -706,7 +706,8 @@ TEST(WebRequestRulesRegistrySimpleTest, StageChecker) {
bool bad_message = false; bool bad_message = false;
scoped_ptr<WebRequestActionSet> actions = scoped_ptr<WebRequestActionSet> actions =
WebRequestActionSet::Create(NULL, rule.actions, &error, &bad_message); WebRequestActionSet::Create(
NULL, NULL, rule.actions, &error, &bad_message);
ASSERT_TRUE(error.empty()) << error; ASSERT_TRUE(error.empty()) << error;
ASSERT_FALSE(bad_message); ASSERT_FALSE(bad_message);
ASSERT_TRUE(actions); ASSERT_TRUE(actions);
...@@ -733,7 +734,7 @@ TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) { ...@@ -733,7 +734,7 @@ TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) {
std::string error; std::string error;
bool bad_message = false; bool bad_message = false;
scoped_ptr<WebRequestActionSet> action_set( scoped_ptr<WebRequestActionSet> action_set(
WebRequestActionSet::Create(NULL, actions, &error, &bad_message)); WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
ASSERT_TRUE(error.empty()) << error; ASSERT_TRUE(error.empty()) << error;
ASSERT_FALSE(bad_message); ASSERT_FALSE(bad_message);
ASSERT_TRUE(action_set); ASSERT_TRUE(action_set);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/extensions/blacklist.h" #include "chrome/browser/extensions/blacklist.h"
#include "chrome/browser/extensions/declarative_user_script_master.h"
#include "chrome/browser/extensions/error_console/error_console.h" #include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/install_verifier.h" #include "chrome/browser/extensions/install_verifier.h"
...@@ -196,7 +197,22 @@ scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( ...@@ -196,7 +197,22 @@ scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
DeclarativeUserScriptMaster* DeclarativeUserScriptMaster*
TestExtensionSystem::GetDeclarativeUserScriptMasterByExtension( TestExtensionSystem::GetDeclarativeUserScriptMasterByExtension(
const ExtensionId& extension_id) { const ExtensionId& extension_id) {
return NULL; DCHECK(ready().is_signaled());
DeclarativeUserScriptMaster* master = NULL;
for (ScopedVector<DeclarativeUserScriptMaster>::iterator it =
declarative_user_script_masters_.begin();
it != declarative_user_script_masters_.end();
++it) {
if ((*it)->extension_id() == extension_id) {
master = *it;
break;
}
}
if (!master) {
master = new DeclarativeUserScriptMaster(profile_, extension_id);
declarative_user_script_masters_.push_back(master);
}
return master;
} }
// static // static
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_
#define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_
#include "base/memory/scoped_vector.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/one_shot_event.h" #include "extensions/common/one_shot_event.h"
...@@ -100,6 +101,7 @@ class TestExtensionSystem : public ExtensionSystem { ...@@ -100,6 +101,7 @@ class TestExtensionSystem : public ExtensionSystem {
scoped_ptr<StateStore> state_store_; scoped_ptr<StateStore> state_store_;
// A pointer to the TestingValueStore owned by |state_store_|. // A pointer to the TestingValueStore owned by |state_store_|.
TestingValueStore* value_store_; TestingValueStore* value_store_;
ScopedVector<DeclarativeUserScriptMaster> declarative_user_script_masters_;
scoped_ptr<Blacklist> blacklist_; scoped_ptr<Blacklist> blacklist_;
scoped_ptr<StandardManagementPolicyProvider> scoped_ptr<StandardManagementPolicyProvider>
standard_management_policy_provider_; standard_management_policy_provider_;
......
...@@ -570,7 +570,7 @@ void UserScriptLoader::SendUpdate( ...@@ -570,7 +570,7 @@ void UserScriptLoader::SendUpdate(
if (base::SharedMemory::IsHandleValid(handle_for_process)) { if (base::SharedMemory::IsHandleValid(handle_for_process)) {
process->Send(new ExtensionMsg_UpdateUserScripts( process->Send(new ExtensionMsg_UpdateUserScripts(
handle_for_process, "" /* owner */, changed_extensions)); handle_for_process, owner_extension_id_, changed_extensions));
} }
} }
......
...@@ -66,6 +66,8 @@ class UserScript { ...@@ -66,6 +66,8 @@ class UserScript {
// particular injection point is guaranteed. // particular injection point is guaranteed.
RUN_DEFERRED, // The user script's injection was deferred for permissions RUN_DEFERRED, // The user script's injection was deferred for permissions
// reasons, and was executed at a later time. // reasons, and was executed at a later time.
BROWSER_DRIVEN, // The user script will be injected when triggered by an
// IPC in the browser process.
RUN_LOCATION_LAST // Leave this as the last item. RUN_LOCATION_LAST // Leave this as the last item.
}; };
......
...@@ -48,6 +48,7 @@ void ScriptsRunInfo::LogRun(blink::WebFrame* frame, ...@@ -48,6 +48,7 @@ void ScriptsRunInfo::LogRun(blink::WebFrame* frame,
UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
break; break;
case UserScript::RUN_DEFERRED: case UserScript::RUN_DEFERRED:
case UserScript::BROWSER_DRIVEN:
// TODO(rdevlin.cronin): Add histograms. // TODO(rdevlin.cronin): Add histograms.
break; break;
case UserScript::UNDEFINED: case UserScript::UNDEFINED:
......
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