OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/plugins/plugin_observer.h" | 5 #include "chrome/browser/plugins/plugin_observer.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/metrics/histogram.h" | |
10 #include "base/process_util.h" | |
9 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
10 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
12 #include "chrome/browser/api/infobars/infobar_service.h" | 14 #include "chrome/browser/api/infobars/infobar_service.h" |
13 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" | 15 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
16 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
17 #include "chrome/browser/metrics/metrics_service.h" | 19 #include "chrome/browser/metrics/metrics_service.h" |
18 #include "chrome/browser/plugins/plugin_finder.h" | 20 #include "chrome/browser/plugins/plugin_finder.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 : content::WebContentsObserver(web_contents), | 177 : content::WebContentsObserver(web_contents), |
176 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 178 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
177 } | 179 } |
178 | 180 |
179 PluginObserver::~PluginObserver() { | 181 PluginObserver::~PluginObserver() { |
180 #if defined(ENABLE_PLUGIN_INSTALLATION) | 182 #if defined(ENABLE_PLUGIN_INSTALLATION) |
181 STLDeleteValues(&plugin_placeholders_); | 183 STLDeleteValues(&plugin_placeholders_); |
182 #endif | 184 #endif |
183 } | 185 } |
184 | 186 |
185 void PluginObserver::PluginCrashed(const FilePath& plugin_path) { | 187 void PluginObserver::PluginCrashed(const FilePath& plugin_path, |
188 base::ProcessId plugin_pid) { | |
186 DCHECK(!plugin_path.value().empty()); | 189 DCHECK(!plugin_path.value().empty()); |
187 | 190 |
188 string16 plugin_name = | 191 string16 plugin_name = |
189 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 192 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
193 string16 infobar_text; | |
194 #if defined(OS_WIN) | |
195 // Find out whether the plugin process is still alive. | |
196 base::ProcessHandle plugin_handle = base::kNullProcessHandle; | |
197 bool open_result = base::OpenProcessHandleWithAccess( | |
198 plugin_pid, PROCESS_QUERY_INFORMATION | SYNCHRONIZE, &plugin_handle); | |
199 bool is_running = false; | |
200 if (open_result) { | |
201 is_running = base::GetTerminationStatus(plugin_handle, NULL) == | |
jschuh
2013/01/09 00:36:17
This will work only if a handle to the dead proces
yzshen1
2013/01/09 00:45:50
I tried to figure out how to hold a handle instead
jschuh
2013/01/09 01:29:16
Well, the odds of it getting reused are very slim.
| |
202 base::TERMINATION_STATUS_STILL_RUNNING; | |
203 base::CloseProcessHandle(plugin_handle); | |
204 } | |
205 | |
206 if (is_running) { | |
207 infobar_text = l10n_util::GetStringFUTF16(IDS_PLUGIN_DISCONNECTED_PROMPT, | |
208 plugin_name); | |
209 UMA_HISTOGRAM_COUNTS("Plugin.ShowDisconnectedInfobar", 1); | |
210 } else { | |
211 infobar_text = l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, | |
212 plugin_name); | |
213 UMA_HISTOGRAM_COUNTS("Plugin.ShowCrashedInfobar", 1); | |
214 } | |
215 #else | |
216 // Calling the POSIX version of base::GetTerminationStatus() may affect other | |
217 // code which is interested in the process termination status. (Please see the | |
218 // comment of the function.) Therefore, it shouldn't be used to distinguish | |
219 // disconnections from crashes. | |
220 infobar_text = l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, | |
221 plugin_name); | |
222 UMA_HISTOGRAM_COUNTS("Plugin.ShowCrashedInfobar", 1); | |
223 #endif | |
224 | |
190 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 225 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
191 IDR_INFOBAR_PLUGIN_CRASHED); | 226 IDR_INFOBAR_PLUGIN_CRASHED); |
192 InfoBarService* infobar_service = | 227 InfoBarService* infobar_service = |
193 InfoBarService::FromWebContents(web_contents()); | 228 InfoBarService::FromWebContents(web_contents()); |
194 infobar_service->AddInfoBar( | 229 infobar_service->AddInfoBar( |
195 new SimpleAlertInfoBarDelegate( | 230 new SimpleAlertInfoBarDelegate( |
196 infobar_service, | 231 infobar_service, |
197 icon, | 232 icon, |
198 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), | 233 infobar_text, |
199 true)); | 234 true)); |
200 } | 235 } |
201 | 236 |
202 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { | 237 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { |
203 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) | 238 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) |
204 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | 239 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, |
205 OnBlockedOutdatedPlugin) | 240 OnBlockedOutdatedPlugin) |
206 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, | 241 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, |
207 OnBlockedUnauthorizedPlugin) | 242 OnBlockedUnauthorizedPlugin) |
208 #if defined(ENABLE_PLUGIN_INSTALLATION) | 243 #if defined(ENABLE_PLUGIN_INSTALLATION) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 InfoBarService::FromWebContents(web_contents()); | 414 InfoBarService::FromWebContents(web_contents()); |
380 infobar_service->AddInfoBar( | 415 infobar_service->AddInfoBar( |
381 new PluginMetroModeInfoBarDelegate( | 416 new PluginMetroModeInfoBarDelegate( |
382 infobar_service, | 417 infobar_service, |
383 PluginMetroModeInfoBarDelegate::DESKTOP_MODE_REQUIRED, | 418 PluginMetroModeInfoBarDelegate::DESKTOP_MODE_REQUIRED, |
384 plugin->name())); | 419 plugin->name())); |
385 #else | 420 #else |
386 NOTREACHED(); | 421 NOTREACHED(); |
387 #endif | 422 #endif |
388 } | 423 } |
OLD | NEW |