Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_infobar_delegate_desktop.cc
blob693180a83994070b0b5986737bd0bf682954ec59
1 // Copyright 2015 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/banners/app_banner_infobar_delegate_desktop.h"
7 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h"
8 #include "chrome/browser/banners/app_banner_metrics.h"
9 #include "chrome/browser/banners/app_banner_settings_helper.h"
10 #include "chrome/browser/extensions/bookmark_app_helper.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/common/render_messages.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "components/infobars/core/infobar.h"
15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
20 namespace banners {
22 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop(
23 scoped_refptr<AppBannerDataFetcherDesktop> fetcher,
24 const content::Manifest& web_manifest,
25 extensions::BookmarkAppHelper* bookmark_app_helper,
26 int event_request_id)
27 : ConfirmInfoBarDelegate(),
28 fetcher_(fetcher),
29 web_manifest_(web_manifest),
30 bookmark_app_helper_(bookmark_app_helper),
31 event_request_id_(event_request_id),
32 has_user_interaction_(false) {
35 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() {
36 if (!has_user_interaction_)
37 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED);
40 // static
41 infobars::InfoBar* AppBannerInfoBarDelegateDesktop::Create(
42 scoped_refptr<AppBannerDataFetcherDesktop> fetcher,
43 content::WebContents* web_contents,
44 const content::Manifest& web_manifest,
45 extensions::BookmarkAppHelper* bookmark_app_helper,
46 int event_request_id) {
47 InfoBarService* infobar_service =
48 InfoBarService::FromWebContents(web_contents);
49 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
50 scoped_ptr<ConfirmInfoBarDelegate>(new AppBannerInfoBarDelegateDesktop(
51 fetcher, web_manifest, bookmark_app_helper, event_request_id))));
54 infobars::InfoBarDelegate::Type
55 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const {
56 return PAGE_ACTION_TYPE;
59 int AppBannerInfoBarDelegateDesktop::GetIconID() const {
60 return IDR_INFOBAR_APP_BANNER;
63 base::string16 AppBannerInfoBarDelegateDesktop::GetMessageText() const {
64 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE);
67 int AppBannerInfoBarDelegateDesktop::GetButtons() const {
68 return BUTTON_OK;
71 base::string16 AppBannerInfoBarDelegateDesktop::GetButtonLabel(
72 InfoBarButton button) const {
73 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON);
76 bool AppBannerInfoBarDelegateDesktop::Accept() {
77 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
78 has_user_interaction_ = true;
80 bookmark_app_helper_->CreateFromAppBanner(
81 base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp,
82 fetcher_),
83 web_manifest_);
84 return true;
87 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() {
88 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
89 has_user_interaction_ = true;
91 content::WebContents* web_contents =
92 InfoBarService::WebContentsFromInfoBar(infobar());
93 if (web_contents) {
94 fetcher_.get()->Cancel();
96 web_contents->GetMainFrame()->Send(
97 new ChromeViewMsg_AppBannerDismissed(
98 web_contents->GetMainFrame()->GetRoutingID(),
99 event_request_id_));
101 AppBannerSettingsHelper::RecordBannerDismissEvent(
102 web_contents, web_manifest_.start_url.spec(),
103 AppBannerSettingsHelper::WEB);
107 } // namespace banners