Chromium Code Reviews| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 17 #include "extensions/common/user_script.h" | 18 #include "extensions/common/user_script.h" |
| 18 #include "third_party/WebKit/public/web/WebScriptSource.h" | 19 #include "extensions/renderer/script_injection.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | |
| 19 | 21 |
| 20 class GURL; | 22 class GURL; |
| 21 | 23 |
| 22 namespace blink { | 24 namespace blink { |
| 23 class WebFrame; | 25 class WebFrame; |
| 24 } | 26 } |
| 25 | 27 |
| 26 using blink::WebScriptSource; | 28 namespace content { |
| 29 class RenderView; | |
| 30 } | |
| 27 | 31 |
| 28 namespace extensions { | 32 namespace extensions { |
| 29 class Extension; | 33 class Extension; |
| 30 class ExtensionSet; | 34 class ExtensionSet; |
| 31 | 35 |
| 32 // Manages installed UserScripts for a render process. | 36 // Manages installed UserScripts for a render process. |
| 33 class UserScriptSlave { | 37 class UserScriptSlave { |
| 34 public: | 38 public: |
| 35 explicit UserScriptSlave(const ExtensionSet* extensions); | 39 explicit UserScriptSlave(const ExtensionSet* extensions); |
| 36 ~UserScriptSlave(); | 40 ~UserScriptSlave(); |
| 37 | 41 |
| 38 // Returns the unique set of extension IDs this UserScriptSlave knows about. | 42 // Returns the unique set of extension IDs this UserScriptSlave knows about. |
| 39 void GetActiveExtensions(std::set<std::string>* extension_ids); | 43 void GetActiveExtensions(std::set<std::string>* extension_ids); |
| 40 | 44 |
| 45 // Gets the extension with the given |id|, if one exists. | |
| 46 const Extension* GetExtension(const std::string& extension_id); | |
| 47 | |
| 41 // Update the parsed scripts from shared memory. | 48 // Update the parsed scripts from shared memory. |
| 42 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | 49 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
| 43 | 50 |
| 44 // Inject the appropriate scripts into a frame based on its URL. | |
| 45 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | |
| 46 // testability. | |
| 47 void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location); | |
| 48 | |
| 49 // 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 |
| 50 // |frame|. If no isolated world has been created for that extension, | 52 // |frame|. If no isolated world has been created for that extension, |
| 51 // one will be created and initialized. | 53 // one will be created and initialized. |
| 52 int GetIsolatedWorldIdForExtension(const Extension* extension, | 54 int GetIsolatedWorldIdForExtension(const Extension* extension, |
| 53 blink::WebFrame* frame); | 55 blink::WebFrame* frame); |
| 54 | 56 |
| 55 // 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 |
| 56 // 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 |
| 57 // string. | 59 // string. |
| 58 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); | 60 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id); |
| 59 | 61 |
| 60 void RemoveIsolatedWorld(const std::string& extension_id); | 62 void RemoveIsolatedWorld(const std::string& extension_id); |
| 61 | 63 |
| 64 // Inject the appropriate scripts into a frame based on its URL. | |
| 65 // TODO(aa): Extract a UserScriptFrame interface out of this to improve | |
| 66 // testability. | |
| 67 void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location); | |
| 68 | |
| 62 private: | 69 private: |
| 70 // Log the data from scripts being run, including doing UMA and notifying the | |
| 71 // browser. | |
| 72 void LogScriptsRun(blink::WebFrame* frame, | |
| 73 UserScript::RunLocation location, | |
| 74 const ScriptInjection::ScriptsRunInfo& info); | |
| 75 | |
| 63 // Shared memory containing raw script data. | 76 // Shared memory containing raw script data. |
| 64 scoped_ptr<base::SharedMemory> shared_memory_; | 77 scoped_ptr<base::SharedMemory> shared_memory_; |
| 65 | 78 |
| 66 // Parsed script data. | 79 // Parsed script data, ready to inject. |
| 67 std::vector<UserScript*> scripts_; | 80 std::vector<ScriptInjection*> script_injections_; |
|
not at google - send to devlin
2014/05/15 23:23:21
mind changing this to a ScopedVector?
Devlin
2014/05/16 22:32:20
Sure.
| |
| 68 STLElementDeleter<std::vector<UserScript*> > script_deleter_; | 81 STLElementDeleter<std::vector<ScriptInjection*> > script_deleter_; |
| 69 | |
| 70 // Greasemonkey API source that is injected with the scripts. | |
| 71 base::StringPiece api_js_; | |
| 72 | 82 |
| 73 // Extension metadata. | 83 // Extension metadata. |
| 74 const ExtensionSet* extensions_; | 84 const ExtensionSet* extensions_; |
| 75 | 85 |
| 76 typedef std::map<std::string, int> IsolatedWorldMap; | 86 typedef std::map<std::string, int> IsolatedWorldMap; |
| 77 IsolatedWorldMap isolated_world_ids_; | 87 IsolatedWorldMap isolated_world_ids_; |
| 78 | 88 |
| 79 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); | 89 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 } // namespace extensions | 92 } // namespace extensions |
| 83 | 93 |
| 84 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ | 94 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_ |
| OLD | NEW |