| 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/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/infobars/core/infobar_manager.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class FilePath; | 20 class FilePath; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace infobars { | 23 namespace infobars { |
| 23 class InfoBarDelegate; | 24 class InfoBarDelegate; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // Manages per-tab state with regard to hung plugins. This only handles | 27 // Manages per-tab state with regard to hung plugins. This only handles |
| 27 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which | 28 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which |
| 28 // may have native windows) can not be handled with infobars and have a | 29 // may have native windows) can not be handled with infobars and have a |
| 29 // separate OS-specific hang monitoring. | 30 // separate OS-specific hang monitoring. |
| 30 // | 31 // |
| 31 // Our job is: | 32 // Our job is: |
| 32 // - Pop up an infobar when a plugin is hung. | 33 // - Pop up an infobar when a plugin is hung. |
| 33 // - Terminate the plugin process if the user so chooses. | 34 // - Terminate the plugin process if the user so chooses. |
| 34 // - Periodically re-show the hung plugin infobar if the user closes it without | 35 // - Periodically re-show the hung plugin infobar if the user closes it without |
| 35 // terminating the plugin. | 36 // terminating the plugin. |
| 36 // - Hide the infobar if the plugin starts responding again. | 37 // - Hide the infobar if the plugin starts responding again. |
| 37 // - Keep track of all of this for any number of plugins. | 38 // - Keep track of all of this for any number of plugins. |
| 38 class HungPluginTabHelper | 39 class HungPluginTabHelper |
| 39 : public infobars::InfoBarManager::Observer, | 40 : public content::WebContentsObserver, |
| 40 public content::WebContentsObserver, | 41 public content::NotificationObserver, |
| 41 public content::WebContentsUserData<HungPluginTabHelper> { | 42 public content::WebContentsUserData<HungPluginTabHelper> { |
| 42 public: | 43 public: |
| 43 virtual ~HungPluginTabHelper(); | 44 virtual ~HungPluginTabHelper(); |
| 44 | 45 |
| 45 // content::WebContentsObserver: | 46 // content::WebContentsObserver: |
| 46 virtual void PluginCrashed(const base::FilePath& plugin_path, | 47 virtual void PluginCrashed(const base::FilePath& plugin_path, |
| 47 base::ProcessId plugin_pid) OVERRIDE; | 48 base::ProcessId plugin_pid) OVERRIDE; |
| 48 virtual void PluginHungStatusChanged(int plugin_child_id, | 49 virtual void PluginHungStatusChanged(int plugin_child_id, |
| 49 const base::FilePath& plugin_path, | 50 const base::FilePath& plugin_path, |
| 50 bool is_hung) OVERRIDE; | 51 bool is_hung) OVERRIDE; |
| 51 | 52 |
| 53 // content::NotificationObserver: |
| 54 virtual void Observe(int type, |
| 55 const content::NotificationSource& source, |
| 56 const content::NotificationDetails& details) OVERRIDE; |
| 57 |
| 52 // Called by an infobar when the user selects to kill the plugin. | 58 // Called by an infobar when the user selects to kill the plugin. |
| 53 void KillPlugin(int child_id); | 59 void KillPlugin(int child_id); |
| 54 | 60 |
| 55 private: | 61 private: |
| 56 friend class content::WebContentsUserData<HungPluginTabHelper>; | 62 friend class content::WebContentsUserData<HungPluginTabHelper>; |
| 57 | 63 |
| 58 struct PluginState; | 64 struct PluginState; |
| 59 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; | 65 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; |
| 60 | 66 |
| 61 explicit HungPluginTabHelper(content::WebContents* contents); | 67 explicit HungPluginTabHelper(content::WebContents* contents); |
| 62 | 68 |
| 63 // Called on a timer for a hung plugin to re-show the bar. | 69 // Called on a timer for a hung plugin to re-show the bar. |
| 64 void OnReshowTimer(int child_id); | 70 void OnReshowTimer(int child_id); |
| 65 | 71 |
| 66 // Shows the bar for the plugin identified by the given state, updating the | 72 // Shows the bar for the plugin identified by the given state, updating the |
| 67 // state accordingly. The plugin must not have an infobar already. | 73 // state accordingly. The plugin must not have an infobar already. |
| 68 void ShowBar(int child_id, PluginState* state); | 74 void ShowBar(int child_id, PluginState* state); |
| 69 | 75 |
| 70 // Closes the infobar associated with the given state. Note that this can | 76 // Closes the infobar associated with the given state. Note that this can |
| 71 // be called even if the bar is not opened, in which case it will do nothing. | 77 // be called even if the bar is not opened, in which case it will do nothing. |
| 72 void CloseBar(PluginState* state); | 78 void CloseBar(PluginState* state); |
| 73 | 79 |
| 74 // infobars::InfoBarManager::Observer: | 80 content::NotificationRegistrar registrar_; |
| 75 virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, | |
| 76 bool animate) OVERRIDE; | |
| 77 | 81 |
| 78 // All currently hung plugins. | 82 // All currently hung plugins. |
| 79 PluginStateMap hung_plugins_; | 83 PluginStateMap hung_plugins_; |
| 80 | 84 |
| 81 // The number of hung plugin infobars open. We use this to determine when we | |
| 82 // should remove ourself as an observer of InfoBarManager notifications. | |
| 83 int number_of_infobars_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); | 85 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 88 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
| OLD | NEW |