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

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

Issue 321993003: Refactor renderer-side script injection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missing files Created 6 years, 6 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 | Annotate | Revision Log
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_INJECTION_LIST_H_
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_LIST_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/shared_memory.h"
16 #include "base/observer_list.h"
17 #include "content/public/renderer/render_process_observer.h"
18 #include "extensions/common/user_script.h"
19
20 class GURL;
21
22 namespace blink {
23 class WebFrame;
24 }
25
26 namespace extensions {
27 class Extension;
28 class ExtensionSet;
29 class ScriptInjection;
30
31 // The UserScriptInjectionList is a collection of UserScripts which knows how
32 // to update itself from SharedMemory and also knows how to create
33 // ScriptInjections for UserScripts to inject on a page.
34 class UserScriptInjectionList : public content::RenderProcessObserver {
not at google - send to devlin 2014/06/15 23:53:38 I would say "nit: this class doesn't have List sem
Devlin 2014/06/16 18:11:17 Done.
35 public:
36 class Observer {
37 public:
38 virtual void OnUserScriptsUpdated(
39 const std::set<std::string>& changed_extensions,
40 const std::vector<UserScript*>& scripts) = 0;
41 };
42
43 // Returns the URL to use as the document url when checking permissions for
44 // script injection.
45 static GURL GetDocumentUrlForFrame(blink::WebFrame* frame);
not at google - send to devlin 2014/06/15 23:53:38 this function is only used from script_injection_m
Devlin 2014/06/16 18:11:17 It was in ScriptInjectionManager, but doesn't need
46
47 UserScriptInjectionList();
48 virtual ~UserScriptInjectionList();
49
50 // Adds or removes observers.
51 void AddObserver(Observer* observer);
52 void RemoveObserver(Observer* observer);
53
54 // Appends the ids of the extensions that have user scripts to |ids|.
55 void GetActiveExtensionIds(std::set<std::string>* ids) const;
56
57 // Populate |injections| with any ScriptInjections that should run on the
58 // given |web_frame| and |tab_id|, at the given |run_location|.
59 // |extensions| is passed in to verify the corresponding extension is still
60 // valid.
61 void GetInjections(ScopedVector<ScriptInjection>* injections,
62 blink::WebFrame* web_frame,
63 int tab_id,
64 UserScript::RunLocation run_location,
65 const GURL& document_url,
66 const ExtensionSet* extensions);
not at google - send to devlin 2014/06/15 23:53:38 just pass in |extensions| as a constructor/member
Devlin 2014/06/16 18:11:17 Done.
67
68 private:
69 // content::RenderProcessObserver implementation.
70 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
71
72 // Handle the UpdateUserScripts extension message.
73 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory,
74 const std::set<std::string>& changed_extensions);
75
76 // Update the parsed scripts from |shared memory|.
77 bool UpdateScripts(base::SharedMemoryHandle shared_memory);
78
79 // Returns a new ScriptInjection for the given |script| to execute in the
80 // |web_frame|, or NULL if the script should not execute.
81 scoped_ptr<ScriptInjection> GetInjectionForScript(
82 UserScript* script,
83 blink::WebFrame* web_frame,
84 int tab_id,
85 UserScript::RunLocation run_location,
86 const GURL& document_url,
87 const Extension* extension);
88
89 // Shared memory containing raw script data.
90 scoped_ptr<base::SharedMemory> shared_memory_;
91
92 // The UserScripts this injector manages.
93 ScopedVector<UserScript> scripts_;
94
95 // The associated observers.
96 ObserverList<Observer> observers_;
97
98 DISALLOW_COPY_AND_ASSIGN(UserScriptInjectionList);
99 };
100
101 } // namespace extensions
102
103 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698