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