Chromium Code Reviews| Index: extensions/renderer/user_script_injection_list.h |
| diff --git a/extensions/renderer/user_script_injection_list.h b/extensions/renderer/user_script_injection_list.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc22bf56e3290e3ffbef550d8a1f30bff85b6dbd |
| --- /dev/null |
| +++ b/extensions/renderer/user_script_injection_list.h |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_LIST_H_ |
| +#define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_LIST_H_ |
| + |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "base/memory/shared_memory.h" |
| +#include "base/observer_list.h" |
| +#include "content/public/renderer/render_process_observer.h" |
| +#include "extensions/common/user_script.h" |
| + |
| +class GURL; |
| + |
| +namespace blink { |
| +class WebFrame; |
| +} |
| + |
| +namespace extensions { |
| +class Extension; |
| +class ExtensionSet; |
| +class ScriptInjection; |
| + |
| +// The UserScriptInjectionList is a collection of UserScripts which knows how |
| +// to update itself from SharedMemory and also knows how to create |
| +// ScriptInjections for UserScripts to inject on a page. |
| +class UserScriptInjectionList : public content::RenderProcessObserver { |
|
not at google - send to devlin
2014/06/15 23:53:38
I would say "nit: this class doesn't have List sem
Devlin
2014/06/16 18:11:17
Done.
|
| + public: |
| + class Observer { |
| + public: |
| + virtual void OnUserScriptsUpdated( |
| + const std::set<std::string>& changed_extensions, |
| + const std::vector<UserScript*>& scripts) = 0; |
| + }; |
| + |
| + // Returns the URL to use as the document url when checking permissions for |
| + // script injection. |
| + static GURL GetDocumentUrlForFrame(blink::WebFrame* frame); |
|
not at google - send to devlin
2014/06/15 23:53:38
this function is only used from script_injection_m
Devlin
2014/06/16 18:11:17
It was in ScriptInjectionManager, but doesn't need
|
| + |
| + UserScriptInjectionList(); |
| + virtual ~UserScriptInjectionList(); |
| + |
| + // Adds or removes observers. |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| + // Appends the ids of the extensions that have user scripts to |ids|. |
| + void GetActiveExtensionIds(std::set<std::string>* ids) const; |
| + |
| + // Populate |injections| with any ScriptInjections that should run on the |
| + // given |web_frame| and |tab_id|, at the given |run_location|. |
| + // |extensions| is passed in to verify the corresponding extension is still |
| + // valid. |
| + void GetInjections(ScopedVector<ScriptInjection>* injections, |
| + blink::WebFrame* web_frame, |
| + int tab_id, |
| + UserScript::RunLocation run_location, |
| + const GURL& document_url, |
| + const ExtensionSet* extensions); |
|
not at google - send to devlin
2014/06/15 23:53:38
just pass in |extensions| as a constructor/member
Devlin
2014/06/16 18:11:17
Done.
|
| + |
| + private: |
| + // content::RenderProcessObserver implementation. |
| + virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; |
| + |
| + // Handle the UpdateUserScripts extension message. |
| + void OnUpdateUserScripts(base::SharedMemoryHandle shared_memory, |
| + const std::set<std::string>& changed_extensions); |
| + |
| + // Update the parsed scripts from |shared memory|. |
| + bool UpdateScripts(base::SharedMemoryHandle shared_memory); |
| + |
| + // Returns a new ScriptInjection for the given |script| to execute in the |
| + // |web_frame|, or NULL if the script should not execute. |
| + scoped_ptr<ScriptInjection> GetInjectionForScript( |
| + UserScript* script, |
| + blink::WebFrame* web_frame, |
| + int tab_id, |
| + UserScript::RunLocation run_location, |
| + const GURL& document_url, |
| + const Extension* extension); |
| + |
| + // Shared memory containing raw script data. |
| + scoped_ptr<base::SharedMemory> shared_memory_; |
| + |
| + // The UserScripts this injector manages. |
| + ScopedVector<UserScript> scripts_; |
| + |
| + // The associated observers. |
| + ObserverList<Observer> observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UserScriptInjectionList); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_LIST_H_ |