OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #include "chrome/browser/ui/android/infobar/infobar_android.h" |
| 5 |
| 6 #include "base/android/jni_android.h" |
| 7 #include "base/android/jni_string.h" |
| 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/browser/android/resource_mapper.h" |
| 10 #include "chrome/browser/infobars/infobar.h" |
| 11 #include "chrome/browser/infobars/infobar_delegate.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "jni/InfoBar_jni.h" |
| 14 |
| 15 namespace gfx { |
| 16 class Image; |
| 17 } |
| 18 |
| 19 using base::android::AttachCurrentThread; |
| 20 using base::android::JavaRef; |
| 21 |
| 22 |
| 23 // static constants defined in infobar.h we don't really use them for anything |
| 24 // but they are required. The values are copied from the GTK implementation. |
| 25 const int InfoBar::kSeparatorLineHeight = 1; |
| 26 const int InfoBar::kDefaultArrowTargetHeight = 9; |
| 27 const int InfoBar::kMaximumArrowTargetHeight = 24; |
| 28 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; |
| 29 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; |
| 30 const int InfoBar::kDefaultBarTargetHeight = 36; |
| 31 |
| 32 InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) |
| 33 : InfoBar(owner, delegate), |
| 34 delegate_(delegate) { |
| 35 DCHECK(delegate_); |
| 36 DCHECK(delegate_->owner()); |
| 37 } |
| 38 |
| 39 InfoBarAndroid::~InfoBarAndroid() {} |
| 40 |
| 41 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { |
| 42 DCHECK(replacement); |
| 43 if (!java_info_bar_.is_null()) { |
| 44 replacement->set_java_infobar(java_info_bar_); |
| 45 java_info_bar_.Reset(); |
| 46 } |
| 47 } |
| 48 |
| 49 void InfoBarAndroid::set_java_infobar(const JavaRef<jobject>& java_info_bar) { |
| 50 DCHECK(java_info_bar_.is_null()); |
| 51 java_info_bar_.Reset(java_info_bar); |
| 52 } |
| 53 |
| 54 bool InfoBarAndroid::HasSetJavaInfoBar() const { |
| 55 return !java_info_bar_.is_null(); |
| 56 } |
| 57 |
| 58 void InfoBarAndroid::OnButtonClicked( |
| 59 JNIEnv* env, jobject obj, jint action, jstring action_value) { |
| 60 DCHECK(delegate_); |
| 61 std::string value = base::android::ConvertJavaStringToUTF8(env, action_value); |
| 62 ProcessButton(action, value); |
| 63 } |
| 64 |
| 65 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) { |
| 66 delegate_->InfoBarDismissed(); |
| 67 } |
| 68 |
| 69 void InfoBarAndroid::OnInfoBarClosed(JNIEnv* env, jobject obj) { |
| 70 java_info_bar_.Reset(); // So we don't notify Java. |
| 71 if (owner()) |
| 72 RemoveSelf(); |
| 73 } |
| 74 |
| 75 void InfoBarAndroid::CloseInfoBar() { |
| 76 CloseJavaInfoBar(); |
| 77 if (owner()) |
| 78 RemoveSelf(); |
| 79 } |
| 80 |
| 81 void InfoBarAndroid::CloseJavaInfoBar() { |
| 82 if (!java_info_bar_.is_null()) { |
| 83 JNIEnv* env = AttachCurrentThread(); |
| 84 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); |
| 85 } |
| 86 } |
| 87 |
| 88 int InfoBarAndroid::GetEnumeratedIconId() { |
| 89 DCHECK(delegate_); |
| 90 return ResourceMapper::MapFromChromiumId(delegate_->GetIconID()); |
| 91 } |
| 92 |
| 93 // ----------------------------------------------------------------------------- |
| 94 // Native JNI methods |
| 95 // ----------------------------------------------------------------------------- |
| 96 |
| 97 // Register native methods |
| 98 bool RegisterNativeInfoBar(JNIEnv* env) { |
| 99 return RegisterNativesImpl(env); |
| 100 } |
OLD | NEW |