Revert of Output closure-compiled JavaScript files (patchset #10 id:180001 of https...
[chromium-blink-merge.git] / extensions / renderer / user_script_set.h
blobab2b585bdf3be9ccd8475b7e77089838cd79132d
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_SET_H_
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_
8 #include <set>
9 #include <string>
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"
20 class GURL;
22 namespace blink {
23 class WebFrame;
26 namespace extensions {
27 class ExtensionSet;
28 class ScriptInjection;
30 // The UserScriptSet is a collection of UserScripts which knows how to update
31 // itself from SharedMemory and create ScriptInjections for UserScripts to
32 // inject on a page.
33 class UserScriptSet {
34 public:
35 class Observer {
36 public:
37 virtual void OnUserScriptsUpdated(
38 const std::set<std::string>& changed_extensions,
39 const std::vector<UserScript*>& scripts) = 0;
42 explicit UserScriptSet(const ExtensionSet* extensions);
43 ~UserScriptSet();
45 // Adds or removes observers.
46 void AddObserver(Observer* observer);
47 void RemoveObserver(Observer* observer);
49 // Appends the ids of the extensions that have user scripts to |ids|.
50 void GetActiveExtensionIds(std::set<std::string>* ids) const;
52 // Append any ScriptInjections that should run on the given |web_frame| and
53 // |tab_id|, at the given |run_location|, to |injections|.
54 // |extensions| is passed in to verify the corresponding extension is still
55 // valid.
56 void GetInjections(ScopedVector<ScriptInjection>* injections,
57 blink::WebFrame* web_frame,
58 int tab_id,
59 UserScript::RunLocation run_location);
61 scoped_ptr<ScriptInjection> GetDeclarativeScriptInjection(
62 int script_id,
63 blink::WebFrame* web_frame,
64 int tab_id,
65 UserScript::RunLocation run_location,
66 const GURL& document_url);
68 // Updates scripts given the shared memory region containing user scripts.
69 // Returns true if the scripts were successfully updated.
70 bool UpdateUserScripts(base::SharedMemoryHandle shared_memory,
71 const std::set<std::string>& changed_extensions);
73 const std::vector<UserScript*>& scripts() const { return scripts_.get(); }
75 private:
76 // Returns a new ScriptInjection for the given |script| to execute in the
77 // |web_frame|, or NULL if the script should not execute.
78 scoped_ptr<ScriptInjection> GetInjectionForScript(
79 UserScript* script,
80 blink::WebFrame* web_frame,
81 int tab_id,
82 UserScript::RunLocation run_location,
83 const GURL& document_url,
84 bool is_declarative);
86 // Shared memory containing raw script data.
87 scoped_ptr<base::SharedMemory> shared_memory_;
89 // The set of all known extensions. Owned by the Dispatcher.
90 const ExtensionSet* extensions_;
92 // The UserScripts this injector manages.
93 ScopedVector<UserScript> scripts_;
95 // The associated observers.
96 ObserverList<Observer> observers_;
98 DISALLOW_COPY_AND_ASSIGN(UserScriptSet);
101 } // namespace extensions
103 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_