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/ui/hung_plugin_tab_helper.h" | 5 #include "chrome/browser/ui/hung_plugin_tab_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
15 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
16 #include "components/infobars/core/confirm_infobar_delegate.h" | 15 #include "components/infobars/core/confirm_infobar_delegate.h" |
17 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
18 #include "content/public/browser/browser_child_process_host_iterator.h" | 17 #include "content/public/browser/browser_child_process_host_iterator.h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/child_process_data.h" | 19 #include "content/public/browser/child_process_data.h" |
21 #include "content/public/browser/notification_details.h" | |
22 #include "content/public/browser/notification_service.h" | |
23 #include "content/public/browser/plugin_service.h" | 20 #include "content/public/browser/plugin_service.h" |
24 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/common/process_type.h" | 22 #include "content/public/common/process_type.h" |
26 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
27 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
29 #include "grit/locale_settings.h" | 26 #include "grit/locale_settings.h" |
30 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
32 | 29 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 251 |
255 HungPluginTabHelper::PluginState::~PluginState() { | 252 HungPluginTabHelper::PluginState::~PluginState() { |
256 } | 253 } |
257 | 254 |
258 | 255 |
259 // HungPluginTabHelper -------------------------------------------------------- | 256 // HungPluginTabHelper -------------------------------------------------------- |
260 | 257 |
261 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HungPluginTabHelper); | 258 DEFINE_WEB_CONTENTS_USER_DATA_KEY(HungPluginTabHelper); |
262 | 259 |
263 HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents) | 260 HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents) |
264 : content::WebContentsObserver(contents) { | 261 : content::WebContentsObserver(contents), |
265 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 262 number_of_infobars_(0) { |
266 content::NotificationService::AllSources()); | |
267 } | 263 } |
268 | 264 |
269 HungPluginTabHelper::~HungPluginTabHelper() { | 265 HungPluginTabHelper::~HungPluginTabHelper() { |
tfarina
2014/06/07 05:26:21
Peter, I got the backtrace for this.
It is this (
| |
266 DCHECK_EQ(0, number_of_infobars_); | |
Peter Kasting
2014/06/03 18:41:45
Are you sure we're guaranteed that the InfoBarMana
| |
270 } | 267 } |
271 | 268 |
272 void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path, | 269 void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path, |
273 base::ProcessId plugin_pid) { | 270 base::ProcessId plugin_pid) { |
274 // TODO(brettw) ideally this would take the child process ID. When we do this | 271 // TODO(brettw) ideally this would take the child process ID. When we do this |
275 // for NaCl plugins, we'll want to know exactly which process it was since | 272 // for NaCl plugins, we'll want to know exactly which process it was since |
276 // the path won't be useful. | 273 // the path won't be useful. |
277 InfoBarService* infobar_service = | 274 InfoBarService* infobar_service = |
278 InfoBarService::FromWebContents(web_contents()); | 275 InfoBarService::FromWebContents(web_contents()); |
279 if (!infobar_service) | 276 if (!infobar_service) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 311 |
315 base::string16 plugin_name = | 312 base::string16 plugin_name = |
316 content::PluginService::GetInstance()->GetPluginDisplayNameByPath( | 313 content::PluginService::GetInstance()->GetPluginDisplayNameByPath( |
317 plugin_path); | 314 plugin_path); |
318 | 315 |
319 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); | 316 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); |
320 hung_plugins_[plugin_child_id] = state; | 317 hung_plugins_[plugin_child_id] = state; |
321 ShowBar(plugin_child_id, state.get()); | 318 ShowBar(plugin_child_id, state.get()); |
322 } | 319 } |
323 | 320 |
324 void HungPluginTabHelper::Observe( | 321 void HungPluginTabHelper::OnInfoBarRemoved(infobars::InfoBar* infobar, |
325 int type, | 322 bool animate) { |
326 const content::NotificationSource& source, | 323 --number_of_infobars_; |
Peter Kasting
2014/06/03 18:41:45
This is not safe. You get called on every kind of
tfarina
2014/06/07 05:26:21
Done.
| |
327 const content::NotificationDetails& details) { | 324 |
Peter Kasting
2014/06/03 18:41:45
Nit: I'd avoid this newline (2 places)
tfarina
2014/06/07 05:26:21
Done.
| |
328 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 325 if (number_of_infobars_ == 0) |
329 infobars::InfoBar* infobar = | 326 InfoBarService::FromWebContents(web_contents())->RemoveObserver(this); |
330 content::Details<infobars::InfoBar::RemovedDetails>(details)->first; | 327 |
331 for (PluginStateMap::iterator i = hung_plugins_.begin(); | 328 for (PluginStateMap::iterator i = hung_plugins_.begin(); |
332 i != hung_plugins_.end(); ++i) { | 329 i != hung_plugins_.end(); ++i) { |
333 PluginState* state = i->second.get(); | 330 PluginState* state = i->second.get(); |
334 if (state->infobar == infobar) { | 331 if (state->infobar == infobar) { |
335 state->infobar = NULL; | 332 state->infobar = NULL; |
336 | 333 |
337 // Schedule the timer to re-show the infobar if the plugin continues to be | 334 // Schedule the timer to re-show the infobar if the plugin continues to be |
338 // hung. | 335 // hung. |
339 state->timer.Start(FROM_HERE, state->next_reshow_delay, | 336 state->timer.Start(FROM_HERE, state->next_reshow_delay, |
340 base::Bind(&HungPluginTabHelper::OnReshowTimer, | 337 base::Bind(&HungPluginTabHelper::OnReshowTimer, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 402 |
406 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) { | 403 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) { |
407 InfoBarService* infobar_service = | 404 InfoBarService* infobar_service = |
408 InfoBarService::FromWebContents(web_contents()); | 405 InfoBarService::FromWebContents(web_contents()); |
409 if (!infobar_service) | 406 if (!infobar_service) |
410 return; | 407 return; |
411 | 408 |
412 DCHECK(!state->infobar); | 409 DCHECK(!state->infobar); |
413 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this, | 410 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this, |
414 child_id, state->name); | 411 child_id, state->name); |
412 | |
413 if (state->infobar) { | |
414 ++number_of_infobars_; | |
415 | |
416 if (number_of_infobars_ == 1) | |
417 infobar_service->AddObserver(this); | |
418 } | |
415 } | 419 } |
416 | 420 |
417 void HungPluginTabHelper::CloseBar(PluginState* state) { | 421 void HungPluginTabHelper::CloseBar(PluginState* state) { |
418 InfoBarService* infobar_service = | 422 InfoBarService* infobar_service = |
419 InfoBarService::FromWebContents(web_contents()); | 423 InfoBarService::FromWebContents(web_contents()); |
420 if (infobar_service && state->infobar) { | 424 if (infobar_service && state->infobar) { |
421 infobar_service->RemoveInfoBar(state->infobar); | 425 infobar_service->RemoveInfoBar(state->infobar); |
422 state->infobar = NULL; | 426 state->infobar = NULL; |
423 } | 427 } |
424 } | 428 } |
OLD | NEW |