Add Reapply() to declarative action interface. This is needed for...

Add Reapply() to declarative action interface. This is needed for RequestContentScript to work correctly from one matching page to the next.

BUG=377978

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

Cr-Commit-Position: refs/heads/master@{#291094}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291094 0039d316-1c4b-4281-b951-d872f2087c98
parent 9fdfbe2a
...@@ -156,6 +156,12 @@ class DeclarativeActionSet { ...@@ -156,6 +156,12 @@ class DeclarativeActionSet {
const base::Time& extension_install_time, const base::Time& extension_install_time,
typename ActionT::ApplyInfo* apply_info) const; typename ActionT::ApplyInfo* apply_info) const;
// Rules call this method when their conditions are fulfilled, but Apply has
// already been called.
void Reapply(const std::string& extension_id,
const base::Time& extension_install_time,
typename ActionT::ApplyInfo* apply_info) const;
// Rules call this method when they have stateful conditions, and those // Rules call this method when they have stateful conditions, and those
// conditions stop being fulfilled. Rules with event-based conditions (e.g. a // conditions stop being fulfilled. Rules with event-based conditions (e.g. a
// network request happened) will never Revert() an action. // network request happened) will never Revert() an action.
...@@ -383,6 +389,16 @@ void DeclarativeActionSet<ActionT>::Apply( ...@@ -383,6 +389,16 @@ void DeclarativeActionSet<ActionT>::Apply(
(*i)->Apply(extension_id, extension_install_time, apply_info); (*i)->Apply(extension_id, extension_install_time, apply_info);
} }
template<typename ActionT>
void DeclarativeActionSet<ActionT>::Reapply(
const std::string& extension_id,
const base::Time& extension_install_time,
typename ActionT::ApplyInfo* apply_info) const {
for (typename Actions::const_iterator i = actions_.begin();
i != actions_.end(); ++i)
(*i)->Reapply(extension_id, extension_install_time, apply_info);
}
template<typename ActionT> template<typename ActionT>
void DeclarativeActionSet<ActionT>::Revert( void DeclarativeActionSet<ActionT>::Revert(
const std::string& extension_id, const std::string& extension_id,
......
...@@ -70,6 +70,10 @@ class ShowPageAction : public ContentAction { ...@@ -70,6 +70,10 @@ class ShowPageAction : public ContentAction {
ExtensionActionAPI::Get(apply_info->profile)->NotifyChange( ExtensionActionAPI::Get(apply_info->profile)->NotifyChange(
action, apply_info->tab, apply_info->profile); action, apply_info->tab, apply_info->profile);
} }
// The page action is already showing, so nothing needs to be done here.
virtual void Reapply(const std::string& extension_id,
const base::Time& extension_install_time,
ApplyInfo* apply_info) const OVERRIDE {}
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 {
...@@ -125,6 +129,13 @@ class RequestContentScript : public ContentAction { ...@@ -125,6 +129,13 @@ class RequestContentScript : public ContentAction {
// load new user script. // load new user script.
} }
virtual void Reapply(const std::string& extension_id,
const base::Time& extension_install_time,
ApplyInfo* apply_info) const OVERRIDE {
// TODO(markdittmer): Invoke UserScriptMaster declarative script loader:
// 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 {
......
...@@ -45,10 +45,14 @@ class ContentAction : public base::RefCounted<ContentAction> { ...@@ -45,10 +45,14 @@ class ContentAction : public base::RefCounted<ContentAction> {
// Applies or reverts this ContentAction on a particular tab for a particular // Applies or reverts this ContentAction on a particular tab for a particular
// extension. Revert exists to keep the actions up to date as the page // extension. Revert exists to keep the actions up to date as the page
// changes. // changes. Reapply exists to reapply changes to a new page, even if the
// previous page also matched relevant conditions.
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 = 0; ApplyInfo* apply_info) const = 0;
virtual void Reapply(const std::string& extension_id,
const base::Time& extension_install_time,
ApplyInfo* apply_info) const = 0;
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 = 0; ApplyInfo* apply_info) const = 0;
......
...@@ -80,8 +80,12 @@ void ContentRulesRegistry::Apply( ...@@ -80,8 +80,12 @@ void ContentRulesRegistry::Apply(
}; };
for (std::set<ContentRule*>::const_iterator it = matching_rules.begin(); for (std::set<ContentRule*>::const_iterator it = matching_rules.begin();
it != matching_rules.end(); ++it) { it != matching_rules.end(); ++it) {
if (!ContainsKey(prev_matching_rules, *it)) if (!ContainsKey(prev_matching_rules, *it)) {
(*it)->actions().Apply((*it)->extension_id(), base::Time(), &apply_info); (*it)->actions().Apply((*it)->extension_id(), base::Time(), &apply_info);
} else {
(*it)->actions().Reapply(
(*it)->extension_id(), base::Time(), &apply_info);
}
} }
for (std::set<ContentRule*>::const_iterator it = prev_matching_rules.begin(); for (std::set<ContentRule*>::const_iterator it = prev_matching_rules.begin();
it != prev_matching_rules.end(); ++it) { it != prev_matching_rules.end(); ++it) {
......
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