| 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/content_confirm_infobar_delegate.h" |
| 15 #include "chrome/browser/infobars/infobar.h" | 15 #include "chrome/browser/infobars/infobar.h" |
| 16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.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" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 // Ignore the case where we didn't find the plugin, it may have terminated | 122 // Ignore the case where we didn't find the plugin, it may have terminated |
| 123 // before this function could run. | 123 // before this function could run. |
| 124 } | 124 } |
| 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 ContentConfirmInfoBarDelegate { |
| 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 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(content::WebContents* web_contents, |
| 142 HungPluginTabHelper* helper, |
| 142 int plugin_child_id, | 143 int plugin_child_id, |
| 143 const base::string16& plugin_name); | 144 const base::string16& plugin_name); |
| 144 virtual ~HungPluginInfoBarDelegate(); | 145 virtual ~HungPluginInfoBarDelegate(); |
| 145 | 146 |
| 146 // ConfirmInfoBarDelegate: | 147 // ConfirmInfoBarDelegate: |
| 147 virtual int GetIconID() const OVERRIDE; | 148 virtual int GetIconID() const OVERRIDE; |
| 148 virtual base::string16 GetMessageText() const OVERRIDE; | 149 virtual base::string16 GetMessageText() const OVERRIDE; |
| 149 virtual int GetButtons() const OVERRIDE; | 150 virtual int GetButtons() const OVERRIDE; |
| 150 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 151 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 151 virtual bool Accept() OVERRIDE; | 152 virtual bool Accept() OVERRIDE; |
| 152 | 153 |
| 153 HungPluginTabHelper* helper_; | 154 HungPluginTabHelper* helper_; |
| 154 int plugin_child_id_; | 155 int plugin_child_id_; |
| 155 | 156 |
| 156 base::string16 message_; | 157 base::string16 message_; |
| 157 base::string16 button_text_; | 158 base::string16 button_text_; |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 // static | 161 // static |
| 161 InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, | 162 InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 162 HungPluginTabHelper* helper, | 163 HungPluginTabHelper* helper, |
| 163 int plugin_child_id, | 164 int plugin_child_id, |
| 164 const base::string16& plugin_name) { | 165 const base::string16& plugin_name) { |
| 165 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 166 return infobar_service->AddInfoBar( |
| 166 scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( | 167 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 167 helper, plugin_child_id, plugin_name)))); | 168 new HungPluginInfoBarDelegate(infobar_service->web_contents(), |
| 169 helper, |
| 170 plugin_child_id, |
| 171 plugin_name)))); |
| 168 } | 172 } |
| 169 | 173 |
| 170 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( | 174 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( |
| 175 content::WebContents* web_contents, |
| 171 HungPluginTabHelper* helper, | 176 HungPluginTabHelper* helper, |
| 172 int plugin_child_id, | 177 int plugin_child_id, |
| 173 const base::string16& plugin_name) | 178 const base::string16& plugin_name) |
| 174 : ConfirmInfoBarDelegate(), | 179 : ContentConfirmInfoBarDelegate(web_contents), |
| 175 helper_(helper), | 180 helper_(helper), |
| 176 plugin_child_id_(plugin_child_id), | 181 plugin_child_id_(plugin_child_id), |
| 177 message_(l10n_util::GetStringFUTF16( | 182 message_( |
| 178 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, plugin_name)), | 183 l10n_util::GetStringFUTF16(IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, |
| 184 plugin_name)), |
| 179 button_text_(l10n_util::GetStringUTF16( | 185 button_text_(l10n_util::GetStringUTF16( |
| 180 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR_KILLBUTTON)) { | 186 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR_KILLBUTTON)) {} |
| 181 } | |
| 182 | 187 |
| 183 HungPluginInfoBarDelegate::~HungPluginInfoBarDelegate() { | 188 HungPluginInfoBarDelegate::~HungPluginInfoBarDelegate() { |
| 184 } | 189 } |
| 185 | 190 |
| 186 int HungPluginInfoBarDelegate::GetIconID() const { | 191 int HungPluginInfoBarDelegate::GetIconID() const { |
| 187 return IDR_INFOBAR_PLUGIN_CRASHED; | 192 return IDR_INFOBAR_PLUGIN_CRASHED; |
| 188 } | 193 } |
| 189 | 194 |
| 190 base::string16 HungPluginInfoBarDelegate::GetMessageText() const { | 195 base::string16 HungPluginInfoBarDelegate::GetMessageText() const { |
| 191 return message_; | 196 return message_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 InfoBarService::FromWebContents(web_contents()); | 282 InfoBarService::FromWebContents(web_contents()); |
| 278 if (!infobar_service) | 283 if (!infobar_service) |
| 279 return; | 284 return; |
| 280 | 285 |
| 281 // For now, just do a brute-force search to see if we have this plugin. Since | 286 // For now, just do a brute-force search to see if we have this plugin. Since |
| 282 // we'll normally have 0 or 1, this is fast. | 287 // we'll normally have 0 or 1, this is fast. |
| 283 for (PluginStateMap::iterator i = hung_plugins_.begin(); | 288 for (PluginStateMap::iterator i = hung_plugins_.begin(); |
| 284 i != hung_plugins_.end(); ++i) { | 289 i != hung_plugins_.end(); ++i) { |
| 285 if (i->second->path == plugin_path) { | 290 if (i->second->path == plugin_path) { |
| 286 if (i->second->infobar) | 291 if (i->second->infobar) |
| 287 infobar_service->RemoveInfoBar(i->second->infobar); | 292 infobar_service->infobar_manager().RemoveInfoBar(i->second->infobar); |
| 288 hung_plugins_.erase(i); | 293 hung_plugins_.erase(i); |
| 289 break; | 294 break; |
| 290 } | 295 } |
| 291 } | 296 } |
| 292 } | 297 } |
| 293 | 298 |
| 294 void HungPluginTabHelper::PluginHungStatusChanged( | 299 void HungPluginTabHelper::PluginHungStatusChanged( |
| 295 int plugin_child_id, | 300 int plugin_child_id, |
| 296 const base::FilePath& plugin_path, | 301 const base::FilePath& plugin_path, |
| 297 bool is_hung) { | 302 bool is_hung) { |
| 298 InfoBarService* infobar_service = | 303 InfoBarService* infobar_service = |
| 299 InfoBarService::FromWebContents(web_contents()); | 304 InfoBarService::FromWebContents(web_contents()); |
| 300 if (!infobar_service) | 305 if (!infobar_service) |
| 301 return; | 306 return; |
| 302 | 307 |
| 303 PluginStateMap::iterator found = hung_plugins_.find(plugin_child_id); | 308 PluginStateMap::iterator found = hung_plugins_.find(plugin_child_id); |
| 304 if (found != hung_plugins_.end()) { | 309 if (found != hung_plugins_.end()) { |
| 305 if (!is_hung) { | 310 if (!is_hung) { |
| 306 // Hung plugin became un-hung, close the infobar and delete our info. | 311 // Hung plugin became un-hung, close the infobar and delete our info. |
| 307 if (found->second->infobar) | 312 if (found->second->infobar) |
| 308 infobar_service->RemoveInfoBar(found->second->infobar); | 313 infobar_service->infobar_manager().RemoveInfoBar( |
| 314 found->second->infobar); |
| 309 hung_plugins_.erase(found); | 315 hung_plugins_.erase(found); |
| 310 } | 316 } |
| 311 return; | 317 return; |
| 312 } | 318 } |
| 313 | 319 |
| 314 base::string16 plugin_name = | 320 base::string16 plugin_name = |
| 315 content::PluginService::GetInstance()->GetPluginDisplayNameByPath( | 321 content::PluginService::GetInstance()->GetPluginDisplayNameByPath( |
| 316 plugin_path); | 322 plugin_path); |
| 317 | 323 |
| 318 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); | 324 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 415 |
| 410 DCHECK(!state->infobar); | 416 DCHECK(!state->infobar); |
| 411 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this, | 417 state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this, |
| 412 child_id, state->name); | 418 child_id, state->name); |
| 413 } | 419 } |
| 414 | 420 |
| 415 void HungPluginTabHelper::CloseBar(PluginState* state) { | 421 void HungPluginTabHelper::CloseBar(PluginState* state) { |
| 416 InfoBarService* infobar_service = | 422 InfoBarService* infobar_service = |
| 417 InfoBarService::FromWebContents(web_contents()); | 423 InfoBarService::FromWebContents(web_contents()); |
| 418 if (infobar_service && state->infobar) { | 424 if (infobar_service && state->infobar) { |
| 419 infobar_service->RemoveInfoBar(state->infobar); | 425 infobar_service->infobar_manager().RemoveInfoBar(state->infobar); |
| 420 state->infobar = NULL; | 426 state->infobar = NULL; |
| 421 } | 427 } |
| 422 } | 428 } |
| OLD | NEW |