#ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
#define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
#include <map>
#include <set>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
#include "base/synchronization/waitable_event_watcher.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time.h"
#include "build/build_config.h"
#include "content/browser/plugin_process_host.h"
#include "content/browser/ppapi_plugin_process_host.h"
#include "content/common/content_export.h"
#include "content/public/browser/plugin_service.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel_handle.h"
#if defined(OS_WIN)
#include "base/memory/scoped_ptr.h"
#include "base/win/registry.h"
#endif
#if defined(OS_POSIX) && !defined(OS_OPENBSD)
#include "base/files/file_path_watcher.h"
#endif
class PluginDirWatcherDelegate;
class PluginLoaderPosix;
namespace base {
class MessageLoopProxy;
}
namespace content {
class BrowserContext;
class PluginServiceFilter;
class ResourceContext;
struct PepperPluginInfo;
}
namespace webkit {
namespace npapi {
class PluginGroup;
class PluginList;
}
}
struct PluginServiceFilterParams {
int render_process_id;
int render_view_id;
GURL page_url;
content::ResourceContext* resource_context;
};
class CONTENT_EXPORT PluginServiceImpl
: NON_EXPORTED_BASE(public content::PluginService),
public base::WaitableEventWatcher::Delegate {
public:
static PluginServiceImpl* GetInstance();
virtual void Init() OVERRIDE;
virtual void StartWatchingPlugins() OVERRIDE;
virtual bool GetPluginInfoArray(
const GURL& url,
const std::string& mime_type,
bool allow_wildcard,
std::vector<webkit::WebPluginInfo>* info,
std::vector<std::string>* actual_mime_types) OVERRIDE;
virtual bool GetPluginInfo(int render_process_id,
int render_view_id,
content::ResourceContext* context,
const GURL& url,
const GURL& page_url,
const std::string& mime_type,
bool allow_wildcard,
bool* is_stale,
webkit::WebPluginInfo* info,
std::string* actual_mime_type) OVERRIDE;
virtual bool GetPluginInfoByPath(const FilePath& plugin_path,
webkit::WebPluginInfo* info) OVERRIDE;
virtual string16 GetPluginDisplayNameByPath(const FilePath& path) OVERRIDE;
virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE;
virtual void GetPluginGroups(
const GetPluginGroupsCallback& callback) OVERRIDE;
virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
const FilePath& plugin_path) OVERRIDE;
virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE;
virtual content::PluginServiceFilter* GetFilter() OVERRIDE;
virtual void ForcePluginShutdown(const FilePath& plugin_path) OVERRIDE;
virtual bool IsPluginUnstable(const FilePath& plugin_path) OVERRIDE;
virtual void RefreshPlugins() OVERRIDE;
virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE;
virtual void AddExtraPluginDir(const FilePath& path) OVERRIDE;
virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE;
virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE;
virtual void RegisterInternalPlugin(
const webkit::WebPluginInfo& info, bool add_at_beginning) OVERRIDE;
virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE;
virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE;
virtual void SetPluginListForTesting(
webkit::npapi::PluginList* plugin_list) OVERRIDE;
#if defined(OS_MACOSX)
virtual void AppActivated() OVERRIDE;
#endif
PluginProcessHost* FindOrStartNpapiPluginProcess(
const FilePath& plugin_path);
PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
const FilePath& plugin_path,
const FilePath& profile_data_directory,
PpapiPluginProcessHost::PluginClient* client);
PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess(
const FilePath& plugin_path);
void OpenChannelToNpapiPlugin(int render_process_id,
int render_view_id,
const GURL& url,
const GURL& page_url,
const std::string& mime_type,
PluginProcessHost::Client* client);
void OpenChannelToPpapiPlugin(const FilePath& plugin_path,
const FilePath& profile_data_directory,
PpapiPluginProcessHost::PluginClient* client);
void OpenChannelToPpapiBroker(const FilePath& path,
PpapiPluginProcessHost::BrokerClient* client);
void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
void RegisterPluginCrash(const FilePath& plugin_path);
private:
friend struct DefaultSingletonTraits<PluginServiceImpl>;
PluginServiceImpl();
virtual ~PluginServiceImpl();
virtual void OnWaitableEventSignaled(
base::WaitableEvent* waitable_event) OVERRIDE;
PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
PpapiPluginProcessHost* FindPpapiPluginProcess(
const FilePath& plugin_path,
const FilePath& profile_data_directory);
PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
void RegisterPepperPlugins();
#if defined(OS_WIN)
void GetPluginsInternal(base::MessageLoopProxy* target_loop,
const GetPluginsCallback& callback);
#endif
void ForwardGetAllowedPluginForOpenChannelToPlugin(
const PluginServiceFilterParams& params,
const GURL& url,
const std::string& mime_type,
PluginProcessHost::Client* client,
const std::vector<webkit::WebPluginInfo>&);
void GetAllowedPluginForOpenChannelToPlugin(
int render_process_id,
int render_view_id,
const GURL& url,
const GURL& page_url,
const std::string& mime_type,
PluginProcessHost::Client* client,
content::ResourceContext* resource_context);
void FinishOpenChannelToPlugin(
const FilePath& plugin_path,
PluginProcessHost::Client* client);
#if defined(OS_POSIX) && !defined(OS_OPENBSD)
static void RegisterFilePathWatcher(
base::files::FilePathWatcher* watcher,
const FilePath& path,
base::files::FilePathWatcher::Delegate* delegate);
#endif
webkit::npapi::PluginList* plugin_list_;
#if defined(OS_WIN)
base::win::RegKey hkcu_key_;
base::win::RegKey hklm_key_;
scoped_ptr<base::WaitableEvent> hkcu_event_;
scoped_ptr<base::WaitableEvent> hklm_event_;
base::WaitableEventWatcher hkcu_watcher_;
base::WaitableEventWatcher hklm_watcher_;
#endif
#if defined(OS_POSIX) && !defined(OS_OPENBSD)
ScopedVector<base::files::FilePathWatcher> file_watchers_;
scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
#endif
std::vector<content::PepperPluginInfo> ppapi_plugins_;
content::PluginServiceFilter* filter_;
std::set<PluginProcessHost::Client*> pending_plugin_clients_;
#if defined(OS_WIN)
base::SequencedWorkerPool::SequenceToken plugin_list_token_;
#endif
#if defined(OS_POSIX)
scoped_refptr<PluginLoaderPosix> plugin_loader_;
#endif
std::map<FilePath, std::vector<base::Time> > crash_times_;
DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl);
};
#endif