| 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" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 NOTREACHED(); | 168 NOTREACHED(); |
| 169 } | 169 } |
| 170 GetHostContentSettingsMap(is_incognito) | 170 GetHostContentSettingsMap(is_incognito) |
| 171 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(url), | 171 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(url), |
| 172 secondary_pattern, content_type, std::string(), | 172 secondary_pattern, content_type, std::string(), |
| 173 setting); | 173 setting); |
| 174 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); | 174 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); |
| 175 } | 175 } |
| 176 | 176 |
| 177 static void GetFullscreenOrigins(JNIEnv* env, | 177 static void GetFullscreenOrigins(JNIEnv* env, |
| 178 jclass clazz, | 178 const JavaParamRef<jclass>& clazz, |
| 179 jobject list, | 179 const JavaParamRef<jobject>& list, |
| 180 jboolean managedOnly) { | 180 jboolean managedOnly) { |
| 181 GetOrigins(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, list, managedOnly); | 181 GetOrigins(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, list, managedOnly); |
| 182 } | 182 } |
| 183 | 183 |
| 184 static jint GetFullscreenSettingForOrigin(JNIEnv* env, | 184 static jint GetFullscreenSettingForOrigin(JNIEnv* env, |
| 185 jclass clazz, | 185 const JavaParamRef<jclass>& clazz, |
| 186 jstring origin, | 186 const JavaParamRef<jstring>& origin, |
| 187 jstring embedder, | 187 const JavaParamRef<jstring>& embedder, |
| 188 jboolean is_incognito) { | 188 jboolean is_incognito) { |
| 189 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, origin, | 189 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, origin, |
| 190 embedder, is_incognito); | 190 embedder, is_incognito); |
| 191 } | 191 } |
| 192 | 192 |
| 193 static void SetFullscreenSettingForOrigin(JNIEnv* env, | 193 static void SetFullscreenSettingForOrigin(JNIEnv* env, |
| 194 jclass clazz, | 194 const JavaParamRef<jclass>& clazz, |
| 195 jstring origin, | 195 const JavaParamRef<jstring>& origin, |
| 196 jstring embedder, | 196 const JavaParamRef<jstring>& embedder, |
| 197 jint value, | 197 jint value, |
| 198 jboolean is_incognito) { | 198 jboolean is_incognito) { |
| 199 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); | 199 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); |
| 200 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, origin, | 200 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_FULLSCREEN, origin, |
| 201 ContentSettingsPattern::FromURLNoWildcard(embedder_url), | 201 ContentSettingsPattern::FromURLNoWildcard(embedder_url), |
| 202 value, is_incognito); | 202 value, is_incognito); |
| 203 } | 203 } |
| 204 | 204 |
| 205 static void GetGeolocationOrigins(JNIEnv* env, | 205 static void GetGeolocationOrigins(JNIEnv* env, |
| 206 jclass clazz, | 206 const JavaParamRef<jclass>& clazz, |
| 207 jobject list, | 207 const JavaParamRef<jobject>& list, |
| 208 jboolean managedOnly) { | 208 jboolean managedOnly) { |
| 209 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly); | 209 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly); |
| 210 } | 210 } |
| 211 | 211 |
| 212 static jint GetGeolocationSettingForOrigin(JNIEnv* env, | 212 static jint GetGeolocationSettingForOrigin( |
| 213 jclass clazz, | 213 JNIEnv* env, |
| 214 jstring origin, | 214 const JavaParamRef<jclass>& clazz, |
| 215 jstring embedder, | 215 const JavaParamRef<jstring>& origin, |
| 216 jboolean is_incognito) { | 216 const JavaParamRef<jstring>& embedder, |
| 217 jboolean is_incognito) { |
| 217 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, origin, | 218 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, origin, |
| 218 embedder, is_incognito); | 219 embedder, is_incognito); |
| 219 } | 220 } |
| 220 | 221 |
| 221 static void SetGeolocationSettingForOrigin(JNIEnv* env, | 222 static void SetGeolocationSettingForOrigin( |
| 222 jclass clazz, | 223 JNIEnv* env, |
| 223 jstring origin, | 224 const JavaParamRef<jclass>& clazz, |
| 224 jstring embedder, | 225 const JavaParamRef<jstring>& origin, |
| 225 jint value, | 226 const JavaParamRef<jstring>& embedder, |
| 226 jboolean is_incognito) { | 227 jint value, |
| 228 jboolean is_incognito) { |
| 227 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); | 229 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); |
| 228 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, origin, | 230 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, origin, |
| 229 ContentSettingsPattern::FromURLNoWildcard(embedder_url), | 231 ContentSettingsPattern::FromURLNoWildcard(embedder_url), |
| 230 value, is_incognito); | 232 value, is_incognito); |
| 231 } | 233 } |
| 232 | 234 |
| 233 static void GetMidiOrigins(JNIEnv* env, jclass clazz, jobject list) { | 235 static void GetMidiOrigins(JNIEnv* env, |
| 236 const JavaParamRef<jclass>& clazz, |
| 237 const JavaParamRef<jobject>& list) { |
| 234 GetOrigins(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, list, false); | 238 GetOrigins(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, list, false); |
| 235 } | 239 } |
| 236 | 240 |
| 237 static jint GetMidiSettingForOrigin(JNIEnv* env, | 241 static jint GetMidiSettingForOrigin(JNIEnv* env, |
| 238 jclass clazz, | 242 const JavaParamRef<jclass>& clazz, |
| 239 jstring origin, | 243 const JavaParamRef<jstring>& origin, |
| 240 jstring embedder, | 244 const JavaParamRef<jstring>& embedder, |
| 241 jboolean is_incognito) { | 245 jboolean is_incognito) { |
| 242 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin, | 246 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin, |
| 243 embedder, is_incognito); | 247 embedder, is_incognito); |
| 244 } | 248 } |
| 245 | 249 |
| 246 static void SetMidiSettingForOrigin(JNIEnv* env, | 250 static void SetMidiSettingForOrigin(JNIEnv* env, |
| 247 jclass clazz, | 251 const JavaParamRef<jclass>& clazz, |
| 248 jstring origin, | 252 const JavaParamRef<jstring>& origin, |
| 249 jstring embedder, | 253 const JavaParamRef<jstring>& embedder, |
| 250 jint value, | 254 jint value, |
| 251 jboolean is_incognito) { | 255 jboolean is_incognito) { |
| 252 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); | 256 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); |
| 253 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin, | 257 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MIDI_SYSEX, origin, |
| 254 ContentSettingsPattern::FromURLNoWildcard(embedder_url), | 258 ContentSettingsPattern::FromURLNoWildcard(embedder_url), |
| 255 value, is_incognito); | 259 value, is_incognito); |
| 256 } | 260 } |
| 257 | 261 |
| 258 static void GetProtectedMediaIdentifierOrigins(JNIEnv* env, jclass clazz, | 262 static void GetProtectedMediaIdentifierOrigins( |
| 259 jobject list) { | 263 JNIEnv* env, |
| 264 const JavaParamRef<jclass>& clazz, |
| 265 const JavaParamRef<jobject>& list) { |
| 260 GetOrigins(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, list, | 266 GetOrigins(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, list, |
| 261 false); | 267 false); |
| 262 } | 268 } |
| 263 | 269 |
| 264 static jint GetProtectedMediaIdentifierSettingForOrigin(JNIEnv* env, | 270 static jint GetProtectedMediaIdentifierSettingForOrigin( |
| 265 jclass clazz, | 271 JNIEnv* env, |
| 266 jstring origin, | 272 const JavaParamRef<jclass>& clazz, |
| 267 jstring embedder, | 273 const JavaParamRef<jstring>& origin, |
| 268 jboolean is_incognito) { | 274 const JavaParamRef<jstring>& embedder, |
| 275 jboolean is_incognito) { |
| 269 return GetSettingForOrigin(env, | 276 return GetSettingForOrigin(env, |
| 270 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, | 277 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, |
| 271 origin, embedder, is_incognito); | 278 origin, embedder, is_incognito); |
| 272 } | 279 } |
| 273 | 280 |
| 274 static void SetProtectedMediaIdentifierSettingForOrigin(JNIEnv* env, | 281 static void SetProtectedMediaIdentifierSettingForOrigin( |
| 275 jclass clazz, | 282 JNIEnv* env, |
| 276 jstring origin, | 283 const JavaParamRef<jclass>& clazz, |
| 277 jstring embedder, | 284 const JavaParamRef<jstring>& origin, |
| 278 jint value, | 285 const JavaParamRef<jstring>& embedder, |
| 279 jboolean is_incognito) { | 286 jint value, |
| 287 jboolean is_incognito) { |
| 280 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); | 288 GURL embedder_url(ConvertJavaStringToUTF8(env, embedder)); |
| 281 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, | 289 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, |
| 282 origin, | 290 origin, |
| 283 ContentSettingsPattern::FromURLNoWildcard(embedder_url), | 291 ContentSettingsPattern::FromURLNoWildcard(embedder_url), |
| 284 value, is_incognito); | 292 value, is_incognito); |
| 285 } | 293 } |
| 286 | 294 |
| 287 static void GetPushNotificationOrigins(JNIEnv* env, | 295 static void GetPushNotificationOrigins(JNIEnv* env, |
| 288 jclass clazz, | 296 const JavaParamRef<jclass>& clazz, |
| 289 jobject list) { | 297 const JavaParamRef<jobject>& list) { |
| 290 GetOrigins(env, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, list, false); | 298 GetOrigins(env, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, list, false); |
| 291 } | 299 } |
| 292 | 300 |
| 293 static jint GetPushNotificationSettingForOrigin(JNIEnv* env, | 301 static jint GetPushNotificationSettingForOrigin( |
| 294 jclass clazz, | 302 JNIEnv* env, |
| 295 jstring origin, | 303 const JavaParamRef<jclass>& clazz, |
| 296 jstring embedder, | 304 const JavaParamRef<jstring>& origin, |
| 297 jboolean is_incognito) { | 305 const JavaParamRef<jstring>& embedder, |
| 306 jboolean is_incognito) { |
| 298 return DesktopNotificationProfileUtil::GetContentSetting( | 307 return DesktopNotificationProfileUtil::GetContentSetting( |
| 299 GetActiveUserProfile(is_incognito), | 308 GetActiveUserProfile(is_incognito), |
| 300 GURL(ConvertJavaStringToUTF8(env, origin))); | 309 GURL(ConvertJavaStringToUTF8(env, origin))); |
| 301 } | 310 } |
| 302 | 311 |
| 303 static void SetPushNotificationSettingForOrigin(JNIEnv* env, | 312 static void SetPushNotificationSettingForOrigin( |
| 304 jclass clazz, | 313 JNIEnv* env, |
| 305 jstring origin, | 314 const JavaParamRef<jclass>& clazz, |
| 306 jstring embedder, | 315 const JavaParamRef<jstring>& origin, |
| 307 jint value, | 316 const JavaParamRef<jstring>& embedder, |
| 308 jboolean is_incognito) { | 317 jint value, |
| 318 jboolean is_incognito) { |
| 309 // TODO(peter): Web Notification permission behaves differently from all other | 319 // TODO(peter): Web Notification permission behaves differently from all other |
| 310 // permission types. See https://crbug.com/416894. | 320 // permission types. See https://crbug.com/416894. |
| 311 Profile* profile = GetActiveUserProfile(is_incognito); | 321 Profile* profile = GetActiveUserProfile(is_incognito); |
| 312 GURL url = GURL(ConvertJavaStringToUTF8(env, origin)); | 322 GURL url = GURL(ConvertJavaStringToUTF8(env, origin)); |
| 313 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 323 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 314 switch (value) { | 324 switch (value) { |
| 315 case -1: | 325 case -1: |
| 316 DesktopNotificationProfileUtil::ClearSetting( | 326 DesktopNotificationProfileUtil::ClearSetting( |
| 317 profile, ContentSettingsPattern::FromURLNoWildcard(url)); | 327 profile, ContentSettingsPattern::FromURLNoWildcard(url)); |
| 318 break; | 328 break; |
| 319 case 1: | 329 case 1: |
| 320 DesktopNotificationProfileUtil::GrantPermission(profile, url); | 330 DesktopNotificationProfileUtil::GrantPermission(profile, url); |
| 321 setting = CONTENT_SETTING_ALLOW; | 331 setting = CONTENT_SETTING_ALLOW; |
| 322 break; | 332 break; |
| 323 case 2: | 333 case 2: |
| 324 DesktopNotificationProfileUtil::DenyPermission(profile, url); | 334 DesktopNotificationProfileUtil::DenyPermission(profile, url); |
| 325 setting = CONTENT_SETTING_BLOCK; | 335 setting = CONTENT_SETTING_BLOCK; |
| 326 break; | 336 break; |
| 327 default: | 337 default: |
| 328 NOTREACHED(); | 338 NOTREACHED(); |
| 329 } | 339 } |
| 330 WebSiteSettingsUmaUtil::LogPermissionChange( | 340 WebSiteSettingsUmaUtil::LogPermissionChange( |
| 331 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 341 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
| 332 } | 342 } |
| 333 | 343 |
| 334 static void GetCameraOrigins(JNIEnv* env, | 344 static void GetCameraOrigins(JNIEnv* env, |
| 335 jclass clazz, | 345 const JavaParamRef<jclass>& clazz, |
| 336 jobject list, | 346 const JavaParamRef<jobject>& list, |
| 337 jboolean managedOnly) { | 347 jboolean managedOnly) { |
| 338 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly); | 348 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly); |
| 339 } | 349 } |
| 340 | 350 |
| 341 static void GetMicrophoneOrigins(JNIEnv* env, | 351 static void GetMicrophoneOrigins(JNIEnv* env, |
| 342 jclass clazz, | 352 const JavaParamRef<jclass>& clazz, |
| 343 jobject list, | 353 const JavaParamRef<jobject>& list, |
| 344 jboolean managedOnly) { | 354 jboolean managedOnly) { |
| 345 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly); | 355 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly); |
| 346 } | 356 } |
| 347 | 357 |
| 348 static jint GetMicrophoneSettingForOrigin(JNIEnv* env, | 358 static jint GetMicrophoneSettingForOrigin(JNIEnv* env, |
| 349 jclass clazz, | 359 const JavaParamRef<jclass>& clazz, |
| 350 jstring origin, | 360 const JavaParamRef<jstring>& origin, |
| 351 jstring embedder, | 361 const JavaParamRef<jstring>& embedder, |
| 352 jboolean is_incognito) { | 362 jboolean is_incognito) { |
| 353 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, origin, | 363 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, origin, |
| 354 embedder, is_incognito); | 364 embedder, is_incognito); |
| 355 } | 365 } |
| 356 | 366 |
| 357 static jint GetCameraSettingForOrigin(JNIEnv* env, | 367 static jint GetCameraSettingForOrigin(JNIEnv* env, |
| 358 jclass clazz, | 368 const JavaParamRef<jclass>& clazz, |
| 359 jstring origin, | 369 const JavaParamRef<jstring>& origin, |
| 360 jstring embedder, | 370 const JavaParamRef<jstring>& embedder, |
| 361 jboolean is_incognito) { | 371 jboolean is_incognito) { |
| 362 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 372 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 363 origin, embedder, is_incognito); | 373 origin, embedder, is_incognito); |
| 364 } | 374 } |
| 365 | 375 |
| 366 static void SetMicrophoneSettingForOrigin(JNIEnv* env, | 376 static void SetMicrophoneSettingForOrigin(JNIEnv* env, |
| 367 jclass clazz, | 377 const JavaParamRef<jclass>& clazz, |
| 368 jstring origin, | 378 const JavaParamRef<jstring>& origin, |
| 369 jstring embedder, | 379 const JavaParamRef<jstring>& embedder, |
| 370 jint value, | 380 jint value, |
| 371 jboolean is_incognito) { | 381 jboolean is_incognito) { |
| 372 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, origin, | 382 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, origin, |
| 373 ContentSettingsPattern::Wildcard(), value, is_incognito); | 383 ContentSettingsPattern::Wildcard(), value, is_incognito); |
| 374 } | 384 } |
| 375 | 385 |
| 376 static void SetCameraSettingForOrigin(JNIEnv* env, | 386 static void SetCameraSettingForOrigin(JNIEnv* env, |
| 377 jclass clazz, | 387 const JavaParamRef<jclass>& clazz, |
| 378 jstring origin, | 388 const JavaParamRef<jstring>& origin, |
| 379 jstring embedder, | 389 const JavaParamRef<jstring>& embedder, |
| 380 jint value, | 390 jint value, |
| 381 jboolean is_incognito) { | 391 jboolean is_incognito) { |
| 382 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, origin, | 392 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, origin, |
| 383 ContentSettingsPattern::Wildcard(), value, is_incognito); | 393 ContentSettingsPattern::Wildcard(), value, is_incognito); |
| 384 } | 394 } |
| 385 | 395 |
| 386 static scoped_refptr<content_settings::CookieSettings> GetCookieSettings() { | 396 static scoped_refptr<content_settings::CookieSettings> GetCookieSettings() { |
| 387 // A single cookie setting applies to both incognito and non-incognito. | 397 // A single cookie setting applies to both incognito and non-incognito. |
| 388 Profile* profile = ProfileManager::GetActiveUserProfile(); | 398 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 389 return CookieSettingsFactory::GetForProfile(profile); | 399 return CookieSettingsFactory::GetForProfile(profile); |
| 390 } | 400 } |
| 391 | 401 |
| 392 static void GetCookieOrigins(JNIEnv* env, | 402 static void GetCookieOrigins(JNIEnv* env, |
| 393 jclass clazz, | 403 const JavaParamRef<jclass>& clazz, |
| 394 jobject list, | 404 const JavaParamRef<jobject>& list, |
| 395 jboolean managedOnly) { | 405 jboolean managedOnly) { |
| 396 ContentSettingsForOneType all_settings; | 406 ContentSettingsForOneType all_settings; |
| 397 GetCookieSettings()->GetCookieSettings(&all_settings); | 407 GetCookieSettings()->GetCookieSettings(&all_settings); |
| 398 const ContentSetting default_setting = | 408 const ContentSetting default_setting = |
| 399 GetCookieSettings()->GetDefaultCookieSetting(nullptr); | 409 GetCookieSettings()->GetDefaultCookieSetting(nullptr); |
| 400 for (const auto& settings_it : all_settings) { | 410 for (const auto& settings_it : all_settings) { |
| 401 if (settings_it.setting == default_setting) | 411 if (settings_it.setting == default_setting) |
| 402 continue; | 412 continue; |
| 403 if (managedOnly && | 413 if (managedOnly && |
| 404 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) != | 414 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) != |
| 405 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) { | 415 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) { |
| 406 continue; | 416 continue; |
| 407 } | 417 } |
| 408 const std::string& origin = settings_it.primary_pattern.ToString(); | 418 const std::string& origin = settings_it.primary_pattern.ToString(); |
| 409 const std::string& embedder = settings_it.secondary_pattern.ToString(); | 419 const std::string& embedder = settings_it.secondary_pattern.ToString(); |
| 410 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin); | 420 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin); |
| 411 ScopedJavaLocalRef<jstring> jembedder; | 421 ScopedJavaLocalRef<jstring> jembedder; |
| 412 if (embedder != origin) | 422 if (embedder != origin) |
| 413 jembedder = ConvertUTF8ToJavaString(env, embedder); | 423 jembedder = ConvertUTF8ToJavaString(env, embedder); |
| 414 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list, | 424 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list, |
| 415 jorigin.obj(), jembedder.obj()); | 425 jorigin.obj(), jembedder.obj()); |
| 416 } | 426 } |
| 417 } | 427 } |
| 418 | 428 |
| 419 static jint GetCookieSettingForOrigin(JNIEnv* env, | 429 static jint GetCookieSettingForOrigin(JNIEnv* env, |
| 420 jclass clazz, | 430 const JavaParamRef<jclass>& clazz, |
| 421 jstring origin, | 431 const JavaParamRef<jstring>& origin, |
| 422 jstring embedder, | 432 const JavaParamRef<jstring>& embedder, |
| 423 jboolean is_incognito) { | 433 jboolean is_incognito) { |
| 424 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin, | 434 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin, |
| 425 embedder, false); | 435 embedder, false); |
| 426 } | 436 } |
| 427 | 437 |
| 428 static void SetCookieSettingForOrigin(JNIEnv* env, | 438 static void SetCookieSettingForOrigin(JNIEnv* env, |
| 429 jclass clazz, | 439 const JavaParamRef<jclass>& clazz, |
| 430 jstring origin, | 440 const JavaParamRef<jstring>& origin, |
| 431 jstring embedder, | 441 const JavaParamRef<jstring>& embedder, |
| 432 jint value, | 442 jint value, |
| 433 jboolean is_incognito) { | 443 jboolean is_incognito) { |
| 434 GURL url(ConvertJavaStringToUTF8(env, origin)); | 444 GURL url(ConvertJavaStringToUTF8(env, origin)); |
| 435 ContentSettingsPattern primary_pattern( | 445 ContentSettingsPattern primary_pattern( |
| 436 ContentSettingsPattern::FromURLNoWildcard(url)); | 446 ContentSettingsPattern::FromURLNoWildcard(url)); |
| 437 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard()); | 447 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard()); |
| 438 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 448 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 439 if (value == -1) { | 449 if (value == -1) { |
| 440 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern); | 450 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern); |
| 441 } else { | 451 } else { |
| 442 setting = value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 452 setting = value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 443 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern, | 453 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern, |
| 444 setting); | 454 setting); |
| 445 } | 455 } |
| 446 WebSiteSettingsUmaUtil::LogPermissionChange( | 456 WebSiteSettingsUmaUtil::LogPermissionChange( |
| 447 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 457 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
| 448 } | 458 } |
| 449 | 459 |
| 450 static jboolean IsContentSettingsPatternValid(JNIEnv* env, jclass clazz, | 460 static jboolean IsContentSettingsPatternValid( |
| 451 jstring pattern) { | 461 JNIEnv* env, |
| 462 const JavaParamRef<jclass>& clazz, |
| 463 const JavaParamRef<jstring>& pattern) { |
| 452 return ContentSettingsPattern::FromString( | 464 return ContentSettingsPattern::FromString( |
| 453 ConvertJavaStringToUTF8(env, pattern)).IsValid(); | 465 ConvertJavaStringToUTF8(env, pattern)).IsValid(); |
| 454 } | 466 } |
| 455 | 467 |
| 456 static jboolean UrlMatchesContentSettingsPattern(JNIEnv* env, | 468 static jboolean UrlMatchesContentSettingsPattern( |
| 457 jclass clazz, | 469 JNIEnv* env, |
| 458 jstring jurl, | 470 const JavaParamRef<jclass>& clazz, |
| 459 jstring jpattern) { | 471 const JavaParamRef<jstring>& jurl, |
| 472 const JavaParamRef<jstring>& jpattern) { |
| 460 ContentSettingsPattern pattern = ContentSettingsPattern::FromString( | 473 ContentSettingsPattern pattern = ContentSettingsPattern::FromString( |
| 461 ConvertJavaStringToUTF8(env, jpattern)); | 474 ConvertJavaStringToUTF8(env, jpattern)); |
| 462 return pattern.Matches(GURL(ConvertJavaStringToUTF8(env, jurl))); | 475 return pattern.Matches(GURL(ConvertJavaStringToUTF8(env, jurl))); |
| 463 } | 476 } |
| 464 | 477 |
| 465 namespace { | 478 namespace { |
| 466 | 479 |
| 467 class SiteDataDeleteHelper : | 480 class SiteDataDeleteHelper : |
| 468 public base::RefCountedThreadSafe<SiteDataDeleteHelper>, | 481 public base::RefCountedThreadSafe<SiteDataDeleteHelper>, |
| 469 public CookiesTreeModel::Observer { | 482 public CookiesTreeModel::Observer { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 // TODO(jknotten): These methods should not be static. Instead we should | 740 // TODO(jknotten): These methods should not be static. Instead we should |
| 728 // expose a class to Java so that the fetch requests can be cancelled, | 741 // expose a class to Java so that the fetch requests can be cancelled, |
| 729 // and manage the lifetimes of the callback (and indirectly the helper | 742 // and manage the lifetimes of the callback (and indirectly the helper |
| 730 // by having a reference to it). | 743 // by having a reference to it). |
| 731 | 744 |
| 732 // The helper methods (StartFetching, DeleteLocalStorageFile, DeleteDatabase) | 745 // The helper methods (StartFetching, DeleteLocalStorageFile, DeleteDatabase) |
| 733 // are asynchronous. A "use after free" error is not possible because the | 746 // are asynchronous. A "use after free" error is not possible because the |
| 734 // helpers keep a reference to themselves for the duration of their tasks, | 747 // helpers keep a reference to themselves for the duration of their tasks, |
| 735 // which includes callback invocation. | 748 // which includes callback invocation. |
| 736 | 749 |
| 737 static void FetchLocalStorageInfo(JNIEnv* env, jclass clazz, | 750 static void FetchLocalStorageInfo(JNIEnv* env, |
| 738 jobject java_callback) { | 751 const JavaParamRef<jclass>& clazz, |
| 752 const JavaParamRef<jobject>& java_callback) { |
| 739 Profile* profile = ProfileManager::GetActiveUserProfile(); | 753 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 740 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( | 754 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( |
| 741 new BrowsingDataLocalStorageHelper(profile)); | 755 new BrowsingDataLocalStorageHelper(profile)); |
| 742 // local_storage_callback will delete itself when it is run. | 756 // local_storage_callback will delete itself when it is run. |
| 743 LocalStorageInfoReadyCallback* local_storage_callback = | 757 LocalStorageInfoReadyCallback* local_storage_callback = |
| 744 new LocalStorageInfoReadyCallback( | 758 new LocalStorageInfoReadyCallback( |
| 745 ScopedJavaLocalRef<jobject>(env, java_callback)); | 759 ScopedJavaLocalRef<jobject>(env, java_callback)); |
| 746 local_storage_helper->StartFetching( | 760 local_storage_helper->StartFetching( |
| 747 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, | 761 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, |
| 748 base::Unretained(local_storage_callback))); | 762 base::Unretained(local_storage_callback))); |
| 749 } | 763 } |
| 750 | 764 |
| 751 static void FetchStorageInfo(JNIEnv* env, jclass clazz, jobject java_callback) { | 765 static void FetchStorageInfo(JNIEnv* env, |
| 766 const JavaParamRef<jclass>& clazz, |
| 767 const JavaParamRef<jobject>& java_callback) { |
| 752 Profile* profile = ProfileManager::GetActiveUserProfile(); | 768 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 753 scoped_refptr<StorageInfoFetcher> storage_info_fetcher(new StorageInfoFetcher( | 769 scoped_refptr<StorageInfoFetcher> storage_info_fetcher(new StorageInfoFetcher( |
| 754 content::BrowserContext::GetDefaultStoragePartition( | 770 content::BrowserContext::GetDefaultStoragePartition( |
| 755 profile)->GetQuotaManager(), | 771 profile)->GetQuotaManager(), |
| 756 ScopedJavaLocalRef<jobject>(env, java_callback))); | 772 ScopedJavaLocalRef<jobject>(env, java_callback))); |
| 757 storage_info_fetcher->Run(); | 773 storage_info_fetcher->Run(); |
| 758 } | 774 } |
| 759 | 775 |
| 760 static void ClearLocalStorageData(JNIEnv* env, jclass clazz, jstring jorigin) { | 776 static void ClearLocalStorageData(JNIEnv* env, |
| 777 const JavaParamRef<jclass>& clazz, |
| 778 const JavaParamRef<jstring>& jorigin) { |
| 761 Profile* profile = ProfileManager::GetActiveUserProfile(); | 779 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 762 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = | 780 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = |
| 763 new BrowsingDataLocalStorageHelper(profile); | 781 new BrowsingDataLocalStorageHelper(profile); |
| 764 GURL origin_url = GURL(ConvertJavaStringToUTF8(env, jorigin)); | 782 GURL origin_url = GURL(ConvertJavaStringToUTF8(env, jorigin)); |
| 765 local_storage_helper->DeleteOrigin(origin_url); | 783 local_storage_helper->DeleteOrigin(origin_url); |
| 766 } | 784 } |
| 767 | 785 |
| 768 static void ClearStorageData(JNIEnv* env, | 786 static void ClearStorageData(JNIEnv* env, |
| 769 jclass clazz, | 787 const JavaParamRef<jclass>& clazz, |
| 770 jstring jhost, | 788 const JavaParamRef<jstring>& jhost, |
| 771 jint type, | 789 jint type, |
| 772 jobject java_callback) { | 790 const JavaParamRef<jobject>& java_callback) { |
| 773 Profile* profile = ProfileManager::GetActiveUserProfile(); | 791 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 774 std::string host = ConvertJavaStringToUTF8(env, jhost); | 792 std::string host = ConvertJavaStringToUTF8(env, jhost); |
| 775 scoped_refptr<StorageDataDeleter> storage_data_deleter(new StorageDataDeleter( | 793 scoped_refptr<StorageDataDeleter> storage_data_deleter(new StorageDataDeleter( |
| 776 content::BrowserContext::GetDefaultStoragePartition( | 794 content::BrowserContext::GetDefaultStoragePartition( |
| 777 profile)->GetQuotaManager(), | 795 profile)->GetQuotaManager(), |
| 778 host, | 796 host, |
| 779 static_cast<storage::StorageType>(type), | 797 static_cast<storage::StorageType>(type), |
| 780 ScopedJavaLocalRef<jobject>(env, java_callback))); | 798 ScopedJavaLocalRef<jobject>(env, java_callback))); |
| 781 storage_data_deleter->Run(); | 799 storage_data_deleter->Run(); |
| 782 } | 800 } |
| 783 | 801 |
| 784 static void ClearCookieData(JNIEnv* env, jclass clazz, jstring jorigin) { | 802 static void ClearCookieData(JNIEnv* env, |
| 803 const JavaParamRef<jclass>& clazz, |
| 804 const JavaParamRef<jstring>& jorigin) { |
| 785 Profile* profile = ProfileManager::GetActiveUserProfile(); | 805 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 786 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 806 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
| 787 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( | 807 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( |
| 788 new SiteDataDeleteHelper(profile, url)); | 808 new SiteDataDeleteHelper(profile, url)); |
| 789 site_data_deleter->Run(); | 809 site_data_deleter->Run(); |
| 790 } | 810 } |
| 791 | 811 |
| 792 // Register native methods | 812 // Register native methods |
| 793 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 813 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
| 794 return RegisterNativesImpl(env); | 814 return RegisterNativesImpl(env); |
| 795 } | 815 } |
| OLD | NEW |