| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/website_settings_popup_android.h" | 5 #include "chrome/browser/ui/android/website_settings_popup_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/website_settings/website_settings.h" | 12 #include "chrome/browser/ui/website_settings/website_settings.h" |
| 13 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 13 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
| 14 #include "components/content_settings/core/common/content_settings.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/cert_store.h" | 17 #include "content/public/browser/cert_store.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "grit/generated_resources.h" |
| 20 #include "jni/WebsiteSettingsPopup_jni.h" | 22 #include "jni/WebsiteSettingsPopup_jni.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 | 24 |
| 23 using base::android::ConvertUTF16ToJavaString; | 25 using base::android::ConvertUTF16ToJavaString; |
| 24 using base::android::ConvertUTF8ToJavaString; | 26 using base::android::ConvertUTF8ToJavaString; |
| 25 | 27 |
| 26 // static | 28 // static |
| 27 static jlong Init(JNIEnv* env, | 29 static jlong Init(JNIEnv* env, |
| 28 jclass clazz, | 30 jclass clazz, |
| 29 jobject obj, | 31 jobject obj, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 nav_entry->GetSSL(), | 60 nav_entry->GetSSL(), |
| 59 content::CertStore::GetInstance())); | 61 content::CertStore::GetInstance())); |
| 60 } | 62 } |
| 61 | 63 |
| 62 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} | 64 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} |
| 63 | 65 |
| 64 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { | 66 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { |
| 65 delete this; | 67 delete this; |
| 66 } | 68 } |
| 67 | 69 |
| 70 void WebsiteSettingsPopupAndroid::OnPermissionSettingChanged(JNIEnv* env, |
| 71 jobject obj, |
| 72 jint type, |
| 73 jint setting) { |
| 74 ContentSettingsType content_setting_type = |
| 75 static_cast<ContentSettingsType>(type); |
| 76 ContentSetting content_setting = static_cast<ContentSetting>(setting); |
| 77 presenter_->OnSitePermissionChanged(content_setting_type, content_setting); |
| 78 } |
| 79 |
| 68 void WebsiteSettingsPopupAndroid::SetIdentityInfo( | 80 void WebsiteSettingsPopupAndroid::SetIdentityInfo( |
| 69 const IdentityInfo& identity_info) { | 81 const IdentityInfo& identity_info) { |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | 82 JNIEnv* env = base::android::AttachCurrentThread(); |
| 71 | 83 |
| 72 enum PageInfoConnectionType connection_type = CONNECTION_UNKNOWN; | 84 enum PageInfoConnectionType connection_type = CONNECTION_UNKNOWN; |
| 73 switch (identity_info.connection_status) { | 85 switch (identity_info.connection_status) { |
| 74 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: | 86 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: |
| 75 connection_type = CONNECTION_UNKNOWN; | 87 connection_type = CONNECTION_UNKNOWN; |
| 76 break; | 88 break; |
| 77 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: | 89 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: |
| 78 connection_type = CONNECTION_ENCRYPTED; | 90 connection_type = CONNECTION_ENCRYPTED; |
| 79 break; | 91 break; |
| 80 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT: | 92 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT: |
| 81 connection_type = CONNECTION_MIXED_CONTENT; | 93 connection_type = CONNECTION_MIXED_CONTENT; |
| 82 break; | 94 break; |
| 83 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: | 95 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: |
| 84 connection_type = CONNECTION_UNENCRYPTED; | 96 connection_type = CONNECTION_UNENCRYPTED; |
| 85 break; | 97 break; |
| 86 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: | 98 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: |
| 87 connection_type = CONNECTION_ENCRYPTED_ERROR; | 99 connection_type = CONNECTION_ENCRYPTED_ERROR; |
| 88 break; | 100 break; |
| 89 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE: | 101 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE: |
| 90 connection_type = CONNECTION_INTERNAL_PAGE; | 102 connection_type = CONNECTION_INTERNAL_PAGE; |
| 91 break; | 103 break; |
| 92 default: | 104 default: |
| 93 NOTREACHED(); | 105 NOTREACHED(); |
| 94 break; | 106 break; |
| 95 } | 107 } |
| 96 | 108 |
| 97 Java_WebsiteSettingsPopup_setURLTitle( | 109 int scheme_end_index = url_.scheme().size(); |
| 110 // The last index of the domain doesn't include the trailing slash. If the URL |
| 111 // is non-standard, just say the whole URL is the domain (e.g. about:blank). |
| 112 int domain_end_index = url_.IsStandard() |
| 113 ? url_.GetWithEmptyPath().spec().size() - 1 |
| 114 : url_.spec().size(); |
| 115 |
| 116 Java_WebsiteSettingsPopup_setURL( |
| 98 env, | 117 env, |
| 99 popup_jobject_.obj(), | 118 popup_jobject_.obj(), |
| 100 ConvertUTF8ToJavaString(env, url_.scheme()).obj(), | 119 ConvertUTF8ToJavaString(env, url_.spec()).obj(), |
| 101 ConvertUTF8ToJavaString(env, url_.host()).obj(), | 120 static_cast<jint>(connection_type), |
| 102 ConvertUTF8ToJavaString(env, url_.path()).obj(), | 121 static_cast<jint>(scheme_end_index), |
| 103 static_cast<jint>(connection_type)); | 122 static_cast<jint>(domain_end_index)); |
| 104 | 123 |
| 105 Java_WebsiteSettingsPopup_setConnectionMessage( | 124 Java_WebsiteSettingsPopup_setConnectionMessage( |
| 106 env, | 125 env, |
| 107 popup_jobject_.obj(), | 126 popup_jobject_.obj(), |
| 108 ConvertUTF16ToJavaString( | 127 ConvertUTF16ToJavaString( |
| 109 env, | 128 env, |
| 110 l10n_util::GetStringUTF16( | 129 l10n_util::GetStringUTF16( |
| 111 WebsiteSettingsUI::GetConnectionSummaryMessageID( | 130 WebsiteSettingsUI::GetConnectionSummaryMessageID( |
| 112 identity_info.connection_status))).obj()); | 131 identity_info.connection_status))).obj()); |
| 113 | 132 |
| 114 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); | 133 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); |
| 115 } | 134 } |
| 116 | 135 |
| 117 void WebsiteSettingsPopupAndroid::SetCookieInfo( | 136 void WebsiteSettingsPopupAndroid::SetCookieInfo( |
| 118 const CookieInfoList& cookie_info_list) { | 137 const CookieInfoList& cookie_info_list) { |
| 119 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
| 120 } | 139 } |
| 121 | 140 |
| 122 void WebsiteSettingsPopupAndroid::SetPermissionInfo( | 141 void WebsiteSettingsPopupAndroid::SetPermissionInfo( |
| 123 const PermissionInfoList& permission_info_list) { | 142 const PermissionInfoList& permission_info_list) { |
| 124 NOTIMPLEMENTED(); | 143 JNIEnv* env = base::android::AttachCurrentThread(); |
| 144 |
| 145 // On Android, we only want to display a subset of the available options in a |
| 146 // particular order, but only if their value is different from the default. |
| 147 std::vector<ContentSettingsType> permissions_to_display; |
| 148 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 149 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
| 150 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 151 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_IMAGES); |
| 152 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 153 permissions_to_display.push_back(CONTENT_SETTINGS_TYPE_POPUPS); |
| 154 |
| 155 std::map<ContentSettingsType, ContentSetting> |
| 156 user_specified_settings_to_display; |
| 157 |
| 158 for (const auto& permission : permission_info_list) { |
| 159 if (std::find(permissions_to_display.begin(), |
| 160 permissions_to_display.end(), |
| 161 permission.type) != permissions_to_display.end() && |
| 162 permission.setting != CONTENT_SETTING_DEFAULT) { |
| 163 user_specified_settings_to_display[permission.type] = permission.setting; |
| 164 } |
| 165 } |
| 166 |
| 167 for (const auto& permission : permissions_to_display) { |
| 168 if (ContainsKey(user_specified_settings_to_display, permission)) { |
| 169 base::string16 setting_title = |
| 170 WebsiteSettingsUI::PermissionTypeToUIString(permission); |
| 171 |
| 172 Java_WebsiteSettingsPopup_addPermissionSection( |
| 173 env, |
| 174 popup_jobject_.obj(), |
| 175 ConvertUTF16ToJavaString(env, setting_title).obj(), |
| 176 static_cast<jint>(permission), |
| 177 static_cast<jint>(user_specified_settings_to_display[permission])); |
| 178 } |
| 179 } |
| 125 } | 180 } |
| 126 | 181 |
| 127 void WebsiteSettingsPopupAndroid::SetSelectedTab( | 182 void WebsiteSettingsPopupAndroid::SetSelectedTab( |
| 128 WebsiteSettingsUI::TabId tab_id) { | 183 WebsiteSettingsUI::TabId tab_id) { |
| 129 // There's no tab UI on Android - only connection info is shown. | 184 // There's no tab UI on Android - only connection info is shown. |
| 130 NOTIMPLEMENTED(); | 185 NOTIMPLEMENTED(); |
| 131 } | 186 } |
| 132 | 187 |
| 133 void WebsiteSettingsPopupAndroid::SetFirstVisit( | 188 void WebsiteSettingsPopupAndroid::SetFirstVisit( |
| 134 const base::string16& first_visit) { | 189 const base::string16& first_visit) { |
| 135 NOTIMPLEMENTED(); | 190 NOTIMPLEMENTED(); |
| 136 } | 191 } |
| 137 | 192 |
| 138 // static | 193 // static |
| 139 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | 194 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( |
| 140 JNIEnv* env) { | 195 JNIEnv* env) { |
| 141 return RegisterNativesImpl(env); | 196 return RegisterNativesImpl(env); |
| 142 } | 197 } |
| OLD | NEW |