OLD | NEW |
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 HostID& host_id) { |
21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id); | 24 UserScriptMasterMap::iterator it = |
| 25 declarative_user_script_masters_.find(host_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(host_id); |
| 31 } |
| 32 |
| 33 DeclarativeUserScriptMaster* |
| 34 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster( |
| 35 const HostID& host_id) { |
26 linked_ptr<DeclarativeUserScriptMaster> master( | 36 linked_ptr<DeclarativeUserScriptMaster> master( |
27 new DeclarativeUserScriptMaster(profile_, id)); | 37 new DeclarativeUserScriptMaster(profile_, host_id)); |
28 declarative_user_script_masters_[id] = master; | 38 declarative_user_script_masters_[host_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->host_id().id() == extension->id()) |
| 49 master->ClearScripts(); |
| 50 } |
| 51 } |
| 52 |
| 53 } // namespace extensions |
OLD | NEW |