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

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

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

Powered by Google App Engine
This is Rietveld 408576698