Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / android / infobars / infobar_android.cc
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.
4
5 #include "chrome/browser/ui/android/infobars/infobar_android.h"
6
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_service.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/infobars/core/infobar_delegate.h"
14 #include "jni/InfoBar_jni.h"
15
16
17 // InfoBar --------------------------------------------------------------------
18
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 infobars::InfoBar::kSeparatorLineHeight = 1;
22 const int infobars::InfoBar::kDefaultArrowTargetHeight = 9;
23 const int infobars::InfoBar::kMaximumArrowTargetHeight = 24;
24 const int infobars::InfoBar::kDefaultArrowTargetHalfWidth =
25     kDefaultArrowTargetHeight;
26 const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14;
27 const int infobars::InfoBar::kDefaultBarTargetHeight = 36;
28
29 // InfoBarAndroid -------------------------------------------------------------
30
31 InfoBarAndroid::InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate)
32     : infobars::InfoBar(delegate.Pass()) {
33 }
34
35 InfoBarAndroid::~InfoBarAndroid() {
36 }
37
38 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) {
39   DCHECK(replacement);
40   if (!java_info_bar_.is_null()) {
41     replacement->set_java_infobar(java_info_bar_);
42     java_info_bar_.Reset();
43   }
44 }
45
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);
50 }
51
52 bool InfoBarAndroid::HasSetJavaInfoBar() const {
53   return !java_info_bar_.is_null();
54 }
55
56 void InfoBarAndroid::OnButtonClicked(JNIEnv* env,
57                                      jobject obj,
58                                      jint action,
59                                      jstring action_value) {
60   std::string value = base::android::ConvertJavaStringToUTF8(env, action_value);
61   ProcessButton(action, value);
62 }
63
64 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) {
65   delegate()->InfoBarDismissed();
66   RemoveSelf();
67 }
68
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());
73   }
74 }
75
76 int InfoBarAndroid::GetEnumeratedIconId() {
77   return ResourceMapper::MapFromChromiumId(delegate()->GetIconID());
78 }
79
80
81 // Native JNI methods ---------------------------------------------------------
82
83 bool RegisterNativeInfoBar(JNIEnv* env) {
84   return RegisterNativesImpl(env);
85 }