| 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 FilePath; | 20 class FilePath; |
| 21 class InfoBarDelegate; |
| 21 | 22 |
| 22 // Manages per-tab state with regard to hung plugins. This only handles | 23 // Manages per-tab state with regard to hung plugins. This only handles |
| 23 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which | 24 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which |
| 24 // may have native windows) can not be handled with infobars and have a | 25 // may have native windows) can not be handled with infobars and have a |
| 25 // separate OS-specific hang monitoring. | 26 // separate OS-specific hang monitoring. |
| 26 // | 27 // |
| 27 // Our job is: | 28 // Our job is: |
| 28 // - Pop up an infobar when a plugin is hung. | 29 // - Pop up an infobar when a plugin is hung. |
| 29 // - Terminate the plugin process if the user so chooses. | 30 // - Terminate the plugin process if the user so chooses. |
| 30 // - Periodically re-show the hung plugin infobar if the user closes it without | 31 // - Periodically re-show the hung plugin infobar if the user closes it without |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE; | 43 virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE; |
| 43 virtual void PluginHungStatusChanged(int plugin_child_id, | 44 virtual void PluginHungStatusChanged(int plugin_child_id, |
| 44 const FilePath& plugin_path, | 45 const FilePath& plugin_path, |
| 45 bool is_hung) OVERRIDE; | 46 bool is_hung) OVERRIDE; |
| 46 | 47 |
| 47 // NotificationObserver overrides. | 48 // NotificationObserver overrides. |
| 48 virtual void Observe(int type, | 49 virtual void Observe(int type, |
| 49 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
| 50 const content::NotificationDetails& details) OVERRIDE; | 51 const content::NotificationDetails& details) OVERRIDE; |
| 51 | 52 |
| 53 // Called by an infobar when the user selects to kill the plugin. |
| 54 void KillPlugin(int child_id); |
| 55 |
| 52 private: | 56 private: |
| 53 explicit HungPluginTabHelper(content::WebContents* contents); | 57 explicit HungPluginTabHelper(content::WebContents* contents); |
| 54 friend class content::WebContentsUserData<HungPluginTabHelper>; | 58 friend class content::WebContentsUserData<HungPluginTabHelper>; |
| 55 | 59 |
| 56 class InfoBarDelegate; | |
| 57 friend class InfoBarDelegate; | |
| 58 | |
| 59 // Per-plugin state (since there could be more than one plugin hung). The | 60 // Per-plugin state (since there could be more than one plugin hung). The |
| 60 // integer key is the child process ID of the plugin process. This maintains | 61 // integer key is the child process ID of the plugin process. This maintains |
| 61 // the state for all plugins on this page that are currently hung, whether or | 62 // the state for all plugins on this page that are currently hung, whether or |
| 62 // not we're currently showing the infobar. | 63 // not we're currently showing the infobar. |
| 63 struct PluginState { | 64 struct PluginState { |
| 64 // Initializes the plugin state to be a hung plugin. | 65 // Initializes the plugin state to be a hung plugin. |
| 65 PluginState(const FilePath& p, const string16& n); | 66 PluginState(const FilePath& p, const string16& n); |
| 66 ~PluginState(); | 67 ~PluginState(); |
| 67 | 68 |
| 68 FilePath path; | 69 FilePath path; |
| 69 string16 name; | 70 string16 name; |
| 70 | 71 |
| 71 // Possibly-null if we're not showing an infobar right now. | 72 // Possibly-null if we're not showing an infobar right now. |
| 72 InfoBarDelegate* info_bar; | 73 InfoBarDelegate* info_bar; |
| 73 | 74 |
| 74 // Time to delay before re-showing the infobar for a hung plugin. This is | 75 // Time to delay before re-showing the infobar for a hung plugin. This is |
| 75 // increased each time the user cancels it. | 76 // increased each time the user cancels it. |
| 76 base::TimeDelta next_reshow_delay; | 77 base::TimeDelta next_reshow_delay; |
| 77 | 78 |
| 78 // Handles calling the helper when the infobar should be re-shown. | 79 // Handles calling the helper when the infobar should be re-shown. |
| 79 base::Timer timer; | 80 base::Timer timer; |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 // Since the scope of the timer manages our callback, this struct should | 83 // Since the scope of the timer manages our callback, this struct should |
| 83 // not be copied. | 84 // not be copied. |
| 84 DISALLOW_COPY_AND_ASSIGN(PluginState); | 85 DISALLOW_COPY_AND_ASSIGN(PluginState); |
| 85 }; | 86 }; |
| 86 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; | 87 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; |
| 87 | 88 |
| 88 // Called by an infobar when the user selects to kill the plugin. | |
| 89 void KillPlugin(int child_id); | |
| 90 | |
| 91 // Called on a timer for a hung plugin to re-show the bar. | 89 // Called on a timer for a hung plugin to re-show the bar. |
| 92 void OnReshowTimer(int child_id); | 90 void OnReshowTimer(int child_id); |
| 93 | 91 |
| 94 // Shows the bar for the plugin identified by the given state, updating the | 92 // Shows the bar for the plugin identified by the given state, updating the |
| 95 // state accordingly. The plugin must not have an infobar already. | 93 // state accordingly. The plugin must not have an infobar already. |
| 96 void ShowBar(int child_id, PluginState* state); | 94 void ShowBar(int child_id, PluginState* state); |
| 97 | 95 |
| 98 // Closes the infobar associated with the given state. Note that this can | 96 // Closes the infobar associated with the given state. Note that this can |
| 99 // be called even if the bar is not opened, in which case it will do nothing. | 97 // be called even if the bar is not opened, in which case it will do nothing. |
| 100 void CloseBar(PluginState* state); | 98 void CloseBar(PluginState* state); |
| 101 | 99 |
| 102 content::NotificationRegistrar registrar_; | 100 content::NotificationRegistrar registrar_; |
| 103 | 101 |
| 104 // All currently hung plugins. | 102 // All currently hung plugins. |
| 105 PluginStateMap hung_plugins_; | 103 PluginStateMap hung_plugins_; |
| 106 | 104 |
| 107 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); | 105 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 108 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
| OLD | NEW |