1 // Copyright 2013 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/ui/android/infobars/infobar_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/strings/string_util.h"
10 #include "chrome/browser/android/resource_mapper.h"
11 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/infobars/infobar_delegate.h"
13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "jni/InfoBar_jni.h"
17 // InfoBar --------------------------------------------------------------------
19 // Static constants defined in infobar.h. We don't really use them for anything
20 // but they are required. The values are copied from the GTK implementation.
21 const int InfoBar::kSeparatorLineHeight
= 1;
22 const int InfoBar::kDefaultArrowTargetHeight
= 9;
23 const int InfoBar::kMaximumArrowTargetHeight
= 24;
24 const int InfoBar::kDefaultArrowTargetHalfWidth
= kDefaultArrowTargetHeight
;
25 const int InfoBar::kMaximumArrowTargetHalfWidth
= 14;
26 const int InfoBar::kDefaultBarTargetHeight
= 36;
29 // InfoBarAndroid -------------------------------------------------------------
31 InfoBarAndroid::InfoBarAndroid(InfoBarService
* owner
, InfoBarDelegate
* delegate
)
32 : InfoBar(owner
, delegate
) {
35 InfoBarAndroid::~InfoBarAndroid() {
38 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid
* replacement
) {
40 if (!java_info_bar_
.is_null()) {
41 replacement
->set_java_infobar(java_info_bar_
);
42 java_info_bar_
.Reset();
46 void InfoBarAndroid::set_java_infobar(
47 const base::android::JavaRef
<jobject
>& java_info_bar
) {
48 DCHECK(java_info_bar_
.is_null());
49 java_info_bar_
.Reset(java_info_bar
);
52 bool InfoBarAndroid::HasSetJavaInfoBar() const {
53 return !java_info_bar_
.is_null();
56 void InfoBarAndroid::OnButtonClicked(JNIEnv
* env
,
59 jstring action_value
) {
60 std::string value
= base::android::ConvertJavaStringToUTF8(env
, action_value
);
61 ProcessButton(action
, value
);
64 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv
* env
, jobject obj
) {
65 delegate()->InfoBarDismissed();
69 void InfoBarAndroid::CloseJavaInfoBar() {
70 if (!java_info_bar_
.is_null()) {
71 JNIEnv
* env
= base::android::AttachCurrentThread();
72 Java_InfoBar_closeInfoBar(env
, java_info_bar_
.obj());
76 int InfoBarAndroid::GetEnumeratedIconId() {
77 return ResourceMapper::MapFromChromiumId(delegate()->GetIconID());
81 // Native JNI methods ---------------------------------------------------------
83 bool RegisterNativeInfoBar(JNIEnv
* env
) {
84 return RegisterNativesImpl(env
);