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(); |
| 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 const std::vector<UserScript*>& scripts() const { return scripts_.get(); } | |
|
Devlin
2014/07/29 17:11:57
nit: accessor should go last (just above "private:
Mark Dittmer
2014/07/29 22:01:13
Done.
| |
| 51 | |
| 50 // Appends the ids of the extensions that have user scripts to |ids|. | 52 // Appends the ids of the extensions that have user scripts to |ids|. |
| 51 void GetActiveExtensionIds(std::set<std::string>* ids) const; | 53 void GetActiveExtensionIds(std::set<std::string>* ids) const; |
| 52 | 54 |
| 53 // Populate |injections| with any ScriptInjections that should run on the | 55 // Populate |injections| with any ScriptInjections that should run on the |
| 54 // given |web_frame| and |tab_id|, at the given |run_location|. | 56 // given |web_frame| and |tab_id|, at the given |run_location|. |
| 55 // |extensions| is passed in to verify the corresponding extension is still | 57 // |extensions| is passed in to verify the corresponding extension is still |
| 56 // valid. | 58 // valid. |
| 57 void GetInjections(ScopedVector<ScriptInjection>* injections, | 59 void GetInjections(ScopedVector<ScriptInjection>* injections, |
| 58 blink::WebFrame* web_frame, | 60 blink::WebFrame* web_frame, |
| 59 int tab_id, | 61 int tab_id, |
| 60 UserScript::RunLocation run_location); | 62 UserScript::RunLocation run_location); |
| 61 | 63 |
| 62 private: | 64 // Handle the UpdateUserScripts extension message. Return true if the |
|
Devlin
2014/07/29 17:11:57
This is kinda lying - it doesn't really handle the
Mark Dittmer
2014/07/29 22:01:13
Done.
| |
| 63 // content::RenderProcessObserver implementation. | 65 // method follows through on notifying observers of the change, or false if |
| 64 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | 66 // an error occurred. |
| 65 | 67 bool OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, |
| 66 // Handle the UpdateUserScripts extension message. | |
| 67 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, | |
| 68 const std::set<std::string>& changed_extensions); | 68 const std::set<std::string>& changed_extensions); |
| 69 | 69 |
| 70 private: | |
| 70 // Update the parsed scripts from |shared memory|. | 71 // Update the parsed scripts from |shared memory|. |
| 71 bool UpdateScripts(base::SharedMemoryHandle shared_memory); | 72 bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
| 72 | 73 |
| 73 // Returns a new ScriptInjection for the given |script| to execute in the | 74 // Returns a new ScriptInjection for the given |script| to execute in the |
| 74 // |web_frame|, or NULL if the script should not execute. | 75 // |web_frame|, or NULL if the script should not execute. |
| 75 scoped_ptr<ScriptInjection> GetInjectionForScript( | 76 scoped_ptr<ScriptInjection> GetInjectionForScript( |
| 76 UserScript* script, | 77 UserScript* script, |
| 77 blink::WebFrame* web_frame, | 78 blink::WebFrame* web_frame, |
| 78 int tab_id, | 79 int tab_id, |
| 79 UserScript::RunLocation run_location, | 80 UserScript::RunLocation run_location, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 91 | 92 |
| 92 // The associated observers. | 93 // The associated observers. |
| 93 ObserverList<Observer> observers_; | 94 ObserverList<Observer> observers_; |
| 94 | 95 |
| 95 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); | 96 DISALLOW_COPY_AND_ASSIGN(UserScriptSet); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 } // namespace extensions | 99 } // namespace extensions |
| 99 | 100 |
| 100 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ | 101 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_ |
| OLD | NEW |