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