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"
19 #include "ui/gfx/vector_icons_public.h"
23 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop(
24 scoped_refptr
<AppBannerDataFetcherDesktop
> fetcher
,
25 const content::Manifest
& web_manifest
,
26 extensions::BookmarkAppHelper
* bookmark_app_helper
,
28 : ConfirmInfoBarDelegate(),
30 web_manifest_(web_manifest
),
31 bookmark_app_helper_(bookmark_app_helper
),
32 event_request_id_(event_request_id
),
33 has_user_interaction_(false) {
36 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() {
37 if (!has_user_interaction_
)
38 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED
);
42 infobars::InfoBar
* AppBannerInfoBarDelegateDesktop::Create(
43 scoped_refptr
<AppBannerDataFetcherDesktop
> fetcher
,
44 content::WebContents
* web_contents
,
45 const content::Manifest
& web_manifest
,
46 extensions::BookmarkAppHelper
* bookmark_app_helper
,
47 int event_request_id
) {
48 InfoBarService
* infobar_service
=
49 InfoBarService::FromWebContents(web_contents
);
50 return infobar_service
->AddInfoBar(infobar_service
->CreateConfirmInfoBar(
51 scoped_ptr
<ConfirmInfoBarDelegate
>(new AppBannerInfoBarDelegateDesktop(
52 fetcher
, web_manifest
, bookmark_app_helper
, event_request_id
))));
55 infobars::InfoBarDelegate::Type
56 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const {
57 return PAGE_ACTION_TYPE
;
60 int AppBannerInfoBarDelegateDesktop::GetIconId() const {
61 return IDR_INFOBAR_APP_BANNER
;
64 gfx::VectorIconId
AppBannerInfoBarDelegateDesktop::GetVectorIconId() const {
65 #if defined(OS_MACOSX)
66 return gfx::VectorIconId::VECTOR_ICON_NONE
;
68 return gfx::VectorIconId::APPS
;
72 base::string16
AppBannerInfoBarDelegateDesktop::GetMessageText() const {
73 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE
);
76 int AppBannerInfoBarDelegateDesktop::GetButtons() const {
80 base::string16
AppBannerInfoBarDelegateDesktop::GetButtonLabel(
81 InfoBarButton button
) const {
82 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON
);
85 bool AppBannerInfoBarDelegateDesktop::Accept() {
86 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED
);
87 has_user_interaction_
= true;
89 bookmark_app_helper_
->CreateFromAppBanner(
90 base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp
,
96 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() {
97 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED
);
98 has_user_interaction_
= true;
100 content::WebContents
* web_contents
=
101 InfoBarService::WebContentsFromInfoBar(infobar());
103 fetcher_
.get()->Cancel();
105 web_contents
->GetMainFrame()->Send(
106 new ChromeViewMsg_AppBannerDismissed(
107 web_contents
->GetMainFrame()->GetRoutingID(),
110 AppBannerSettingsHelper::RecordBannerDismissEvent(
111 web_contents
, web_manifest_
.start_url
.spec(),
112 AppBannerSettingsHelper::WEB
);
116 } // namespace banners