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