#ifndef EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_
#define EXTENSIONS_RENDERER_USER_SCRIPT_SET_H_
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/memory/read_only_shared_memory_region.h"
#include "base/observer_list.h"
#include "extensions/common/mojom/host_id.mojom-forward.h"
#include "extensions/common/mojom/run_location.mojom-shared.h"
#include "extensions/common/user_script.h"
#include "third_party/blink/public/platform/web_string.h"
class GURL;
namespace content {
class RenderFrame;
}
namespace extensions {
class ScriptInjection;
class UserScriptSet {
public:
class Observer {
public:
virtual void OnUserScriptsUpdated() = 0;
virtual void OnUserScriptSetDestroyed() = 0;
};
explicit UserScriptSet(mojom::HostID host_id);
UserScriptSet(const UserScriptSet&) = delete;
UserScriptSet& operator=(const UserScriptSet&) = delete;
~UserScriptSet();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void GetInjections(std::vector<std::unique_ptr<ScriptInjection>>* injections,
content::RenderFrame* render_frame,
int tab_id,
mojom::RunLocation run_location,
bool log_activity);
std::unique_ptr<ScriptInjection> GetDeclarativeScriptInjection(
const std::string& script_id,
content::RenderFrame* render_frame,
int tab_id,
mojom::RunLocation run_location,
const GURL& document_url,
bool log_activity);
bool UpdateUserScripts(base::ReadOnlySharedMemoryRegion shared_memory);
bool HasScripts() const { return !scripts_.empty(); }
void ClearUserScripts();
blink::WebString GetJsSource(const UserScript::File& file,
bool emulate_greasemonkey);
blink::WebString GetCssSource(const UserScript::File& file);
private:
std::unique_ptr<ScriptInjection> GetInjectionForScript(
const UserScript* script,
content::RenderFrame* render_frame,
int tab_id,
mojom::RunLocation run_location,
const GURL& document_url,
bool is_declarative,
bool log_activity);
base::ReadOnlySharedMemoryMapping shared_memory_mapping_;
UserScriptList scripts_;
std::map<GURL, blink::WebString> script_sources_;
mojom::HostID host_id_;
base::ObserverList<Observer>::Unchecked observers_;
};
}
#endif