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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
17 #include "chrome/common/extensions/user_script.h" | 17 #include "chrome/common/extensions/user_script.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
19 | 19 |
| 20 class Extension; |
20 class ExtensionSet; | 21 class ExtensionSet; |
21 | 22 |
22 namespace WebKit { | 23 namespace WebKit { |
23 class WebFrame; | 24 class WebFrame; |
24 } | 25 } |
25 | 26 |
26 using WebKit::WebScriptSource; | 27 using WebKit::WebScriptSource; |
27 | 28 |
28 // Manages installed UserScripts for a render process. | 29 // Manages installed UserScripts for a render process. |
29 class UserScriptSlave { | 30 class UserScriptSlave { |
30 public: | 31 public: |
31 UserScriptSlave(const ExtensionSet* extensions); | 32 explicit UserScriptSlave(const ExtensionSet* extensions); |
32 ~UserScriptSlave(); | 33 ~UserScriptSlave(); |
33 | 34 |
34 // Returns the unique set of extension IDs this UserScriptSlave knows about. | 35 // Returns the unique set of extension IDs this UserScriptSlave knows about. |
35 void GetActiveExtensions(std::set<std::string>* extension_ids); | 36 void GetActiveExtensions(std::set<std::string>* extension_ids); |
36 | 37 |
37 // Update the parsed scripts from shared memory. | 38 // Update the parsed scripts from shared memory. |
38 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | 39 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
39 | 40 |
40 // Inject the appropriate scripts into a frame based on its URL. | 41 // Inject the appropriate scripts into a frame based on its URL. |
41 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | 42 // TODO(aa): Extract a UserScriptFrame interface out of this to improve |
42 // testability. | 43 // testability. |
43 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); | 44 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); |
44 | 45 |
45 static int GetIsolatedWorldId(const std::string& extension_id); | 46 // Gets the isolated world ID to use for the given |extension| in the given |
| 47 // |frame|. If no isolated world has been created for that extension, |
| 48 // one will be created and initialized. |
| 49 static int GetIsolatedWorldId(const Extension* extension, |
| 50 WebKit::WebFrame* frame); |
46 | 51 |
47 static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources, | 52 static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources, |
48 const std::string& extension_id); | 53 const std::string& extension_id); |
49 private: | 54 private: |
| 55 static void InitializeIsolatedWorld(int isolated_world_id, |
| 56 const Extension* extension); |
| 57 |
50 // Shared memory containing raw script data. | 58 // Shared memory containing raw script data. |
51 scoped_ptr<base::SharedMemory> shared_memory_; | 59 scoped_ptr<base::SharedMemory> shared_memory_; |
52 | 60 |
53 // Parsed script data. | 61 // Parsed script data. |
54 std::vector<UserScript*> scripts_; | 62 std::vector<UserScript*> scripts_; |
55 STLElementDeleter<std::vector<UserScript*> > script_deleter_; | 63 STLElementDeleter<std::vector<UserScript*> > script_deleter_; |
56 | 64 |
57 // Greasemonkey API source that is injected with the scripts. | 65 // Greasemonkey API source that is injected with the scripts. |
58 base::StringPiece api_js_; | 66 base::StringPiece api_js_; |
59 | 67 |
60 // Extension metadata. | 68 // Extension metadata. |
61 const ExtensionSet* extensions_; | 69 const ExtensionSet* extensions_; |
62 | 70 |
63 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); | 71 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); |
64 }; | 72 }; |
65 | 73 |
66 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ | 74 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ |
OLD | NEW |