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

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

Issue 901203003: Redo how AppBannerInfoBars are created and stored (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving init before the early return so that restored tabs also get them Created 5 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h"
6 6
7 #include "base/android/jni_android.h"
7 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" 10 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
10 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
11 #include "components/infobars/core/infobar.h" 12 #include "components/infobars/core/infobar.h"
12 #include "components/infobars/core/infobar_manager.h" 13 #include "components/infobars/core/infobar_manager.h"
13 #include "ui/base/l10n/l10n_util.h"
14 14
15 namespace banners { 15 namespace banners {
16 16
17 infobars::InfoBar* AppBannerInfoBarDelegate::CreateForWebApp( 17 // static
18 AppBannerInfoBar* AppBannerInfoBarDelegate::CreateForWebApp(
18 infobars::InfoBarManager* infobar_manager, 19 infobars::InfoBarManager* infobar_manager,
19 const AppDelegate* app_delegate, 20 AppDelegate* app_delegate,
20 const base::string16& app_name,
21 const GURL& url) { 21 const GURL& url) {
22 scoped_ptr<AppBannerInfoBarDelegate> delegate(new AppBannerInfoBarDelegate( 22 scoped_ptr<AppBannerInfoBarDelegate> delegate(new AppBannerInfoBarDelegate(
23 app_delegate, 23 app_delegate));
24 app_name, 24 AppBannerInfoBar* infobar = new AppBannerInfoBar(delegate.Pass(), url);
25 url)); 25 return infobar_manager->AddInfoBar(make_scoped_ptr(infobar))
26 26 ? infobar : nullptr;
27 return infobar_manager->AddInfoBar(
28 make_scoped_ptr(new AppBannerInfoBar(delegate.Pass(), url)));
29 } 27 }
30 28
31 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate( 29 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate(AppDelegate* app_delegate)
32 const AppDelegate* helper, 30 : delegate_(app_delegate) {
33 const base::string16& app_title,
34 const GURL& url)
35 : delegate_(helper),
36 app_title_(app_title),
37 url_(url),
38 button_text_(l10n_util::GetStringUTF16(
39 IDS_APP_INSTALL_ALERTS_ADD_TO_HOMESCREEN)) {
40 } 31 }
41 32
42 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() { 33 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() {
34 DCHECK(delegate_);
35 delegate_->OnInfoBarDestroyed();
43 } 36 }
44 37
45 base::string16 AppBannerInfoBarDelegate::GetMessageText() const { 38 base::string16 AppBannerInfoBarDelegate::GetMessageText() const {
46 return app_title_; 39 DCHECK(delegate_);
40 return delegate_->GetTitle();
47 } 41 }
48 42
49 int AppBannerInfoBarDelegate::GetButtons() const { 43 int AppBannerInfoBarDelegate::GetButtons() const {
50 return BUTTON_OK; 44 return BUTTON_OK;
51 } 45 }
52 46
53 base::string16 AppBannerInfoBarDelegate::GetButtonLabel(InfoBarButton button)
54 const {
55 return button_text_;
56 }
57
58 gfx::Image AppBannerInfoBarDelegate::GetIcon() const { 47 gfx::Image AppBannerInfoBarDelegate::GetIcon() const {
59 DCHECK(delegate_); 48 DCHECK(delegate_);
60 return delegate_->GetIcon(); 49 return delegate_->GetIcon();
61 } 50 }
62 51
63 void AppBannerInfoBarDelegate::InfoBarDismissed() { 52 void AppBannerInfoBarDelegate::InfoBarDismissed() {
64 DCHECK(delegate_); 53 DCHECK(delegate_);
65 delegate_->Block(); 54 delegate_->Block();
66 } 55 }
67 56
68 bool AppBannerInfoBarDelegate::Accept() { 57 bool AppBannerInfoBarDelegate::Accept() {
69 DCHECK(delegate_); 58 DCHECK(delegate_);
70 delegate_->Install(); 59 return delegate_->OnButtonClicked();
71 return true;
72 } 60 }
73 61
74 } // namespace banners 62 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_infobar_delegate.h ('k') | chrome/browser/android/banners/app_banner_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698