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"
22 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop(
23 scoped_refptr
<AppBannerDataFetcherDesktop
> fetcher
,
24 const content::Manifest
& web_manifest
,
25 extensions::BookmarkAppHelper
* bookmark_app_helper
,
27 : ConfirmInfoBarDelegate(),
29 web_manifest_(web_manifest
),
30 bookmark_app_helper_(bookmark_app_helper
),
31 event_request_id_(event_request_id
) {
34 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() {
38 infobars::InfoBar
* AppBannerInfoBarDelegateDesktop::Create(
39 scoped_refptr
<AppBannerDataFetcherDesktop
> fetcher
,
40 content::WebContents
* web_contents
,
41 const content::Manifest
& web_manifest
,
42 extensions::BookmarkAppHelper
* bookmark_app_helper
,
43 int event_request_id
) {
44 InfoBarService
* infobar_service
=
45 InfoBarService::FromWebContents(web_contents
);
46 return infobar_service
->AddInfoBar(infobar_service
->CreateConfirmInfoBar(
47 scoped_ptr
<ConfirmInfoBarDelegate
>(new AppBannerInfoBarDelegateDesktop(
48 fetcher
, web_manifest
, bookmark_app_helper
, event_request_id
))));
51 infobars::InfoBarDelegate::Type
52 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const {
53 return PAGE_ACTION_TYPE
;
56 int AppBannerInfoBarDelegateDesktop::GetIconID() const {
57 return IDR_INFOBAR_APP_BANNER
;
60 base::string16
AppBannerInfoBarDelegateDesktop::GetMessageText() const {
61 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE
);
64 int AppBannerInfoBarDelegateDesktop::GetButtons() const {
68 base::string16
AppBannerInfoBarDelegateDesktop::GetButtonLabel(
69 InfoBarButton button
) const {
70 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON
);
73 bool AppBannerInfoBarDelegateDesktop::Accept() {
74 bookmark_app_helper_
->CreateFromAppBanner(
75 base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp
,
81 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() {
82 content::WebContents
* web_contents
=
83 InfoBarService::WebContentsFromInfoBar(infobar());
85 fetcher_
.get()->Cancel();
87 web_contents
->GetMainFrame()->Send(
88 new ChromeViewMsg_AppBannerDismissed(
89 web_contents
->GetMainFrame()->GetRoutingID(),
92 AppBannerSettingsHelper::RecordBannerDismissEvent(
93 web_contents
, web_manifest_
.start_url
.spec(),
94 AppBannerSettingsHelper::WEB
);
98 } // namespace banners