Revert "Remove old references to AppBannerInfoBarDelegate JNI"
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_infobar_delegate.cc
blobb32bfa315dbc5eb55a6f451129fa58fd771ec0d1
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/android/banners/app_banner_infobar_delegate.h"
7 #include "base/android/jni_android.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/infobars/core/infobar_manager.h"
15 namespace banners {
17 // static
18 AppBannerInfoBar* AppBannerInfoBarDelegate::CreateForNativeApp(
19 infobars::InfoBarManager* infobar_manager,
20 AppDelegate* app_delegate,
21 const base::android::ScopedJavaGlobalRef<jobject>& japp_data) {
22 scoped_ptr<AppBannerInfoBarDelegate> delegate(new AppBannerInfoBarDelegate(
23 app_delegate));
24 AppBannerInfoBar* infobar = new AppBannerInfoBar(delegate.Pass(), japp_data);
25 return infobar_manager->AddInfoBar(make_scoped_ptr(infobar))
26 ? infobar : nullptr;
29 // static
30 AppBannerInfoBar* AppBannerInfoBarDelegate::CreateForWebApp(
31 infobars::InfoBarManager* infobar_manager,
32 AppDelegate* app_delegate,
33 const GURL& url) {
34 scoped_ptr<AppBannerInfoBarDelegate> delegate(new AppBannerInfoBarDelegate(
35 app_delegate));
36 AppBannerInfoBar* infobar = new AppBannerInfoBar(delegate.Pass(), url);
37 return infobar_manager->AddInfoBar(make_scoped_ptr(infobar))
38 ? infobar : nullptr;
41 AppBannerInfoBarDelegate::AppBannerInfoBarDelegate(AppDelegate* app_delegate)
42 : delegate_(app_delegate) {
45 AppBannerInfoBarDelegate::~AppBannerInfoBarDelegate() {
46 DCHECK(delegate_);
47 delegate_->OnInfoBarDestroyed();
50 base::string16 AppBannerInfoBarDelegate::GetMessageText() const {
51 DCHECK(delegate_);
52 return delegate_->GetTitle();
55 int AppBannerInfoBarDelegate::GetButtons() const {
56 return BUTTON_OK;
59 gfx::Image AppBannerInfoBarDelegate::GetIcon() const {
60 DCHECK(delegate_);
61 return delegate_->GetIcon();
64 void AppBannerInfoBarDelegate::InfoBarDismissed() {
65 DCHECK(delegate_);
66 delegate_->Block();
69 bool AppBannerInfoBarDelegate::Accept() {
70 DCHECK(delegate_);
71 return delegate_->OnButtonClicked();
74 bool AppBannerInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
75 DCHECK(delegate_);
76 return delegate_->OnLinkClicked();
79 } // namespace banners