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