| 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 #ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
| 19 | 19 |
| 20 class InfoBarDelegate; |
| 21 |
| 22 namespace base { |
| 20 class FilePath; | 23 class FilePath; |
| 21 class InfoBarDelegate; | 24 } |
| 22 | 25 |
| 23 // Manages per-tab state with regard to hung plugins. This only handles | 26 // Manages per-tab state with regard to hung plugins. This only handles |
| 24 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which | 27 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which |
| 25 // may have native windows) can not be handled with infobars and have a | 28 // may have native windows) can not be handled with infobars and have a |
| 26 // separate OS-specific hang monitoring. | 29 // separate OS-specific hang monitoring. |
| 27 // | 30 // |
| 28 // Our job is: | 31 // Our job is: |
| 29 // - Pop up an infobar when a plugin is hung. | 32 // - Pop up an infobar when a plugin is hung. |
| 30 // - Terminate the plugin process if the user so chooses. | 33 // - Terminate the plugin process if the user so chooses. |
| 31 // - Periodically re-show the hung plugin infobar if the user closes it without | 34 // - Periodically re-show the hung plugin infobar if the user closes it without |
| 32 // terminating the plugin. | 35 // terminating the plugin. |
| 33 // - Hide the infobar if the plugin starts responding again. | 36 // - Hide the infobar if the plugin starts responding again. |
| 34 // - Keep track of all of this for any number of plugins. | 37 // - Keep track of all of this for any number of plugins. |
| 35 class HungPluginTabHelper | 38 class HungPluginTabHelper |
| 36 : public content::WebContentsObserver, | 39 : public content::WebContentsObserver, |
| 37 public content::NotificationObserver, | 40 public content::NotificationObserver, |
| 38 public content::WebContentsUserData<HungPluginTabHelper> { | 41 public content::WebContentsUserData<HungPluginTabHelper> { |
| 39 public: | 42 public: |
| 40 virtual ~HungPluginTabHelper(); | 43 virtual ~HungPluginTabHelper(); |
| 41 | 44 |
| 42 // content::WebContentsObserver overrides: | 45 // content::WebContentsObserver overrides: |
| 43 virtual void PluginCrashed(const FilePath& plugin_path, | 46 virtual void PluginCrashed(const base::FilePath& plugin_path, |
| 44 base::ProcessId plugin_pid) OVERRIDE; | 47 base::ProcessId plugin_pid) OVERRIDE; |
| 45 virtual void PluginHungStatusChanged(int plugin_child_id, | 48 virtual void PluginHungStatusChanged(int plugin_child_id, |
| 46 const FilePath& plugin_path, | 49 const base::FilePath& plugin_path, |
| 47 bool is_hung) OVERRIDE; | 50 bool is_hung) OVERRIDE; |
| 48 | 51 |
| 49 // NotificationObserver overrides. | 52 // NotificationObserver overrides. |
| 50 virtual void Observe(int type, | 53 virtual void Observe(int type, |
| 51 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
| 52 const content::NotificationDetails& details) OVERRIDE; | 55 const content::NotificationDetails& details) OVERRIDE; |
| 53 | 56 |
| 54 // Called by an infobar when the user selects to kill the plugin. | 57 // Called by an infobar when the user selects to kill the plugin. |
| 55 void KillPlugin(int child_id); | 58 void KillPlugin(int child_id); |
| 56 | 59 |
| 57 private: | 60 private: |
| 58 explicit HungPluginTabHelper(content::WebContents* contents); | 61 explicit HungPluginTabHelper(content::WebContents* contents); |
| 59 friend class content::WebContentsUserData<HungPluginTabHelper>; | 62 friend class content::WebContentsUserData<HungPluginTabHelper>; |
| 60 | 63 |
| 61 // Per-plugin state (since there could be more than one plugin hung). The | 64 // Per-plugin state (since there could be more than one plugin hung). The |
| 62 // integer key is the child process ID of the plugin process. This maintains | 65 // integer key is the child process ID of the plugin process. This maintains |
| 63 // the state for all plugins on this page that are currently hung, whether or | 66 // the state for all plugins on this page that are currently hung, whether or |
| 64 // not we're currently showing the infobar. | 67 // not we're currently showing the infobar. |
| 65 struct PluginState { | 68 struct PluginState { |
| 66 // Initializes the plugin state to be a hung plugin. | 69 // Initializes the plugin state to be a hung plugin. |
| 67 PluginState(const FilePath& p, const string16& n); | 70 PluginState(const base::FilePath& p, const string16& n); |
| 68 ~PluginState(); | 71 ~PluginState(); |
| 69 | 72 |
| 70 FilePath path; | 73 base::FilePath path; |
| 71 string16 name; | 74 string16 name; |
| 72 | 75 |
| 73 // Possibly-null if we're not showing an infobar right now. | 76 // Possibly-null if we're not showing an infobar right now. |
| 74 InfoBarDelegate* info_bar; | 77 InfoBarDelegate* info_bar; |
| 75 | 78 |
| 76 // Time to delay before re-showing the infobar for a hung plugin. This is | 79 // Time to delay before re-showing the infobar for a hung plugin. This is |
| 77 // increased each time the user cancels it. | 80 // increased each time the user cancels it. |
| 78 base::TimeDelta next_reshow_delay; | 81 base::TimeDelta next_reshow_delay; |
| 79 | 82 |
| 80 // Handles calling the helper when the infobar should be re-shown. | 83 // Handles calling the helper when the infobar should be re-shown. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 | 103 |
| 101 content::NotificationRegistrar registrar_; | 104 content::NotificationRegistrar registrar_; |
| 102 | 105 |
| 103 // All currently hung plugins. | 106 // All currently hung plugins. |
| 104 PluginStateMap hung_plugins_; | 107 PluginStateMap hung_plugins_; |
| 105 | 108 |
| 106 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); | 109 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 112 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
| OLD | NEW |