Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / extensions / renderer / user_script_slave.h
blobfc3da79ae05a9223e52566cc1118043fb3b75119
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/shared_memory.h"
15 #include "base/stl_util.h"
16 #include "base/strings/string_piece.h"
17 #include "extensions/common/user_script.h"
18 #include "third_party/WebKit/public/web/WebScriptSource.h"
20 class GURL;
22 namespace blink {
23 class WebFrame;
26 using blink::WebScriptSource;
28 namespace extensions {
29 class Extension;
30 class ExtensionSet;
32 // Manages installed UserScripts for a render process.
33 class UserScriptSlave {
34 public:
35 explicit UserScriptSlave(const ExtensionSet* extensions);
36 ~UserScriptSlave();
38 // Returns the unique set of extension IDs this UserScriptSlave knows about.
39 void GetActiveExtensions(std::set<std::string>* extension_ids);
41 // Update the parsed scripts from shared memory.
42 bool UpdateScripts(base::SharedMemoryHandle shared_memory);
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);
49 // 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,
51 // one will be created and initialized.
52 int GetIsolatedWorldIdForExtension(const Extension* extension,
53 blink::WebFrame* frame);
55 // 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
57 // string.
58 std::string GetExtensionIdForIsolatedWorld(int isolated_world_id);
60 void RemoveIsolatedWorld(const std::string& extension_id);
62 private:
63 // Shared memory containing raw script data.
64 scoped_ptr<base::SharedMemory> shared_memory_;
66 // Parsed script data.
67 std::vector<UserScript*> scripts_;
68 STLElementDeleter<std::vector<UserScript*> > script_deleter_;
70 // Greasemonkey API source that is injected with the scripts.
71 base::StringPiece api_js_;
73 // Extension metadata.
74 const ExtensionSet* extensions_;
76 typedef std::map<std::string, int> IsolatedWorldMap;
77 IsolatedWorldMap isolated_world_ids_;
79 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave);
82 } // namespace extensions
84 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SLAVE_H_