OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_USER_SCRIPT_SLAVE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
12 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
13 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
14 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
15 #include "chrome/common/extensions/user_script.h" | 16 #include "chrome/common/extensions/user_script.h" |
| 17 #include "webkit/api/public/WebScriptSource.h" |
16 | 18 |
17 namespace WebKit { | 19 namespace WebKit { |
18 class WebFrame; | 20 class WebFrame; |
19 } | 21 } |
20 | 22 |
| 23 using WebKit::WebScriptSource; |
| 24 |
21 // Manages installed UserScripts for a render process. | 25 // Manages installed UserScripts for a render process. |
22 class UserScriptSlave { | 26 class UserScriptSlave { |
23 public: | 27 public: |
24 UserScriptSlave(); | 28 UserScriptSlave(); |
25 | 29 |
26 // Update the parsed scripts from shared memory. | 30 // Update the parsed scripts from shared memory. |
27 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | 31 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
28 | 32 |
29 // Inject the appropriate scripts into a frame based on its URL. | 33 // Inject the appropriate scripts into a frame based on its URL. |
30 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | 34 // TODO(aa): Extract a UserScriptFrame interface out of this to improve |
31 // testability. | 35 // testability. |
32 bool InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); | 36 bool InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); |
33 | 37 |
| 38 static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources, |
| 39 const std::string& extension_id); |
34 private: | 40 private: |
35 // Shared memory containing raw script data. | 41 // Shared memory containing raw script data. |
36 scoped_ptr<base::SharedMemory> shared_memory_; | 42 scoped_ptr<base::SharedMemory> shared_memory_; |
37 | 43 |
38 // Parsed script data. | 44 // Parsed script data. |
39 std::vector<UserScript*> scripts_; | 45 std::vector<UserScript*> scripts_; |
40 STLElementDeleter<std::vector<UserScript*> > script_deleter_; | 46 STLElementDeleter<std::vector<UserScript*> > script_deleter_; |
41 | 47 |
42 // Greasemonkey API source that is injected with the scripts. | 48 // Greasemonkey API source that is injected with the scripts. |
43 base::StringPiece api_js_; | 49 base::StringPiece api_js_; |
44 | 50 |
45 // The line number of the first line of the user script among all of the | 51 // The line number of the first line of the user script among all of the |
46 // injected javascript. This is used to make reported errors correspond with | 52 // injected javascript. This is used to make reported errors correspond with |
47 // the proper line in the user script. | 53 // the proper line in the user script. |
48 int user_script_start_line_; | 54 int user_script_start_line_; |
49 | 55 |
50 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); | 56 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); |
51 }; | 57 }; |
52 | 58 |
53 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 59 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
OLD | NEW |