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> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "content/public/renderer/render_process_observer.h" | 15 #include "content/public/renderer/render_process_observer.h" |
16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
17 #include "extensions/common/user_script.h" | 17 #include "extensions/common/user_script.h" |
18 #include "extensions/renderer/user_script_set.h" | 18 #include "extensions/renderer/user_script_set.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class RenderFrame; | 21 class RenderFrame; |
22 } | 22 } |
23 | 23 |
24 namespace IPC { | 24 namespace IPC { |
25 class Message; | 25 class Message; |
26 } | 26 } |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 | 29 |
30 class ExtensionSet; | |
31 class ScriptInjection; | 30 class ScriptInjection; |
32 | 31 |
33 // Manager for separate UserScriptSets, one for each shared memory region. | 32 // Manager for separate UserScriptSets, one for each shared memory region. |
34 // Regions are organized as follows: | 33 // Regions are organized as follows: |
35 // static_scripts -- contains all extensions' scripts that are statically | 34 // static_scripts -- contains all extensions' scripts that are statically |
36 // declared in the extension manifest. | 35 // declared in the extension manifest. |
37 // programmatic_scripts -- one region per host (extension or WebUI) containing | 36 // programmatic_scripts -- one region per host (extension or WebUI) containing |
38 // only programmatically-declared scripts, instantiated | 37 // only programmatically-declared scripts, instantiated |
39 // when an extension first creates a declarative rule | 38 // when an extension first creates a declarative rule |
40 // that would, if triggered, request a script injection. | 39 // that would, if triggered, request a script injection. |
41 class UserScriptSetManager : public content::RenderProcessObserver { | 40 class UserScriptSetManager : public content::RenderProcessObserver { |
42 public: | 41 public: |
43 // Like a UserScriptSet::Observer, but automatically subscribes to all sets | 42 // Like a UserScriptSet::Observer, but automatically subscribes to all sets |
44 // associated with the manager. | 43 // associated with the manager. |
45 class Observer { | 44 class Observer { |
46 public: | 45 public: |
47 virtual void OnUserScriptsUpdated( | 46 virtual void OnUserScriptsUpdated( |
48 const std::set<HostID>& changed_hosts, | 47 const std::set<HostID>& changed_hosts, |
49 const std::vector<UserScript*>& scripts) = 0; | 48 const std::vector<UserScript*>& scripts) = 0; |
50 }; | 49 }; |
51 | 50 |
52 UserScriptSetManager(const ExtensionSet* extensions); | 51 UserScriptSetManager(); |
53 | 52 |
54 ~UserScriptSetManager() override; | 53 ~UserScriptSetManager() override; |
55 | 54 |
56 void AddObserver(Observer* observer); | 55 void AddObserver(Observer* observer); |
57 void RemoveObserver(Observer* observer); | 56 void RemoveObserver(Observer* observer); |
58 | 57 |
59 // Looks up the script injection associated with |script_id| and | 58 // Looks up the script injection associated with |script_id| and |
60 // |extension_id| in the context of the given |web_frame|, |tab_id|, | 59 // |extension_id| in the context of the given |web_frame|, |tab_id|, |
61 // and |url|. | 60 // and |url|. |
62 scoped_ptr<ScriptInjection> GetInjectionForDeclarativeScript( | 61 scoped_ptr<ScriptInjection> GetInjectionForDeclarativeScript( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 const std::set<HostID>& changed_hosts, | 93 const std::set<HostID>& changed_hosts, |
95 bool whitelisted_only); | 94 bool whitelisted_only); |
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. | |
105 const ExtensionSet* extensions_; | |
106 | |
107 // The associated observers. | 103 // The associated observers. |
108 base::ObserverList<Observer> observers_; | 104 base::ObserverList<Observer> observers_; |
109 | 105 |
110 DISALLOW_COPY_AND_ASSIGN(UserScriptSetManager); | 106 DISALLOW_COPY_AND_ASSIGN(UserScriptSetManager); |
111 }; | 107 }; |
112 | 108 |
113 } // namespace extensions | 109 } // namespace extensions |
114 | 110 |
115 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | 111 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ |
OLD | NEW |