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_SLAVE_H_ | 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ |
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ | 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 28 matching lines...) Expand all Loading... |
39 explicit UserScriptSlave(const ExtensionSet* extensions); | 39 explicit UserScriptSlave(const ExtensionSet* extensions); |
40 ~UserScriptSlave(); | 40 ~UserScriptSlave(); |
41 | 41 |
42 // Returns the unique set of extension IDs this UserScriptSlave knows about. | 42 // Returns the unique set of extension IDs this UserScriptSlave knows about. |
43 void GetActiveExtensions(std::set<std::string>* extension_ids); | 43 void GetActiveExtensions(std::set<std::string>* extension_ids); |
44 | 44 |
45 // Gets the extension with the given |id|, if one exists. | 45 // Gets the extension with the given |id|, if one exists. |
46 const Extension* GetExtension(const std::string& extension_id); | 46 const Extension* GetExtension(const std::string& extension_id); |
47 | 47 |
48 // Update the parsed scripts from shared memory. | 48 // Update the parsed scripts from shared memory. |
49 // If |changed_extensions| is not empty, only those extensions will be | 49 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
50 // updated. | |
51 // Otherwise, all extensions will be updated. | |
52 bool UpdateScripts(base::SharedMemoryHandle shared_memory, | |
53 const std::set<std::string>& changed_extensions); | |
54 | 50 |
55 // Gets the isolated world ID to use for the given |extension| in the given | 51 // Gets the isolated world ID to use for the given |extension| in the given |
56 // |frame|. If no isolated world has been created for that extension, | 52 // |frame|. If no isolated world has been created for that extension, |
57 // one will be created and initialized. | 53 // one will be created and initialized. |
58 int GetIsolatedWorldIdForExtension(const Extension* extension, | 54 int GetIsolatedWorldIdForExtension(const Extension* extension, |
59 blink::WebFrame* frame); | 55 blink::WebFrame* frame); |
60 | 56 |
61 // Gets the id of the extension running in a given isolated world. If no such | 57 // Gets the id of the extension running in a given isolated world. If no such |
62 // isolated world exists, or no extension is running in it, returns empty | 58 // isolated world exists, or no extension is running in it, returns empty |
63 // string. | 59 // string. |
64 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); | 60 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); |
65 | 61 |
66 void RemoveIsolatedWorld(const std::string& extension_id); | 62 void RemoveIsolatedWorld(const std::string& extension_id); |
67 | 63 |
68 // Inject the appropriate scripts into a frame based on its URL. | 64 // Inject the appropriate scripts into a frame based on its URL. |
69 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | 65 // TODO(aa): Extract a UserScriptFrame interface out of this to improve |
70 // testability. | 66 // testability. |
71 void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location); | 67 void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location); |
72 | 68 |
73 // Allow an extension to inject scripts that were previously delayed for user | |
74 // approval. | |
75 void OnContentScriptGrantedPermission( | |
76 content::RenderView* render_view, int request_id); | |
77 | |
78 // Notify the UserScriptSlave that the |frame| is detached, and about to die. | |
79 void FrameDetached(blink::WebFrame* frame); | |
80 | |
81 private: | 69 private: |
82 // Log the data from scripts being run, including doing UMA and notifying the | 70 // Log the data from scripts being run, including doing UMA and notifying the |
83 // browser. | 71 // browser. |
84 void LogScriptsRun(blink::WebFrame* frame, | 72 void LogScriptsRun(blink::WebFrame* frame, |
85 UserScript::RunLocation location, | 73 UserScript::RunLocation location, |
86 const ScriptInjection::ScriptsRunInfo& info); | 74 const ScriptInjection::ScriptsRunInfo& info); |
87 | 75 |
88 // Shared memory containing raw script data. | 76 // Shared memory containing raw script data. |
89 scoped_ptr<base::SharedMemory> shared_memory_; | 77 scoped_ptr<base::SharedMemory> shared_memory_; |
90 | 78 |
91 // Parsed script data, ready to inject. | 79 // Parsed script data, ready to inject. |
92 ScopedVector<ScriptInjection> script_injections_; | 80 ScopedVector<ScriptInjection> script_injections_; |
93 | 81 |
94 // Extension metadata. | 82 // Extension metadata. |
95 const ExtensionSet* extensions_; | 83 const ExtensionSet* extensions_; |
96 | 84 |
97 typedef std::map<std::string, int> IsolatedWorldMap; | 85 typedef std::map<std::string, int> IsolatedWorldMap; |
98 IsolatedWorldMap isolated_world_ids_; | 86 IsolatedWorldMap isolated_world_ids_; |
99 | 87 |
100 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); | 88 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); |
101 }; | 89 }; |
102 | 90 |
103 } // namespace extensions | 91 } // namespace extensions |
104 | 92 |
105 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ | 93 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ |
OLD | NEW |