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
3 // found in the LICENSE file.
5 #include "chrome/browser/plugin_installer_infobar_delegate.h"
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/google/google_util.h"
9 #include "chrome/browser/infobars/infobar_tab_helper.h"
10 #include "chrome/browser/plugin_installer.h"
11 #include "content/browser/renderer_host/render_view_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h"
15 #include "grit/theme_resources_standard.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
19 using content::OpenURLParams
;
20 using content::Referrer
;
22 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
23 InfoBarTabHelper
* infobar_helper
,
24 PluginInstaller
* installer
,
25 const base::Closure
& callback
,
26 const string16
& message
)
27 : ConfirmInfoBarDelegate(infobar_helper
),
28 WeakPluginInstallerObserver(installer
),
33 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() {
36 InfoBarDelegate
* PluginInstallerInfoBarDelegate::Create(
37 InfoBarTabHelper
* infobar_helper
,
38 PluginInstaller
* installer
,
39 const base::Closure
& callback
) {
41 switch (installer
->state()) {
42 case PluginInstaller::kStateIdle
:
43 message
= l10n_util::GetStringFUTF16(
44 IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT
, installer
->name());
46 case PluginInstaller::kStateDownloading
:
47 message
= l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING
);
50 return new PluginInstallerInfoBarDelegate(
51 infobar_helper
, installer
, callback
, message
);
54 gfx::Image
* PluginInstallerInfoBarDelegate::GetIcon() const {
55 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
56 IDR_INFOBAR_PLUGIN_INSTALL
);
59 string16
PluginInstallerInfoBarDelegate::GetMessageText() const {
63 int PluginInstallerInfoBarDelegate::GetButtons() const {
64 return callback_
.is_null() ? BUTTON_NONE
: BUTTON_OK
;
67 string16
PluginInstallerInfoBarDelegate::GetButtonLabel(
68 InfoBarButton button
) const {
69 DCHECK_EQ(BUTTON_OK
, button
);
70 return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON
);
73 bool PluginInstallerInfoBarDelegate::Accept() {
78 string16
PluginInstallerInfoBarDelegate::GetLinkText() const {
79 return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_PROBLEMSINSTALLING
);
82 bool PluginInstallerInfoBarDelegate::LinkClicked(
83 WindowOpenDisposition disposition
) {
84 GURL
url(installer()->help_url());
86 url
= google_util::AppendGoogleLocaleParam(GURL(
87 "https://www.google.com/support/chrome/bin/answer.py?answer=142064"));
92 (disposition
== CURRENT_TAB
) ? NEW_FOREGROUND_TAB
: disposition
,
93 content::PAGE_TRANSITION_LINK
, false);
94 owner()->web_contents()->OpenURL(params
);
98 void PluginInstallerInfoBarDelegate::DidStartDownload() {
99 ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING
));
102 void PluginInstallerInfoBarDelegate::DidFinishDownload() {
103 ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_INSTALLING
));
106 void PluginInstallerInfoBarDelegate::DownloadError(const std::string
& message
) {
108 l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT
));
111 void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() {
113 owner()->RemoveInfoBar(this);
116 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar(
117 const string16
& message
) {
118 // Return early if the message doesn't change. This is important in case the
119 // PluginInstaller is still iterating over its observers (otherwise we would
120 // keep replacing infobar delegates infinitely).
121 if (message_
== message
)
125 InfoBarDelegate
* delegate
= new PluginInstallerInfoBarDelegate(
126 owner(), installer(), base::Closure(), message
);
127 owner()->ReplaceInfoBar(this, delegate
);