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

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

Issue 1164973003: Add initial support for runtime permissions in android M. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 <vector>
8
7 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
9 #include "base/logging.h" 12 #include "base/logging.h"
10 #include "chrome/browser/android/resource_mapper.h" 13 #include "chrome/browser/android/resource_mapper.h"
14 #include "chrome/browser/content_settings/permission_infobar_delegate.h"
11 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/media/media_stream_infobar_delegate.h"
17 #include "components/content_settings/core/common/content_settings_types.h"
12 #include "components/infobars/core/confirm_infobar_delegate.h" 18 #include "components/infobars/core/confirm_infobar_delegate.h"
19 #include "content/public/browser/android/content_view_core.h"
20 #include "content/public/browser/web_contents.h"
13 #include "jni/ConfirmInfoBarDelegate_jni.h" 21 #include "jni/ConfirmInfoBarDelegate_jni.h"
22 #include "ui/android/window_android.h"
14 #include "ui/gfx/android/java_bitmap.h" 23 #include "ui/gfx/android/java_bitmap.h"
15 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
16 25
17 // InfoBarService ------------------------------------------------------------- 26 // InfoBarService -------------------------------------------------------------
18 27
19 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( 28 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
20 scoped_ptr<ConfirmInfoBarDelegate> delegate) { 29 scoped_ptr<ConfirmInfoBarDelegate> delegate) {
21 return make_scoped_ptr(new ConfirmInfoBar(delegate.Pass())); 30 return make_scoped_ptr(new ConfirmInfoBar(delegate.Pass()));
22 } 31 }
23 32
(...skipping 22 matching lines...) Expand all
46 env, delegate->GetMessageText()); 55 env, delegate->GetMessageText());
47 base::android::ScopedJavaLocalRef<jstring> link_text = 56 base::android::ScopedJavaLocalRef<jstring> link_text =
48 base::android::ConvertUTF16ToJavaString( 57 base::android::ConvertUTF16ToJavaString(
49 env, delegate->GetLinkText()); 58 env, delegate->GetLinkText());
50 59
51 ScopedJavaLocalRef<jobject> java_bitmap; 60 ScopedJavaLocalRef<jobject> java_bitmap;
52 if (!delegate->GetIcon().IsEmpty()) { 61 if (!delegate->GetIcon().IsEmpty()) {
53 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); 62 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap());
54 } 63 }
55 64
65 std::vector<int> content_settings;
66 if (delegate->AsPermissionInfobarDelegate()) {
67 content_settings.push_back(
68 delegate->AsPermissionInfobarDelegate()->content_setting());
69 } else if (delegate->AsMediaStreamInfoBarDelegate()) {
70 MediaStreamInfoBarDelegate* media_delegate =
71 delegate->AsMediaStreamInfoBarDelegate();
72 if (media_delegate->IsRequestingVideoAccess()) {
73 content_settings.push_back(
74 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
75 } else if (media_delegate->IsRequestingMicrophoneAccess()) {
76 content_settings.push_back(
77 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
78 }
79 }
80
81 content::WebContents* web_contents =
82 InfoBarService::WebContentsFromInfoBar(this);
83 DCHECK(web_contents);
84 content::ContentViewCore* cvc =
85 content::ContentViewCore::FromWebContents(web_contents);
86 DCHECK(cvc);
87 base::android::ScopedJavaLocalRef<jobject> jwindow_android =
88 cvc->GetWindowAndroid()->GetJavaObject();
89
56 return Java_ConfirmInfoBarDelegate_showConfirmInfoBar( 90 return Java_ConfirmInfoBarDelegate_showConfirmInfoBar(
57 env, java_confirm_delegate_.obj(), reinterpret_cast<intptr_t>(this), 91 env, java_confirm_delegate_.obj(), reinterpret_cast<intptr_t>(this),
58 GetEnumeratedIconId(), java_bitmap.obj(), message_text.obj(), 92 jwindow_android.obj(), GetEnumeratedIconId(), java_bitmap.obj(),
59 link_text.obj(), ok_button_text.obj(), cancel_button_text.obj()); 93 message_text.obj(), link_text.obj(), ok_button_text.obj(),
94 cancel_button_text.obj(),
95 base::android::ToJavaIntArray(env, content_settings).obj());
60 } 96 }
61 97
62 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env, jobject obj) { 98 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env, jobject obj) {
63 if (!owner()) 99 if (!owner())
64 return; // We're closing; don't call anything, it might access the owner. 100 return; // We're closing; don't call anything, it might access the owner.
65 101
66 if (GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB)) 102 if (GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB))
67 RemoveSelf(); 103 RemoveSelf();
68 } 104 }
69 105
(...skipping 20 matching lines...) Expand all
90 return (delegate->GetButtons() & button) ? 126 return (delegate->GetButtons() & button) ?
91 delegate->GetButtonLabel(button) : base::string16(); 127 delegate->GetButtonLabel(button) : base::string16();
92 } 128 }
93 129
94 130
95 // Native JNI methods --------------------------------------------------------- 131 // Native JNI methods ---------------------------------------------------------
96 132
97 bool RegisterConfirmInfoBarDelegate(JNIEnv* env) { 133 bool RegisterConfirmInfoBarDelegate(JNIEnv* env) {
98 return RegisterNativesImpl(env); 134 return RegisterNativesImpl(env);
99 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698