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 EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ |
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 | 29 |
30 class ExtensionSet; | 30 class ExtensionSet; |
31 class ScriptInjection; | 31 class ScriptInjection; |
32 | 32 |
33 // Manager for separate UserScriptSets, one for each shared memory region. | 33 // Manager for separate UserScriptSets, one for each shared memory region. |
34 // Regions are organized as follows: | 34 // Regions are organized as follows: |
35 // static_scripts -- contains all extensions' scripts that are statically | 35 // static_scripts -- contains all extensions' scripts that are statically |
36 // declared in the extension manifest. | 36 // declared in the extension manifest. |
37 // programmatic_scripts -- one region per extension containing only | 37 // programmatic_scripts -- one region per host (extension or WebUI) containing |
38 // programmatically-declared scripts, instantiated | 38 // only programmatically-declared scripts, instantiated |
39 // when an extension first creates a declarative rule | 39 // when an extension first creates a declarative rule |
40 // that would, if triggered, request a script injection. | 40 // that would, if triggered, request a script injection. |
41 class UserScriptSetManager : public content::RenderProcessObserver { | 41 class UserScriptSetManager : public content::RenderProcessObserver { |
42 public: | 42 public: |
43 // Like a UserScriptSet::Observer, but automatically subscribes to all sets | 43 // Like a UserScriptSet::Observer, but automatically subscribes to all sets |
44 // associated with the manager. | 44 // associated with the manager. |
45 class Observer { | 45 class Observer { |
46 public: | 46 public: |
47 virtual void OnUserScriptsUpdated( | 47 virtual void OnUserScriptsUpdated( |
48 const std::set<std::string>& changed_extensions, | 48 const std::set<HostID>& changed_hosts, |
49 const std::vector<UserScript*>& scripts) = 0; | 49 const std::vector<UserScript*>& scripts) = 0; |
50 }; | 50 }; |
51 | 51 |
52 UserScriptSetManager(const ExtensionSet* extensions); | 52 UserScriptSetManager(const ExtensionSet* extensions); |
53 | 53 |
54 ~UserScriptSetManager() override; | 54 ~UserScriptSetManager() override; |
55 | 55 |
56 void AddObserver(Observer* observer); | 56 void AddObserver(Observer* observer); |
57 void RemoveObserver(Observer* observer); | 57 void RemoveObserver(Observer* observer); |
58 | 58 |
(...skipping 15 matching lines...) Expand all Loading... |
74 UserScript::RunLocation run_location); | 74 UserScript::RunLocation run_location); |
75 | 75 |
76 // Get active extension IDs from |static_scripts| and each of | 76 // Get active extension IDs from |static_scripts| and each of |
77 // |programmatic_scripts_|. | 77 // |programmatic_scripts_|. |
78 void GetAllActiveExtensionIds(std::set<std::string>* ids) const; | 78 void GetAllActiveExtensionIds(std::set<std::string>* ids) const; |
79 | 79 |
80 const UserScriptSet* static_scripts() const { return &static_scripts_; } | 80 const UserScriptSet* static_scripts() const { return &static_scripts_; } |
81 | 81 |
82 private: | 82 private: |
83 // Map for per-extension sets that may be defined programmatically. | 83 // Map for per-extension sets that may be defined programmatically. |
84 typedef std::map<ExtensionId, linked_ptr<UserScriptSet> > UserScriptSetMap; | 84 typedef std::map<HostID, linked_ptr<UserScriptSet> > UserScriptSetMap; |
85 | 85 |
86 // content::RenderProcessObserver implementation. | 86 // content::RenderProcessObserver implementation. |
87 bool OnControlMessageReceived(const IPC::Message& message) override; | 87 bool OnControlMessageReceived(const IPC::Message& message) override; |
88 | 88 |
89 UserScriptSet* GetProgrammaticScriptsByExtension( | 89 UserScriptSet* GetProgrammaticScriptsByHostID(const HostID& host_id); |
90 const ExtensionId& extensionId); | |
91 | 90 |
92 // Handle the UpdateUserScripts extension message. | 91 // Handle the UpdateUserScripts extension message. |
93 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, | 92 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, |
94 const ExtensionId& extension_id, | 93 const HostID& host_id, |
95 const std::set<std::string>& changed_extensions); | 94 const std::set<HostID>& changed_hosts); |
96 | 95 |
97 // Scripts statically defined in extension manifests. | 96 // Scripts statically defined in extension manifests. |
98 UserScriptSet static_scripts_; | 97 UserScriptSet static_scripts_; |
99 | 98 |
100 // Scripts programmatically-defined through API calls (initialized and stored | 99 // Scripts programmatically-defined through API calls (initialized and stored |
101 // per-extension). | 100 // per-extension). |
102 UserScriptSetMap programmatic_scripts_; | 101 UserScriptSetMap programmatic_scripts_; |
103 | 102 |
104 // The set of all known extensions. Owned by the Dispatcher. | 103 // The set of all known extensions. Owned by the Dispatcher. |
105 const ExtensionSet* extensions_; | 104 const ExtensionSet* extensions_; |
106 | 105 |
107 // The associated observers. | 106 // The associated observers. |
108 ObserverList<Observer> observers_; | 107 ObserverList<Observer> observers_; |
109 | 108 |
110 DISALLOW_COPY_AND_ASSIGN(UserScriptSetManager); | 109 DISALLOW_COPY_AND_ASSIGN(UserScriptSetManager); |
111 }; | 110 }; |
112 | 111 |
113 } // namespace extensions | 112 } // namespace extensions |
114 | 113 |
115 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | 114 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ |
OLD | NEW |