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

Side by Side Diff: chrome/browser/extensions/declarative_user_script_manager.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/declarative_user_script_manager.h" 5 #include "chrome/browser/extensions/declarative_user_script_manager.h"
6 6
7 #include "chrome/browser/extensions/declarative_user_script_master.h" 7 #include "chrome/browser/extensions/declarative_user_script_master.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "extensions/browser/extension_registry.h"
8 10
9 namespace extensions { 11 namespace extensions {
10 12
11 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile) 13 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile)
12 : profile_(profile) { 14 : profile_(profile), extension_registry_observer_(this) {
15 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
13 } 16 }
14 17
15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { 18 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
16 } 19 }
17 20
18 DeclarativeUserScriptMaster* 21 DeclarativeUserScriptMaster*
19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( 22 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
20 const std::string& id) { 23 const ConsumerID& consumer_id) {
Devlin 2015/01/21 23:25:20 Thinking about this more, this means that every ti
Xi Han 2015/01/22 17:19:36 This is a good point, and I realize that the curre
21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id); 24 UserScriptMasterMap::iterator it =
25 declarative_user_script_masters_.find(consumer_id);
22 26
23 if (it != declarative_user_script_masters_.end()) 27 if (it != declarative_user_script_masters_.end())
24 return it->second.get(); 28 return it->second.get();
25 29
30 return CreateDeclarativeUserScriptMaster(consumer_id);
31 }
32
33 DeclarativeUserScriptMaster*
34 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
35 const ConsumerID& consumer_id) {
26 linked_ptr<DeclarativeUserScriptMaster> master( 36 linked_ptr<DeclarativeUserScriptMaster> master(
27 new DeclarativeUserScriptMaster(profile_, id)); 37 new DeclarativeUserScriptMaster(profile_, consumer_id));
28 declarative_user_script_masters_[id] = master; 38 declarative_user_script_masters_[consumer_id] = master;
29 return master.get(); 39 return master.get();
30 } 40 }
31 41
32 } // extensions 42 void DeclarativeUserScriptManager::OnExtensionUnloaded(
43 content::BrowserContext* browser_context,
44 const Extension* extension,
45 UnloadedExtensionInfo::Reason reason) {
46 for (const auto& val : declarative_user_script_masters_) {
47 DeclarativeUserScriptMaster* master = val.second.get();
48 if (master->consumer_id().host_id() == extension->id())
49 master->ClearScripts();
50 }
51 }
52
53 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698