Allow Flash (and other plugins) to be installed without restarting the browser. This works by monitoring the MozillaPlugins registry key and reloading the plugin list afterwards.
Note: I'll commit the WebKit change separately, but putting it in this change right now so everything can be reviewed together. BUG=10574 Review URL: http://codereview.chromium.org/88020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14377 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
+3
-6
@@ -351,8 +351,9 @@ bool RegKey::DeleteValue(const tchar * value_name) {
|
||||
}
|
||||
|
||||
bool RegKey::StartWatching() {
|
||||
assert(watch_event_ == 0);
|
||||
watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (!watch_event_)
|
||||
watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
DWORD filter = REG_NOTIFY_CHANGE_NAME |
|
||||
REG_NOTIFY_CHANGE_ATTRIBUTES |
|
||||
REG_NOTIFY_CHANGE_LAST_SET |
|
||||
@@ -382,10 +383,6 @@ bool RegKey::StopWatching() {
|
||||
bool RegKey::HasChanged() {
|
||||
if (watch_event_) {
|
||||
if (WaitForSingleObject(watch_event_, 0) == WAIT_OBJECT_0) {
|
||||
// An event only gets signaled once, then it's done, so we have
|
||||
// to set up another event to watch.
|
||||
CloseHandle(watch_event_);
|
||||
watch_event_ = 0;
|
||||
StartWatching();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ class RegKey {
|
||||
bool StopWatching();
|
||||
|
||||
inline bool IsWatching() const { return watch_event_ != 0; }
|
||||
HANDLE watch_event() const { return watch_event_; }
|
||||
HKEY Handle() const { return key_; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/thread.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/chrome_plugin_host.h"
|
||||
#include "chrome/browser/chrome_thread.h"
|
||||
#include "chrome/browser/plugin_process_host.h"
|
||||
#include "chrome/browser/renderer_host/render_process_host.h"
|
||||
#include "chrome/browser/renderer_host/resource_message_filter.h"
|
||||
#include "chrome/common/chrome_plugin_lib.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/logging_chrome.h"
|
||||
#include "chrome/common/render_messages.h"
|
||||
#include "webkit/glue/plugins/plugin_constants_win.h"
|
||||
#include "webkit/glue/plugins/plugin_list.h"
|
||||
|
||||
// static
|
||||
@@ -35,9 +37,32 @@ PluginService::PluginService()
|
||||
std::wstring path = command_line->GetSwitchValue(switches::kLoadPlugin);
|
||||
if (!path.empty())
|
||||
NPAPI::PluginList::AddExtraPluginPath(FilePath::FromWStringHack(path));
|
||||
|
||||
#if defined(OS_WIN)
|
||||
hkcu_key_.Create(
|
||||
HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY);
|
||||
hklm_key_.Create(
|
||||
HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY);
|
||||
if (hkcu_key_.StartWatching()) {
|
||||
hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
|
||||
hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
|
||||
}
|
||||
|
||||
if (hklm_key_.StartWatching()) {
|
||||
hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
|
||||
hklm_watcher_.StartWatching(hklm_event_.get(), this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PluginService::~PluginService() {
|
||||
#if defined(OS_WIN)
|
||||
// Release the events since they're owned by RegKey, not WaitableEvent.
|
||||
hkcu_watcher_.StopWatching();
|
||||
hklm_watcher_.StopWatching();
|
||||
hkcu_event_->Release();
|
||||
hklm_event_->Release();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PluginService::GetPlugins(bool refresh,
|
||||
@@ -171,3 +196,21 @@ bool PluginService::HavePluginFor(const std::string& mime_type,
|
||||
allow_wildcard, &info,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void PluginService::OnWaitableEventSignaled(base::WaitableEvent* waitable_event) {
|
||||
#if defined(OS_WIN)
|
||||
if (waitable_event == hkcu_event_.get()) {
|
||||
hkcu_key_.StartWatching();
|
||||
} else {
|
||||
hklm_key_.StartWatching();
|
||||
}
|
||||
|
||||
AutoLock lock(lock_);
|
||||
NPAPI::PluginList::ResetPluginsLoaded();
|
||||
|
||||
for (RenderProcessHost::iterator it = RenderProcessHost::begin();
|
||||
it != RenderProcessHost::end(); ++it) {
|
||||
it->second->Send(new ViewMsg_PurgePluginListCache());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -15,9 +15,14 @@
|
||||
#include "base/lock.h"
|
||||
#include "base/ref_counted.h"
|
||||
#include "base/singleton.h"
|
||||
#include "base/waitable_event_watcher.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "webkit/glue/webplugin.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/registry.h"
|
||||
#endif
|
||||
|
||||
namespace IPC {
|
||||
class Message;
|
||||
}
|
||||
@@ -30,7 +35,7 @@ class ResourceMessageFilter;
|
||||
|
||||
// This can be called on the main thread and IO thread. However it must
|
||||
// be created on the main thread.
|
||||
class PluginService {
|
||||
class PluginService : base::WaitableEventWatcher::Delegate {
|
||||
public:
|
||||
// Returns the PluginService singleton.
|
||||
static PluginService* GetInstance();
|
||||
@@ -109,6 +114,9 @@ class PluginService {
|
||||
PluginService();
|
||||
~PluginService();
|
||||
|
||||
// base::WaitableEventWatcher::Delegate implementation.
|
||||
void OnWaitableEventSignaled(base::WaitableEvent* waitable_event);
|
||||
|
||||
// mapping between plugin path and PluginProcessHost
|
||||
typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap;
|
||||
PluginMap plugin_hosts_;
|
||||
@@ -129,6 +137,16 @@ class PluginService {
|
||||
// webkit_glue since this class is called on the main and IO thread.
|
||||
Lock lock_;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Registry keys for getting notifications when new plugins are installed.
|
||||
RegKey hkcu_key_;
|
||||
RegKey hklm_key_;
|
||||
scoped_ptr<base::WaitableEvent> hkcu_event_;
|
||||
scoped_ptr<base::WaitableEvent> hklm_event_;
|
||||
base::WaitableEventWatcher hkcu_watcher_;
|
||||
base::WaitableEventWatcher hklm_watcher_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PluginService);
|
||||
};
|
||||
|
||||
|
||||
@@ -382,6 +382,9 @@ IPC_BEGIN_MESSAGES(View)
|
||||
// Install the first missing pluign.
|
||||
IPC_MESSAGE_ROUTED0(ViewMsg_InstallMissingPlugin)
|
||||
|
||||
// Tells the renderer to empty its plugin list cache.
|
||||
IPC_MESSAGE_CONTROL0(ViewMsg_PurgePluginListCache)
|
||||
|
||||
IPC_MESSAGE_ROUTED1(ViewMsg_RunFileChooserResponse,
|
||||
std::vector<FilePath> /* selected files */)
|
||||
|
||||
|
||||
@@ -62,13 +62,15 @@ static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
|
||||
RenderThread::RenderThread()
|
||||
: ChildThread(
|
||||
base::Thread::Options(RenderProcess::InProcessPlugins() ?
|
||||
MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)) {
|
||||
MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)),
|
||||
plugin_refresh_allowed_(true) {
|
||||
}
|
||||
|
||||
RenderThread::RenderThread(const std::wstring& channel_name)
|
||||
: ChildThread(
|
||||
base::Thread::Options(RenderProcess::InProcessPlugins() ?
|
||||
MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)) {
|
||||
MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)),
|
||||
plugin_refresh_allowed_(true) {
|
||||
SetChannelName(channel_name);
|
||||
}
|
||||
|
||||
@@ -197,6 +199,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
|
||||
OnExtensionHandleEvent)
|
||||
IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
|
||||
OnSetExtensionFunctionNames)
|
||||
IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
|
||||
OnPurgePluginListCache)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
}
|
||||
|
||||
@@ -335,3 +339,13 @@ void RenderThread::OnExtensionHandleEvent(const std::string event_name,
|
||||
const std::string event_data) {
|
||||
RendererExtensionBindings::HandleEvent(event_name, event_data);
|
||||
}
|
||||
|
||||
void RenderThread::OnPurgePluginListCache() {
|
||||
// The call below will cause a GetPlugins call with refresh=true, but at this
|
||||
// point we already know that the browser has refreshed its list, so disable
|
||||
// refresh temporarily to prevent each renderer process causing the list to be
|
||||
// regenerated.
|
||||
plugin_refresh_allowed_ = false;
|
||||
WebKit::resetPluginCache();
|
||||
plugin_refresh_allowed_ = true;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ class RenderThread : public RenderThreadBase,
|
||||
return user_script_slave_.get();
|
||||
}
|
||||
|
||||
bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; }
|
||||
|
||||
// Do DNS prefetch resolution of a hostname.
|
||||
void Resolve(const char* name, size_t length);
|
||||
|
||||
@@ -129,6 +131,7 @@ class RenderThread : public RenderThreadBase,
|
||||
void OnExtensionHandleMessage(const std::string& message, int channel_id);
|
||||
void OnExtensionHandleEvent(const std::string event_name,
|
||||
const std::string event_data);
|
||||
void OnPurgePluginListCache();
|
||||
|
||||
// Gather usage statistics from the in-memory cache and inform our host.
|
||||
// These functions should be call periodically so that the host can make
|
||||
@@ -157,6 +160,9 @@ class RenderThread : public RenderThreadBase,
|
||||
|
||||
scoped_refptr<DevToolsAgentFilter> devtools_agent_filter_;
|
||||
|
||||
// If true, then a GetPlugins call is allowed to rescan the disk.
|
||||
bool plugin_refresh_allowed_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(RenderThread);
|
||||
};
|
||||
|
||||
|
||||
@@ -215,8 +215,10 @@ std::string GetUIResourceProtocol() {
|
||||
}
|
||||
|
||||
bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) {
|
||||
return RenderThread::current()->Send(
|
||||
new ViewHostMsg_GetPlugins(refresh, plugins));
|
||||
if (!RenderThread::current()->plugin_refresh_allowed())
|
||||
refresh = false;
|
||||
return RenderThread::current()->Send(new ViewHostMsg_GetPlugins(
|
||||
refresh, plugins));
|
||||
}
|
||||
|
||||
// static factory function
|
||||
|
||||
@@ -33,4 +33,7 @@
|
||||
// plugin process to paint a window.
|
||||
#define kPaintMessageName L"Chrome_CustomPaint"
|
||||
|
||||
// The name of the registry key which NPAPI plugins update on installation.
|
||||
#define kRegistryMozillaPlugins L"SOFTWARE\\MozillaPlugins"
|
||||
|
||||
#endif // WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H_
|
||||
|
||||
@@ -26,7 +26,6 @@ const TCHAR kRegistryAcrobatReader[] = _T("AcroRd32.exe");
|
||||
const TCHAR kRegistryWindowsMedia[] = _T("wmplayer.exe");
|
||||
const TCHAR kRegistryQuickTime[] = _T("QuickTimePlayer.exe");
|
||||
const TCHAR kRegistryPath[] = _T("Path");
|
||||
const TCHAR kRegistryMozillaPlugins[] = _T("SOFTWARE\\MozillaPlugins");
|
||||
const TCHAR kRegistryFirefoxInstalled[] =
|
||||
_T("SOFTWARE\\Mozilla\\Mozilla Firefox");
|
||||
const TCHAR kMozillaActiveXPlugin[] = _T("npmozax.dll");
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário