| 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 #ifndef CHROME_BROWSER_EXTENSIONS_SHARED_USER_SCRIPT_MASTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SHARED_USER_SCRIPT_MASTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include "base/memory/shared_memory.h" |
| 9 | |
| 10 #include "base/scoped_observer.h" | |
| 11 #include "chrome/browser/extensions/user_script_loader.h" | 9 #include "chrome/browser/extensions/user_script_loader.h" |
| 10 #include "content/public/browser/notification_observer.h" |
| 11 #include "content/public/browser/notification_registrar.h" |
| 12 #include "extensions/browser/extension_registry_observer.h" | 12 #include "extensions/browser/extension_registry_observer.h" |
| 13 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
| 14 #include "extensions/common/extension_set.h" |
| 14 #include "extensions/common/user_script.h" | 15 #include "extensions/common/user_script.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class BrowserContext; | 18 class BrowserContext; |
| 18 } | 19 } |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 25 class ContentVerifier; |
| 24 class ExtensionRegistry; | 26 class ExtensionRegistry; |
| 25 | 27 |
| 26 // Manages statically-defined user scripts for all extensions. Owns a | 28 // UserScriptLoader for extensions. |
| 27 // UserScriptLoader to which file loading and shared memory management | 29 class ExtensionUserScriptLoader : public UserScriptLoader, |
| 28 // operations are delegated. | 30 public ExtensionRegistryObserver { |
| 29 class SharedUserScriptMaster : public ExtensionRegistryObserver { | |
| 30 public: | 31 public: |
| 31 explicit SharedUserScriptMaster(Profile* profile); | 32 ExtensionUserScriptLoader(Profile* profile, |
| 32 ~SharedUserScriptMaster() override; | 33 const ConsumerID& consumer_id, |
| 33 | 34 bool listen_for_extension_system_loaded); |
| 34 // Provides access to loader state method: scripts_ready(). | 35 ~ExtensionUserScriptLoader() override; |
| 35 bool scripts_ready() const { return loader_.scripts_ready(); } | |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 static bool LoadScriptContent(ConsumerID* consumer_id, |
| 39 UserScript::File* script_file, |
| 40 const SubstitutionMap* localization_messages, |
| 41 scoped_refptr<ContentVerifier> verifier); |
| 42 |
| 43 // UserScriptLoader implementation. |
| 44 void UpdateConsumersInfo() override; |
| 45 bool ready() override; |
| 46 ContentVerifier* GetContentVerifier() override; |
| 47 LoadUserScriptsFunctionCallback GetLoadUserScriptsFunction() override; |
| 48 void SendUpdate(content::RenderProcessHost* process, |
| 49 base::SharedMemoryHandle handle_for_process, |
| 50 const std::set<ConsumerID>& changed_consumers) override; |
| 51 |
| 38 // ExtensionRegistryObserver implementation. | 52 // ExtensionRegistryObserver implementation. |
| 39 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
| 40 const Extension* extension) override; | |
| 41 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 53 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 42 const Extension* extension, | 54 const Extension* extension, |
| 43 UnloadedExtensionInfo::Reason reason) override; | 55 UnloadedExtensionInfo::Reason reason) override; |
| 44 | 56 |
| 45 // Gets an extension's scripts' metadata; i.e., gets a list of UserScript | 57 // Initiates script load when we have been waiting for the extension system |
| 46 // objects that contains script info, but not the contents of the scripts. | 58 // to be ready. |
| 47 const std::set<UserScript> GetScriptsMetadata(const Extension* extension); | 59 void OnExtensionSystemReady(); |
| 48 | 60 |
| 49 // Script loader that handles loading contents of scripts into shared memory | 61 // If the extensions service has finished loading its initial set of |
| 50 // and notifying renderers of scripts in shared memory. | 62 // extensions. |
| 51 UserScriptLoader loader_; | 63 bool extension_system_ready_; |
| 52 | |
| 53 // The profile for which the scripts managed here are installed. | |
| 54 Profile* profile_; | |
| 55 | 64 |
| 56 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 65 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 57 extension_registry_observer_; | 66 extension_registry_observer_; |
| 58 | 67 |
| 59 DISALLOW_COPY_AND_ASSIGN(SharedUserScriptMaster); | 68 base::WeakPtrFactory<ExtensionUserScriptLoader> weak_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(ExtensionUserScriptLoader); |
| 60 }; | 71 }; |
| 61 | 72 |
| 62 } // namespace extensions | 73 } // namespace extensions |
| 63 | 74 |
| 64 #endif // CHROME_BROWSER_EXTENSIONS_SHARED_USER_SCRIPT_MASTER_H_ | 75 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_USER_SCRIPT_LOADER_H_ |
| OLD | NEW |