1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// 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_desktop.h"
#include "chrome/browser/banners/app_banner_data_fetcher_desktop.h"
#include "chrome/browser/banners/app_banner_metrics.h"
#include "chrome/browser/banners/app_banner_settings_helper.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 "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 {
AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop(
scoped_refptr<AppBannerDataFetcherDesktop> fetcher,
const content::Manifest& web_manifest,
extensions::BookmarkAppHelper* bookmark_app_helper,
int event_request_id)
: ConfirmInfoBarDelegate(),
fetcher_(fetcher),
web_manifest_(web_manifest),
bookmark_app_helper_(bookmark_app_helper),
event_request_id_(event_request_id) {
}
AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() {
}
// static
infobars::InfoBar* AppBannerInfoBarDelegateDesktop::Create(
scoped_refptr<AppBannerDataFetcherDesktop> fetcher,
content::WebContents* web_contents,
const content::Manifest& web_manifest,
extensions::BookmarkAppHelper* bookmark_app_helper,
int event_request_id) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
scoped_ptr<ConfirmInfoBarDelegate>(new AppBannerInfoBarDelegateDesktop(
fetcher, web_manifest, bookmark_app_helper, event_request_id))));
}
infobars::InfoBarDelegate::Type
AppBannerInfoBarDelegateDesktop::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
int AppBannerInfoBarDelegateDesktop::GetIconID() const {
return IDR_INFOBAR_APP_BANNER;
}
base::string16 AppBannerInfoBarDelegateDesktop::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE);
}
int AppBannerInfoBarDelegateDesktop::GetButtons() const {
return BUTTON_OK;
}
base::string16 AppBannerInfoBarDelegateDesktop::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON);
}
bool AppBannerInfoBarDelegateDesktop::Accept() {
bookmark_app_helper_->CreateFromAppBanner(
base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp,
fetcher_),
web_manifest_);
return true;
}
void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() {
content::WebContents* web_contents =
InfoBarService::WebContentsFromInfoBar(infobar());
if (web_contents) {
fetcher_.get()->Cancel();
web_contents->GetMainFrame()->Send(
new ChromeViewMsg_AppBannerDismissed(
web_contents->GetMainFrame()->GetRoutingID(),
event_request_id_));
AppBannerSettingsHelper::RecordBannerDismissEvent(
web_contents, web_manifest_.start_url.spec(),
AppBannerSettingsHelper::WEB);
}
}
} // namespace banners
|