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/plugins/plugin_infobar_delegates.h" | 5 #include "chrome/browser/plugins/plugin_infobar_delegates.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 infobar()->RemoveSelf(); | 206 infobar()->RemoveSelf(); |
207 } | 207 } |
208 | 208 |
209 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( | 209 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( |
210 const base::string16& message) { | 210 const base::string16& message) { |
211 // Return early if the message doesn't change. This is important in case the | 211 // Return early if the message doesn't change. This is important in case the |
212 // PluginInstaller is still iterating over its observers (otherwise we would | 212 // PluginInstaller is still iterating over its observers (otherwise we would |
213 // keep replacing infobar delegates infinitely). | 213 // keep replacing infobar delegates infinitely). |
214 if ((message_ == message) || !infobar()->owner()) | 214 if ((message_ == message) || !infobar()->owner()) |
215 return; | 215 return; |
216 PluginInstallerInfoBarDelegate::Replace( | 216 Replace(infobar(), installer(), plugin_metadata_->Clone(), message); |
217 infobar(), installer(), plugin_metadata_->Clone(), false, message); | |
218 } | 217 } |
219 | 218 |
220 | 219 // static |
221 // PluginInstallerInfoBarDelegate --------------------------------------------- | 220 void OutdatedPluginInfoBarDelegate::Replace( |
222 | |
223 void PluginInstallerInfoBarDelegate::Create( | |
224 InfoBarService* infobar_service, | |
225 PluginInstaller* installer, | |
226 scoped_ptr<PluginMetadata> plugin_metadata, | |
227 const InstallCallback& callback) { | |
228 base::string16 name(plugin_metadata->name()); | |
229 #if defined(OS_WIN) | |
230 if (base::win::IsMetroProcess()) { | |
231 PluginMetroModeInfoBarDelegate::Create( | |
232 infobar_service, PluginMetroModeInfoBarDelegate::MISSING_PLUGIN, name); | |
233 return; | |
234 } | |
235 #endif | |
236 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | |
237 scoped_ptr<ConfirmInfoBarDelegate>(new PluginInstallerInfoBarDelegate( | |
238 installer, plugin_metadata.Pass(), callback, true, | |
239 l10n_util::GetStringFUTF16( | |
240 (installer->state() == PluginInstaller::INSTALLER_STATE_IDLE) | |
241 ? IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT | |
242 : IDS_PLUGIN_DOWNLOADING, | |
243 name))))); | |
244 } | |
245 | |
246 void PluginInstallerInfoBarDelegate::Replace( | |
247 infobars::InfoBar* infobar, | 221 infobars::InfoBar* infobar, |
248 PluginInstaller* installer, | 222 PluginInstaller* installer, |
249 scoped_ptr<PluginMetadata> plugin_metadata, | 223 scoped_ptr<PluginMetadata> plugin_metadata, |
250 bool new_install, | |
251 const base::string16& message) { | 224 const base::string16& message) { |
252 DCHECK(infobar->owner()); | 225 DCHECK(infobar->owner()); |
253 infobar->owner()->ReplaceInfoBar( | 226 infobar->owner()->ReplaceInfoBar( |
254 infobar, | 227 infobar, |
255 infobar->owner()->CreateConfirmInfoBar( | 228 infobar->owner()->CreateConfirmInfoBar( |
256 scoped_ptr<ConfirmInfoBarDelegate>(new PluginInstallerInfoBarDelegate( | 229 scoped_ptr<ConfirmInfoBarDelegate>(new OutdatedPluginInfoBarDelegate( |
257 installer, plugin_metadata.Pass(), | 230 installer, plugin_metadata.Pass(), message)))); |
258 PluginInstallerInfoBarDelegate::InstallCallback(), new_install, | |
259 message)))); | |
260 } | 231 } |
261 | 232 |
262 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( | |
263 PluginInstaller* installer, | |
264 scoped_ptr<PluginMetadata> plugin_metadata, | |
265 const InstallCallback& callback, | |
266 bool new_install, | |
267 const base::string16& message) | |
268 : ConfirmInfoBarDelegate(), | |
269 WeakPluginInstallerObserver(installer), | |
270 plugin_metadata_(plugin_metadata.Pass()), | |
271 callback_(callback), | |
272 new_install_(new_install), | |
273 message_(message) { | |
274 } | |
275 | |
276 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() { | |
277 } | |
278 | |
279 int PluginInstallerInfoBarDelegate::GetIconID() const { | |
280 return IDR_INFOBAR_PLUGIN_INSTALL; | |
281 } | |
282 | |
283 base::string16 PluginInstallerInfoBarDelegate::GetMessageText() const { | |
284 return message_; | |
285 } | |
286 | |
287 int PluginInstallerInfoBarDelegate::GetButtons() const { | |
288 return callback_.is_null() ? BUTTON_NONE : BUTTON_OK; | |
289 } | |
290 | |
291 base::string16 PluginInstallerInfoBarDelegate::GetButtonLabel( | |
292 InfoBarButton button) const { | |
293 DCHECK_EQ(BUTTON_OK, button); | |
294 return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON); | |
295 } | |
296 | |
297 bool PluginInstallerInfoBarDelegate::Accept() { | |
298 callback_.Run(plugin_metadata_.get()); | |
299 return false; | |
300 } | |
301 | |
302 base::string16 PluginInstallerInfoBarDelegate::GetLinkText() const { | |
303 return l10n_util::GetStringUTF16(new_install_ ? | |
304 IDS_PLUGININSTALLER_PROBLEMSINSTALLING : | |
305 IDS_PLUGININSTALLER_PROBLEMSUPDATING); | |
306 } | |
307 | |
308 bool PluginInstallerInfoBarDelegate::LinkClicked( | |
309 WindowOpenDisposition disposition) { | |
310 GURL url(plugin_metadata_->help_url()); | |
311 if (url.is_empty()) { | |
312 url = GURL( | |
313 "https://www.google.com/support/chrome/bin/answer.py?answer=142064"); | |
314 } | |
315 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL( | |
316 content::OpenURLParams( | |
317 url, content::Referrer(), | |
318 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
319 ui::PAGE_TRANSITION_LINK, false)); | |
320 return false; | |
321 } | |
322 | |
323 void PluginInstallerInfoBarDelegate::DownloadStarted() { | |
324 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, | |
325 plugin_metadata_->name())); | |
326 } | |
327 | |
328 void PluginInstallerInfoBarDelegate::DownloadCancelled() { | |
329 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED, | |
330 plugin_metadata_->name())); | |
331 } | |
332 | |
333 void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) { | |
334 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT, | |
335 plugin_metadata_->name())); | |
336 } | |
337 | |
338 void PluginInstallerInfoBarDelegate::DownloadFinished() { | |
339 ReplaceWithInfoBar( | |
340 l10n_util::GetStringFUTF16( | |
341 new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING, | |
342 plugin_metadata_->name())); | |
343 } | |
344 | |
345 void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() { | |
346 infobar()->RemoveSelf(); | |
347 } | |
348 | |
349 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( | |
350 const base::string16& message) { | |
351 // Return early if the message doesn't change. This is important in case the | |
352 // PluginInstaller is still iterating over its observers (otherwise we would | |
353 // keep replacing infobar delegates infinitely). | |
354 if ((message_ == message) || !infobar()->owner()) | |
355 return; | |
356 Replace(infobar(), installer(), plugin_metadata_->Clone(), new_install_, | |
357 message); | |
358 } | |
359 | |
360 | |
361 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
362 | 234 |
363 // PluginMetroModeInfoBarDelegate --------------------------------------------- | 235 // PluginMetroModeInfoBarDelegate --------------------------------------------- |
364 | 236 |
365 // static | 237 // static |
366 void PluginMetroModeInfoBarDelegate::Create( | 238 void PluginMetroModeInfoBarDelegate::Create( |
367 InfoBarService* infobar_service, | 239 InfoBarService* infobar_service, |
368 PluginMetroModeInfoBarDelegate::Mode mode, | 240 PluginMetroModeInfoBarDelegate::Mode mode, |
369 const base::string16& name) { | 241 const base::string16& name) { |
370 infobar_service->AddInfoBar( | 242 infobar_service->AddInfoBar( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 "https://support.google.com/chrome/?p=ib_redirect_to_desktop"), | 308 "https://support.google.com/chrome/?p=ib_redirect_to_desktop"), |
437 content::Referrer(), | 309 content::Referrer(), |
438 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 310 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
439 ui::PAGE_TRANSITION_LINK, false)); | 311 ui::PAGE_TRANSITION_LINK, false)); |
440 return false; | 312 return false; |
441 } | 313 } |
442 | 314 |
443 #endif // defined(OS_WIN) | 315 #endif // defined(OS_WIN) |
444 | 316 |
445 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 317 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
OLD | NEW |