| 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" | |
| 11 | 10 |
| 12 namespace extensions { | 11 namespace extensions { |
| 13 | 12 |
| 14 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( | 13 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(Profile* profile, |
| 15 Profile* profile, | 14 const HostID& host_id) |
| 16 const ExtensionId& extension_id) | 15 : host_id_(host_id), |
| 17 : extension_id_(extension_id), | |
| 18 loader_(profile, | 16 loader_(profile, |
| 19 extension_id, | 17 host_id, |
| 20 false /* listen_for_extension_system_loaded */), | 18 false /* listen_for_extension_system_loaded */) { |
| 21 extension_registry_observer_(this) { | |
| 22 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); | |
| 23 } | 19 } |
| 24 | 20 |
| 25 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { | 21 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { |
| 26 } | 22 } |
| 27 | 23 |
| 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 | |
| 36 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { | 24 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) { |
| 37 std::set<UserScript> set; | 25 std::set<UserScript> set; |
| 38 set.insert(script); | 26 set.insert(script); |
| 39 loader_.AddScripts(set); | 27 loader_.AddScripts(set); |
| 40 } | 28 } |
| 41 | 29 |
| 42 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { | 30 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) { |
| 43 std::set<UserScript> set; | 31 std::set<UserScript> set; |
| 44 set.insert(script); | 32 set.insert(script); |
| 45 loader_.RemoveScripts(set); | 33 loader_.RemoveScripts(set); |
| 46 } | 34 } |
| 47 | 35 |
| 48 void DeclarativeUserScriptMaster::ClearScripts() { | 36 void DeclarativeUserScriptMaster::ClearScripts() { |
| 49 loader_.ClearScripts(); | 37 loader_.ClearScripts(); |
| 50 } | 38 } |
| 51 | 39 |
| 52 } // namespace extensions | 40 } // namespace extensions |
| OLD | NEW |