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

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

Issue 1989963003: Set User-Agent and Accept-Language request headers for PWS requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/pref_service_bridge.h" 5 #include "chrome/browser/android/preferences/pref_service_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 env, GetPrefService()->GetString( 1089 env, GetPrefService()->GetString(
1090 prefs::kSupervisedUserSecondCustodianProfileImageURL)); 1090 prefs::kSupervisedUserSecondCustodianProfileImageURL));
1091 } 1091 }
1092 1092
1093 // static 1093 // static
1094 bool PrefServiceBridge::RegisterPrefServiceBridge(JNIEnv* env) { 1094 bool PrefServiceBridge::RegisterPrefServiceBridge(JNIEnv* env) {
1095 return RegisterNativesImpl(env); 1095 return RegisterNativesImpl(env);
1096 } 1096 }
1097 1097
1098 // static 1098 // static
1099 // This logic should be kept in sync with prependToAcceptLanguagesIfNecessary in
1100 // chrome/android/java/src/org/chromium/chrome/browser/
1101 // physicalweb/PwsClientImpl.java
1099 void PrefServiceBridge::PrependToAcceptLanguagesIfNecessary( 1102 void PrefServiceBridge::PrependToAcceptLanguagesIfNecessary(
1100 const std::string& locale, 1103 const std::string& locale,
1101 std::string* accept_languages) { 1104 std::string* accept_languages) {
1102 if (locale.size() != 5u || locale[2] != '_') // not well-formed 1105 if (locale.size() != 5u || locale[2] != '_') // not well-formed
1103 return; 1106 return;
1104 1107
1105 std::string language(locale.substr(0, 2)); 1108 std::string language(locale.substr(0, 2));
1106 std::string region(locale.substr(3, 2)); 1109 std::string region(locale.substr(3, 2));
1107 1110
1108 // Java mostly follows ISO-639-1 and ICU, except for the following three. 1111 // Java mostly follows ISO-639-1 and ICU, except for the following three.
1109 // See documentation on java.util.Locale constructor for more. 1112 // See documentation on java.util.Locale constructor for more.
1110 if (language == "iw") { 1113 if (language == "iw") {
1111 language = "he"; 1114 language = "he";
1112 } else if (language == "ji") { 1115 } else if (language == "ji") {
1113 language = "yi"; 1116 language = "yi";
1114 } else if (language == "in") { 1117 } else if (language == "in") {
1115 language = "id"; 1118 language = "id";
1116 } 1119 }
1117 1120
1118 std::string language_region(language + "-" + region); 1121 std::string language_region(language + "-" + region);
1119 1122
1120 if (accept_languages->find(language_region) == std::string::npos) { 1123 if (accept_languages->find(language_region) == std::string::npos) {
1121 std::vector<std::string> parts; 1124 std::vector<std::string> parts;
1122 parts.push_back(language_region); 1125 parts.push_back(language_region);
1123 // If language is not in the accept languages list, also add language code. 1126 // If language is not in the accept languages list, also add language code.
1127 // This will work with the IDS_ACCEPT_LANGUAGE localized strings bundled
1128 // with Chrome but may fail on arbitrary lists of language tags due to
1129 // differences in case and whitespace.
1124 if (accept_languages->find(language + ",") == std::string::npos && 1130 if (accept_languages->find(language + ",") == std::string::npos &&
1125 !std::equal(language.rbegin(), language.rend(), 1131 !std::equal(language.rbegin(), language.rend(),
1126 accept_languages->rbegin())) { 1132 accept_languages->rbegin())) {
1127 parts.push_back(language); 1133 parts.push_back(language);
1128 } 1134 }
1129 parts.push_back(*accept_languages); 1135 parts.push_back(*accept_languages);
1130 *accept_languages = base::JoinString(parts, ","); 1136 *accept_languages = base::JoinString(parts, ",");
1131 } 1137 }
1132 } 1138 }
1133 1139
1134 // static 1140 // static
1135 std::string PrefServiceBridge::GetAndroidPermissionForContentSetting( 1141 std::string PrefServiceBridge::GetAndroidPermissionForContentSetting(
1136 ContentSettingsType content_type) { 1142 ContentSettingsType content_type) {
1137 JNIEnv* env = AttachCurrentThread(); 1143 JNIEnv* env = AttachCurrentThread();
1138 base::android::ScopedJavaLocalRef<jstring> android_permission = 1144 base::android::ScopedJavaLocalRef<jstring> android_permission =
1139 Java_PrefServiceBridge_getAndroidPermissionForContentSetting( 1145 Java_PrefServiceBridge_getAndroidPermissionForContentSetting(
1140 env, content_type); 1146 env, content_type);
1141 if (android_permission.is_null()) 1147 if (android_permission.is_null())
1142 return std::string(); 1148 return std::string();
1143 1149
1144 return ConvertJavaStringToUTF8(android_permission); 1150 return ConvertJavaStringToUTF8(android_permission);
1145 } 1151 }
1146 1152
1147 static void SetSupervisedUserId(JNIEnv* env, 1153 static void SetSupervisedUserId(JNIEnv* env,
1148 const JavaParamRef<jobject>& obj, 1154 const JavaParamRef<jobject>& obj,
1149 const JavaParamRef<jstring>& pref) { 1155 const JavaParamRef<jstring>& pref) {
1150 GetPrefService()->SetString(prefs::kSupervisedUserId, 1156 GetPrefService()->SetString(prefs::kSupervisedUserId,
1151 ConvertJavaStringToUTF8(env, pref)); 1157 ConvertJavaStringToUTF8(env, pref));
1152 } 1158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698