Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6923)

Unified Diff: chrome/browser/extensions/api/declarative_content/content_action.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change ConsumerID to class; remove usages of linked_ptr, and nits. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..58559db0a5d44c30cd058b86dea5390dc4403913 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"
Devlin 2015/01/20 17:51:04 nit: Don't need this, right?
Xi Han 2015/01/21 21:30:16 Sorry, forget to clean up.
#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,33 @@ struct ContentActionFactory {
base::LazyInstance<ContentActionFactory>::Leaky
g_content_action_factory = LAZY_INSTANCE_INITIALIZER;
+using RequestContentScriptKey = RequestContentScript::RequestKey;
+
+using RequestContentScriptKeyToIDMap =
+ std::map<RequestContentScriptKey, ConsumerID>;
+
+// A map of ConsumerIDs for the given RequestContentScript ids.
+// Different types of input ids need to define their own maps to store the
+// mappings from ids to ConsumerIDs.
+base::LazyInstance<RequestContentScriptKeyToIDMap>
+ request_content_script_key_to_id_map_ = LAZY_INSTANCE_INITIALIZER;
+
+// Looks up and returns the ConsumerID by the given RequestContentScriptKey;
+// if one does not exist, a new object will be created and returned.
+const ConsumerID& GetConsumerID(const RequestContentScriptKey& key,
+ ConsumerID::HostType host_type,
+ ConsumerID::InstanceType instance_type) {
+ RequestContentScriptKeyToIDMap& map =
+ request_content_script_key_to_id_map_.Get();
+ RequestContentScriptKeyToIDMap::iterator it = map.find(key);
Devlin 2015/01/20 17:51:05 instead of lines 263 - 268, do: if (it == map.end(
Xi Han 2015/01/21 21:30:16 Goods better, updated.
+ if (it != map.end())
+ return it->second;
+
+ map[key] = ConsumerID(host_type, key.host_id, instance_type,
+ ConsumerID::GetNextID());
+ return map[key];
+}
+
} // namespace
//
@@ -350,11 +379,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,9 +393,8 @@ RequestContentScript::RequestContentScript(
DeclarativeUserScriptMaster* master,
const Extension* extension,
const ScriptData& script_data) {
- InitScript(extension, script_data);
-
master_ = master;
+ InitScript(extension, script_data);
AddScript();
}
@@ -376,7 +406,7 @@ RequestContentScript::~RequestContentScript() {
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);

Powered by Google App Engine
This is Rietveld 408576698