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

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: Another round of comments of Devlin@. 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..25641812a9a19fdbb27e77b5a37863bf1172b4cb 100644
--- a/chrome/browser/extensions/api/declarative_content/content_action.cc
+++ b/chrome/browser/extensions/api/declarative_content/content_action.cc
@@ -22,6 +22,7 @@
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/common/consumer_id.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
#include "ui/gfx/image/image.h"
@@ -239,6 +240,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();
+ auto it = map.find(key);
+ if (it == map.end()) {
+ it = map.insert(std::make_pair(key,
+ ConsumerID(host_type, key, instance_type,
+ true /* is_declarative*/))).first;
+ }
+ return it->second;
+}
+
} // 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());
Devlin 2015/01/21 23:25:20 I think the typedef to RequestKey actually makes i
Xi Han 2015/01/22 17:19:36 Sorry, but no. To support <webview>, we need to ex
+ 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 +392,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 +405,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