Chromium Code Reviews| 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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 class Extension; | 27 class Extension; |
| 28 class ExtensionSet; | 28 class ExtensionSet; |
| 29 class ScriptInjection; | 29 class ScriptInjection; |
| 30 | 30 |
| 31 // The UserScriptSet is a collection of UserScripts which knows how to update | 31 // The UserScriptSet is a collection of UserScripts which knows how to update |
| 32 // itself from SharedMemory and create ScriptInjections for UserScripts to | 32 // itself from SharedMemory and create ScriptInjections for UserScripts to |
| 33 // inject on a page. | 33 // inject on a page. |
| 34 class UserScriptSet : public content::RenderProcessObserver { | 34 class UserScriptSet { |
| 35 public: | 35 public: |
| 36 class Observer { | 36 class Observer { |
| 37 public: | 37 public: |
| 38 virtual void OnUserScriptsUpdated( | 38 virtual void OnUserScriptsUpdated( |
| 39 const std::set<std::string>& changed_extensions, | 39 const std::set<std::string>& changed_extensions, |
| 40 const std::vector<UserScript*>& scripts) = 0; | 40 const std::vector<UserScript*>& scripts) = 0; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 UserScriptSet(const ExtensionSet* extensions); | 43 explicit UserScriptSet(const ExtensionSet* extensions); |
| 44 virtual ~UserScriptSet(); | 44 virtual ~UserScriptSet(); |
|
Devlin
2014/07/29 22:06:39
nit: no longer need virtual destructor
Mark Dittmer
2014/07/29 22:20:41
Done.
| |
| 45 | 45 |
| 46 // Adds or removes observers. | 46 // Adds or removes observers. |
| 47 void AddObserver(Observer* observer); | 47 void AddObserver(Observer* observer); |
| 48 void RemoveObserver(Observer* observer); | 48 void RemoveObserver(Observer* observer); |
| 49 | 49 |
| 50 // Appends the ids of the extensions that have user scripts to |ids|. | 50 // Appends the ids of the extensions that have user scripts to |ids|. |
| 51 void GetActiveExtensionIds(std::set<std::string>* ids) const; | 51 void GetActiveExtensionIds(std::set<std::string>* ids) const; |
| 52 | 52 |
| 53 // Populate |injections| with any ScriptInjections that should run on the | 53 // Populate |injections| with any ScriptInjections that should run on the |
| 54 // given |web_frame| and |tab_id|, at the given |run_location|. | 54 // given |web_frame| and |tab_id|, at the given |run_location|. |
| 55 // |extensions| is passed in to verify the corresponding extension is still | 55 // |extensions| is passed in to verify the corresponding extension is still |
| 56 // valid. | 56 // valid. |
| 57 void GetInjections(ScopedVector<ScriptInjection>* injections, | 57 void GetInjections(ScopedVector<ScriptInjection>* injections, |
| 58 blink::WebFrame* web_frame, | 58 blink::WebFrame* web_frame, |
| 59 int tab_id, | 59 int tab_id, |
| 60 UserScript::RunLocation run_location); | 60 UserScript::RunLocation run_location); |
| 61 | 61 |
| 62 private: | 62 // Updates scripts given the shared memory region containing user scripts. |
| 63 // content::RenderProcessObserver implementation. | 63 // Returns true if the scripts were successfully updated. |
| 64 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | 64 bool OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, |
|
Devlin
2014/07/29 22:06:39
nit: just call this UpdateUserScripts.
Mark Dittmer
2014/07/29 22:20:41
Done.
| |
| 65 | |
| 66 // Handle the UpdateUserScripts extension message. | |
| 67 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, | |
| 68 const std::set<std::string>& changed_extensions); | 65 const std::set<std::string>& changed_extensions); |
| 69 | 66 |
| 70 // Update the parsed scripts from |shared memory|. | 67 const std::vector<UserScript*>& scripts() const { return scripts_.get(); } |
| 71 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | |
| 72 | 68 |
| 69 private: | |
| 73 // Returns a new ScriptInjection for the given |script| to execute in the | 70 // Returns a new ScriptInjection for the given |script| to execute in the |
| 74 // |web_frame|, or NULL if the script should not execute. | 71 // |web_frame|, or NULL if the script should not execute. |
| 75 scoped_ptr<ScriptInjection> GetInjectionForScript( | 72 scoped_ptr<ScriptInjection> GetInjectionForScript( |
| 76 UserScript* script, | 73 UserScript* script, |
| 77 blink::WebFrame* web_frame, | 74 blink::WebFrame* web_frame, |
| 78 int tab_id, | 75 int tab_id, |
| 79 UserScript::RunLocation run_location, | 76 UserScript::RunLocation run_location, |
| 80 const GURL& document_url, | 77 const GURL& document_url, |
| 81 const Extension* extension); | 78 const Extension* extension); |
| 82 | 79 |
| 83 // Shared memory containing raw script data. | 80 // Shared memory containing raw script data. |
| 84 scoped_ptr<base::SharedMemory> shared_memory_; | 81 scoped_ptr<base::SharedMemory> shared_memory_; |
| 85 | 82 |
| 86 // The set of all known extensions. Owned by the Dispatcher. | 83 // The set of all known extensions. Owned by the Dispatcher. |
| 87 const ExtensionSet* extensions_; | 84 const ExtensionSet* extensions_; |
| 88 | 85 |
| 89 // The UserScripts this injector manages. | 86 // The UserScripts this injector manages. |
| 90 ScopedVector<UserScript> scripts_; | 87 ScopedVector<UserScript> scripts_; |
| 91 | 88 |
| 92 // The associated observers. | 89 // The associated observers. |
| 93 ObserverList<Observer> observers_; | 90 ObserverList<Observer> observers_; |
| 94 | 91 |
| 95 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); | 92 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); |
| 96 }; | 93 }; |
| 97 | 94 |
| 98 } // namespace extensions | 95 } // namespace extensions |
| 99 | 96 |
| 100 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ | 97 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
| OLD | NEW |