Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/preferences/website_preference_bridge.h" | 5 #include "chrome/browser/android/preferences/website_preference_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 16 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 16 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
| 17 #include "chrome/browser/browsing_data/local_data_container.h" | 17 #include "chrome/browser/browsing_data/local_data_container.h" |
| 18 #include "chrome/browser/content_settings/cookie_settings.h" | 18 #include "chrome/browser/content_settings/cookie_settings.h" |
| 19 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 19 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 22 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
| 25 #include "jni/WebsitePreferenceBridge_jni.h" | 25 #include "jni/WebsitePreferenceBridge_jni.h" |
| 26 #include "storage/browser/quota/quota_client.h" | 26 #include "storage/browser/quota/quota_client.h" |
| 27 #include "storage/browser/quota/quota_manager.h" | 27 #include "storage/browser/quota/quota_manager.h" |
| 28 #include "url/url_constants.h" | 28 #include "url/url_constants.h" |
| 29 | 29 |
| 30 using base::android::ConvertJavaStringToUTF8; | 30 using base::android::ConvertJavaStringToUTF8; |
| 31 using base::android::ConvertUTF8ToJavaString; | 31 using base::android::ConvertUTF8ToJavaString; |
| 32 using base::android::JavaRef; | 32 using base::android::JavaRef; |
| 33 using base::android::ScopedJavaGlobalRef; | 33 using base::android::ScopedJavaGlobalRef; |
| 34 using base::android::ScopedJavaLocalRef; | 34 using base::android::ScopedJavaLocalRef; |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 | 36 |
| 37 namespace { | |
| 38 | |
| 39 static void LogPermissionChange(ContentSettingsType type, | |
| 40 ContentSetting setting) { | |
| 41 ContentSettingsTypeHistogram histogram_value = | |
| 42 ContentSettingTypeToHistogramValue(type); | |
| 43 DCHECK_NE(histogram_value, CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID) | |
| 44 << "Invalid content setting type specified."; | |
| 45 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged", | |
| 46 histogram_value, | |
| 47 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES); | |
| 48 | |
| 49 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) { | |
| 50 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Allowed", | |
| 51 histogram_value, | |
| 52 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES); | |
| 53 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) { | |
| 54 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Blocked", | |
| 55 histogram_value, | |
| 56 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES); | |
| 57 } else if (setting == ContentSetting::CONTENT_SETTING_DEFAULT || | |
| 58 setting == ContentSetting::CONTENT_SETTING_ASK) { | |
| 59 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Ask", | |
|
Finnur
2015/02/23 14:15:27
'Ask' is, as I recall, not something we can set fo
Miguel Garcia
2015/02/23 14:35:21
Done.
| |
| 60 histogram_value, | |
| 61 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES); | |
| 62 } else { | |
| 63 NOTREACHED(); | |
| 64 } | |
| 65 } | |
| 66 } // namespace | |
| 67 | |
| 37 static HostContentSettingsMap* GetHostContentSettingsMap() { | 68 static HostContentSettingsMap* GetHostContentSettingsMap() { |
| 38 Profile* profile = ProfileManager::GetActiveUserProfile(); | 69 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 39 return profile->GetHostContentSettingsMap(); | 70 return profile->GetHostContentSettingsMap(); |
| 40 } | 71 } |
| 41 | 72 |
| 42 static void GetOrigins(JNIEnv* env, | 73 static void GetOrigins(JNIEnv* env, |
| 43 ContentSettingsType content_type, | 74 ContentSettingsType content_type, |
| 44 jobject list, | 75 jobject list, |
| 45 jboolean managedOnly) { | 76 jboolean managedOnly) { |
| 46 ContentSettingsForOneType all_settings; | 77 ContentSettingsForOneType all_settings; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 case 2: setting = CONTENT_SETTING_BLOCK; break; | 176 case 2: setting = CONTENT_SETTING_BLOCK; break; |
| 146 default: | 177 default: |
| 147 NOTREACHED(); | 178 NOTREACHED(); |
| 148 } | 179 } |
| 149 GetHostContentSettingsMap()->SetContentSetting( | 180 GetHostContentSettingsMap()->SetContentSetting( |
| 150 ContentSettingsPattern::FromURLNoWildcard(url), | 181 ContentSettingsPattern::FromURLNoWildcard(url), |
| 151 secondary_pattern, | 182 secondary_pattern, |
| 152 content_type, | 183 content_type, |
| 153 std::string(), | 184 std::string(), |
| 154 setting); | 185 setting); |
| 186 LogPermissionChange(content_type, setting); | |
| 155 } | 187 } |
| 156 | 188 |
| 157 static void GetGeolocationOrigins(JNIEnv* env, | 189 static void GetGeolocationOrigins(JNIEnv* env, |
| 158 jclass clazz, | 190 jclass clazz, |
| 159 jobject list, | 191 jobject list, |
| 160 jboolean managedOnly) { | 192 jboolean managedOnly) { |
| 161 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly); | 193 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly); |
| 162 } | 194 } |
| 163 | 195 |
| 164 static jint GetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz, | 196 static jint GetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 ProfileManager::GetActiveUserProfile(), | 254 ProfileManager::GetActiveUserProfile(), |
| 223 GURL(ConvertJavaStringToUTF8(env, origin))); | 255 GURL(ConvertJavaStringToUTF8(env, origin))); |
| 224 } | 256 } |
| 225 | 257 |
| 226 static void SetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz, | 258 static void SetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz, |
| 227 jstring origin, jstring embedder, jint value) { | 259 jstring origin, jstring embedder, jint value) { |
| 228 // TODO(peter): Web Notification permission behaves differently from all other | 260 // TODO(peter): Web Notification permission behaves differently from all other |
| 229 // permission types. See https://crbug.com/416894. | 261 // permission types. See https://crbug.com/416894. |
| 230 Profile* profile = ProfileManager::GetActiveUserProfile(); | 262 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 231 GURL url = GURL(ConvertJavaStringToUTF8(env, origin)); | 263 GURL url = GURL(ConvertJavaStringToUTF8(env, origin)); |
| 232 | 264 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 233 switch (value) { | 265 switch (value) { |
| 234 case -1: | 266 case -1: |
| 235 DesktopNotificationProfileUtil::ClearSetting( | 267 DesktopNotificationProfileUtil::ClearSetting( |
| 236 profile, ContentSettingsPattern::FromURLNoWildcard(url)); | 268 profile, ContentSettingsPattern::FromURLNoWildcard(url)); |
| 237 break; | 269 break; |
| 238 case 1: | 270 case 1: |
| 239 DesktopNotificationProfileUtil::GrantPermission(profile, url); | 271 DesktopNotificationProfileUtil::GrantPermission(profile, url); |
| 272 setting = CONTENT_SETTING_ALLOW; | |
| 240 break; | 273 break; |
| 241 case 2: | 274 case 2: |
| 242 DesktopNotificationProfileUtil::DenyPermission(profile, url); | 275 DesktopNotificationProfileUtil::DenyPermission(profile, url); |
| 276 setting = CONTENT_SETTING_BLOCK; | |
| 243 break; | 277 break; |
| 244 default: | 278 default: |
| 245 NOTREACHED(); | 279 NOTREACHED(); |
| 246 } | 280 } |
| 281 LogPermissionChange(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | |
| 247 } | 282 } |
| 248 | 283 |
| 249 static void GetVoiceAndVideoCaptureOrigins(JNIEnv* env, | 284 static void GetVoiceAndVideoCaptureOrigins(JNIEnv* env, |
| 250 jclass clazz, | 285 jclass clazz, |
| 251 jobject list, | 286 jobject list, |
| 252 jboolean managedOnly) { | 287 jboolean managedOnly) { |
| 253 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly); | 288 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly); |
| 254 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly); | 289 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly); |
| 255 } | 290 } |
| 256 | 291 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 jstring origin, jstring embedder, jint value) { | 355 jstring origin, jstring embedder, jint value) { |
| 321 GURL url(ConvertJavaStringToUTF8(env, origin)); | 356 GURL url(ConvertJavaStringToUTF8(env, origin)); |
| 322 ContentSettingsPattern primary_pattern( | 357 ContentSettingsPattern primary_pattern( |
| 323 ContentSettingsPattern::FromURLNoWildcard(url)); | 358 ContentSettingsPattern::FromURLNoWildcard(url)); |
| 324 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard()); | 359 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard()); |
| 325 if (value == -1) { | 360 if (value == -1) { |
| 326 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern); | 361 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern); |
| 327 } else { | 362 } else { |
| 328 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern, | 363 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern, |
| 329 value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 364 value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 330 } | 365 } |
|
Finnur
2015/02/23 14:15:27
What about adding...
ContentSetting setting =
Miguel Garcia
2015/02/23 14:35:21
Good catch thanks.
On 2015/02/23 14:15:27, Finnur
| |
| 331 } | 366 } |
| 332 | 367 |
| 333 namespace { | 368 namespace { |
| 334 | 369 |
| 335 class SiteDataDeleteHelper : | 370 class SiteDataDeleteHelper : |
| 336 public base::RefCountedThreadSafe<SiteDataDeleteHelper>, | 371 public base::RefCountedThreadSafe<SiteDataDeleteHelper>, |
| 337 public CookiesTreeModel::Observer { | 372 public CookiesTreeModel::Observer { |
| 338 public: | 373 public: |
| 339 SiteDataDeleteHelper(Profile* profile, const GURL& domain) | 374 SiteDataDeleteHelper(Profile* profile, const GURL& domain) |
| 340 : profile_(profile), domain_(domain), ending_batch_processing_(false) { | 375 : profile_(profile), domain_(domain), ending_batch_processing_(false) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 681 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
| 647 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( | 682 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( |
| 648 new SiteDataDeleteHelper(profile, url)); | 683 new SiteDataDeleteHelper(profile, url)); |
| 649 site_data_deleter->Run(); | 684 site_data_deleter->Run(); |
| 650 } | 685 } |
| 651 | 686 |
| 652 // Register native methods | 687 // Register native methods |
| 653 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 688 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
| 654 return RegisterNativesImpl(env); | 689 return RegisterNativesImpl(env); |
| 655 } | 690 } |
| OLD | NEW |