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

Side by Side Diff: chrome/browser/ui/android/infobars/confirm_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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/confirm_infobar.h" 5 #include "chrome/browser/ui/android/infobars/confirm_infobar.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 #include <vector>
9 9
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_array.h"
12 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
15 #include "build/build_config.h"
16 #include "chrome/browser/android/resource_mapper.h"
17 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/media/media_stream_infobar_delegate_android.h"
19 #include "chrome/browser/permissions/permission_infobar_delegate.h"
20 #include "components/content_settings/core/common/content_settings_types.h"
21 #include "components/infobars/core/confirm_infobar_delegate.h" 13 #include "components/infobars/core/confirm_infobar_delegate.h"
22 #include "content/public/browser/android/content_view_core.h" 14 #include "content/public/browser/android/content_view_core.h"
23 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
24 #include "jni/ConfirmInfoBar_jni.h" 16 #include "jni/ConfirmInfoBar_jni.h"
25 #include "ui/android/window_android.h" 17 #include "ui/android/window_android.h"
26 #include "ui/gfx/android/java_bitmap.h" 18 #include "ui/gfx/android/java_bitmap.h"
27 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
28 20
29 using base::android::JavaParamRef; 21 using base::android::JavaParamRef;
30 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
31 23
32 // InfoBarService ------------------------------------------------------------- 24 // InfoBarService -------------------------------------------------------------
33 25
34 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( 26 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
35 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { 27 std::unique_ptr<ConfirmInfoBarDelegate> delegate) {
36 return base::WrapUnique(new ConfirmInfoBar(std::move(delegate))); 28 return base::WrapUnique(new ConfirmInfoBar(std::move(delegate)));
37 } 29 }
38 30
39 31
40 // ConfirmInfoBar ------------------------------------------------------------- 32 // ConfirmInfoBar -------------------------------------------------------------
41 33
42 ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate) 34 ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate)
43 : InfoBarAndroid(std::move(delegate)) {} 35 : InfoBarAndroid(std::move(delegate)) {}
44 36
45 ConfirmInfoBar::~ConfirmInfoBar() { 37 ConfirmInfoBar::~ConfirmInfoBar() {
46 } 38 }
47 39
48 base::android::ScopedJavaLocalRef<jobject> ConfirmInfoBar::CreateRenderInfoBar( 40 ScopedJavaLocalRef<jobject> ConfirmInfoBar::CreateRenderInfoBar(JNIEnv* env) {
49 JNIEnv* env) { 41 ScopedJavaLocalRef<jstring> ok_button_text =
50 base::android::ScopedJavaLocalRef<jstring> ok_button_text =
51 base::android::ConvertUTF16ToJavaString( 42 base::android::ConvertUTF16ToJavaString(
52 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); 43 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
53 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = 44 ScopedJavaLocalRef<jstring> cancel_button_text =
54 base::android::ConvertUTF16ToJavaString( 45 base::android::ConvertUTF16ToJavaString(
55 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 46 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
56 ConfirmInfoBarDelegate* delegate = GetDelegate(); 47 ConfirmInfoBarDelegate* delegate = GetDelegate();
57 base::android::ScopedJavaLocalRef<jstring> message_text = 48 ScopedJavaLocalRef<jstring> message_text =
58 base::android::ConvertUTF16ToJavaString( 49 base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText());
59 env, delegate->GetMessageText()); 50 ScopedJavaLocalRef<jstring> link_text =
60 base::android::ScopedJavaLocalRef<jstring> link_text = 51 base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText());
61 base::android::ConvertUTF16ToJavaString(
62 env, delegate->GetLinkText());
63 52
64 ScopedJavaLocalRef<jobject> java_bitmap; 53 ScopedJavaLocalRef<jobject> java_bitmap;
65 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && 54 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID &&
66 !delegate->GetIcon().IsEmpty()) { 55 !delegate->GetIcon().IsEmpty()) {
67 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); 56 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap());
68 } 57 }
69 58
70 std::vector<int> content_settings;
71 if (delegate->AsPermissionInfobarDelegate()) {
72 content_settings.push_back(
73 delegate->AsPermissionInfobarDelegate()->content_setting());
74 }
75
76 return Java_ConfirmInfoBar_create( 59 return Java_ConfirmInfoBar_create(
77 env, GetWindowAndroid().obj(), GetEnumeratedIconId(), java_bitmap.obj(), 60 env, GetEnumeratedIconId(), java_bitmap.obj(), message_text.obj(),
78 message_text.obj(), link_text.obj(), ok_button_text.obj(), 61 link_text.obj(), ok_button_text.obj(), cancel_button_text.obj());
79 cancel_button_text.obj(),
80 base::android::ToJavaIntArray(env, content_settings).obj());
81 } 62 }
82 63
83 base::android::ScopedJavaLocalRef<jobject> ConfirmInfoBar::GetWindowAndroid() { 64 ScopedJavaLocalRef<jobject> ConfirmInfoBar::GetWindowAndroid() {
84 content::WebContents* web_contents = 65 content::WebContents* web_contents =
85 InfoBarService::WebContentsFromInfoBar(this); 66 InfoBarService::WebContentsFromInfoBar(this);
86 DCHECK(web_contents); 67 DCHECK(web_contents);
87 content::ContentViewCore* cvc = 68 content::ContentViewCore* cvc =
88 content::ContentViewCore::FromWebContents(web_contents); 69 content::ContentViewCore::FromWebContents(web_contents);
89 DCHECK(cvc); 70 DCHECK(cvc);
90 return cvc->GetWindowAndroid()->GetJavaObject(); 71 return cvc->GetWindowAndroid()->GetJavaObject();
91 } 72 }
92 73
93 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env, 74 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env,
(...skipping 20 matching lines...) Expand all
114 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { 95 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
115 return delegate()->AsConfirmInfoBarDelegate(); 96 return delegate()->AsConfirmInfoBarDelegate();
116 } 97 }
117 98
118 base::string16 ConfirmInfoBar::GetTextFor( 99 base::string16 ConfirmInfoBar::GetTextFor(
119 ConfirmInfoBarDelegate::InfoBarButton button) { 100 ConfirmInfoBarDelegate::InfoBarButton button) {
120 ConfirmInfoBarDelegate* delegate = GetDelegate(); 101 ConfirmInfoBarDelegate* delegate = GetDelegate();
121 return (delegate->GetButtons() & button) ? 102 return (delegate->GetButtons() & button) ?
122 delegate->GetButtonLabel(button) : base::string16(); 103 delegate->GetButtonLabel(button) : base::string16();
123 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698