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 | |
5 #include "chrome/browser/ui/android/page_info/website_settings_popup_android.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_array.h" | |
9 #include "base/android/jni_string.h" | |
10 #include "base/stl_util.h" | |
11 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h
" | |
12 #include "chrome/browser/infobars/infobar_service.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/browser/ssl/security_state_tab_helper.h" | |
15 #include "chrome/browser/ui/page_info/website_settings.h" | |
16 #include "chrome/browser/ui/page_info/website_settings_ui.h" | |
17 #include "components/content_settings/core/common/content_settings.h" | |
18 #include "components/content_settings/core/common/content_settings_types.h" | |
19 #include "components/security_state/core/security_state.h" | |
20 #include "content/public/browser/browser_context.h" | |
21 #include "content/public/browser/navigation_controller.h" | |
22 #include "content/public/browser/navigation_entry.h" | |
23 #include "content/public/browser/web_contents.h" | |
24 #include "jni/WebsiteSettingsPopup_jni.h" | |
25 #include "url/origin.h" | |
26 | |
27 using base::android::ConvertUTF16ToJavaString; | |
28 using base::android::ConvertUTF8ToJavaString; | |
29 using base::android::JavaParamRef; | |
30 | |
31 // static | |
32 static jlong Init(JNIEnv* env, | |
33 const JavaParamRef<jclass>& clazz, | |
34 const JavaParamRef<jobject>& obj, | |
35 const JavaParamRef<jobject>& java_web_contents) { | |
36 content::WebContents* web_contents = | |
37 content::WebContents::FromJavaWebContents(java_web_contents); | |
38 | |
39 return reinterpret_cast<intptr_t>( | |
40 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); | |
41 } | |
42 | |
43 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( | |
44 JNIEnv* env, | |
45 jobject java_website_settings_pop, | |
46 content::WebContents* web_contents) | |
47 : search_geolocation_service_(nullptr) { | |
48 // Important to use GetVisibleEntry to match what's showing in the omnibox. | |
49 content::NavigationEntry* nav_entry = | |
50 web_contents->GetController().GetVisibleEntry(); | |
51 if (nav_entry == NULL) | |
52 return; | |
53 | |
54 url_ = nav_entry->GetURL(); | |
55 | |
56 popup_jobject_.Reset(env, java_website_settings_pop); | |
57 | |
58 SecurityStateTabHelper* helper = | |
59 SecurityStateTabHelper::FromWebContents(web_contents); | |
60 DCHECK(helper); | |
61 security_state::SecurityInfo security_info; | |
62 helper->GetSecurityInfo(&security_info); | |
63 | |
64 search_geolocation_service_ = | |
65 SearchGeolocationService::Factory::GetForBrowserContext( | |
66 web_contents->GetBrowserContext()); | |
67 | |
68 presenter_.reset(new WebsiteSettings( | |
69 this, Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
70 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, | |
71 nav_entry->GetURL(), security_info)); | |
72 } | |
73 | |
74 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} | |
75 | |
76 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, | |
77 const JavaParamRef<jobject>& obj) { | |
78 delete this; | |
79 } | |
80 | |
81 void WebsiteSettingsPopupAndroid::RecordWebsiteSettingsAction( | |
82 JNIEnv* env, | |
83 const JavaParamRef<jobject>& obj, | |
84 jint action) { | |
85 presenter_->RecordWebsiteSettingsAction( | |
86 static_cast<WebsiteSettings::WebsiteSettingsAction>(action)); | |
87 } | |
88 | |
89 void WebsiteSettingsPopupAndroid::SetIdentityInfo( | |
90 const IdentityInfo& identity_info) { | |
91 JNIEnv* env = base::android::AttachCurrentThread(); | |
92 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = | |
93 identity_info.GetSecurityDescription(); | |
94 | |
95 Java_WebsiteSettingsPopup_setSecurityDescription( | |
96 env, popup_jobject_, | |
97 ConvertUTF16ToJavaString(env, security_description->summary), | |
98 ConvertUTF16ToJavaString(env, security_description->details)); | |
99 } | |
100 | |
101 void WebsiteSettingsPopupAndroid::SetCookieInfo( | |
102 const CookieInfoList& cookie_info_list) { | |
103 NOTIMPLEMENTED(); | |
104 } | |
105 | |
106 void WebsiteSettingsPopupAndroid::SetPermissionInfo( | |
107 const PermissionInfoList& permission_info_list, | |
108 ChosenObjectInfoList chosen_object_info_list) { | |
109 JNIEnv* env = base::android::AttachCurrentThread(); | |
110 | |
111 // On Android, we only want to display a subset of the available options in a | |
112 // particular order, but only if their value is different from the default. | |
113 std::vector<ContentSettingsType> permissions_to_display; | |
114 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
115 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
116 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
117 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
118 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_IMAGES); | |
119 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
120 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_POPUPS); | |
121 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_AUTOPLAY); | |
122 | |
123 std::map<ContentSettingsType, ContentSetting> | |
124 user_specified_settings_to_display; | |
125 | |
126 for (const auto& permission : permission_info_list) { | |
127 if (base::ContainsValue(permissions_to_display, permission.type)) { | |
128 if (permission.setting != CONTENT_SETTING_DEFAULT) { | |
129 user_specified_settings_to_display[permission.type] = | |
130 permission.setting; | |
131 } else if (permission.type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
132 if (search_geolocation_service_ && | |
133 search_geolocation_service_->UseDSEGeolocationSetting( | |
134 url::Origin(url_))) { | |
135 user_specified_settings_to_display[permission.type] = | |
136 search_geolocation_service_->GetDSEGeolocationSetting() | |
137 ? CONTENT_SETTING_ALLOW | |
138 : CONTENT_SETTING_BLOCK; | |
139 } | |
140 } | |
141 } | |
142 } | |
143 | |
144 for (const auto& permission : permissions_to_display) { | |
145 if (base::ContainsKey(user_specified_settings_to_display, permission)) { | |
146 base::string16 setting_title = | |
147 WebsiteSettingsUI::PermissionTypeToUIString(permission); | |
148 | |
149 Java_WebsiteSettingsPopup_addPermissionSection( | |
150 env, popup_jobject_, ConvertUTF16ToJavaString(env, setting_title), | |
151 static_cast<jint>(permission), | |
152 static_cast<jint>(user_specified_settings_to_display[permission])); | |
153 } | |
154 } | |
155 | |
156 for (const auto& chosen_object : chosen_object_info_list) { | |
157 base::string16 object_title = | |
158 WebsiteSettingsUI::ChosenObjectToUIString(*chosen_object); | |
159 | |
160 Java_WebsiteSettingsPopup_addPermissionSection( | |
161 env, popup_jobject_, ConvertUTF16ToJavaString(env, object_title), | |
162 static_cast<jint>(chosen_object->ui_info.content_settings_type), | |
163 static_cast<jint>(CONTENT_SETTING_ALLOW)); | |
164 } | |
165 | |
166 Java_WebsiteSettingsPopup_updatePermissionDisplay(env, popup_jobject_); | |
167 } | |
168 | |
169 // static | |
170 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | |
171 JNIEnv* env) { | |
172 return RegisterNativesImpl(env); | |
173 } | |
OLD | NEW |