Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | |
| 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "base/memory/shared_memory.h" | |
| 15 #include "base/observer_list.h" | |
| 16 #include "content/public/renderer/render_process_observer.h" | |
| 17 #include "extensions/common/extension.h" | |
| 18 #include "extensions/common/user_script.h" | |
| 19 | |
| 20 namespace IPC { | |
| 21 | |
| 22 class Message; | |
| 23 | |
| 24 } // namespace IPC | |
| 25 | |
| 26 namespace blink { | |
| 27 | |
| 28 class WebFrame; | |
| 29 | |
| 30 } // namespace blink | |
| 31 | |
| 32 namespace extensions { | |
| 33 | |
| 34 class ExtensionSet; | |
| 35 class ScriptInjection; | |
| 36 class UserScriptSet; | |
| 37 | |
| 38 // Manager for separate UserScriptSets, one for each shared memory region. | |
| 39 // Regions are organized as follows: | |
| 40 // static_scripts -- contains all extensions' scripts that are statically | |
| 41 // declared in the extension manifest. | |
| 42 // programmatic_scripts -- one region per script, instantiated lazily; | |
|
Jeffrey Yasskin
2014/07/24 21:09:20
"lazily" isn't precise. Do you mean that each one
Mark Dittmer
2014/07/25 15:09:05
Good point on precision of language. I mean the fi
| |
| 43 // contains the extension's programmatically | |
| 44 // declared scripts. | |
| 45 class UserScriptSetManager : public content::RenderProcessObserver { | |
| 46 public: | |
| 47 // Like a UserScriptSet::Observer, but automatically subscribes to all sets | |
| 48 // associated with the manager. | |
| 49 class Observer { | |
| 50 public: | |
| 51 virtual void OnUserScriptsUpdated( | |
| 52 const std::set<std::string>& changed_extensions, | |
| 53 const std::vector<UserScript*>& scripts) = 0; | |
| 54 }; | |
| 55 | |
| 56 UserScriptSetManager(const ExtensionSet* extensions); | |
| 57 | |
| 58 virtual ~UserScriptSetManager(); | |
| 59 | |
| 60 // ScopedObserver Source implementation. | |
| 61 void AddObserver(Observer* observer); | |
| 62 void RemoveObserver(Observer* observer); | |
| 63 | |
| 64 // content::RenderProcessObserver implementation. | |
| 65 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 66 | |
| 67 const UserScriptSet* static_scripts() const { return static_scripts_.get(); } | |
| 68 | |
| 69 const linked_ptr<UserScriptSet> ProgrammaticScripts( | |
|
Jeffrey Yasskin
2014/07/24 21:09:20
Generally don't return linked_ptr<>s. They're used
Mark Dittmer
2014/07/25 15:09:05
Yes. Raw pointers are fine here. Done.
| |
| 70 const ExtensionId& extensionId); | |
| 71 | |
| 72 // Get injections from |static_scripts| and each of |programmatic_scripts|. | |
|
Jeffrey Yasskin
2014/07/24 21:09:20
What's this function do with its other arguments?
| |
| 73 void GetAllInjections(ScopedVector<ScriptInjection>* injections, | |
| 74 blink::WebFrame* web_frame, | |
| 75 int tab_id, | |
| 76 UserScript::RunLocation run_location); | |
| 77 | |
| 78 // Get active extension IDs from |static_scripts| and each of | |
| 79 // |programmatic_scripts|. | |
| 80 void GetAllActiveExtensionIds(std::set<std::string>* ids) const; | |
| 81 | |
| 82 private: | |
| 83 // Map for per-extension sets that may be defined programmatically. | |
| 84 typedef std::map<ExtensionId, linked_ptr<UserScriptSet> > UserScriptSetMap; | |
| 85 | |
| 86 // Handle the UpdateUserScripts extension message. | |
| 87 void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, | |
| 88 const ExtensionId& extension_id, | |
| 89 const std::set<std::string>& changed_extensions); | |
| 90 | |
| 91 // Scripts statically defined in extension manifests. | |
| 92 scoped_ptr<UserScriptSet> static_scripts_; | |
|
Jeffrey Yasskin
2014/07/24 21:09:20
You can store a UserScriptSet by value, rather tha
Mark Dittmer
2014/07/25 15:09:05
Added clarifying comment. This wraps UserScriptSet
| |
| 93 | |
| 94 // Scripts programmatically defined through API calls (initialized and stored | |
| 95 // per-extension). | |
| 96 UserScriptSetMap programmatic_scripts_; | |
| 97 | |
| 98 // The set of all known extensions. Owned by the Dispatcher. | |
| 99 const ExtensionSet* extensions_; | |
| 100 | |
| 101 // The associated observers. | |
| 102 ObserverList<Observer> observers_; | |
| 103 }; | |
| 104 | |
| 105 } // namespace extensions | |
| 106 | |
| 107 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_SET_MANAGER_H_ | |
| OLD | NEW |