| Index: chrome/browser/extensions/api/declarative_content/content_action.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_content/content_action.cc b/chrome/browser/extensions/api/declarative_content/content_action.cc
|
| index e0ff006e16d05bc8418a6014f331bb6300debe48..bc764f4841c8a2066bf2d793958ec5aa4128bcb8 100644
|
| --- a/chrome/browser/extensions/api/declarative_content/content_action.cc
|
| +++ b/chrome/browser/extensions/api/declarative_content/content_action.cc
|
| @@ -7,6 +7,7 @@
|
| #include <map>
|
|
|
| #include "base/lazy_instance.h"
|
| +#include "base/memory/linked_ptr.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
|
| @@ -22,6 +23,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "extensions/browser/extension_registry.h"
|
| #include "extensions/browser/extension_system.h"
|
| +#include "extensions/common/consumer.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_messages.h"
|
| #include "ui/gfx/image/image.h"
|
| @@ -239,6 +241,32 @@ struct ContentActionFactory {
|
| base::LazyInstance<ContentActionFactory>::Leaky
|
| g_content_action_factory = LAZY_INSTANCE_INITIALIZER;
|
|
|
| +using RequestContentScriptKey = RequestContentScript::RequestKey;
|
| +
|
| +using RequestContentScriptKeyToIDMap =
|
| + std::map<RequestContentScriptKey, linked_ptr<ConsumerID>>;
|
| +
|
| +// A map of ConsumerIDs for the given RequestContentScript ids.
|
| +// Different types of input ids will define their own maps to store the
|
| +// mappings from ids to ConsumerIDs.
|
| +static base::LazyInstance<RequestContentScriptKeyToIDMap>
|
| + request_content_script_key_to_id_map_ = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +const ConsumerID& GetConsumerID(
|
| + const RequestContentScriptKey& key,
|
| + ConsumerID::HostType host_type,
|
| + ConsumerID::InstanceType instance_type) {
|
| + RequestContentScriptKeyToIDMap::iterator it =
|
| + request_content_script_key_to_id_map_.Get().find(key);
|
| + if (it != request_content_script_key_to_id_map_.Get().end())
|
| + return *(it->second.get());
|
| +
|
| + linked_ptr<ConsumerID> consumer_id(new ConsumerID(
|
| + host_type, key.host_id, instance_type, ConsumerID::GetNextID()));
|
| + request_content_script_key_to_id_map_.Get()[key] = consumer_id;
|
| + return *(consumer_id.get());
|
| +}
|
| +
|
| } // namespace
|
|
|
| //
|
| @@ -350,11 +378,13 @@ RequestContentScript::RequestContentScript(
|
| content::BrowserContext* browser_context,
|
| const Extension* extension,
|
| const ScriptData& script_data) {
|
| - InitScript(extension, script_data);
|
| -
|
| + const RequestKey key(extension->id());
|
| + const ConsumerID& consumer_id = GetConsumerID(
|
| + key, ConsumerID::EXTENSIONS, ConsumerID::TAB);
|
| master_ = ExtensionSystem::Get(browser_context)
|
| ->declarative_user_script_manager()
|
| - ->GetDeclarativeUserScriptMasterByID(extension->id());
|
| + ->GetDeclarativeUserScriptMasterByID(consumer_id);
|
| + InitScript(extension, script_data);
|
| AddScript();
|
| }
|
|
|
| @@ -362,21 +392,20 @@ RequestContentScript::RequestContentScript(
|
| DeclarativeUserScriptMaster* master,
|
| const Extension* extension,
|
| const ScriptData& script_data) {
|
| + master_.reset(master);
|
| InitScript(extension, script_data);
|
| -
|
| - master_ = master;
|
| AddScript();
|
| }
|
|
|
| RequestContentScript::~RequestContentScript() {
|
| - DCHECK(master_);
|
| + DCHECK(master_.get());
|
| master_->RemoveScript(script_);
|
| }
|
|
|
| void RequestContentScript::InitScript(const Extension* extension,
|
| const ScriptData& script_data) {
|
| script_.set_id(UserScript::GenerateUserScriptID());
|
| - script_.set_extension_id(extension->id());
|
| + script_.set_consumer_id(master_->consumer_id());
|
| script_.set_run_location(UserScript::BROWSER_DRIVEN);
|
| script_.set_match_all_frames(script_data.all_frames);
|
| script_.set_match_about_blank(script_data.match_about_blank);
|
|
|