Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: extensions/renderer/user_script_set_manager.h

Issue 404613006: Declarative content scripts: Renderer-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix use of scoped and linked ptrs, better documentation Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/observer_list.h"
15 #include "content/public/renderer/render_process_observer.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/user_script.h"
18 #include "extensions/renderer/user_script_set.h"
19
20 namespace IPC {
21
Devlin 2014/07/28 18:15:28 nit: we usually make these forward declarations a
Mark Dittmer 2014/07/28 22:21:28 Done.
22 class Message;
23
24 } // namespace IPC
25
26 namespace blink {
27
28 class WebFrame;
29
30 } // namespace blink
31
32 namespace extensions {
33
34 class ExtensionSet;
35 class ScriptInjection;
36
37 // Manager for separate UserScriptSets, one for each shared memory region.
38 // Regions are organized as follows:
39 // static_scripts -- contains all extensions' scripts that are statically
40 // declared in the extension manifest.
41 // programmatic_scripts -- one region per extension containing only
42 // programmatically declared scripts, instantiated
Devlin 2014/07/28 18:15:28 nit of nits: programmatically-declared
Mark Dittmer 2014/07/28 22:21:29 Done.
43 // when an extension first creates a declarative rule
44 // that would, if triggered, request a script injection.
45 class UserScriptSetManager : public content::RenderProcessObserver {
46 public:
47 // Like a UserScriptSet::Observer, but automatically subscribes to all sets
48 // associated with the manager.
49 class Observer {
50 public:
51 virtual void OnUserScriptsUpdated(
52 const std::set<std::string>& changed_extensions,
53 const std::vector<UserScript*>& scripts) = 0;
54 };
55
56 UserScriptSetManager(const ExtensionSet* extensions);
57
58 virtual ~UserScriptSetManager();
59
60 // ScopedObserver Source implementation.
Devlin 2014/07/28 18:15:28 nit: Usually "X implementation." refers to a direc
Mark Dittmer 2014/07/28 22:21:29 Done.
61 void AddObserver(Observer* observer);
62 void RemoveObserver(Observer* observer);
63
64 // content::RenderProcessObserver implementation.
65 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
Devlin 2014/07/28 18:15:28 Make this private.
Mark Dittmer 2014/07/28 22:21:29 Done.
66
67 const UserScriptSet* static_scripts() const { return &static_scripts_; }
68
69 const UserScriptSet* ProgrammaticScripts(const ExtensionId& extensionId);
Devlin 2014/07/28 18:15:28 If an accessor is "complex" (colloquially, not tec
Mark Dittmer 2014/07/28 22:21:28 Done.
70
71 // Put all injections from |static_scripts| and each of |programmatic_scripts|
72 // into |injections| via successive calls to
73 // UserScriptSet::GetInjections(injections, web_frame, tab_id, run_location).
Devlin 2014/07/28 18:15:28 nit: Try not to include implementation details in
Mark Dittmer 2014/07/28 22:21:28 It's good to get the details right! Done.
74 void GetAllInjections(ScopedVector<ScriptInjection>* injections,
75 blink::WebFrame* web_frame,
76 int tab_id,
77 UserScript::RunLocation run_location);
78
79 // Get active extension IDs from |static_scripts| and each of
80 // |programmatic_scripts|.
81 void GetAllActiveExtensionIds(std::set<std::string>* ids) const;
82
83 private:
84 // Map for per-extension sets that may be defined programmatically.
85 typedef std::map<ExtensionId, linked_ptr<UserScriptSet> > UserScriptSetMap;
86
87 // Handle the UpdateUserScripts extension message.
88 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory,
89 const ExtensionId& extension_id,
90 const std::set<std::string>& changed_extensions);
91
92 // Scripts statically defined in extension manifests.
93 UserScriptSet static_scripts_;
94
95 // Scripts programmatically defined through API calls (initialized and stored
96 // per-extension).
97 UserScriptSetMap programmatic_scripts_;
98
99 // The set of all known extensions. Owned by the Dispatcher.
100 const ExtensionSet* extensions_;
101
102 // The associated observers.
103 ObserverList<Observer> observers_;
Devlin 2014/07/28 18:15:28 DISALLOW_COPY_AND_ASSIGN()
Mark Dittmer 2014/07/28 22:21:28 Done.
104 };
105
106 } // namespace extensions
107
108 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698