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

Side by Side Diff: chrome/browser/android/preferences/website_preference_bridge.cc

Issue 1864163005: Switch Cookie to use ContentSettingException instead of CookieInfo on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one missing comments to be addressed Created 4 years, 7 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
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const JavaParamRef<jclass>& clazz, 399 const JavaParamRef<jclass>& clazz,
400 const JavaParamRef<jstring>& origin, 400 const JavaParamRef<jstring>& origin,
401 jint value, 401 jint value,
402 jboolean is_incognito) { 402 jboolean is_incognito) {
403 // Here 'nullptr' indicates that camera uses wildcard for embedder. 403 // Here 'nullptr' indicates that camera uses wildcard for embedder.
404 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, origin, 404 SetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, origin,
405 nullptr, static_cast<ContentSetting>(value), 405 nullptr, static_cast<ContentSetting>(value),
406 is_incognito); 406 is_incognito);
407 } 407 }
408 408
409 static scoped_refptr<content_settings::CookieSettings> GetCookieSettings() {
410 // A single cookie setting applies to both incognito and non-incognito.
411 Profile* profile = ProfileManager::GetActiveUserProfile();
412 return CookieSettingsFactory::GetForProfile(profile);
413 }
414
415 static void GetCookieOrigins(JNIEnv* env,
416 const JavaParamRef<jclass>& clazz,
417 const JavaParamRef<jobject>& list,
418 jboolean managedOnly) {
419 ContentSettingsForOneType all_settings;
420 GetCookieSettings()->GetCookieSettings(&all_settings);
421 const ContentSetting default_setting =
422 GetCookieSettings()->GetDefaultCookieSetting(nullptr);
423 for (const auto& settings_it : all_settings) {
424 if (settings_it.setting == default_setting)
425 continue;
426 if (managedOnly &&
427 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) !=
428 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) {
429 continue;
430 }
431 const std::string& origin = settings_it.primary_pattern.ToString();
432 const std::string& embedder = settings_it.secondary_pattern.ToString();
433 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin);
434 ScopedJavaLocalRef<jstring> jembedder;
435 if (embedder != origin)
436 jembedder = ConvertUTF8ToJavaString(env, embedder);
437 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list,
438 jorigin.obj(), jembedder.obj());
439 }
440 }
441
442 static jint GetCookieSettingForOrigin(JNIEnv* env,
443 const JavaParamRef<jclass>& clazz,
444 const JavaParamRef<jstring>& origin,
445 const JavaParamRef<jstring>& embedder,
446 jboolean is_incognito) {
447 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin,
448 embedder, false);
449 }
450
451 static void SetCookieSettingForOrigin(JNIEnv* env,
452 const JavaParamRef<jclass>& clazz,
453 const JavaParamRef<jstring>& origin,
454 const JavaParamRef<jstring>& embedder,
455 jint value,
456 jboolean is_incognito) {
457 GURL url(ConvertJavaStringToUTF8(env, origin));
458 ContentSetting setting = static_cast<ContentSetting>(value);
459 if (setting == CONTENT_SETTING_DEFAULT) {
460 GetCookieSettings()->ResetCookieSetting(url);
461 } else {
462 GetCookieSettings()->SetCookieSetting(url, setting);
463 }
464 WebSiteSettingsUmaUtil::LogPermissionChange(CONTENT_SETTINGS_TYPE_COOKIES,
465 setting);
466 }
467
468 static jboolean IsContentSettingsPatternValid( 409 static jboolean IsContentSettingsPatternValid(
469 JNIEnv* env, 410 JNIEnv* env,
470 const JavaParamRef<jclass>& clazz, 411 const JavaParamRef<jclass>& clazz,
471 const JavaParamRef<jstring>& pattern) { 412 const JavaParamRef<jstring>& pattern) {
472 return ContentSettingsPattern::FromString( 413 return ContentSettingsPattern::FromString(
473 ConvertJavaStringToUTF8(env, pattern)).IsValid(); 414 ConvertJavaStringToUTF8(env, pattern)).IsValid();
474 } 415 }
475 416
476 static jboolean UrlMatchesContentSettingsPattern( 417 static jboolean UrlMatchesContentSettingsPattern(
477 JNIEnv* env, 418 JNIEnv* env,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 693 GURL url(ConvertJavaStringToUTF8(env, jorigin));
753 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 694 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
754 new SiteDataDeleteHelper(profile, url)); 695 new SiteDataDeleteHelper(profile, url));
755 site_data_deleter->Run(); 696 site_data_deleter->Run();
756 } 697 }
757 698
758 // Register native methods 699 // Register native methods
759 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 700 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
760 return RegisterNativesImpl(env); 701 return RegisterNativesImpl(env);
761 } 702 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698