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

Side by Side Diff: chrome/browser/ui/android/infobars/permission_infobar.cc

Issue 2250053002: Clean up the PermissionInfoBarDelegate hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobar-remember-decision
Patch Set: Address comments Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/android/infobars/permission_infobar.h" 5 #include "chrome/browser/ui/android/infobars/permission_infobar.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/android/jni_array.h" 11 #include "base/android/jni_array.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "chrome/browser/permissions/permission_infobar_delegate.h" 14 #include "chrome/browser/permissions/permission_infobar_delegate.h"
15 #include "chrome/browser/ui/android/infobars/confirm_infobar.h" 15 #include "chrome/browser/ui/android/infobars/confirm_infobar.h"
16 #include "components/content_settings/core/common/content_settings_types.h" 16 #include "components/content_settings/core/common/content_settings_types.h"
17 #include "jni/PermissionInfoBar_jni.h" 17 #include "jni/PermissionInfoBar_jni.h"
18 #include "ui/gfx/android/java_bitmap.h" 18 #include "ui/gfx/android/java_bitmap.h"
19 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
20 20
21 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
22 22
23 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( 23 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar(
24 std::unique_ptr<PermissionInfobarDelegate> delegate) { 24 std::unique_ptr<PermissionInfoBarDelegate> delegate) {
25 return base::WrapUnique(new PermissionInfoBar(std::move(delegate))); 25 return base::WrapUnique(new PermissionInfoBar(std::move(delegate)));
26 } 26 }
27 27
28 PermissionInfoBar::PermissionInfoBar( 28 PermissionInfoBar::PermissionInfoBar(
29 std::unique_ptr<PermissionInfobarDelegate> delegate) 29 std::unique_ptr<PermissionInfoBarDelegate> delegate)
30 : ConfirmInfoBar(std::move(delegate)) {} 30 : ConfirmInfoBar(std::move(delegate)) {}
31 31
32 PermissionInfoBar::~PermissionInfoBar() = default; 32 PermissionInfoBar::~PermissionInfoBar() = default;
33 33
34 PermissionInfobarDelegate* PermissionInfoBar::GetDelegate() { 34 PermissionInfoBarDelegate* PermissionInfoBar::GetDelegate() {
35 return delegate()->AsPermissionInfobarDelegate(); 35 return delegate()->AsPermissionInfoBarDelegate();
36 } 36 }
37 37
38 ScopedJavaLocalRef<jobject> PermissionInfoBar::CreateRenderInfoBar( 38 ScopedJavaLocalRef<jobject> PermissionInfoBar::CreateRenderInfoBar(
39 JNIEnv* env) { 39 JNIEnv* env) {
40 ScopedJavaLocalRef<jstring> ok_button_text = 40 ScopedJavaLocalRef<jstring> ok_button_text =
41 base::android::ConvertUTF16ToJavaString( 41 base::android::ConvertUTF16ToJavaString(
42 env, GetTextFor(PermissionInfobarDelegate::BUTTON_OK)); 42 env, GetTextFor(PermissionInfoBarDelegate::BUTTON_OK));
43 ScopedJavaLocalRef<jstring> cancel_button_text = 43 ScopedJavaLocalRef<jstring> cancel_button_text =
44 base::android::ConvertUTF16ToJavaString( 44 base::android::ConvertUTF16ToJavaString(
45 env, GetTextFor(PermissionInfobarDelegate::BUTTON_CANCEL)); 45 env, GetTextFor(PermissionInfoBarDelegate::BUTTON_CANCEL));
46 PermissionInfobarDelegate* delegate = GetDelegate(); 46 PermissionInfoBarDelegate* delegate = GetDelegate();
47 ScopedJavaLocalRef<jstring> message_text = 47 ScopedJavaLocalRef<jstring> message_text =
48 base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText()); 48 base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText());
49 ScopedJavaLocalRef<jstring> link_text = 49 ScopedJavaLocalRef<jstring> link_text =
50 base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText()); 50 base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText());
51 51
52 ScopedJavaLocalRef<jobject> java_bitmap; 52 ScopedJavaLocalRef<jobject> java_bitmap;
53 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && 53 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID &&
54 !delegate->GetIcon().IsEmpty()) { 54 !delegate->GetIcon().IsEmpty()) {
55 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); 55 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap());
56 } 56 }
57 57
58 std::vector<int> content_settings{delegate->content_setting()}; 58 std::vector<int> content_settings{delegate->content_setting()};
59 59
60 return Java_PermissionInfoBar_create( 60 return Java_PermissionInfoBar_create(
61 env, GetWindowAndroid().obj(), GetEnumeratedIconId(), java_bitmap.obj(), 61 env, GetWindowAndroid().obj(), GetEnumeratedIconId(), java_bitmap.obj(),
62 message_text.obj(), link_text.obj(), ok_button_text.obj(), 62 message_text.obj(), link_text.obj(), ok_button_text.obj(),
63 cancel_button_text.obj(), 63 cancel_button_text.obj(),
64 base::android::ToJavaIntArray(env, content_settings).obj(), 64 base::android::ToJavaIntArray(env, content_settings).obj(),
65 delegate->ShouldShowPersistenceToggle()); 65 delegate->ShouldShowPersistenceToggle());
66 } 66 }
67 67
68 void PermissionInfoBar::ProcessButton(int action) { 68 void PermissionInfoBar::ProcessButton(int action) {
69 // Check if the delegate asked us to display a persistence toggle. If so, 69 // Check if the delegate asked us to display a persistence toggle. If so,
70 // inform it of the toggle state. 70 // inform it of the toggle state.
71 PermissionInfobarDelegate* delegate = GetDelegate(); 71 PermissionInfoBarDelegate* delegate = GetDelegate();
72 if (delegate->ShouldShowPersistenceToggle()) { 72 if (delegate->ShouldShowPersistenceToggle()) {
73 delegate->set_persist(Java_PermissionInfoBar_isPersistSwitchOn( 73 delegate->set_persist(Java_PermissionInfoBar_isPersistSwitchOn(
74 base::android::AttachCurrentThread(), GetJavaInfoBar())); 74 base::android::AttachCurrentThread(), GetJavaInfoBar()));
75 } 75 }
76 76
77 ConfirmInfoBar::ProcessButton(action); 77 ConfirmInfoBar::ProcessButton(action);
78 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698