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_SET_H_ | 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ | 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "content/public/renderer/render_process_observer.h" | 17 #include "content/public/renderer/render_process_observer.h" |
18 #include "extensions/common/user_script.h" | 18 #include "extensions/common/user_script.h" |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 class WebFrame; | 23 class WebFrame; |
24 } | 24 } |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 class Extension; | |
28 class ExtensionSet; | 27 class ExtensionSet; |
29 class ScriptInjection; | 28 class ScriptInjection; |
30 | 29 |
31 // The UserScriptSet is a collection of UserScripts which knows how to update | 30 // The UserScriptSet is a collection of UserScripts which knows how to update |
32 // itself from SharedMemory and create ScriptInjections for UserScripts to | 31 // itself from SharedMemory and create ScriptInjections for UserScripts to |
33 // inject on a page. | 32 // inject on a page. |
34 class UserScriptSet { | 33 class UserScriptSet { |
35 public: | 34 public: |
36 class Observer { | 35 class Observer { |
37 public: | 36 public: |
(...skipping 19 matching lines...) Expand all Loading... |
57 void GetInjections(ScopedVector<ScriptInjection>* injections, | 56 void GetInjections(ScopedVector<ScriptInjection>* injections, |
58 blink::WebFrame* web_frame, | 57 blink::WebFrame* web_frame, |
59 int tab_id, | 58 int tab_id, |
60 UserScript::RunLocation run_location); | 59 UserScript::RunLocation run_location); |
61 | 60 |
62 scoped_ptr<ScriptInjection> GetDeclarativeScriptInjection( | 61 scoped_ptr<ScriptInjection> GetDeclarativeScriptInjection( |
63 int script_id, | 62 int script_id, |
64 blink::WebFrame* web_frame, | 63 blink::WebFrame* web_frame, |
65 int tab_id, | 64 int tab_id, |
66 UserScript::RunLocation run_location, | 65 UserScript::RunLocation run_location, |
67 const GURL& document_url, | 66 const GURL& document_url); |
68 const Extension* extension); | |
69 | 67 |
70 // Updates scripts given the shared memory region containing user scripts. | 68 // Updates scripts given the shared memory region containing user scripts. |
71 // Returns true if the scripts were successfully updated. | 69 // Returns true if the scripts were successfully updated. |
72 bool UpdateUserScripts(base::SharedMemoryHandle shared_memory, | 70 bool UpdateUserScripts(base::SharedMemoryHandle shared_memory, |
73 const std::set<std::string>& changed_extensions); | 71 const std::set<std::string>& changed_extensions); |
74 | 72 |
75 const std::vector<UserScript*>& scripts() const { return scripts_.get(); } | 73 const std::vector<UserScript*>& scripts() const { return scripts_.get(); } |
76 | 74 |
77 private: | 75 private: |
78 // Returns a new ScriptInjection for the given |script| to execute in the | 76 // Returns a new ScriptInjection for the given |script| to execute in the |
79 // |web_frame|, or NULL if the script should not execute. | 77 // |web_frame|, or NULL if the script should not execute. |
80 scoped_ptr<ScriptInjection> GetInjectionForScript( | 78 scoped_ptr<ScriptInjection> GetInjectionForScript( |
81 UserScript* script, | 79 UserScript* script, |
82 blink::WebFrame* web_frame, | 80 blink::WebFrame* web_frame, |
83 int tab_id, | 81 int tab_id, |
84 UserScript::RunLocation run_location, | 82 UserScript::RunLocation run_location, |
85 const GURL& document_url, | 83 const GURL& document_url, |
86 const Extension* extension, | |
87 bool is_declarative); | 84 bool is_declarative); |
88 | 85 |
89 // Shared memory containing raw script data. | 86 // Shared memory containing raw script data. |
90 scoped_ptr<base::SharedMemory> shared_memory_; | 87 scoped_ptr<base::SharedMemory> shared_memory_; |
91 | 88 |
92 // The set of all known extensions. Owned by the Dispatcher. | 89 // The set of all known extensions. Owned by the Dispatcher. |
93 const ExtensionSet* extensions_; | 90 const ExtensionSet* extensions_; |
94 | 91 |
95 // The UserScripts this injector manages. | 92 // The UserScripts this injector manages. |
96 ScopedVector<UserScript> scripts_; | 93 ScopedVector<UserScript> scripts_; |
97 | 94 |
98 // The associated observers. | 95 // The associated observers. |
99 ObserverList<Observer> observers_; | 96 ObserverList<Observer> observers_; |
100 | 97 |
101 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); | 98 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); |
102 }; | 99 }; |
103 | 100 |
104 } // namespace extensions | 101 } // namespace extensions |
105 | 102 |
106 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ | 103 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
OLD | NEW |