Index: chrome/browser/banners/app_banner_infobar_delegate.cc |
diff --git a/chrome/browser/banners/app_banner_infobar_delegate.cc b/chrome/browser/banners/app_banner_infobar_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6866c06ee5db9dd897014982cfd4662019b0c3e8 |
--- /dev/null |
+++ b/chrome/browser/banners/app_banner_infobar_delegate.cc |
@@ -0,0 +1,97 @@ |
+// 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/banners/app_banner_infobar_delegate.h" |
+ |
+#include "base/metrics/histogram.h" |
+#include "base/strings/string16.h" |
+#include "chrome/browser/banners/app_banner_data_fetcher.h" |
+#include "chrome/browser/banners/app_banner_metrics.h" |
+#include "chrome/browser/banners/app_banner_settings_helper.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/extensions/bookmark_app_helper.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/common/render_messages.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "components/infobars/core/infobar.h" |
+#include "components/infobars/core/infobar_manager.h" |
+#include "components/rappor/rappor_utils.h" |
+#include "content/public/browser/render_frame_host.h" |
+#include "content/public/browser/web_contents.h" |
+#include "grit/theme_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace banners { |
+ |
+AppBannerInfoBarDelegate::AppBannerInfoBarDelegate( |
+ scoped_refptr<AppBannerDataFetcher> fetcher, |
+ const content::Manifest& web_app_data, |
+ extensions::BookmarkAppHelper* bookmark_app_helper, |
+ int event_request_id) |
+ : ConfirmInfoBarDelegate(), |
+ fetcher_(fetcher), |
+ web_app_data_(web_app_data), |
+ bookmark_app_helper_(bookmark_app_helper), |
+ event_request_id_(event_request_id) { |
+} |
+ |
+AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() { } |
+ |
+// static |
+infobars::InfoBar* AppBannerInfoBarDelegate::Create( |
+ scoped_refptr<AppBannerDataFetcher> fetcher, |
+ content::WebContents* web_contents, |
+ const content::Manifest& web_app_data, |
+ extensions::BookmarkAppHelper* bookmark_app_helper, |
+ int event_request_id) { |
+ InfoBarService* infobar_service = |
+ InfoBarService::FromWebContents(web_contents); |
+ return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
benwells
2015/06/02 05:53:35
The way the banner is added is inconsistent betwee
dominickn (DO NOT USE)
2015/06/02 06:51:32
I tried doing it consistently, and created an AppB
|
+ scoped_ptr<ConfirmInfoBarDelegate>(new AppBannerInfoBarDelegate( |
+ fetcher, web_app_data, bookmark_app_helper, event_request_id)))); |
+} |
+ |
+infobars::InfoBarDelegate::Type |
+AppBannerInfoBarDelegate::GetInfoBarType() const { |
+ return PAGE_ACTION_TYPE; |
+} |
+ |
+int AppBannerInfoBarDelegate::GetIconID() const { |
+ return IDR_INFOBAR_APP_BANNER; |
+} |
+ |
+base::string16 AppBannerInfoBarDelegate::GetMessageText() const { |
+ return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE); |
+} |
+ |
+base::string16 AppBannerInfoBarDelegate::GetButtonLabel( |
+ InfoBarButton button) const { |
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) |
+ ? IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON |
+ : IDS_ADD_TO_SHELF_INFOBAR_NEVER_BUTTON); |
benwells
2015/06/02 05:53:35
Having it sohw 'Never' is problematic. The heurist
|
+} |
+ |
+bool AppBannerInfoBarDelegate::Accept() { |
+ bookmark_app_helper_->CreateFromAppBanner( |
+ base::Bind(&AppBannerDataFetcher::FinishCreateBookmarkApp, fetcher_), |
+ web_app_data_); |
+ return true; |
+} |
+ |
+bool AppBannerInfoBarDelegate::Cancel() { |
+ content::WebContents* web_contents = |
+ InfoBarService::WebContentsFromInfoBar(infobar()); |
+ if (web_contents) { |
benwells
2015/06/02 05:53:35
Does the data fetcher need to be canceled at this
dominickn (DO NOT USE)
2015/06/02 06:51:32
Done.
|
+ AppBannerSettingsHelper::RecordBannerDismissEvent( |
+ web_contents, web_app_data_.start_url.spec(), |
+ "AppBanner.WebApp.Dismissed", event_request_id_); |
+ } |
+ return true; |
+} |
+ |
+void AppBannerInfoBarDelegate::InfoBarDismissed() { |
+ Cancel(); |
+} |
+ |
+} // namespace banners |