Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: chrome/browser/banners/app_banner_infobar_delegate.cc

Issue 1161233005: Implement app banner info bars on desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stop-icon-overgeneration
Patch Set: Fixing display bug on Android Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/banners/app_banner_infobar_delegate.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/strings/string16.h"
9 #include "chrome/browser/banners/app_banner_data_fetcher.h"
10 #include "chrome/browser/banners/app_banner_metrics.h"
11 #include "chrome/browser/banners/app_banner_settings_helper.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/bookmark_app_helper.h"
14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/common/render_messages.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "components/infobars/core/infobar.h"
18 #include "components/infobars/core/infobar_manager.h"
19 #include "components/rappor/rappor_utils.h"
20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h"
22 #include "grit/theme_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24
25 namespace banners {
26
27 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate(
28 scoped_refptr<AppBannerDataFetcher> fetcher,
29 const content::Manifest& web_app_data,
30 extensions::BookmarkAppHelper* bookmark_app_helper,
31 int event_request_id)
32 : ConfirmInfoBarDelegate(),
33 fetcher_(fetcher),
34 web_app_data_(web_app_data),
35 bookmark_app_helper_(bookmark_app_helper),
36 event_request_id_(event_request_id) {
37 }
38
39 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() { }
40
41 // static
42 infobars::InfoBar* AppBannerInfoBarDelegate::Create(
43 scoped_refptr<AppBannerDataFetcher> fetcher,
44 content::WebContents* web_contents,
45 const content::Manifest& web_app_data,
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(
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
51 scoped_ptr<ConfirmInfoBarDelegate>(new AppBannerInfoBarDelegate(
52 fetcher, web_app_data, bookmark_app_helper, event_request_id))));
53 }
54
55 infobars::InfoBarDelegate::Type
56 AppBannerInfoBarDelegate::GetInfoBarType() const {
57 return PAGE_ACTION_TYPE;
58 }
59
60 int AppBannerInfoBarDelegate::GetIconID() const {
61 return IDR_INFOBAR_APP_BANNER;
62 }
63
64 base::string16 AppBannerInfoBarDelegate::GetMessageText() const {
65 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE);
66 }
67
68 base::string16 AppBannerInfoBarDelegate::GetButtonLabel(
69 InfoBarButton button) const {
70 return l10n_util::GetStringUTF16((button == BUTTON_OK)
71 ? IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON
72 : IDS_ADD_TO_SHELF_INFOBAR_NEVER_BUTTON);
benwells 2015/06/02 05:53:35 Having it sohw 'Never' is problematic. The heurist
73 }
74
75 bool AppBannerInfoBarDelegate::Accept() {
76 bookmark_app_helper_->CreateFromAppBanner(
77 base::Bind(&AppBannerDataFetcher::FinishCreateBookmarkApp, fetcher_),
78 web_app_data_);
79 return true;
80 }
81
82 bool AppBannerInfoBarDelegate::Cancel() {
83 content::WebContents* web_contents =
84 InfoBarService::WebContentsFromInfoBar(infobar());
85 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.
86 AppBannerSettingsHelper::RecordBannerDismissEvent(
87 web_contents, web_app_data_.start_url.spec(),
88 "AppBanner.WebApp.Dismissed", event_request_id_);
89 }
90 return true;
91 }
92
93 void AppBannerInfoBarDelegate::InfoBarDismissed() {
94 Cancel();
95 }
96
97 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698