Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/preferences/pref_service_bridge.h" | |
| 6 | |
| 7 #include <jni.h> | |
| 8 | |
| 9 #include "base/android/build_info.h" | |
| 10 #include "base/android/jni_android.h" | |
| 11 #include "base/android/jni_string.h" | |
| 12 #include "base/android/jni_weak_ref.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/files/file_util.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/prefs/pref_service.h" | |
| 17 #include "base/strings/string_util.h" | |
| 18 #include "base/values.h" | |
| 19 #include "chrome/browser/browser_process.h" | |
| 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | |
| 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
| 22 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 23 #include "chrome/browser/net/prediction_options.h" | |
| 24 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
| 25 #include "chrome/browser/profiles/profile_manager.h" | |
| 26 #include "chrome/browser/translate/chrome_translate_client.h" | |
| 27 #include "chrome/browser/ui/android/android_about_app_info.h" | |
| 28 #include "chrome/common/chrome_version_info.h" | |
| 29 #include "chrome/common/pref_names.h" | |
| 30 #include "chrome/grit/locale_settings.h" | |
| 31 #include "components/content_settings/core/common/content_settings.h" | |
| 32 #include "components/content_settings/core/common/content_settings_pattern.h" | |
| 33 #include "components/password_manager/core/common/password_manager_pref_names.h" | |
| 34 #include "components/translate/core/browser/translate_prefs.h" | |
| 35 #include "components/translate/core/common/translate_pref_names.h" | |
| 36 #include "content/public/browser/browser_thread.h" | |
| 37 #include "content/public/common/user_agent.h" | |
| 38 #include "jni/PrefServiceBridge_jni.h" | |
| 39 #include "ui/base/l10n/l10n_util.h" | |
| 40 | |
| 41 using base::android::AttachCurrentThread; | |
| 42 using base::android::CheckException; | |
| 43 using base::android::ConvertJavaStringToUTF8; | |
| 44 using base::android::ConvertUTF8ToJavaString; | |
| 45 using base::android::ScopedJavaLocalRef; | |
| 46 using content::BrowserThread; | |
| 47 | |
| 48 namespace { | |
| 49 | |
| 50 enum NetworkPredictionOptions { | |
| 51 NETWORK_PREDICTION_ALWAYS, | |
| 52 NETWORK_PREDICTION_WIFI_ONLY, | |
| 53 NETWORK_PREDICTION_NEVER, | |
| 54 }; | |
| 55 | |
| 56 Profile* GetOriginalProfile() { | |
| 57 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); | |
| 58 } | |
| 59 | |
| 60 bool GetBooleanForContentSetting(HostContentSettingsMap* content_settings, | |
| 61 ContentSettingsType type) { | |
| 62 switch (content_settings->GetDefaultContentSetting(type, NULL)) { | |
| 63 case CONTENT_SETTING_BLOCK: | |
| 64 return false; | |
| 65 case CONTENT_SETTING_ALLOW: | |
| 66 return true; | |
| 67 case CONTENT_SETTING_ASK: | |
| 68 default: | |
| 69 return true; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 std::string GetStringForContentSettingsType( | |
| 74 ContentSetting content_setting) { | |
| 75 switch (content_setting) { | |
| 76 case CONTENT_SETTING_BLOCK: | |
| 77 return "block"; | |
| 78 case CONTENT_SETTING_ALLOW: | |
| 79 return "allow"; | |
| 80 case CONTENT_SETTING_ASK: | |
| 81 return "ask"; | |
| 82 case CONTENT_SETTING_SESSION_ONLY: | |
| 83 return "session"; | |
| 84 case CONTENT_SETTING_NUM_SETTINGS: | |
| 85 return "num_settings"; | |
| 86 case CONTENT_SETTING_DEFAULT: | |
| 87 default: | |
| 88 return "default"; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 bool IsContentSettingManaged(HostContentSettingsMap* content_settings, | |
| 93 ContentSettingsType content_settings_type) { | |
| 94 std::string source; | |
| 95 content_settings->GetDefaultContentSetting(content_settings_type, &source); | |
| 96 HostContentSettingsMap::ProviderType provider = | |
| 97 content_settings->GetProviderTypeFromSource(source); | |
| 98 return provider == HostContentSettingsMap::POLICY_PROVIDER; | |
| 99 } | |
| 100 | |
| 101 void ReturnAbsoluteProfilePathValue(std::string path_value) { | |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 103 JNIEnv* env = AttachCurrentThread(); | |
| 104 ScopedJavaLocalRef<jstring> j_path_value = | |
| 105 ConvertUTF8ToJavaString(env, path_value); | |
| 106 Java_PrefServiceBridge_setProfilePathValue(env, j_path_value.obj()); | |
| 107 } | |
| 108 | |
| 109 void GetAbsolutePath(Profile* profile) { | |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 111 if (profile) { | |
| 112 base::FilePath profile_path = profile->GetPath(); | |
| 113 profile_path = base::MakeAbsoluteFilePath(profile_path); | |
| 114 if (!profile_path.empty()) { | |
| 115 BrowserThread::PostTask( | |
| 116 BrowserThread::UI, FROM_HERE, | |
| 117 base::Bind(&ReturnAbsoluteProfilePathValue, profile_path.value())); | |
| 118 } | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace | |
| 123 | |
| 124 PrefService* GetPrefService() { | |
| 125 return GetOriginalProfile()->GetPrefs(); | |
| 126 } | |
| 127 | |
| 128 // ---------------------------------------------------------------------------- | |
| 129 // Native JNI methods | |
| 130 // ---------------------------------------------------------------------------- | |
| 131 | |
| 132 static void EnsureConsistentGeolocationPreferences(Profile* profile) { | |
|
Ted C
2014/10/21 16:57:21
Should this go in the empty namespace above? It's
Yaron
2014/10/21 17:40:14
Done.
| |
| 133 // On Android, we use the kGeolocationEnabled flag to control geolocation on a | |
| 134 // global basis, rather than the default geolocation host content setting, | |
| 135 // which is only used if no previously stored more specific host exception | |
| 136 // cannot be found. | |
| 137 // | |
| 138 // On Android, there is currently no UI to change this default setting, so it | |
| 139 // needs to default to ASK. Additionally, for users that have previously set | |
| 140 // the default to BLOCK, we set the preference to disable geolocation | |
| 141 // globally. | |
| 142 | |
| 143 ContentSetting defaultSetting = profile->GetHostContentSettingsMap()-> | |
| 144 GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, NULL); | |
| 145 | |
| 146 if (defaultSetting == CONTENT_SETTING_ASK) return; | |
|
Ted C
2014/10/21 16:57:21
should be on the next line
Yaron
2014/10/21 17:40:14
Done.
| |
| 147 | |
| 148 profile->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
| 149 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ASK); | |
| 150 | |
| 151 if (defaultSetting == CONTENT_SETTING_BLOCK) { | |
| 152 profile->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 static jboolean GetAcceptCookiesEnabled(JNIEnv* env, jobject obj) { | |
| 157 return GetBooleanForContentSetting( | |
| 158 GetOriginalProfile()->GetHostContentSettingsMap(), | |
| 159 CONTENT_SETTINGS_TYPE_COOKIES); | |
| 160 } | |
| 161 | |
| 162 static jboolean GetAcceptCookiesManaged(JNIEnv* env, jobject obj) { | |
| 163 return IsContentSettingManaged( | |
| 164 GetOriginalProfile()->GetHostContentSettingsMap(), | |
| 165 CONTENT_SETTINGS_TYPE_COOKIES); | |
| 166 } | |
| 167 | |
| 168 static jboolean GetRememberPasswordsEnabled(JNIEnv* env, jobject obj) { | |
| 169 return GetPrefService()->GetBoolean( | |
| 170 password_manager::prefs::kPasswordManagerSavingEnabled); | |
| 171 } | |
| 172 | |
| 173 static jboolean GetRememberPasswordsManaged(JNIEnv* env, jobject obj) { | |
| 174 return GetPrefService()->IsManagedPreference( | |
| 175 password_manager::prefs::kPasswordManagerSavingEnabled); | |
| 176 } | |
| 177 | |
| 178 static jboolean GetDoNotTrackEnabled(JNIEnv* env, jobject obj) { | |
| 179 return GetPrefService()->GetBoolean(prefs::kEnableDoNotTrack); | |
| 180 } | |
| 181 | |
| 182 static jint GetNetworkPredictionOptions(JNIEnv* env, jobject obj) { | |
| 183 return GetPrefService()->GetInteger(prefs::kNetworkPredictionOptions); | |
| 184 } | |
| 185 | |
| 186 static jboolean GetNetworkPredictionManaged(JNIEnv* env, jobject obj) { | |
| 187 return GetPrefService()->IsManagedPreference( | |
| 188 prefs::kNetworkPredictionOptions); | |
| 189 } | |
| 190 | |
| 191 static jboolean GetPasswordEchoEnabled(JNIEnv* env, jobject obj) { | |
| 192 return GetPrefService()->GetBoolean(prefs::kWebKitPasswordEchoEnabled); | |
| 193 } | |
| 194 | |
| 195 static jboolean GetPrintingEnabled(JNIEnv* env, jobject obj) { | |
| 196 return GetPrefService()->IsManagedPreference(prefs::kPrintingEnabled); | |
| 197 } | |
| 198 | |
| 199 static jboolean GetTranslateEnabled(JNIEnv* env, jobject obj) { | |
| 200 return GetPrefService()->GetBoolean(prefs::kEnableTranslate); | |
| 201 } | |
| 202 | |
| 203 static jboolean GetTranslateManaged(JNIEnv* env, jobject obj) { | |
| 204 return GetPrefService()->IsManagedPreference(prefs::kEnableTranslate); | |
| 205 } | |
| 206 | |
| 207 static jboolean GetSearchSuggestEnabled(JNIEnv* env, jobject obj) { | |
| 208 return GetPrefService()->GetBoolean(prefs::kSearchSuggestEnabled); | |
| 209 } | |
| 210 | |
| 211 static jboolean GetSearchSuggestManaged(JNIEnv* env, jobject obj) { | |
| 212 return GetPrefService()->IsManagedPreference(prefs::kSearchSuggestEnabled); | |
| 213 } | |
| 214 | |
| 215 static void EnsureConsistentProtectedMediaIdentifierPreferences( | |
|
Ted C
2014/10/21 16:57:21
same question as the other Ensure method
Yaron
2014/10/21 17:40:14
Done.
| |
| 216 Profile* profile) { | |
| 217 // We use the kProtectedMediaIdentifierEnabled flag to control protected media | |
| 218 // identifier on a global basis. | |
| 219 // | |
| 220 // On Android, there is currently no UI to change this default setting, so it | |
| 221 // needs to default to ASK. Additionally, for users that have previously set | |
| 222 // the default to BLOCK, we set the preference to disable protected media | |
| 223 // identifier globally. | |
| 224 ContentSetting defaultSetting = | |
| 225 profile->GetHostContentSettingsMap()-> | |
| 226 GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, | |
| 227 NULL); | |
| 228 | |
| 229 if (defaultSetting == CONTENT_SETTING_ASK) return; | |
|
Ted C
2014/10/21 16:57:21
return on the next line
Yaron
2014/10/21 17:40:14
Done.
| |
| 230 | |
| 231 profile->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
| 232 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); | |
| 233 | |
| 234 if (defaultSetting == CONTENT_SETTING_BLOCK) { | |
| 235 profile->GetPrefs()->SetBoolean(prefs::kProtectedMediaIdentifierEnabled, | |
| 236 false); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 static jboolean GetProtectedMediaIdentifierEnabled(JNIEnv* env, jobject obj) { | |
| 241 Profile* profile = GetOriginalProfile(); | |
| 242 EnsureConsistentProtectedMediaIdentifierPreferences(profile); | |
| 243 return GetPrefService()->GetBoolean(prefs::kProtectedMediaIdentifierEnabled); | |
| 244 } | |
| 245 | |
| 246 static jboolean GetAllowLocationEnabled(JNIEnv* env, jobject obj) { | |
| 247 Profile* profile = GetOriginalProfile(); | |
| 248 EnsureConsistentGeolocationPreferences(profile); | |
| 249 return GetPrefService()->GetBoolean(prefs::kGeolocationEnabled); | |
| 250 } | |
| 251 | |
| 252 static jboolean GetAllowLocationManaged(JNIEnv* env, jobject obj) { | |
| 253 return IsContentSettingManaged( | |
| 254 GetOriginalProfile()->GetHostContentSettingsMap(), | |
| 255 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
| 256 } | |
| 257 | |
| 258 static jboolean GetResolveNavigationErrorEnabled(JNIEnv* env, jobject obj) { | |
| 259 return GetPrefService()->GetBoolean(prefs::kAlternateErrorPagesEnabled); | |
| 260 } | |
| 261 | |
| 262 static jboolean GetResolveNavigationErrorManaged(JNIEnv* env, jobject obj) { | |
| 263 return GetPrefService()->IsManagedPreference( | |
| 264 prefs::kAlternateErrorPagesEnabled); | |
| 265 } | |
| 266 | |
| 267 static jboolean GetCrashReportManaged(JNIEnv* env, jobject obj) { | |
| 268 return GetPrefService()->IsManagedPreference( | |
| 269 prefs::kCrashReportingEnabled); | |
| 270 } | |
| 271 | |
| 272 static jboolean GetForceSafeSearch(JNIEnv* env, jobject obj) { | |
| 273 return GetPrefService()->GetBoolean(prefs::kForceSafeSearch); | |
| 274 } | |
| 275 | |
| 276 static jint GetDefaultSupervisedUserFilteringBehavior(JNIEnv* env, | |
| 277 jobject obj) { | |
| 278 return GetPrefService()->GetInteger( | |
| 279 prefs::kDefaultSupervisedUserFilteringBehavior); | |
| 280 } | |
| 281 | |
| 282 static jboolean GetIncognitoModeEnabled(JNIEnv* env, jobject obj) { | |
| 283 PrefService* prefs = GetPrefService(); | |
| 284 IncognitoModePrefs::Availability incognito_pref = | |
| 285 IncognitoModePrefs::GetAvailability(prefs); | |
| 286 DCHECK(incognito_pref == IncognitoModePrefs::ENABLED || | |
| 287 incognito_pref == IncognitoModePrefs::DISABLED) << | |
| 288 "Unsupported incognito mode preference: " << incognito_pref; | |
| 289 return incognito_pref != IncognitoModePrefs::DISABLED; | |
| 290 } | |
| 291 | |
| 292 static jboolean GetIncognitoModeManaged(JNIEnv* env, jobject obj) { | |
| 293 return GetPrefService()->IsManagedPreference( | |
| 294 prefs::kIncognitoModeAvailability); | |
| 295 } | |
| 296 | |
| 297 namespace { | |
| 298 | |
| 299 // Redirects a BrowsingDataRemover completion callback back into Java. | |
| 300 class ClearBrowsingDataObserver : public BrowsingDataRemover::Observer { | |
| 301 public: | |
| 302 // |obj| is expected to be the object passed into ClearBrowsingData(); e.g. a | |
| 303 // ChromePreference. | |
| 304 ClearBrowsingDataObserver(JNIEnv* env, jobject obj) | |
| 305 : weak_chrome_native_preferences_(env, obj) { | |
| 306 } | |
| 307 | |
| 308 virtual void OnBrowsingDataRemoverDone() override { | |
| 309 // Just as a BrowsingDataRemover deletes itself when done, we delete ourself | |
| 310 // when done. No need to remove ourself as an observer given the lifetime | |
| 311 // of BrowsingDataRemover. | |
| 312 scoped_ptr<ClearBrowsingDataObserver> auto_delete(this); | |
| 313 | |
| 314 JNIEnv* env = AttachCurrentThread(); | |
| 315 if (weak_chrome_native_preferences_.get(env).is_null()) | |
| 316 return; | |
| 317 | |
| 318 Java_PrefServiceBridge_browsingDataCleared( | |
| 319 env, weak_chrome_native_preferences_.get(env).obj()); | |
| 320 } | |
| 321 | |
| 322 private: | |
| 323 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; | |
| 324 }; | |
| 325 } // namespace | |
| 326 | |
| 327 static void ClearBrowsingData(JNIEnv* env, jobject obj, jboolean history, | |
| 328 jboolean cache, jboolean cookies_and_site_data, jboolean passwords, | |
| 329 jboolean form_data) { | |
| 330 // BrowsingDataRemover deletes itself. | |
| 331 BrowsingDataRemover* browsing_data_remover = | |
| 332 BrowsingDataRemover::CreateForPeriod( | |
| 333 GetOriginalProfile(), | |
| 334 static_cast<BrowsingDataRemover::TimePeriod>( | |
| 335 BrowsingDataRemover::EVERYTHING)); | |
| 336 browsing_data_remover->AddObserver(new ClearBrowsingDataObserver(env, obj)); | |
|
Ted C
2014/10/21 16:57:21
Hmm...it even seems like the dataobserver could ea
Yaron
2014/10/21 17:40:14
Acknowledged.
| |
| 337 | |
| 338 int remove_mask = 0; | |
| 339 if (history) | |
| 340 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | |
| 341 if (cache) | |
| 342 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | |
| 343 if (cookies_and_site_data) { | |
| 344 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | |
| 345 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; | |
| 346 } | |
| 347 if (passwords) | |
| 348 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | |
| 349 if (form_data) | |
| 350 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | |
| 351 browsing_data_remover->Remove(remove_mask, | |
| 352 BrowsingDataHelper::UNPROTECTED_WEB); | |
| 353 } | |
| 354 | |
| 355 static jboolean GetAllowCookiesEnabled(JNIEnv* env, jobject obj) { | |
| 356 HostContentSettingsMap* content_settings = | |
| 357 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 358 return GetBooleanForContentSetting( | |
| 359 content_settings, CONTENT_SETTINGS_TYPE_COOKIES); | |
| 360 } | |
| 361 | |
| 362 static void SetAllowCookiesEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 363 HostContentSettingsMap* host_content_settings_map = | |
| 364 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 365 host_content_settings_map->SetDefaultContentSetting( | |
| 366 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 367 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 368 } | |
| 369 | |
| 370 static void SetRememberPasswordsEnabled(JNIEnv* env, jobject obj, | |
| 371 jboolean allow) { | |
| 372 GetPrefService()->SetBoolean( | |
| 373 password_manager::prefs::kPasswordManagerSavingEnabled, allow); | |
| 374 } | |
| 375 | |
| 376 static void SetProtectedMediaIdentifierEnabled(JNIEnv* env, | |
| 377 jobject obj, | |
| 378 jboolean is_enabled) { | |
| 379 GetPrefService()->SetBoolean(prefs::kProtectedMediaIdentifierEnabled, | |
| 380 is_enabled); | |
| 381 } | |
| 382 | |
| 383 static void SetAllowLocationEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 384 GetPrefService()->SetBoolean(prefs::kGeolocationEnabled, allow); | |
| 385 } | |
| 386 | |
| 387 static void SetCrashReporting(JNIEnv* env, jobject obj, jboolean reporting) { | |
| 388 PrefService* local_state = g_browser_process->local_state(); | |
| 389 local_state->SetBoolean(prefs::kCrashReportingEnabled, reporting); | |
| 390 } | |
| 391 | |
| 392 static jboolean CanPredictNetworkActions(JNIEnv* env, jobject obj) { | |
| 393 return chrome_browser_net::CanPrefetchAndPrerenderUI(GetPrefService()); | |
| 394 } | |
| 395 | |
| 396 static void SetDoNotTrackEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 397 GetPrefService()->SetBoolean(prefs::kEnableDoNotTrack, allow); | |
| 398 } | |
| 399 | |
| 400 static jstring GetSyncLastAccountName(JNIEnv* env, jobject obj) { | |
| 401 return ConvertUTF8ToJavaString( | |
| 402 env, GetPrefService()->GetString(prefs::kGoogleServicesLastUsername)) | |
| 403 .Release(); | |
| 404 } | |
| 405 | |
| 406 static void SetTranslateEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | |
| 407 GetPrefService()->SetBoolean(prefs::kEnableTranslate, enabled); | |
| 408 } | |
| 409 | |
| 410 static void ResetTranslateDefaults(JNIEnv* env, jobject obj) { | |
| 411 scoped_ptr<translate::TranslatePrefs> translate_prefs = | |
| 412 ChromeTranslateClient::CreateTranslatePrefs(GetPrefService()); | |
| 413 translate_prefs->ResetToDefaults(); | |
| 414 } | |
| 415 | |
| 416 static jboolean GetJavaScriptManaged(JNIEnv* env, jobject obj) { | |
| 417 HostContentSettingsMap* content_settings = | |
| 418 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 419 return IsContentSettingManaged( | |
| 420 content_settings, CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
| 421 } | |
| 422 | |
| 423 static void SetJavaScriptEnabled(JNIEnv* env, jobject obj, jboolean enabled) { | |
| 424 GetPrefService()->SetBoolean(prefs::kWebKitJavascriptEnabled, enabled); | |
| 425 } | |
| 426 | |
| 427 static jboolean GetJavaScriptEnabled(JNIEnv* env, jobject obj) { | |
| 428 // The user pref for Javascript is stored in kWebKitJavascriptEnabled for | |
| 429 // historical reasons, but the content setting is where a possibly managed | |
| 430 // value will be enforced. | |
| 431 HostContentSettingsMap* content_settings = | |
| 432 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 433 | |
| 434 jboolean javascript_enabled = GetBooleanForContentSetting( | |
| 435 content_settings, CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
| 436 if (!GetJavaScriptManaged(env, obj)) { | |
| 437 javascript_enabled &= GetPrefService()->GetBoolean( | |
| 438 prefs::kWebKitJavascriptEnabled); | |
| 439 } | |
| 440 return javascript_enabled; | |
| 441 } | |
| 442 | |
| 443 static void SetPasswordEchoEnabled(JNIEnv* env, | |
| 444 jobject obj, | |
| 445 jboolean passwordEchoEnabled) { | |
| 446 GetPrefService()->SetBoolean(prefs::kWebKitPasswordEchoEnabled, | |
| 447 passwordEchoEnabled); | |
| 448 } | |
| 449 | |
| 450 | |
|
Ted C
2014/10/21 16:57:21
remove extra blank line
Yaron
2014/10/21 17:40:14
Done.
| |
| 451 static jboolean GetAllowPopupsEnabled(JNIEnv* env, jobject obj) { | |
| 452 HostContentSettingsMap* content_settings = | |
| 453 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 454 return GetBooleanForContentSetting(content_settings, | |
| 455 CONTENT_SETTINGS_TYPE_POPUPS); | |
| 456 } | |
| 457 | |
| 458 static jboolean GetAllowPopupsManaged(JNIEnv* env, jobject obj) { | |
| 459 HostContentSettingsMap* content_settings = | |
| 460 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 461 return IsContentSettingManaged(content_settings, | |
| 462 CONTENT_SETTINGS_TYPE_POPUPS); | |
| 463 } | |
| 464 | |
| 465 static void SetAllowPopupsEnabled(JNIEnv* env, jobject obj, jboolean allow) { | |
| 466 HostContentSettingsMap* host_content_settings_map = | |
| 467 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 468 host_content_settings_map->SetDefaultContentSetting( | |
| 469 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 470 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 471 } | |
| 472 | |
| 473 static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) { | |
| 474 return GetPrefService()->GetBoolean(prefs::kAutologinEnabled); | |
| 475 } | |
| 476 | |
| 477 static void SetAutologinEnabled(JNIEnv* env, jobject obj, | |
| 478 jboolean autologinEnabled) { | |
| 479 GetPrefService()->SetBoolean(prefs::kAutologinEnabled, autologinEnabled); | |
| 480 } | |
| 481 | |
| 482 static void SetPopupException(JNIEnv* env, jobject obj, jstring pattern, | |
| 483 jboolean allow) { | |
| 484 HostContentSettingsMap* host_content_settings_map = | |
| 485 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 486 host_content_settings_map->SetContentSetting( | |
| 487 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | |
| 488 ContentSettingsPattern::Wildcard(), | |
| 489 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 490 "", | |
| 491 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | |
| 492 } | |
| 493 | |
| 494 static void RemovePopupException(JNIEnv* env, jobject obj, jstring pattern) { | |
| 495 HostContentSettingsMap* host_content_settings_map = | |
| 496 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 497 host_content_settings_map->SetContentSetting( | |
| 498 ContentSettingsPattern::FromString(ConvertJavaStringToUTF8(env, pattern)), | |
| 499 ContentSettingsPattern::Wildcard(), | |
| 500 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 501 "", | |
| 502 CONTENT_SETTING_DEFAULT); | |
| 503 } | |
| 504 | |
| 505 static void GetPopupExceptions(JNIEnv* env, jobject obj, jobject list) { | |
| 506 HostContentSettingsMap* host_content_settings_map = | |
| 507 GetOriginalProfile()->GetHostContentSettingsMap(); | |
| 508 ContentSettingsForOneType entries; | |
| 509 host_content_settings_map->GetSettingsForOneType( | |
| 510 CONTENT_SETTINGS_TYPE_POPUPS, "", &entries); | |
| 511 for (size_t i = 0; i < entries.size(); ++i) { | |
| 512 Java_PrefServiceBridge_insertPopupExceptionToList( | |
| 513 env, list, | |
| 514 ConvertUTF8ToJavaString( | |
| 515 env, entries[i].primary_pattern.ToString()).obj(), | |
| 516 ConvertUTF8ToJavaString( | |
| 517 env, GetStringForContentSettingsType(entries[i].setting)).obj(), | |
| 518 ConvertUTF8ToJavaString(env, entries[i].source).obj()); | |
| 519 } | |
| 520 } | |
| 521 | |
| 522 static void SetSearchSuggestEnabled(JNIEnv* env, jobject obj, | |
| 523 jboolean enabled) { | |
| 524 GetPrefService()->SetBoolean(prefs::kSearchSuggestEnabled, enabled); | |
| 525 } | |
| 526 | |
| 527 static jstring GetContextualSearchPreference(JNIEnv* env, jobject obj) { | |
| 528 return ConvertUTF8ToJavaString( | |
| 529 env, GetPrefService()->GetString(prefs::kContextualSearchEnabled)). | |
| 530 Release(); | |
| 531 } | |
| 532 | |
| 533 static void SetContextualSearchPreference(JNIEnv* env, jobject obj, | |
| 534 jstring pref) { | |
| 535 GetPrefService()->SetString(prefs::kContextualSearchEnabled, | |
| 536 ConvertJavaStringToUTF8(env, pref)); | |
| 537 } | |
| 538 | |
| 539 static void SetNetworkPredictionOptions(JNIEnv* env, jobject obj, int option) { | |
| 540 GetPrefService()->SetInteger(prefs::kNetworkPredictionOptions, option); | |
| 541 } | |
| 542 | |
| 543 static jboolean NetworkPredictionEnabledHasUserSetting(JNIEnv* env, | |
| 544 jobject obj) { | |
| 545 return GetPrefService()->GetUserPrefValue( | |
| 546 prefs::kNetworkPredictionEnabled) != NULL; | |
| 547 } | |
| 548 | |
| 549 static jboolean NetworkPredictionOptionsHasUserSetting(JNIEnv* env, | |
| 550 jobject obj) { | |
| 551 return GetPrefService()->GetUserPrefValue( | |
| 552 prefs::kNetworkPredictionOptions) != NULL; | |
| 553 } | |
| 554 | |
| 555 static jboolean GetNetworkPredictionEnabledUserPrefValue(JNIEnv* env, | |
| 556 jobject obj) { | |
| 557 const base::Value* network_prediction_enabled = | |
| 558 GetPrefService()->GetUserPrefValue(prefs::kNetworkPredictionEnabled); | |
| 559 DCHECK(network_prediction_enabled); | |
| 560 bool value = false; | |
| 561 DCHECK(network_prediction_enabled->GetAsBoolean(&value)); | |
| 562 return value; | |
| 563 } | |
| 564 | |
| 565 static void SetResolveNavigationErrorEnabled(JNIEnv* env, jobject obj, | |
| 566 jboolean enabled) { | |
| 567 GetPrefService()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); | |
| 568 } | |
| 569 | |
| 570 static jboolean GetFirstRunEulaAccepted(JNIEnv* env, jobject obj) { | |
| 571 return g_browser_process->local_state()->GetBoolean(prefs::kEulaAccepted); | |
| 572 } | |
| 573 | |
| 574 static void SetEulaAccepted(JNIEnv* env, jobject obj) { | |
| 575 g_browser_process->local_state()->SetBoolean(prefs::kEulaAccepted, true); | |
| 576 } | |
| 577 | |
| 578 static void ResetAcceptLanguages(JNIEnv* env, | |
| 579 jobject obj, | |
| 580 jstring default_locale) { | |
| 581 std::string accept_languages(l10n_util::GetStringUTF8(IDS_ACCEPT_LANGUAGES)); | |
| 582 std::string locale_string(ConvertJavaStringToUTF8(env, default_locale)); | |
| 583 | |
| 584 PrependToAcceptLanguagesIfNecessary(locale_string, &accept_languages); | |
| 585 GetPrefService()->SetString(prefs::kAcceptLanguages, accept_languages); | |
| 586 } | |
| 587 | |
| 588 void PrependToAcceptLanguagesIfNecessary(std::string locale, | |
|
Ted C
2014/10/21 16:57:21
any reason this isn't in an empty namespace to avo
Yaron
2014/10/21 17:40:14
Acknowledged.
| |
| 589 std::string* accept_languages) { | |
| 590 if (locale.size() != 5u || locale[2] != '_') // not well-formed | |
| 591 return; | |
| 592 | |
| 593 std::string language(locale.substr(0, 2)); | |
| 594 std::string region(locale.substr(3, 2)); | |
| 595 | |
| 596 // Java mostly follows ISO-639-1 and ICU, except for the following three. | |
| 597 // See documentation on java.util.Locale constructor for more. | |
| 598 if (language == "iw") { | |
| 599 language = "he"; | |
| 600 } else if (language == "ji") { | |
| 601 language = "yi"; | |
| 602 } else if (language == "in") { | |
| 603 language = "id"; | |
| 604 } | |
| 605 | |
| 606 std::string language_region(language + "-" + region); | |
| 607 | |
| 608 if (accept_languages->find(language_region) == std::string::npos) { | |
| 609 std::vector<std::string> parts; | |
| 610 parts.push_back(language_region); | |
| 611 // If language is not in the accept languages list, also add language code. | |
| 612 if (accept_languages->find(language + ",") == std::string::npos && | |
| 613 !std::equal(language.rbegin(), language.rend(), | |
| 614 accept_languages->rbegin())) | |
| 615 parts.push_back(language); | |
| 616 parts.push_back(*accept_languages); | |
| 617 *accept_languages = JoinString(parts, ','); | |
| 618 } | |
| 619 } | |
| 620 | |
| 621 // Sends all information about the different versions to Java. | |
| 622 // From browser_about_handler.cc | |
| 623 static jobject GetAboutVersionStrings(JNIEnv* env, jobject obj) { | |
| 624 chrome::VersionInfo version_info; | |
| 625 std::string os_version = version_info.OSType(); | |
| 626 os_version += " " + AndroidAboutAppInfo::GetOsInfo(); | |
| 627 | |
| 628 base::android::BuildInfo* android_build_info = | |
| 629 base::android::BuildInfo::GetInstance(); | |
| 630 std::string application(android_build_info->package_label()); | |
| 631 application.append(" "); | |
| 632 application.append(version_info.Version()); | |
| 633 | |
| 634 // OK to release, returning to Java. | |
| 635 return Java_PrefServiceBridge_createAboutVersionStrings( | |
| 636 env, | |
| 637 ConvertUTF8ToJavaString(env, application).obj(), | |
| 638 ConvertUTF8ToJavaString(env, content::GetWebKitVersion()).obj(), | |
| 639 ConvertUTF8ToJavaString( | |
| 640 env, AndroidAboutAppInfo::GetJavaScriptVersion()).obj(), | |
| 641 ConvertUTF8ToJavaString(env, os_version).obj()).Release(); | |
| 642 } | |
| 643 | |
| 644 static void SetPathValuesForAboutChrome(JNIEnv* env, jobject obj) { | |
| 645 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 646 base::Bind(&GetAbsolutePath, GetOriginalProfile())); | |
| 647 } | |
| 648 | |
| 649 static jstring GetSupervisedUserCustodianName(JNIEnv* env, jobject obj) { | |
| 650 return ConvertUTF8ToJavaString( | |
| 651 env, GetPrefService()->GetString(prefs::kSupervisedUserCustodianName)) | |
| 652 .Release(); | |
| 653 } | |
|
Ted C
2014/10/21 16:57:21
add blank lines between all these methods for cons
Yaron
2014/10/21 17:40:14
Done.
| |
| 654 static jstring GetSupervisedUserCustodianEmail(JNIEnv* env, jobject obj) { | |
| 655 return ConvertUTF8ToJavaString( | |
| 656 env, GetPrefService()->GetString(prefs::kSupervisedUserCustodianEmail)) | |
| 657 .Release(); | |
| 658 } | |
| 659 static jstring GetSupervisedUserCustodianProfileImageURL(JNIEnv* env, | |
| 660 jobject obj) { | |
| 661 return ConvertUTF8ToJavaString( | |
| 662 env, | |
| 663 GetPrefService()->GetString( | |
| 664 prefs::kSupervisedUserCustodianProfileImageURL)).Release(); | |
| 665 } | |
| 666 static jstring GetSupervisedUserSecondCustodianName(JNIEnv* env, jobject obj) { | |
| 667 return ConvertUTF8ToJavaString( | |
| 668 env, | |
| 669 GetPrefService()->GetString(prefs::kSupervisedUserSecondCustodianName)) | |
| 670 .Release(); | |
| 671 } | |
| 672 static jstring GetSupervisedUserSecondCustodianEmail(JNIEnv* env, jobject obj) { | |
| 673 return ConvertUTF8ToJavaString( | |
| 674 env, | |
| 675 GetPrefService()->GetString(prefs::kSupervisedUserSecondCustodianEmail)) | |
| 676 .Release(); | |
| 677 } | |
| 678 static jstring GetSupervisedUserSecondCustodianProfileImageURL(JNIEnv* env, | |
| 679 jobject obj) { | |
| 680 return ConvertUTF8ToJavaString( | |
| 681 env, | |
| 682 GetPrefService()->GetString( | |
| 683 prefs::kSupervisedUserSecondCustodianProfileImageURL)).Release(); | |
| 684 } | |
| 685 | |
| 686 bool RegisterPrefServiceBridge(JNIEnv* env) { | |
| 687 return RegisterNativesImpl(env); | |
| 688 } | |
| OLD | NEW |