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_master.h" | 5 #include "chrome/browser/extensions/declarative_user_script_master.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "extensions/browser/extension_registry.h" |
10 | 11 |
11 namespace extensions { | 12 namespace extensions { |
12 | 13 |
13 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(Profile* profile, | 14 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( |
14 const HostID& host_id) | 15 Profile* profile, |
15 : host_id_(host_id), | 16 const ExtensionId& extension_id) |
| 17 : extension_id_(extension_id), |
16 loader_(profile, | 18 loader_(profile, |
17 host_id, | 19 extension_id, |
18 false /* listen_for_extension_system_loaded */) { | 20 false /* listen_for_extension_system_loaded */), |
| 21 extension_registry_observer_(this) { |
| 22 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); |
19 } | 23 } |
20 | 24 |
21 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { | 25 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { |
22 } | 26 } |
23 | 27 |
| 28 void DeclarativeUserScriptMaster::OnExtensionUnloaded( |
| 29 content::BrowserContext* browser_context, |
| 30 const Extension* extension, |
| 31 UnloadedExtensionInfo::Reason reason) { |
| 32 if (extension_id_ == extension->id()) |
| 33 ClearScripts(); |
| 34 } |
| 35 |
24 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { | 36 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { |
25 std::set<UserScript> set; | 37 std::set<UserScript> set; |
26 set.insert(script); | 38 set.insert(script); |
27 loader_.AddScripts(set); | 39 loader_.AddScripts(set); |
28 } | 40 } |
29 | 41 |
30 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { | 42 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { |
31 std::set<UserScript> set; | 43 std::set<UserScript> set; |
32 set.insert(script); | 44 set.insert(script); |
33 loader_.RemoveScripts(set); | 45 loader_.RemoveScripts(set); |
34 } | 46 } |
35 | 47 |
36 void DeclarativeUserScriptMaster::ClearScripts() { | 48 void DeclarativeUserScriptMaster::ClearScripts() { |
37 loader_.ClearScripts(); | 49 loader_.ClearScripts(); |
38 } | 50 } |
39 | 51 |
40 } // namespace extensions | 52 } // namespace extensions |
OLD | NEW |