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" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
15 #include "chrome/browser/infobars/infobar.h" | |
16 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/common/chrome_version_info.h" | 16 #include "chrome/common/chrome_version_info.h" |
| 17 #include "components/infobars/core/infobar.h" |
18 #include "content/public/browser/browser_child_process_host_iterator.h" | 18 #include "content/public/browser/browser_child_process_host_iterator.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/plugin_service.h" | 23 #include "content/public/browser/plugin_service.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/common/process_type.h" | 25 #include "content/public/common/process_type.h" |
26 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
27 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
128 | 128 |
129 // HungPluginInfoBarDelegate -------------------------------------------------- | 129 // HungPluginInfoBarDelegate -------------------------------------------------- |
130 | 130 |
131 class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { | 131 class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { |
132 public: | 132 public: |
133 // Creates a hung plugin infobar and delegate and adds the infobar to | 133 // Creates a hung plugin infobar and delegate and adds the infobar to |
134 // |infobar_service|. Returns the infobar if it was successfully added. | 134 // |infobar_service|. Returns the infobar if it was successfully added. |
135 static InfoBar* Create(InfoBarService* infobar_service, | 135 static infobars::InfoBar* Create(InfoBarService* infobar_service, |
136 HungPluginTabHelper* helper, | 136 HungPluginTabHelper* helper, |
137 int plugin_child_id, | 137 int plugin_child_id, |
138 const base::string16& plugin_name); | 138 const base::string16& plugin_name); |
139 | 139 |
140 private: | 140 private: |
141 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, | 141 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, |
142 int plugin_child_id, | 142 int plugin_child_id, |
143 const base::string16& plugin_name); | 143 const base::string16& plugin_name); |
144 virtual ~HungPluginInfoBarDelegate(); | 144 virtual ~HungPluginInfoBarDelegate(); |
145 | 145 |
146 // ConfirmInfoBarDelegate: | 146 // ConfirmInfoBarDelegate: |
147 virtual int GetIconID() const OVERRIDE; | 147 virtual int GetIconID() const OVERRIDE; |
148 virtual base::string16 GetMessageText() const OVERRIDE; | 148 virtual base::string16 GetMessageText() const OVERRIDE; |
149 virtual int GetButtons() const OVERRIDE; | 149 virtual int GetButtons() const OVERRIDE; |
150 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 150 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
151 virtual bool Accept() OVERRIDE; | 151 virtual bool Accept() OVERRIDE; |
152 | 152 |
153 HungPluginTabHelper* helper_; | 153 HungPluginTabHelper* helper_; |
154 int plugin_child_id_; | 154 int plugin_child_id_; |
155 | 155 |
156 base::string16 message_; | 156 base::string16 message_; |
157 base::string16 button_text_; | 157 base::string16 button_text_; |
158 }; | 158 }; |
159 | 159 |
160 // static | 160 // static |
161 InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, | 161 infobars::InfoBar* HungPluginInfoBarDelegate::Create( |
162 HungPluginTabHelper* helper, | 162 InfoBarService* infobar_service, |
163 int plugin_child_id, | 163 HungPluginTabHelper* helper, |
164 const base::string16& plugin_name) { | 164 int plugin_child_id, |
| 165 const base::string16& plugin_name) { |
165 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 166 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
166 scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( | 167 scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( |
167 helper, plugin_child_id, plugin_name)))); | 168 helper, plugin_child_id, plugin_name)))); |
168 } | 169 } |
169 | 170 |
170 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( | 171 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( |
171 HungPluginTabHelper* helper, | 172 HungPluginTabHelper* helper, |
172 int plugin_child_id, | 173 int plugin_child_id, |
173 const base::string16& plugin_name) | 174 const base::string16& plugin_name) |
174 : ConfirmInfoBarDelegate(), | 175 : ConfirmInfoBarDelegate(), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // not we're currently showing the infobar. | 215 // not we're currently showing the infobar. |
215 struct HungPluginTabHelper::PluginState { | 216 struct HungPluginTabHelper::PluginState { |
216 // Initializes the plugin state to be a hung plugin. | 217 // Initializes the plugin state to be a hung plugin. |
217 PluginState(const base::FilePath& p, const base::string16& n); | 218 PluginState(const base::FilePath& p, const base::string16& n); |
218 ~PluginState(); | 219 ~PluginState(); |
219 | 220 |
220 base::FilePath path; | 221 base::FilePath path; |
221 base::string16 name; | 222 base::string16 name; |
222 | 223 |
223 // Possibly-null if we're not showing an infobar right now. | 224 // Possibly-null if we're not showing an infobar right now. |
224 InfoBar* infobar; | 225 infobars::InfoBar* infobar; |
225 | 226 |
226 // Time to delay before re-showing the infobar for a hung plugin. This is | 227 // Time to delay before re-showing the infobar for a hung plugin. This is |
227 // increased each time the user cancels it. | 228 // increased each time the user cancels it. |
228 base::TimeDelta next_reshow_delay; | 229 base::TimeDelta next_reshow_delay; |
229 | 230 |
230 // Handles calling the helper when the infobar should be re-shown. | 231 // Handles calling the helper when the infobar should be re-shown. |
231 base::Timer timer; | 232 base::Timer timer; |
232 | 233 |
233 private: | 234 private: |
234 // Initial delay in seconds before re-showing the hung plugin message. | 235 // Initial delay in seconds before re-showing the hung plugin message. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); | 319 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); |
319 hung_plugins_[plugin_child_id] = state; | 320 hung_plugins_[plugin_child_id] = state; |
320 ShowBar(plugin_child_id, state.get()); | 321 ShowBar(plugin_child_id, state.get()); |
321 } | 322 } |
322 | 323 |
323 void HungPluginTabHelper::Observe( | 324 void HungPluginTabHelper::Observe( |
324 int type, | 325 int type, |
325 const content::NotificationSource& source, | 326 const content::NotificationSource& source, |
326 const content::NotificationDetails& details) { | 327 const content::NotificationDetails& details) { |
327 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 328 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
328 InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; | 329 infobars::InfoBar* infobar = |
| 330 content::Details<infobars::InfoBar::RemovedDetails>(details)->first; |
329 for (PluginStateMap::iterator i = hung_plugins_.begin(); | 331 for (PluginStateMap::iterator i = hung_plugins_.begin(); |
330 i != hung_plugins_.end(); ++i) { | 332 i != hung_plugins_.end(); ++i) { |
331 PluginState* state = i->second.get(); | 333 PluginState* state = i->second.get(); |
332 if (state->infobar == infobar) { | 334 if (state->infobar == infobar) { |
333 state->infobar = NULL; | 335 state->infobar = NULL; |
334 | 336 |
335 // Schedule the timer to re-show the infobar if the plugin continues to be | 337 // Schedule the timer to re-show the infobar if the plugin continues to be |
336 // hung. | 338 // hung. |
337 state->timer.Start(FROM_HERE, state->next_reshow_delay, | 339 state->timer.Start(FROM_HERE, state->next_reshow_delay, |
338 base::Bind(&HungPluginTabHelper::OnReshowTimer, | 340 base::Bind(&HungPluginTabHelper::OnReshowTimer, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 415 } |
414 | 416 |
415 void HungPluginTabHelper::CloseBar(PluginState* state) { | 417 void HungPluginTabHelper::CloseBar(PluginState* state) { |
416 InfoBarService* infobar_service = | 418 InfoBarService* infobar_service = |
417 InfoBarService::FromWebContents(web_contents()); | 419 InfoBarService::FromWebContents(web_contents()); |
418 if (infobar_service && state->infobar) { | 420 if (infobar_service && state->infobar) { |
419 infobar_service->RemoveInfoBar(state->infobar); | 421 infobar_service->RemoveInfoBar(state->infobar); |
420 state->infobar = NULL; | 422 state->infobar = NULL; |
421 } | 423 } |
422 } | 424 } |
OLD | NEW |