OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
18 #include "chrome/common/extensions/user_script.h" | 18 #include "chrome/common/extensions/user_script.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
20 | 20 |
21 class Extension; | |
22 class ExtensionSet; | 21 class ExtensionSet; |
23 class GURL; | 22 class GURL; |
24 | 23 |
| 24 namespace extensions { |
| 25 class Extension; |
| 26 } |
| 27 |
25 namespace WebKit { | 28 namespace WebKit { |
26 class WebFrame; | 29 class WebFrame; |
27 } | 30 } |
28 | 31 |
29 using WebKit::WebScriptSource; | 32 using WebKit::WebScriptSource; |
30 | 33 |
31 // Manages installed UserScripts for a render process. | 34 // Manages installed UserScripts for a render process. |
32 class UserScriptSlave { | 35 class UserScriptSlave { |
33 public: | 36 public: |
34 // Utility to get the URL we will match against for a frame. If the frame has | 37 // Utility to get the URL we will match against for a frame. If the frame has |
(...skipping 10 matching lines...) Expand all Loading... |
45 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | 48 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
46 | 49 |
47 // Inject the appropriate scripts into a frame based on its URL. | 50 // Inject the appropriate scripts into a frame based on its URL. |
48 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | 51 // TODO(aa): Extract a UserScriptFrame interface out of this to improve |
49 // testability. | 52 // testability. |
50 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); | 53 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); |
51 | 54 |
52 // Gets the isolated world ID to use for the given |extension| in the given | 55 // Gets the isolated world ID to use for the given |extension| in the given |
53 // |frame|. If no isolated world has been created for that extension, | 56 // |frame|. If no isolated world has been created for that extension, |
54 // one will be created and initialized. | 57 // one will be created and initialized. |
55 int GetIsolatedWorldIdForExtension(const Extension* extension, | 58 int GetIsolatedWorldIdForExtension(const extensions::Extension* extension, |
56 WebKit::WebFrame* frame); | 59 WebKit::WebFrame* frame); |
57 | 60 |
58 // Gets the id of the extension running in a given isolated world. If no such | 61 // Gets the id of the extension running in a given isolated world. If no such |
59 // isolated world exists, or no extension is running in it, returns empty | 62 // isolated world exists, or no extension is running in it, returns empty |
60 // string. | 63 // string. |
61 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); | 64 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); |
62 | 65 |
63 void RemoveIsolatedWorld(const std::string& extension_id); | 66 void RemoveIsolatedWorld(const std::string& extension_id); |
64 | 67 |
65 private: | 68 private: |
66 static void InitializeIsolatedWorld(int isolated_world_id, | 69 static void InitializeIsolatedWorld(int isolated_world_id, |
67 const Extension* extension); | 70 const extensions::Extension* extension); |
68 | 71 |
69 // Shared memory containing raw script data. | 72 // Shared memory containing raw script data. |
70 scoped_ptr<base::SharedMemory> shared_memory_; | 73 scoped_ptr<base::SharedMemory> shared_memory_; |
71 | 74 |
72 // Parsed script data. | 75 // Parsed script data. |
73 std::vector<UserScript*> scripts_; | 76 std::vector<UserScript*> scripts_; |
74 STLElementDeleter<std::vector<UserScript*> > script_deleter_; | 77 STLElementDeleter<std::vector<UserScript*> > script_deleter_; |
75 | 78 |
76 // Greasemonkey API source that is injected with the scripts. | 79 // Greasemonkey API source that is injected with the scripts. |
77 base::StringPiece api_js_; | 80 base::StringPiece api_js_; |
78 | 81 |
79 // Extension metadata. | 82 // Extension metadata. |
80 const ExtensionSet* extensions_; | 83 const ExtensionSet* extensions_; |
81 | 84 |
82 typedef std::map<std::string, int> IsolatedWorldMap; | 85 typedef std::map<std::string, int> IsolatedWorldMap; |
83 IsolatedWorldMap isolated_world_ids_; | 86 IsolatedWorldMap isolated_world_ids_; |
84 | 87 |
85 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); | 88 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); |
86 }; | 89 }; |
87 | 90 |
88 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 91 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
OLD | NEW |