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" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ConfirmInfoBarDelegate { |
132 public: | 132 public: |
133 // Creates a hung plugin infobar and delegate and adds the infobar to | 133 // Creates a hung plugin infobar delegate and adds it to |infobar_service|. |
134 // |infobar_service|. Returns the infobar if it was successfully added. | 134 // Returns the delegate if it was successfully added. |
135 static InfoBar* Create(InfoBarService* infobar_service, | 135 static HungPluginInfoBarDelegate* Create(InfoBarService* infobar_service, |
136 HungPluginTabHelper* helper, | 136 HungPluginTabHelper* helper, |
137 int plugin_child_id, | 137 int plugin_child_id, |
138 const string16& plugin_name); | 138 const string16& plugin_name); |
139 | 139 |
140 private: | 140 private: |
141 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, | 141 HungPluginInfoBarDelegate(HungPluginTabHelper* helper, |
| 142 InfoBarService* infobar_service, |
142 int plugin_child_id, | 143 int plugin_child_id, |
143 const string16& plugin_name); | 144 const 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 string16 GetMessageText() const OVERRIDE; | 149 virtual string16 GetMessageText() const OVERRIDE; |
149 virtual int GetButtons() const OVERRIDE; | 150 virtual int GetButtons() const OVERRIDE; |
150 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 151 virtual 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 string16 message_; | 157 string16 message_; |
157 string16 button_text_; | 158 string16 button_text_; |
158 }; | 159 }; |
159 | 160 |
160 // static | 161 // static |
161 InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, | 162 HungPluginInfoBarDelegate* HungPluginInfoBarDelegate::Create( |
162 HungPluginTabHelper* helper, | 163 InfoBarService* infobar_service, |
163 int plugin_child_id, | 164 HungPluginTabHelper* helper, |
164 const string16& plugin_name) { | 165 int plugin_child_id, |
165 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 166 const string16& plugin_name) { |
166 scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( | 167 return static_cast<HungPluginInfoBarDelegate*>(infobar_service->AddInfoBar( |
167 helper, plugin_child_id, plugin_name)))); | 168 scoped_ptr<InfoBarDelegate>(new HungPluginInfoBarDelegate( |
| 169 helper, infobar_service, plugin_child_id, plugin_name)))); |
168 } | 170 } |
169 | 171 |
170 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( | 172 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( |
171 HungPluginTabHelper* helper, | 173 HungPluginTabHelper* helper, |
| 174 InfoBarService* infobar_service, |
172 int plugin_child_id, | 175 int plugin_child_id, |
173 const string16& plugin_name) | 176 const string16& plugin_name) |
174 : ConfirmInfoBarDelegate(), | 177 : ConfirmInfoBarDelegate(infobar_service), |
175 helper_(helper), | 178 helper_(helper), |
176 plugin_child_id_(plugin_child_id), | 179 plugin_child_id_(plugin_child_id), |
177 message_(l10n_util::GetStringFUTF16( | 180 message_(l10n_util::GetStringFUTF16( |
178 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, plugin_name)), | 181 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR, plugin_name)), |
179 button_text_(l10n_util::GetStringUTF16( | 182 button_text_(l10n_util::GetStringUTF16( |
180 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR_KILLBUTTON)) { | 183 IDS_BROWSER_HANGMONITOR_PLUGIN_INFOBAR_KILLBUTTON)) { |
181 } | 184 } |
182 | 185 |
183 HungPluginInfoBarDelegate::~HungPluginInfoBarDelegate() { | 186 HungPluginInfoBarDelegate::~HungPluginInfoBarDelegate() { |
184 } | 187 } |
(...skipping 28 matching lines...) Expand all Loading... |
213 // not we're currently showing the infobar. | 216 // not we're currently showing the infobar. |
214 struct HungPluginTabHelper::PluginState { | 217 struct HungPluginTabHelper::PluginState { |
215 // Initializes the plugin state to be a hung plugin. | 218 // Initializes the plugin state to be a hung plugin. |
216 PluginState(const base::FilePath& p, const string16& n); | 219 PluginState(const base::FilePath& p, const string16& n); |
217 ~PluginState(); | 220 ~PluginState(); |
218 | 221 |
219 base::FilePath path; | 222 base::FilePath path; |
220 string16 name; | 223 string16 name; |
221 | 224 |
222 // Possibly-null if we're not showing an infobar right now. | 225 // Possibly-null if we're not showing an infobar right now. |
223 InfoBar* infobar; | 226 InfoBarDelegate* infobar; |
224 | 227 |
225 // Time to delay before re-showing the infobar for a hung plugin. This is | 228 // Time to delay before re-showing the infobar for a hung plugin. This is |
226 // increased each time the user cancels it. | 229 // increased each time the user cancels it. |
227 base::TimeDelta next_reshow_delay; | 230 base::TimeDelta next_reshow_delay; |
228 | 231 |
229 // Handles calling the helper when the infobar should be re-shown. | 232 // Handles calling the helper when the infobar should be re-shown. |
230 base::Timer timer; | 233 base::Timer timer; |
231 | 234 |
232 private: | 235 private: |
233 // Initial delay in seconds before re-showing the hung plugin message. | 236 // Initial delay in seconds before re-showing the hung plugin message. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); | 320 linked_ptr<PluginState> state(new PluginState(plugin_path, plugin_name)); |
318 hung_plugins_[plugin_child_id] = state; | 321 hung_plugins_[plugin_child_id] = state; |
319 ShowBar(plugin_child_id, state.get()); | 322 ShowBar(plugin_child_id, state.get()); |
320 } | 323 } |
321 | 324 |
322 void HungPluginTabHelper::Observe( | 325 void HungPluginTabHelper::Observe( |
323 int type, | 326 int type, |
324 const content::NotificationSource& source, | 327 const content::NotificationSource& source, |
325 const content::NotificationDetails& details) { | 328 const content::NotificationDetails& details) { |
326 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 329 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
327 InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; | 330 // Note: do not dereference. The InfoBarContainer will delete the object when |
| 331 // it gets this notification, we only remove our tracking info, if we have |
| 332 // any. |
| 333 // |
| 334 // TODO(pkasting): This comment will be incorrect and should be removed once |
| 335 // InfoBars own their delegates. |
| 336 InfoBarDelegate* infobar = |
| 337 content::Details<InfoBar::RemovedDetails>(details)->first; |
328 for (PluginStateMap::iterator i = hung_plugins_.begin(); | 338 for (PluginStateMap::iterator i = hung_plugins_.begin(); |
329 i != hung_plugins_.end(); ++i) { | 339 i != hung_plugins_.end(); ++i) { |
330 PluginState* state = i->second.get(); | 340 PluginState* state = i->second.get(); |
331 if (state->infobar == infobar) { | 341 if (state->infobar == infobar) { |
332 state->infobar = NULL; | 342 state->infobar = NULL; |
333 | 343 |
334 // Schedule the timer to re-show the infobar if the plugin continues to be | 344 // Schedule the timer to re-show the infobar if the plugin continues to be |
335 // hung. | 345 // hung. |
336 state->timer.Start(FROM_HERE, state->next_reshow_delay, | 346 state->timer.Start(FROM_HERE, state->next_reshow_delay, |
337 base::Bind(&HungPluginTabHelper::OnReshowTimer, | 347 base::Bind(&HungPluginTabHelper::OnReshowTimer, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 422 } |
413 | 423 |
414 void HungPluginTabHelper::CloseBar(PluginState* state) { | 424 void HungPluginTabHelper::CloseBar(PluginState* state) { |
415 InfoBarService* infobar_service = | 425 InfoBarService* infobar_service = |
416 InfoBarService::FromWebContents(web_contents()); | 426 InfoBarService::FromWebContents(web_contents()); |
417 if (infobar_service && state->infobar) { | 427 if (infobar_service && state->infobar) { |
418 infobar_service->RemoveInfoBar(state->infobar); | 428 infobar_service->RemoveInfoBar(state->infobar); |
419 state->infobar = NULL; | 429 state->infobar = NULL; |
420 } | 430 } |
421 } | 431 } |
OLD | NEW |