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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ++iter; | 117 ++iter; |
118 } | 118 } |
119 // Ignore the case where we didn't find the plugin, it may have terminated | 119 // Ignore the case where we didn't find the plugin, it may have terminated |
120 // before this function could run. | 120 // before this function could run. |
121 } | 121 } |
122 | 122 |
123 } // namespace | 123 } // namespace |
124 | 124 |
125 class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { | 125 class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { |
126 public: | 126 public: |
127 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, | 127 // Creates a hung plugin delegate and adds it to |infobar_service|. Returns |
128 InfoBarService* infobar_service, | 128 // the delegate if it was successfully added. |
129 int plugin_child_id, | 129 static HungPluginInfoBarDelegate* Create(InfoBarService* infobar_service, |
130 const string16& plugin_name); | 130 HungPluginTabHelper* helper, |
131 virtual ~HungPluginInfoBarDelegate(); | 131 int plugin_child_id, |
| 132 const string16& plugin_name); |
132 | 133 |
133 // ConfirmInfoBarDelegate: | 134 // ConfirmInfoBarDelegate: |
134 virtual gfx::Image* GetIcon() const OVERRIDE; | 135 virtual gfx::Image* GetIcon() const OVERRIDE; |
135 virtual string16 GetMessageText() const OVERRIDE; | 136 virtual string16 GetMessageText() const OVERRIDE; |
136 virtual int GetButtons() const OVERRIDE; | 137 virtual int GetButtons() const OVERRIDE; |
137 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 138 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
138 virtual bool Accept() OVERRIDE; | 139 virtual bool Accept() OVERRIDE; |
139 | 140 |
140 private: | 141 private: |
| 142 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, |
| 143 InfoBarService* infobar_service, |
| 144 int plugin_child_id, |
| 145 const string16& plugin_name); |
| 146 virtual ~HungPluginInfoBarDelegate(); |
| 147 |
141 HungPluginTabHelper* helper_; | 148 HungPluginTabHelper* helper_; |
142 int plugin_child_id_; | 149 int plugin_child_id_; |
143 | 150 |
144 string16 message_; | 151 string16 message_; |
145 string16 button_text_; | 152 string16 button_text_; |
146 gfx::Image* icon_; | 153 gfx::Image* icon_; |
147 }; | 154 }; |
148 | 155 |
| 156 // static |
| 157 HungPluginInfoBarDelegate* HungPluginInfoBarDelegate::Create( |
| 158 InfoBarService* infobar_service, |
| 159 HungPluginTabHelper* helper, |
| 160 int plugin_child_id, |
| 161 const string16& plugin_name) { |
| 162 return static_cast<HungPluginInfoBarDelegate*>(infobar_service->AddInfoBar( |
| 163 scoped_ptr<InfoBarDelegate>(new HungPluginInfoBarDelegate( |
| 164 helper, infobar_service, plugin_child_id, plugin_name)))); |
| 165 } |
| 166 |
149 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( | 167 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( |
150 HungPluginTabHelper* helper, | 168 HungPluginTabHelper* helper, |
151 InfoBarService* infobar_service, | 169 InfoBarService* infobar_service, |
152 int plugin_child_id, | 170 int plugin_child_id, |
153 const string16& plugin_name) | 171 const string16& plugin_name) |
154 : ConfirmInfoBarDelegate(infobar_service), | 172 : ConfirmInfoBarDelegate(infobar_service), |
155 helper_(helper), | 173 helper_(helper), |
156 plugin_child_id_(plugin_child_id) { | 174 plugin_child_id_(plugin_child_id) { |
157 message_ = l10n_util::GetStringFUTF16(IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, | 175 message_ = l10n_util::GetStringFUTF16(IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, |
158 plugin_name); | 176 plugin_name); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 ShowBar(child_id, found->second.get()); | 373 ShowBar(child_id, found->second.get()); |
356 } | 374 } |
357 | 375 |
358 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) { | 376 void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) { |
359 InfoBarService* infobar_service = | 377 InfoBarService* infobar_service = |
360 InfoBarService::FromWebContents(web_contents()); | 378 InfoBarService::FromWebContents(web_contents()); |
361 if (!infobar_service) | 379 if (!infobar_service) |
362 return; | 380 return; |
363 | 381 |
364 DCHECK(!state->info_bar); | 382 DCHECK(!state->info_bar); |
365 state->info_bar = new HungPluginInfoBarDelegate(this, infobar_service, | 383 state->info_bar = |
366 child_id, state->name); | 384 HungPluginInfoBarDelegate::Create(infobar_service, this, child_id, |
367 infobar_service->AddInfoBar(state->info_bar); | 385 state->name); |
368 } | 386 } |
369 | 387 |
370 void HungPluginTabHelper::CloseBar(PluginState* state) { | 388 void HungPluginTabHelper::CloseBar(PluginState* state) { |
371 InfoBarService* infobar_service = | 389 InfoBarService* infobar_service = |
372 InfoBarService::FromWebContents(web_contents()); | 390 InfoBarService::FromWebContents(web_contents()); |
373 if (!infobar_service) | 391 if (!infobar_service) |
374 return; | 392 return; |
375 | 393 |
376 if (state->info_bar) { | 394 if (state->info_bar) { |
377 infobar_service->RemoveInfoBar(state->info_bar); | 395 infobar_service->RemoveInfoBar(state->info_bar); |
378 state->info_bar = NULL; | 396 state->info_bar = NULL; |
379 } | 397 } |
380 } | 398 } |
OLD | NEW |