#ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
#define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
#include <map>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/singleton.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "content/public/browser/plugin_service.h"
#include "ppapi/buildflags/buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
#if !BUILDFLAG(ENABLE_PLUGINS)
#error "Plugins should be enabled"
#endif
#if BUILDFLAG(ENABLE_PPAPI)
#include "content/browser/ppapi_plugin_process_host.h"
#endif
namespace content {
class PluginServiceFilter;
struct ContentPluginInfo;
class CONTENT_EXPORT PluginServiceImpl : public PluginService {
public:
static PluginServiceImpl* GetInstance();
PluginServiceImpl(const PluginServiceImpl&) = delete;
PluginServiceImpl& operator=(const PluginServiceImpl&) = delete;
void Init() override;
bool GetPluginInfoArray(const GURL& url,
const std::string& mime_type,
bool allow_wildcard,
std::vector<WebPluginInfo>* info,
std::vector<std::string>* actual_mime_types) override;
bool GetPluginInfo(content::BrowserContext* browser_context,
const GURL& url,
const std::string& mime_type,
bool allow_wildcard,
bool* is_stale,
WebPluginInfo* info,
std::string* actual_mime_type) override;
bool GetPluginInfoByPath(const base::FilePath& plugin_path,
WebPluginInfo* info) override;
std::u16string GetPluginDisplayNameByPath(
const base::FilePath& path) override;
void GetPlugins(GetPluginsCallback callback) override;
std::vector<WebPluginInfo> GetPluginsSynchronous() override;
const ContentPluginInfo* GetRegisteredPluginInfo(
const base::FilePath& plugin_path) override;
void SetFilter(PluginServiceFilter* filter) override;
PluginServiceFilter* GetFilter() override;
bool IsPluginUnstable(const base::FilePath& plugin_path) override;
void RefreshPlugins() override;
void RegisterInternalPlugin(const WebPluginInfo& info,
bool add_at_beginning) override;
void UnregisterInternalPlugin(const base::FilePath& path) override;
void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override;
bool PpapiDevChannelSupported(BrowserContext* browser_context,
const GURL& document_url) override;
#if BUILDFLAG(ENABLE_PPAPI)
PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
int render_process_id,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
const absl::optional<url::Origin>& origin_lock);
void OpenChannelToPpapiPlugin(int render_process_id,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
const absl::optional<url::Origin>& origin_lock,
PpapiPluginProcessHost::PluginClient* client);
#endif
void RegisterPluginCrash(const base::FilePath& plugin_path);
void SetMaxPpapiProcessesPerProfileForTesting(int number) {
max_ppapi_processes_per_profile_ = number;
}
private:
friend struct base::DefaultSingletonTraits<PluginServiceImpl>;
static constexpr int kDefaultMaxPpapiProcessesPerProfile = 15;
PluginServiceImpl();
~PluginServiceImpl() override;
#if BUILDFLAG(ENABLE_PPAPI)
PpapiPluginProcessHost* FindPpapiPluginProcess(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
const absl::optional<url::Origin>& origin_lock);
#endif
void RegisterPlugins();
std::vector<ContentPluginInfo> plugins_;
int max_ppapi_processes_per_profile_ = kDefaultMaxPpapiProcessesPerProfile;
raw_ptr<PluginServiceFilter, DanglingUntriaged> filter_ = nullptr;
std::map<base::FilePath, std::vector<base::Time>> crash_times_;
};
}
#endif