1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// Copyright (c) 2011 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.
#include "chrome/browser/plugin_data_remover.h"
#include "base/command_line.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/synchronization/waitable_event.h"
#include "base/version.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/browser_thread.h"
#include "content/browser/plugin_service.h"
#include "content/common/plugin_messages.h"
#include "webkit/plugins/npapi/plugin_group.h"
#include "webkit/plugins/npapi/plugin_list.h"
#if defined(OS_POSIX)
#include "ipc/ipc_channel_posix.h"
#endif
namespace {
const char* kFlashMimeType = "application/x-shockwave-flash";
// The minimum Flash Player version that implements NPP_ClearSiteData.
const char* kMinFlashVersion = "10.3";
const int64 kRemovalTimeoutMs = 10000;
const uint64 kClearAllData = 0;
} // namespace
PluginDataRemover::PluginDataRemover()
: mime_type_(kFlashMimeType),
is_removing_(false),
event_(new base::WaitableEvent(true, false)),
channel_(NULL) {
}
PluginDataRemover::~PluginDataRemover() {
DCHECK(!is_removing_);
if (channel_)
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_);
}
base::WaitableEvent* PluginDataRemover::StartRemoving(base::Time begin_time) {
DCHECK(!is_removing_);
remove_start_time_ = base::Time::Now();
begin_time_ = begin_time;
is_removing_ = true;
// Balanced in OnChannelOpened or OnError. Exactly one them will eventually be
// called, so we need to keep this object around until then.
AddRef();
PluginService::GetInstance()->OpenChannelToNpapiPlugin(
0, 0, GURL(), mime_type_, this);
BrowserThread::PostDelayedTask(
BrowserThread::IO,
FROM_HERE,
NewRunnableMethod(this, &PluginDataRemover::OnTimeout),
kRemovalTimeoutMs);
return event_.get();
}
void PluginDataRemover::Wait() {
base::Time start_time(base::Time::Now());
bool result = true;
if (is_removing_)
result = event_->Wait();
UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown",
base::Time::Now() - start_time);
UMA_HISTOGRAM_TIMES("ClearPluginData.time_at_shutdown",
base::Time::Now() - remove_start_time_);
DCHECK(result) << "Error waiting for plugin process";
}
int PluginDataRemover::ID() {
// Generate a unique identifier for this PluginProcessHostClient.
return ChildProcessInfo::GenerateChildProcessUniqueId();
}
bool PluginDataRemover::OffTheRecord() {
return false;
}
void PluginDataRemover::SetPluginInfo(
const webkit::npapi::WebPluginInfo& info) {
}
void PluginDataRemover::OnChannelOpened(const IPC::ChannelHandle& handle) {
ConnectToChannel(handle);
// Balancing the AddRef call in StartRemoving.
Release();
}
void PluginDataRemover::ConnectToChannel(const IPC::ChannelHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// If we timed out, don't bother connecting.
if (!is_removing_)
return;
DCHECK(!channel_);
channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this);
if (!channel_->Connect()) {
NOTREACHED() << "Couldn't connect to plugin";
SignalDone();
return;
}
if (!channel_->Send(new PluginMsg_ClearSiteData(std::string(),
kClearAllData,
begin_time_))) {
NOTREACHED() << "Couldn't send ClearSiteData message";
SignalDone();
return;
}
}
void PluginDataRemover::OnError() {
LOG(DFATAL) << "Couldn't open plugin channel";
SignalDone();
// Balancing the AddRef call in StartRemoving.
Release();
}
void PluginDataRemover::OnClearSiteDataResult(bool success) {
LOG_IF(DFATAL, !success) << "ClearSiteData returned error";
UMA_HISTOGRAM_TIMES("ClearPluginData.time",
base::Time::Now() - remove_start_time_);
SignalDone();
}
void PluginDataRemover::OnTimeout() {
LOG_IF(DFATAL, is_removing_) << "Timed out";
SignalDone();
}
bool PluginDataRemover::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PluginDataRemover, msg)
IPC_MESSAGE_HANDLER(PluginHostMsg_ClearSiteDataResult,
OnClearSiteDataResult)
IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP()
return true;
}
void PluginDataRemover::OnChannelError() {
if (is_removing_) {
NOTREACHED() << "Channel error";
SignalDone();
}
}
void PluginDataRemover::SignalDone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!is_removing_)
return;
is_removing_ = false;
event_->Signal();
}
// static
bool PluginDataRemover::IsSupported() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
bool allow_wildcard = false;
webkit::npapi::WebPluginInfo plugin;
std::string mime_type;
if (!webkit::npapi::PluginList::Singleton()->GetPluginInfo(
GURL(), kFlashMimeType, allow_wildcard, &plugin, &mime_type)) {
return false;
}
scoped_ptr<Version> version(
webkit::npapi::PluginGroup::CreateVersionFromString(plugin.version));
scoped_ptr<Version> min_version(Version::GetVersionFromString(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMinClearSiteDataFlashVersion)));
if (!min_version.get())
min_version.reset(Version::GetVersionFromString(kMinFlashVersion));
return webkit::npapi::IsPluginEnabled(plugin) &&
version.get() &&
min_version->CompareTo(*version) == -1;
}
|