Chromium Code Reviews| Index: chrome/browser/android/banners/app_banner_infobar_delegate.cc |
| diff --git a/chrome/browser/android/banners/app_banner_infobar_delegate.cc b/chrome/browser/android/banners/app_banner_infobar_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c1f97de3a5a1c18b4c5939660461aa6ecaa34df8 |
| --- /dev/null |
| +++ b/chrome/browser/android/banners/app_banner_infobar_delegate.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
| + |
| +#include "base/strings/string16.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/infobars/core/infobar.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace banners { |
| + |
| +infobars::InfoBar* AppBannerInfoBarDelegate::CreateForWebApp( |
| + InfoBarService* infobar_service, |
| + const AppDelegate* helper, |
| + const base::string16& app_name, |
| + const GURL& url) { |
| + AppBannerInfoBarDelegate* const delegate = new AppBannerInfoBarDelegate( |
| + helper, |
| + app_name, |
| + url); |
| + |
| + return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| + scoped_ptr<ConfirmInfoBarDelegate>(delegate))); |
| +} |
| + |
| +AppBannerInfoBarDelegate::AppBannerInfoBarDelegate( |
| + const AppDelegate* helper, |
| + const base::string16& app_title, |
| + const GURL& url) |
| + : delegate_(helper), |
| + app_title_(app_title), |
| + url_(url), |
| + button_text_(l10n_util::GetStringUTF16( |
| + IDS_APP_INSTALL_ALERTS_ADD_TO_HOMESCREEN)) { |
| +} |
| + |
| +AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() { |
| +} |
| + |
| +base::string16 AppBannerInfoBarDelegate::GetMessageText() const { |
| + return app_title_; |
| +} |
| + |
| +int AppBannerInfoBarDelegate::GetButtons() const { |
| + return BUTTON_OK; |
| +} |
| + |
| +base::string16 AppBannerInfoBarDelegate::GetButtonLabel(InfoBarButton button) |
| + const { |
| + return button_text_; |
| +} |
| + |
| +gfx::Image AppBannerInfoBarDelegate::GetIcon() const { |
|
newt (away)
2015/02/03 00:57:24
How could delegate_ ever be null? It seems impossi
gone
2015/02/03 01:18:16
Done.
|
| + return delegate_ ? delegate_->GetIcon() : gfx::Image(); |
| +} |
| + |
| +void AppBannerInfoBarDelegate::InfoBarDismissed() { |
| + if (delegate_) |
| + delegate_->Block(); |
| +} |
| + |
| +bool AppBannerInfoBarDelegate::Accept() { |
| + if (delegate_) |
| + delegate_->Install(); |
| + return true; |
| +} |
| + |
| +} // namespace banners |