| 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 <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // The UserScriptSet is a collection of UserScripts which knows how to update | 28 // The UserScriptSet is a collection of UserScripts which knows how to update |
| 29 // itself from SharedMemory and create ScriptInjections for UserScripts to | 29 // itself from SharedMemory and create ScriptInjections for UserScripts to |
| 30 // inject on a page. | 30 // inject on a page. |
| 31 class UserScriptSet { | 31 class UserScriptSet { |
| 32 public: | 32 public: |
| 33 class Observer { | 33 class Observer { |
| 34 public: | 34 public: |
| 35 virtual void OnUserScriptsUpdated( | 35 virtual void OnUserScriptsUpdated( |
| 36 const std::set<HostID>& changed_hosts, | 36 const std::set<HostID>& changed_hosts, |
| 37 const std::vector<UserScript*>& scripts) = 0; | 37 const std::vector<std::unique_ptr<UserScript>>& scripts) = 0; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 UserScriptSet(); | 40 UserScriptSet(); |
| 41 ~UserScriptSet(); | 41 ~UserScriptSet(); |
| 42 | 42 |
| 43 // Adds or removes observers. | 43 // Adds or removes observers. |
| 44 void AddObserver(Observer* observer); | 44 void AddObserver(Observer* observer); |
| 45 void RemoveObserver(Observer* observer); | 45 void RemoveObserver(Observer* observer); |
| 46 | 46 |
| 47 // Appends the ids of the extensions that have user scripts to |ids|. | 47 // Appends the ids of the extensions that have user scripts to |ids|. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 64 UserScript::RunLocation run_location, | 64 UserScript::RunLocation run_location, |
| 65 const GURL& document_url, | 65 const GURL& document_url, |
| 66 bool log_activity); | 66 bool log_activity); |
| 67 | 67 |
| 68 // Updates scripts given the shared memory region containing user scripts. | 68 // Updates scripts given the shared memory region containing user scripts. |
| 69 // Returns true if the scripts were successfully updated. | 69 // Returns true if the scripts were successfully updated. |
| 70 bool UpdateUserScripts(base::SharedMemoryHandle shared_memory, | 70 bool UpdateUserScripts(base::SharedMemoryHandle shared_memory, |
| 71 const std::set<HostID>& changed_hosts, | 71 const std::set<HostID>& changed_hosts, |
| 72 bool whitelisted_only); | 72 bool whitelisted_only); |
| 73 | 73 |
| 74 const std::vector<UserScript*>& scripts() const { return scripts_.get(); } | 74 const std::vector<std::unique_ptr<UserScript>>& scripts() const { |
| 75 return scripts_; |
| 76 } |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 // Returns a new ScriptInjection for the given |script| to execute in the | 79 // Returns a new ScriptInjection for the given |script| to execute in the |
| 78 // |render_frame|, or NULL if the script should not execute. | 80 // |render_frame|, or NULL if the script should not execute. |
| 79 std::unique_ptr<ScriptInjection> GetInjectionForScript( | 81 std::unique_ptr<ScriptInjection> GetInjectionForScript( |
| 80 const UserScript* script, | 82 const UserScript* script, |
| 81 content::RenderFrame* render_frame, | 83 content::RenderFrame* render_frame, |
| 82 int tab_id, | 84 int tab_id, |
| 83 UserScript::RunLocation run_location, | 85 UserScript::RunLocation run_location, |
| 84 const GURL& document_url, | 86 const GURL& document_url, |
| 85 bool is_declarative, | 87 bool is_declarative, |
| 86 bool log_activity); | 88 bool log_activity); |
| 87 | 89 |
| 88 // Shared memory containing raw script data. | 90 // Shared memory containing raw script data. |
| 89 std::unique_ptr<base::SharedMemory> shared_memory_; | 91 std::unique_ptr<base::SharedMemory> shared_memory_; |
| 90 | 92 |
| 91 // The UserScripts this injector manages. | 93 // The UserScripts this injector manages. |
| 92 ScopedVector<UserScript> scripts_; | 94 std::vector<std::unique_ptr<UserScript>> scripts_; |
| 93 | 95 |
| 94 // The associated observers. | 96 // The associated observers. |
| 95 base::ObserverList<Observer> observers_; | 97 base::ObserverList<Observer> observers_; |
| 96 | 98 |
| 97 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); | 99 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 } // namespace extensions | 102 } // namespace extensions |
| 101 | 103 |
| 102 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ | 104 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
| OLD | NEW |