From 6d9c47e8e6d92fc8d99ec31374585e003a84462e Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Tue, 1 Sep 2020 16:01:00 +0200 Subject: [PATCH 1/4] add timezone override patch --- build/bromite_patches_list.txt | 1 + build/patches/Timezone-Override.patch | 1379 +++++++++++++++++++++++++ 2 files changed, 1380 insertions(+) create mode 100644 build/patches/Timezone-Override.patch diff --git a/build/bromite_patches_list.txt b/build/bromite_patches_list.txt index 47487c97..2b6d6a5d 100644 --- a/build/bromite_patches_list.txt +++ b/build/bromite_patches_list.txt @@ -149,3 +149,4 @@ Disable-scroll-to-text-fragment.patch Rollback-dav1d-upgrades-that-break-x86.patch Block-all-connection-requests-with-qjz9zk-in-the-domain-name-or-with-a-trk-scheme.patch Automated-domain-substitution.patch +Timezone-Override.patch diff --git a/build/patches/Timezone-Override.patch b/build/patches/Timezone-Override.patch new file mode 100644 index 00000000..d09e5278 --- /dev/null +++ b/build/patches/Timezone-Override.patch @@ -0,0 +1,1379 @@ +From: root +Date: Tue, 1 Sep 2020 13:42:04 +0000 +Subject: Timezone Override + +--- + .../ChromeSiteSettingsHelpClient.java | 20 ++ + .../browser_ui/site_settings/android/BUILD.gn | 3 + + .../res/layout/time_zone_select_dialog.xml | 18 ++ + ...ezoneoverride_site_settings_preference.xml | 56 +++++ + .../res/xml/single_website_preferences.xml | 2 + + .../res/xml/site_settings_preferences.xml | 4 + + .../java/res/xml/website_preferences.xml | 9 + + .../ContentSettingException.java | 7 +- + .../ContentSettingsResources.java | 29 +++ + .../site_settings/SingleCategorySettings.java | 70 ++++++- + .../site_settings/SingleWebsiteSettings.java | 21 +- + .../site_settings/SiteSettings.java | 2 +- + .../site_settings/SiteSettingsCategory.java | 9 +- + .../site_settings/SiteSettingsHelpClient.java | 7 + + ...imezoneOverrideSiteSettingsPreference.java | 193 ++++++++++++++++++ + .../browser_ui/site_settings/Website.java | 10 + + .../WebsitePermissionsFetcher.java | 4 + + .../WebsitePreferenceBridge.java | 11 + + .../android/website_preference_bridge.cc | 16 ++ + .../strings/android/site_settings.grdp | 35 ++++ + .../browser/content_settings_pref_provider.cc | 17 ++ + .../browser/content_settings_pref_provider.h | 5 + + .../core/browser/content_settings_registry.cc | 13 ++ + .../core/browser/content_settings_utils.cc | 7 + + .../core/browser/host_content_settings_map.cc | 8 + + .../core/browser/host_content_settings_map.h | 3 + + .../core/common/content_settings.cc | 4 +- + .../core/common/content_settings.h | 2 + + .../core/common/content_settings.mojom | 2 + + .../common/content_settings_mojom_traits.cc | 4 +- + .../common/content_settings_mojom_traits.h | 10 + + .../core/common/content_settings_types.h | 3 + + .../core/common/pref_names.cc | 3 + + .../content_settings/core/common/pref_names.h | 2 + + .../renderer/content_settings_agent_impl.cc | 110 ++++++++++ + .../renderer/content_settings_agent_impl.h | 4 + + 36 files changed, 710 insertions(+), 13 deletions(-) + create mode 100755 components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml + create mode 100755 components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml + create mode 100755 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java + +diff --git a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java +--- a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java ++++ b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java +@@ -11,6 +11,12 @@ import org.chromium.chrome.browser.help.HelpAndFeedback; + import org.chromium.chrome.browser.profiles.Profile; + import org.chromium.components.browser_ui.site_settings.SiteSettingsHelpClient; + ++import android.app.Activity; ++import android.content.Context; ++import android.content.Intent; ++import android.net.Uri; ++import android.provider.Browser; ++ + /** + * A SiteSettingsHelpClient instance that provides Chrome-specific help functionality. + */ +@@ -33,4 +39,18 @@ public class ChromeSiteSettingsHelpClient implements SiteSettingsHelpClient { + currentActivity.getString(R.string.help_context_protected_content), + Profile.getLastUsedRegularProfile(), null); + } ++ ++ // bromite #331: Customize Timezone ++ // open github page for explanation about timezone override feature ++ // note: url is hard coded ++ @Override ++ public void launchTimeZoneOverrideHelpAndFeedbackActivity(Activity currentActivity) { ++ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/bromite/bromite/wiki/TimezoneOverride")); ++ // Let Chrome know that this intent is from Chrome, so that it does not close the app when ++ // the user presses 'back' button. ++ intent.putExtra(Browser.EXTRA_APPLICATION_ID, currentActivity.getPackageName()); ++ intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); ++ intent.setPackage(currentActivity.getPackageName()); ++ currentActivity.startActivity(intent); ++ } + } +diff --git a/components/browser_ui/site_settings/android/BUILD.gn b/components/browser_ui/site_settings/android/BUILD.gn +--- a/components/browser_ui/site_settings/android/BUILD.gn ++++ b/components/browser_ui/site_settings/android/BUILD.gn +@@ -74,6 +74,7 @@ android_library("java") { + "java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java", + "java/src/org/chromium/components/browser_ui/site_settings/WebsitePreference.java", + "java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java", ++ "java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java" + ] + annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] + deps = [ +@@ -200,6 +201,8 @@ android_resources("java_resources") { + "java/res/xml/single_website_preferences.xml", + "java/res/xml/site_settings_preferences.xml", + "java/res/xml/website_preferences.xml", ++ "java/res/layout/timezoneoverride_site_settings_preference.xml", ++ "java/res/layout/time_zone_select_dialog.xml", + ] + + deps = [ +diff --git a/components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml b/components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml +new file mode 100755 +--- /dev/null ++++ b/components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml +@@ -0,0 +1,18 @@ ++ ++ ++ ++ ++ ++ ++ +\ No newline at end of file +diff --git a/components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml b/components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml +new file mode 100755 +--- /dev/null ++++ b/components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml +@@ -0,0 +1,56 @@ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +diff --git a/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml b/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml +--- a/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml ++++ b/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml +@@ -53,6 +53,8 @@ + android:key="push_notifications_list" /> + ++ + + ++ ++ + + + ++ ++ ++ ++ + + + ++ ++ + + + 0; + return getString(resource); +@@ -704,6 +725,13 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES) && mRequiresFourStateSetting) { + setting = cookieSettingsExceptionShouldBlock() ? ContentSettingValues.BLOCK + : ContentSettingValues.ALLOW; ++ } else if(mRequiresTriStateSetting) { ++ setting = WebsitePreferenceBridge.getContentSetting(browserContextHandle, mCategory.getContentSettingsType()); ++ if(setting == ContentSettingValues.ALLOW) { ++ setting = ContentSettingValues.BLOCK; ++ } else { ++ setting = ContentSettingValues.ALLOW; ++ } + } else { + setting = (WebsitePreferenceBridge.isCategoryEnabled( + browserContextHandle, mCategory.getContentSettingsType())) +@@ -761,6 +789,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + && !WebsitePreferenceBridge.isCategoryEnabled( + browserContextHandle, ContentSettingsType.AUTOMATIC_DOWNLOADS)) { + exception = true; ++ } else if (mCategory.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE)) { ++ exception = true; + } + if (exception) { + getPreferenceScreen().addPreference(new AddExceptionPreference(getStyledContext(), +@@ -934,7 +964,14 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + TriStateSiteSettingsPreference triStateToggle = + (TriStateSiteSettingsPreference) getPreferenceScreen().findPreference( + TRI_STATE_TOGGLE_KEY); +- return (triStateToggle.getCheckedSetting() == ContentSettingValues.BLOCK); ++ if (triStateToggle != null) ++ return (triStateToggle.getCheckedSetting() == ContentSettingValues.BLOCK); ++ ++ TimezoneOverrideSiteSettingsPreference timeOverrideStatePreference = ++ (TimezoneOverrideSiteSettingsPreference) getPreferenceScreen().findPreference( ++ TIMEOVERRIDE_STATE_TOGGLE_KEY); ++ if (timeOverrideStatePreference != null) ++ return (timeOverrideStatePreference.getCheckedSetting() != ContentSettingValues.ALLOW); + } else if (mRequiresFourStateSetting) { + FourStateCookieSettingsPreference fourStateCookieToggle = + (FourStateCookieSettingsPreference) getPreferenceScreen().findPreference( +@@ -962,6 +999,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + FourStateCookieSettingsPreference fourStateCookieToggle = + (FourStateCookieSettingsPreference) screen.findPreference( + FOUR_STATE_COOKIE_TOGGLE_KEY); ++ TimezoneOverrideSiteSettingsPreference timeOverrideStatePreference = ++ (TimezoneOverrideSiteSettingsPreference) screen.findPreference( ++ TIMEOVERRIDE_STATE_TOGGLE_KEY); + Preference thirdPartyCookies = screen.findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY); + Preference notificationsVibrate = screen.findPreference(NOTIFICATIONS_VIBRATE_TOGGLE_KEY); + Preference notificationsQuietUi = screen.findPreference(NOTIFICATIONS_QUIET_UI_TOGGLE_KEY); +@@ -979,17 +1019,27 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + screen.removePreference(binaryToggle); + screen.removePreference(triStateToggle); + screen.removePreference(fourStateCookieToggle); ++ screen.removePreference(timeOverrideStatePreference); + } else if (mRequiresTriStateSetting) { + screen.removePreference(binaryToggle); + screen.removePreference(fourStateCookieToggle); +- configureTriStateToggle(triStateToggle, contentType); ++ if (contentType == ContentSettingsType.TIMEZONE_OVERRIDE) { ++ screen.removePreference(triStateToggle); ++ configureTimeOverrideStateToggle(timeOverrideStatePreference); ++ } ++ else { ++ screen.removePreference(timeOverrideStatePreference); ++ configureTriStateToggle(triStateToggle, contentType); ++ } + } else if (mRequiresFourStateSetting) { + screen.removePreference(binaryToggle); + screen.removePreference(triStateToggle); ++ screen.removePreference(timeOverrideStatePreference); + configureFourStateCookieToggle(fourStateCookieToggle); + } else { + screen.removePreference(triStateToggle); + screen.removePreference(fourStateCookieToggle); ++ screen.removePreference(timeOverrideStatePreference); + configureBinaryToggle(binaryToggle, contentType); + } + +@@ -1002,6 +1052,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + ContentSettingsFeatureList.IMPROVED_COOKIE_CONTROLS))) { + screen.removePreference(screen.findPreference(COOKIE_INFO_TEXT_KEY)); + } ++ if (!(mCategory.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE))) { ++ screen.removePreference(screen.findPreference(TIMEOVERRIDE_INFO_TEXT)); ++ } + + if (hideSecondaryToggles) { + screen.removePreference(thirdPartyCookies); +@@ -1132,6 +1185,15 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment + triStateToggle.initialize(setting, descriptionIds); + } + ++ private void configureTimeOverrideStateToggle( ++ TimezoneOverrideSiteSettingsPreference timeOverrideStateToggle) { ++ timeOverrideStateToggle.setOnPreferenceChangeListener(this); ++ @ContentSettingValues ++ int setting = WebsitePreferenceBridge.getContentSetting( ++ getSiteSettingsClient().getBrowserContextHandle(), ContentSettingsType.TIMEZONE_OVERRIDE); ++ timeOverrideStateToggle.initialize(setting, getSiteSettingsClient().getBrowserContextHandle()); ++ } ++ + private void configureBinaryToggle(ChromeSwitchPreference binaryToggle, int contentType) { + binaryToggle.setOnPreferenceChangeListener(this); + binaryToggle.setTitle(ContentSettingsResources.getTitle(contentType)); +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java +@@ -94,6 +94,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment + // PermissionInfo.Type.PROTECTED_MEDIA_IDENTIFIER + "sensors_permission_list", // PermissionInfo.Type.SENSORS + "vr_permission_list", // PermissionInfo.Type.VIRTUAL_REALITY ++ "timezone_override_permission_list", // PermissionInfo.Type.TIMEZONE_OVERRIDE + }; + + private static final int REQUEST_CODE_NOTIFICATION_CHANNEL_SETTINGS = 1; +@@ -750,6 +751,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment + setUpPreferenceCommon(preference); + ListPreference listPreference = (ListPreference) preference; + ++ int index = (value == ContentSettingValues.ALLOW ? 0 : 1); + if (getContentSettingsTypeFromPreferenceKey(preference.getKey()) == ContentSettingsType.COOKIES) { + CharSequence[] keys = new String[3]; + CharSequence[] descriptions = new String[3]; +@@ -764,7 +766,23 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment + getString(ContentSettingsResources.getSiteSummary(ContentSettingValues.SESSION_ONLY)); + listPreference.setEntryValues(keys); + listPreference.setEntries(descriptions); +- } else { ++ index = (value == ContentSettingValues.SESSION_ONLY ? 2 : (value == ContentSettingValues.ALLOW ? 0 : 1)); ++ } ++ else if (getContentSettingsTypeFromPreferenceKey(preference.getKey()) == ContentSettingsType.TIMEZONE_OVERRIDE) { ++ CharSequence[] keys = new String[3]; ++ keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); ++ keys[1] = ContentSetting.toString(ContentSettingValues.ASK); ++ keys[2] = ContentSetting.toString(ContentSettingValues.BLOCK); ++ int[] descriptionsId = ContentSettingsResources.getTriStateSettingDescriptionIDs(ContentSettingsType.TIMEZONE_OVERRIDE); ++ CharSequence[] descriptions = new String[3]; ++ descriptions[0] = getString(descriptionsId[0]); ++ descriptions[1] = getString(descriptionsId[1]); ++ descriptions[2] = getString(descriptionsId[2]); ++ listPreference.setEntryValues(keys); ++ listPreference.setEntries(descriptions); ++ index = (value == ContentSettingValues.ASK ? 1 : (value == ContentSettingValues.ALLOW ? 0 : 2)); ++ } ++ else { + CharSequence[] keys = new String[2]; + CharSequence[] descriptions = new String[2]; + keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); +@@ -780,7 +798,6 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment + listPreference.setSummary(isEmbargoed ? getString(R.string.automatically_blocked) : "%s"); + // TODO(crbug.com/735110): Figure out if this is the correct thing to do - here we are + // effectively treating non-ALLOW values as BLOCK. +- int index = (value == ContentSettingValues.SESSION_ONLY ? 2 : (value == ContentSettingValues.ALLOW ? 0 : 1)); + listPreference.setValueIndex(index); + } + +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java +@@ -120,7 +120,7 @@ public class SiteSettings + } else if (Type.SOUND == prefCategory && !checked) { + p.setSummary(ContentSettingsResources.getSoundBlockedListSummary()); + } else if (requiresTriStateSetting) { +- p.setSummary(ContentSettingsResources.getCategorySummary(setting)); ++ p.setSummary(ContentSettingsResources.getCategorySummary(contentType, setting)); + } else { + p.setSummary(ContentSettingsResources.getCategorySummary(contentType, checked)); + } +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java +@@ -42,7 +42,7 @@ public class SiteSettingsCategory { + Type.BACKGROUND_SYNC, Type.BLUETOOTH, Type.BLUETOOTH_SCANNING, Type.CAMERA, + Type.CLIPBOARD, Type.COOKIES, Type.DEVICE_LOCATION, Type.JAVASCRIPT, Type.MICROPHONE, + Type.NFC, Type.NOTIFICATIONS, Type.POPUPS, Type.PROTECTED_MEDIA, Type.SENSORS, +- Type.SOUND, Type.USB, Type.VIRTUAL_REALITY, Type.USE_STORAGE}) ++ Type.SOUND, Type.USB, Type.VIRTUAL_REALITY, Type.USE_STORAGE, Type.TIMEZONE_OVERRIDE}) + @Retention(RetentionPolicy.SOURCE) + public @interface Type { + // Values used to address array index - should be enumerated from 0 and can't have gaps. +@@ -70,10 +70,11 @@ public class SiteSettingsCategory { + int BLUETOOTH = 19; + int VIRTUAL_REALITY = 20; + int USE_STORAGE = 21; // Always last as it should appear in the UI at the bottom. ++ int TIMEZONE_OVERRIDE = 22; + /** + * Number of handled categories used for calculating array sizes. + */ +- int NUM_ENTRIES = 22; ++ int NUM_ENTRIES = 23; + } + + private final BrowserContextHandle mBrowserContextHandle; +@@ -189,6 +190,8 @@ public class SiteSettingsCategory { + return ContentSettingsType.USB_GUARD; + case Type.VIRTUAL_REALITY: + return ContentSettingsType.VR; ++ case Type.TIMEZONE_OVERRIDE: ++ return ContentSettingsType.TIMEZONE_OVERRIDE; + // case Type.ALL_SITES + // case Type.USE_STORAGE + default: +@@ -260,6 +263,8 @@ public class SiteSettingsCategory { + return "use_storage"; + case Type.VIRTUAL_REALITY: + return "virtual_reality"; ++ case Type.TIMEZONE_OVERRIDE: ++ return "timezone_override"; + default: + assert false; + return ""; +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsHelpClient.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsHelpClient.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsHelpClient.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsHelpClient.java +@@ -28,4 +28,11 @@ public interface SiteSettingsHelpClient { + * @see org.chromium.chrome.browser.help.HelpAndFeedback#show + */ + void launchProtectedContentHelpAndFeedbackActivity(Activity currentActivity); ++ ++ /** ++ * Launches a support page related to timezone override content. ++ * ++ * @see org.chromium.chrome.browser.help.HelpAndFeedback#show ++ */ ++ void launchTimeZoneOverrideHelpAndFeedbackActivity(Activity currentActivity); + } +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java +new file mode 100755 +--- /dev/null ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java +@@ -0,0 +1,193 @@ ++// Copyright 2018 The Chromium Authors. All rights reserved. ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++package org.chromium.components.browser_ui.site_settings; ++ ++import org.chromium.base.Log; ++import android.content.Context; ++import android.content.Intent; ++import android.content.DialogInterface; ++import android.view.View; ++import android.widget.RadioGroup; ++import android.widget.Button; ++import android.widget.TextView; ++import android.util.AttributeSet; ++import android.widget.ArrayAdapter; ++import android.widget.ListView; ++import android.view.LayoutInflater; ++import android.widget.AdapterView; ++import android.graphics.Color; ++ ++import androidx.preference.Preference; ++import androidx.preference.PreferenceViewHolder; ++import androidx.appcompat.app.AlertDialog; ++ ++import org.chromium.components.content_settings.ContentSettingValues; ++import org.chromium.components.embedder_support.browser_context.BrowserContextHandle; ++import org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridge; ++import org.chromium.components.browser_ui.widget.RadioButtonWithDescription; ++import org.chromium.components.browser_ui.widget.RadioButtonWithEditText; ++import org.chromium.components.browser_ui.widget.TintedDrawable; ++ ++import java.util.ArrayList; ++import java.util.Arrays; ++import java.util.TimeZone; ++ ++/** ++ * TimezoneOverride Preference for SiteSettings. ++ */ ++public class TimezoneOverrideSiteSettingsPreference ++ extends Preference implements RadioGroup.OnCheckedChangeListener, ++ RadioButtonWithEditText.OnTextChangeListener { ++ private @ContentSettingValues int mSetting = ContentSettingValues.DEFAULT; ++ private RadioButtonWithDescription mAllowed; ++ private RadioButtonWithEditText mAsk; ++ private RadioButtonWithDescription mBlocked; ++ private RadioGroup mRadioGroup; ++ private TextView mSelectButton; ++ ++ private String currentSelected; ++ ++ private BrowserContextHandle mBrowserContextHandle; ++ ++ // reference for translation ++ // 4746227879892920228 "Allow sites to use System Timezone" ++ // 8984679974863410689 "SELECT TIMEZONE FROM LIST" ++ // 3394263620263751240 "bla bla bla" ++ // 5477585238714637279 "Select Timezone" ++ // 6450629284808068080 "Use custom timezone" ++ // 1774419748905152303 "Random Value" ++ // 6315329332061924002 "Default UTC" ++ // 7790128239055164249 "Timezone override" ++ // 2520215895798545849 "Use System Timezone" ++ // 7337126996643069922 "Use random timezone for each page" ++ // remember, hash change if you change default text (not key!) ++ ++ public TimezoneOverrideSiteSettingsPreference(Context context, AttributeSet attrs) { ++ super(context, attrs); ++ ++ setLayoutResource(R.layout.timezoneoverride_site_settings_preference); ++ setSelectable(false); ++ } ++ ++ public void initialize(@ContentSettingValues int setting, BrowserContextHandle browserContextHandle) { ++ mSetting = setting; ++ mBrowserContextHandle = browserContextHandle; ++ } ++ ++ public @ContentSettingValues int getCheckedSetting() { ++ return mSetting; ++ } ++ ++ @Override ++ public void onCheckedChanged(RadioGroup group, int checkedId) { ++ if (mAllowed.isChecked()) { ++ mSetting = ContentSettingValues.ALLOW; ++ } else if (mAsk.isChecked()) { ++ mSetting = ContentSettingValues.ASK; ++ } else if (mBlocked.isChecked()) { ++ mSetting = ContentSettingValues.BLOCK; ++ } ++ ++ callChangeListener(mSetting); ++ } ++ ++ @Override ++ public void onBindViewHolder(PreferenceViewHolder holder) { ++ super.onBindViewHolder(holder); ++ ++ mAllowed = (RadioButtonWithDescription) holder.findViewById(R.id.allowed); ++ mAsk = (RadioButtonWithEditText) holder.findViewById(R.id.ask); ++ mBlocked = (RadioButtonWithDescription) holder.findViewById(R.id.blocked); ++ mRadioGroup = (RadioGroup) holder.findViewById(R.id.radio_button_layout); ++ mRadioGroup.setOnCheckedChangeListener(this); ++ ++ mAsk.setPrimaryText(WebsitePreferenceBridge.getCustomTimezone(mBrowserContextHandle)); ++ mAsk.addTextChangeListener(this); ++ ++ ListView listView = (ListView)holder.findViewById(R.id.listView); ++ ++ mSelectButton = (TextView) holder.findViewById(R.id.select_button); ++ mSelectButton.setOnClickListener(view -> { ++ showSelectTimeZoneDialog(); ++ }); ++ ++ RadioButtonWithDescription radioButton = findRadioButton(mSetting); ++ if (radioButton != null) radioButton.setChecked(true); ++ } ++ ++ private RadioButtonWithDescription findRadioButton(@ContentSettingValues int setting) { ++ if (setting == ContentSettingValues.ALLOW) { ++ return mAllowed; ++ } else if (setting == ContentSettingValues.ASK) { ++ return mAsk; ++ } else if (setting == ContentSettingValues.BLOCK) { ++ return mBlocked; ++ } else { ++ return null; ++ } ++ } ++ ++ public void onTextChanged(CharSequence newText) { ++ WebsitePreferenceBridge.setCustomTimezone(mBrowserContextHandle, newText.toString()); ++ } ++ ++ private void showSelectTimeZoneDialog() { ++ LayoutInflater inflater = ++ (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); ++ View view = inflater.inflate(R.layout.time_zone_select_dialog, null); ++ ++ ListView listView = view.findViewById(R.id.listView); ++ ArrayList timezones = new ArrayList<>(Arrays.asList(TimeZone.getAvailableIDs())); ++ ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, android.R.id.text1, timezones); ++ listView.setAdapter(adapter); ++ ++ currentSelected = String.valueOf(mAsk.getPrimaryText()); ++ listView.post(new Runnable() ++ { ++ public void run() ++ { ++ for (int j = 0; j < timezones.size(); j++) { ++ if(currentSelected.equals(timezones.get(j))) { ++ listView.requestFocusFromTouch(); ++ listView.setSelection(j); ++ adapter.notifyDataSetChanged(); ++ break; ++ } ++ } ++ } ++ }); ++ ++ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { ++ @Override ++ public void onItemClick(AdapterView adapterView, View view, int i, long l) { ++ currentSelected = timezones.get(i); ++ listView.setSelected(true); ++ } ++ }); ++ ++ DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { ++ @Override ++ public void onClick(DialogInterface dialog, int button) { ++ if (button == AlertDialog.BUTTON_POSITIVE) { ++ mAsk.setPrimaryText(currentSelected); ++ } else { ++ dialog.dismiss(); ++ } ++ } ++ }; ++ ++ AlertDialog.Builder alert = ++ new AlertDialog.Builder(getContext(), R.style.Theme_Chromium_AlertDialog); ++ AlertDialog alertDialog = ++ alert.setTitle(R.string.website_settings_select_dialog_title) ++ .setView(view) ++ .setPositiveButton( ++ R.string.website_settings_select_dialog_button, onClickListener) ++ .setNegativeButton(R.string.cancel, onClickListener) ++ .create(); ++ alertDialog.getDelegate().setHandleNativeActionModesEnabled(false); ++ alertDialog.show(); ++ } ++} +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java +@@ -252,6 +252,16 @@ public class Website implements Serializable { + } else { + RecordUserAction.record("SoundContentSetting.UnmuteBy.SiteSettings"); + } ++ } else if (type == ContentSettingException.Type.TIMEZONE_OVERRIDE) { ++ // It is possible to set the permission without having an existing exception, ++ // because we can show the ALLOW state even when this permission is set to the ++ // default. In that case, just set an exception now to ALLOW to enable changing the ++ // permission. ++ if (mContentSettingException[type] == null) { ++ mContentSettingException[type] = ++ new ContentSettingException(ContentSettingsType.TIMEZONE_OVERRIDE, ++ getAddress().getOrigin(), value, ""); ++ } + } + // We want to call setContentSetting even after explicitly setting + // mContentSettingException above because this will trigger the actual change +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java +@@ -163,6 +163,8 @@ public class WebsitePermissionsFetcher { + // AR permission is per-origin and per-embedder. + queue.add(new PermissionInfoFetcher(PermissionInfo.Type.AUGMENTED_REALITY)); + ++ queue.add(new ExceptionInfoFetcher(ContentSettingsType.TIMEZONE_OVERRIDE)); ++ + queue.add(new PermissionsAvailableCallbackRunner(callback)); + + queue.next(); +@@ -257,6 +259,8 @@ public class WebsitePermissionsFetcher { + } else if (category.showSites(SiteSettingsCategory.Type.AUGMENTED_REALITY)) { + // AUGMENTED_REALITY permission is per-origin and per-embedder. + queue.add(new PermissionInfoFetcher(PermissionInfo.Type.AUGMENTED_REALITY)); ++ } else if (category.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE)) { ++ queue.add(new ExceptionInfoFetcher(ContentSettingsType.TIMEZONE_OVERRIDE)); + } + queue.add(new PermissionsAvailableCallbackRunner(callback)); + queue.next(); +diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java +--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java ++++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java +@@ -333,6 +333,8 @@ public class WebsitePreferenceBridge { + switch (contentSettingsType) { + case ContentSettingsType.PROTECTED_MEDIA_IDENTIFIER: + return true; ++ case ContentSettingsType.TIMEZONE_OVERRIDE: ++ return true; + default: + return false; + } +@@ -599,6 +601,13 @@ public class WebsitePreferenceBridge { + contentSettingType, primaryPattern, secondaryPattern, setting); + } + ++ public static String getCustomTimezone(BrowserContextHandle browserContextHandle) { ++ return WebsitePreferenceBridgeJni.get().getCustomTimezone(browserContextHandle); ++ } ++ public static void setCustomTimezone(BrowserContextHandle browserContextHandle, String timezone) { ++ WebsitePreferenceBridgeJni.get().setCustomTimezone(browserContextHandle, timezone); ++ } ++ + @VisibleForTesting + @NativeMethods + public interface Natives { +@@ -734,5 +743,7 @@ public class WebsitePreferenceBridge { + void setSensorsEnabled(BrowserContextHandle browserContextHandle, boolean enabled); + void setSoundEnabled(BrowserContextHandle browserContextHandle, boolean enabled); + void setVrEnabled(BrowserContextHandle browserContextHandle, boolean enabled); ++ String getCustomTimezone(BrowserContextHandle browserContextHandle); ++ void setCustomTimezone(BrowserContextHandle browserContextHandle, String timezone); + } + } +diff --git a/components/browser_ui/site_settings/android/website_preference_bridge.cc b/components/browser_ui/site_settings/android/website_preference_bridge.cc +--- a/components/browser_ui/site_settings/android/website_preference_bridge.cc ++++ b/components/browser_ui/site_settings/android/website_preference_bridge.cc +@@ -1428,3 +1428,19 @@ static jboolean JNI_WebsitePreferenceBridge_GetMicManagedByCustodian( + return IsContentSettingManagedByCustodian( + jbrowser_context_handle, ContentSettingsType::MEDIASTREAM_MIC); + } ++ ++static void JNI_WebsitePreferenceBridge_SetCustomTimezone( ++ JNIEnv* env, ++ const JavaParamRef& jbrowser_context_handle, ++ const JavaParamRef& timezone) { ++ std::string new_timezone = ConvertJavaStringToUTF8(env, timezone); ++ GetHostContentSettingsMap(jbrowser_context_handle)->SetTimezoneOverrideValue(new_timezone); ++} ++ ++static base::android::ScopedJavaLocalRef JNI_WebsitePreferenceBridge_GetCustomTimezone( ++ JNIEnv* env, ++ const JavaParamRef& jbrowser_context_handle) { ++ std::string timezone; ++ GetHostContentSettingsMap(jbrowser_context_handle)->GetTimezoneOverrideValue(timezone); ++ return ConvertUTF8ToJavaString(env, timezone); ++} +diff --git a/components/browser_ui/strings/android/site_settings.grdp b/components/browser_ui/strings/android/site_settings.grdp +--- a/components/browser_ui/strings/android/site_settings.grdp ++++ b/components/browser_ui/strings/android/site_settings.grdp +@@ -66,6 +66,9 @@ + + Virtual reality + ++ ++ Timezone override ++ + + + +@@ -468,6 +471,38 @@ + Block sites from playing protected content + + ++ ++ ++ bla bla bla ++ ++ ++ Use System Timezone ++ ++ ++ Random Value ++ ++ ++ Allow sites to use System Timezone ++ ++ ++ Use custom timezone ++ ++ ++ Default UTC ++ ++ ++ Use random timezone for each page ++ ++ ++ SELECT TIMEZONE FROM LIST ++ ++ ++ Select Timezone ++ ++ ++ Select ++ ++ + + + +diff --git a/components/content_settings/core/browser/content_settings_pref_provider.cc b/components/content_settings/core/browser/content_settings_pref_provider.cc +--- a/components/content_settings/core/browser/content_settings_pref_provider.cc ++++ b/components/content_settings/core/browser/content_settings_pref_provider.cc +@@ -85,6 +85,9 @@ void PrefProvider::RegisterProfilePrefs( + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); + #endif // !defined(OS_ANDROID) + #endif // !defined(OS_IOS) ++ ++ // Bromite #331: Custom Timezone ++ registry->RegisterStringPref(prefs::kContentSettingsCustomTimezone, std::string()); + } + + PrefProvider::PrefProvider(PrefService* prefs, +@@ -148,6 +151,10 @@ PrefProvider::PrefProvider(PrefService* prefs, + num_exceptions); + } + ++ custom_timezone_ = ++ prefs_->GetString( ++ prefs::kContentSettingsCustomTimezone); ++ + TRACE_EVENT_END1("startup", "PrefProvider::PrefProvider", + "NumberOfExceptions", num_exceptions); + } +@@ -287,4 +294,14 @@ void PrefProvider::SetClockForTesting(base::Clock* clock) { + clock_ = clock; + } + ++void PrefProvider::GetPrefTimezoneOverrideValue(std::string& timezone) const { ++ timezone = custom_timezone_; ++} ++ ++void PrefProvider::SetPrefTimezoneOverrideValue(const std::string& timezone) { ++ prefs_->SetString( ++ prefs::kContentSettingsCustomTimezone, timezone); ++ custom_timezone_ = timezone; ++} ++ + } // namespace content_settings +diff --git a/components/content_settings/core/browser/content_settings_pref_provider.h b/components/content_settings/core/browser/content_settings_pref_provider.h +--- a/components/content_settings/core/browser/content_settings_pref_provider.h ++++ b/components/content_settings/core/browser/content_settings_pref_provider.h +@@ -66,6 +66,9 @@ class PrefProvider : public UserModifiableProvider { + + ContentSettingsPref* GetPref(ContentSettingsType type) const; + ++ void GetPrefTimezoneOverrideValue(std::string& timezone) const; ++ void SetPrefTimezoneOverrideValue(const std::string& timezone); ++ + private: + friend class DeadlockCheckerObserver; // For testing. + +@@ -103,6 +106,8 @@ class PrefProvider : public UserModifiableProvider { + + base::Clock* clock_; + ++ std::string custom_timezone_; ++ + DISALLOW_COPY_AND_ASSIGN(PrefProvider); + }; + +diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc +--- a/components/content_settings/core/browser/content_settings_registry.cc ++++ b/components/content_settings/core/browser/content_settings_registry.cc +@@ -590,6 +590,19 @@ void ContentSettingsRegistry::Init() { + ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE, + ContentSettingsInfo::PERSISTENT, + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); ++ ++ // bromite #331: Customize Timezone ++ Register(ContentSettingsType::TIMEZONE_OVERRIDE, "timezone-override", CONTENT_SETTING_ALLOW, ++ WebsiteSettingsInfo::SYNCABLE, ++ WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme), ++ ValidSettings(CONTENT_SETTING_ALLOW, // use system time ++ CONTENT_SETTING_ASK, // utc ++ CONTENT_SETTING_BLOCK), // random ++ WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE, ++ WebsiteSettingsRegistry::ALL_PLATFORMS, // MAY BE PLATFORM_ANDROID ++ ContentSettingsInfo::INHERIT_IN_INCOGNITO, ++ ContentSettingsInfo::PERSISTENT, ++ ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); + } + + void ContentSettingsRegistry::Register( +diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc +--- a/components/content_settings/core/browser/content_settings_utils.cc ++++ b/components/content_settings/core/browser/content_settings_utils.cc +@@ -148,6 +148,13 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map, + &(rules->client_hints_rules)); + map->GetSettingsForOneType(ContentSettingsType::POPUPS, ResourceIdentifier(), + &(rules->popup_redirect_rules)); ++ // bromite #331: Customize Timezone ++ // pass value to render process ++ map->GetSettingsForOneType(ContentSettingsType::TIMEZONE_OVERRIDE, ++ ResourceIdentifier(), &(rules->timezone_override_rules)); ++ std::string timezone; ++ map->GetTimezoneOverrideValue(timezone); ++ rules->timezone_override_value = timezone; + } + + bool IsMorePermissive(ContentSetting a, ContentSetting b) { +diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc +--- a/components/content_settings/core/browser/host_content_settings_map.cc ++++ b/components/content_settings/core/browser/host_content_settings_map.cc +@@ -663,6 +663,14 @@ void HostContentSettingsMap::SetClockForTesting(base::Clock* clock) { + provider->SetClockForTesting(clock); + } + ++void HostContentSettingsMap::GetTimezoneOverrideValue(std::string& timezone) const { ++ GetPrefProvider()->GetPrefTimezoneOverrideValue(timezone); ++} ++ ++void HostContentSettingsMap::SetTimezoneOverrideValue(const std::string& timezone) { ++ GetPrefProvider()->SetPrefTimezoneOverrideValue(timezone); ++} ++ + void HostContentSettingsMap::RecordExceptionMetrics() { + auto* content_setting_registry = + content_settings::ContentSettingsRegistry::GetInstance(); +diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h +--- a/components/content_settings/core/browser/host_content_settings_map.h ++++ b/components/content_settings/core/browser/host_content_settings_map.h +@@ -336,6 +336,9 @@ class HostContentSettingsMap : public content_settings::Observer, + return pref_provider_; + } + ++ void GetTimezoneOverrideValue(std::string& timezone) const; ++ void SetTimezoneOverrideValue(const std::string& timezone); ++ + private: + friend class base::RefCountedThreadSafe; + friend class content_settings::TestUtils; +diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc +--- a/components/content_settings/core/common/content_settings.cc ++++ b/components/content_settings/core/common/content_settings.cc +@@ -90,6 +90,7 @@ constexpr HistogramValue kHistogramValue[] = { + {ContentSettingsType::STORAGE_ACCESS, 67}, + {ContentSettingsType::CAMERA_PAN_TILT_ZOOM, 68}, + {ContentSettingsType::WINDOW_PLACEMENT, 69}, ++ {ContentSettingsType::TIMEZONE_OVERRIDE, 70}, // bromite #331: Customize Timezone + }; + + } // namespace +@@ -176,7 +177,8 @@ bool RendererContentSettingRules::IsRendererContentSetting( + content_type == ContentSettingsType::JAVASCRIPT || + content_type == ContentSettingsType::CLIENT_HINTS || + content_type == ContentSettingsType::POPUPS || +- content_type == ContentSettingsType::MIXEDSCRIPT; ++ content_type == ContentSettingsType::MIXEDSCRIPT || ++ content_type == ContentSettingsType::TIMEZONE_OVERRIDE; // bromite #331: Customize Timezone + } + + RendererContentSettingRules::RendererContentSettingRules() {} +diff --git a/components/content_settings/core/common/content_settings.h b/components/content_settings/core/common/content_settings.h +--- a/components/content_settings/core/common/content_settings.h ++++ b/components/content_settings/core/common/content_settings.h +@@ -79,6 +79,8 @@ struct RendererContentSettingRules { + ContentSettingsForOneType client_hints_rules; + ContentSettingsForOneType popup_redirect_rules; + ContentSettingsForOneType mixed_content_rules; ++ ContentSettingsForOneType timezone_override_rules; ++ std::string timezone_override_value; + }; + + namespace content_settings { +diff --git a/components/content_settings/core/common/content_settings.mojom b/components/content_settings/core/common/content_settings.mojom +--- a/components/content_settings/core/common/content_settings.mojom ++++ b/components/content_settings/core/common/content_settings.mojom +@@ -78,4 +78,6 @@ struct RendererContentSettingRules { + array client_hints_rules; + array popup_redirect_rules; + array mixed_content_rules; ++ array timezone_override_rules; ++ string timezone_override_value; + }; +diff --git a/components/content_settings/core/common/content_settings_mojom_traits.cc b/components/content_settings/core/common/content_settings_mojom_traits.cc +--- a/components/content_settings/core/common/content_settings_mojom_traits.cc ++++ b/components/content_settings/core/common/content_settings_mojom_traits.cc +@@ -101,7 +101,9 @@ bool StructTraitsscript_rules) && + data.ReadClientHintsRules(&out->client_hints_rules) && + data.ReadPopupRedirectRules(&out->popup_redirect_rules) && +- data.ReadMixedContentRules(&out->mixed_content_rules); ++ data.ReadMixedContentRules(&out->mixed_content_rules) && ++ data.ReadTimezoneOverrideRules(&out->timezone_override_rules) && ++ data.ReadTimezoneOverrideValue(&out->timezone_override_value); + } + + } // namespace mojo +diff --git a/components/content_settings/core/common/content_settings_mojom_traits.h b/components/content_settings/core/common/content_settings_mojom_traits.h +--- a/components/content_settings/core/common/content_settings_mojom_traits.h ++++ b/components/content_settings/core/common/content_settings_mojom_traits.h +@@ -149,6 +149,16 @@ struct StructTraits< + return r.mixed_content_rules; + } + ++ static const std::vector& timezone_override_rules( ++ const RendererContentSettingRules& r) { ++ return r.timezone_override_rules; ++ } ++ ++ static const std::string& timezone_override_value( ++ const RendererContentSettingRules& r) { ++ return r.timezone_override_value; ++ } ++ + static bool Read( + content_settings::mojom::RendererContentSettingRulesDataView data, + RendererContentSettingRules* out); +diff --git a/components/content_settings/core/common/content_settings_types.h b/components/content_settings/core/common/content_settings_types.h +--- a/components/content_settings/core/common/content_settings_types.h ++++ b/components/content_settings/core/common/content_settings_types.h +@@ -214,6 +214,9 @@ enum class ContentSettingsType : int32_t { + // Permits creating and placing windows across the set of connected screens. + WINDOW_PLACEMENT, + ++ // bromite #331: Customize Timezone ++ TIMEZONE_OVERRIDE, ++ + NUM_TYPES, + }; + +diff --git a/components/content_settings/core/common/pref_names.cc b/components/content_settings/core/common/pref_names.cc +--- a/components/content_settings/core/common/pref_names.cc ++++ b/components/content_settings/core/common/pref_names.cc +@@ -94,4 +94,7 @@ const char kManagedWebUsbBlockedForUrls[] = + const char kManagedLegacyCookieAccessAllowedForDomains[] = + "profile.managed_legacy_cookie_access_allowed_for_domains"; + ++// Bromite #331: Custom Timezone ++const char kContentSettingsCustomTimezone[] = "profile.content_settings.custom_timezone"; ++ + } // namespace prefs +diff --git a/components/content_settings/core/common/pref_names.h b/components/content_settings/core/common/pref_names.h +--- a/components/content_settings/core/common/pref_names.h ++++ b/components/content_settings/core/common/pref_names.h +@@ -55,6 +55,8 @@ extern const char kManagedWebUsbAskForUrls[]; + extern const char kManagedWebUsbBlockedForUrls[]; + extern const char kManagedLegacyCookieAccessAllowedForDomains[]; + ++extern const char kContentSettingsCustomTimezone[]; ++ + } // namespace prefs + + #endif // COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_PREF_NAMES_H_ +diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc +--- a/components/content_settings/renderer/content_settings_agent_impl.cc ++++ b/components/content_settings/renderer/content_settings_agent_impl.cc +@@ -38,6 +38,11 @@ + #include "url/gurl.h" + #include "url/origin.h" + #include "url/url_constants.h" ++#include "third_party/blink/renderer/core/timezone/timezone_controller.h" ++#include "third_party/blink/renderer/core/inspector/locale_controller.h" ++#include "third_party/blink/renderer/core/inspector/locale_controller.h" ++#include "third_party/icu/source/common/unicode/strenum.h" ++#include "third_party/icu/source/i18n/unicode/timezone.h" + + using blink::WebDocument; + using blink::WebFrame; +@@ -48,6 +53,8 @@ using blink::WebURL; + using blink::WebView; + using content::DocumentState; + ++std::unique_ptr timezone_override_; ++ + namespace content_settings { + namespace { + +@@ -346,6 +353,9 @@ bool ContentSettingsAgentImpl::AllowScript(bool enabled_per_settings) { + allow = allow || IsWhitelistedForContentSettings(); + + cached_script_permissions_[frame] = allow; ++ ++ if (allow) UpdateOverrides(); ++ + return allow; + } + +@@ -572,4 +582,104 @@ bool ContentSettingsAgentImpl::AllowStorageAccess( + return result; + } + ++bool ContentSettingsAgentImpl::UpdateOverrides() { ++ // Evaluate the content setting rules ++ ContentSetting setting = CONTENT_SETTING_ALLOW; ++ ++ if (content_setting_rules_) { ++ blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); ++ ++ setting = GetContentSettingFromRules( ++ content_setting_rules_->timezone_override_rules, frame, ++ url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()); ++ } ++ return UpdateTimeZoneOverride(setting, content_setting_rules_->timezone_override_value); ++ //&& UpdateLocaleOverride(setting); ++} ++ ++// bromite #331: Customize Timezone ++bool ContentSettingsAgentImpl::UpdateTimeZoneOverride(ContentSetting setting, const std::string& timezone_override_value) { ++ // base/i18n/icu_util.cc # 329 ++ //VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride start"; ++ //VLOG(0) << "---" << timezone_override_value; ++ ++ /* timezone_id: third_party/icu/source/i18n/timezone.cpp ++ We first try to lookup the zone ID in our system list. If this ++ * fails, we try to parse it as a custom string GMT[+-]hh:mm. If ++ * all else fails, we return GMT, which is probably not what the ++ * user wants, but at least is a functioning TimeZone object. ++ */ ++ String timezone_id; ++ ++ if(setting == CONTENT_SETTING_ALLOW) { ++ // system time ++ if(timezone_override_) { ++ timezone_override_.reset(); ++ } ++ return true; ++ } else if(setting == CONTENT_SETTING_BLOCK) { ++ // timezone random ++ UErrorCode ec = U_ZERO_ERROR; ++ int32_t rawOffset = ((rand() % 24)-12) * 3600 * 1000; ++ icu::StringEnumeration* timezones = icu::TimeZone::createEnumeration(rawOffset); // Obtain timezones by GMT timezone offset ++ if (timezones) { ++ const char *tzID; ++ int32_t length; ++ if((tzID = timezones->next(&length, ec)) != NULL) { ++ timezone_id = String(tzID); ++ } ++ delete timezones; ++ } ++ } else if( setting == CONTENT_SETTING_ASK) { ++ if(timezone_override_value.empty()) ++ timezone_id = "GMT+00:00"; ++ else ++ timezone_id = String(timezone_override_value.c_str()); ++ } ++ ++ if(blink::TimeZoneController::HasTimeZoneOverride() == false) { ++ timezone_override_.reset(); ++ timezone_override_ = blink::TimeZoneController::SetTimeZoneOverride(timezone_id); ++ if (!timezone_override_) { ++ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - Invalid timezone id '" << timezone_id << "'"; ++ return false; ++ } else { ++ // VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - setting to " << timezone_id; ++ return true; ++ } ++ } else { ++ // VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - already set"; ++ return false; ++ } ++} ++ ++ ++// this code is never call ++// just for future reference ++bool ContentSettingsAgentImpl::UpdateLocaleOverride(ContentSetting setting) { ++ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride start"; ++ ++ String locale_id; ++ ++ if(setting == CONTENT_SETTING_ALLOW) { ++ // system locale ++ blink::LocaleController::instance().SetLocaleOverride(""); ++ return true; ++ } else if(setting == CONTENT_SETTING_BLOCK) { ++ // third_party/icu/source/common/locid.cpp ++ locale_id = "en"; ++ } else if( setting == CONTENT_SETTING_ASK) { ++ locale_id = "en"; ++ } ++ ++ String override_ = blink::LocaleController::instance().SetLocaleOverride(locale_id); ++ if (!override_.IsEmpty()) { ++ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride - " << override_; ++ return false; ++ } else { ++ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride - setting to " << locale_id; ++ return true; ++ } ++} ++ + } // namespace content_settings +diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h +--- a/components/content_settings/renderer/content_settings_agent_impl.h ++++ b/components/content_settings/renderer/content_settings_agent_impl.h +@@ -194,6 +194,10 @@ class ContentSettingsAgentImpl + + mojo::AssociatedReceiverSet receivers_; + ++ bool UpdateOverrides(); ++ bool UpdateTimeZoneOverride(ContentSetting setting, const std::string& timezone_override_value); ++ bool UpdateLocaleOverride(ContentSetting setting); ++ + DISALLOW_COPY_AND_ASSIGN(ContentSettingsAgentImpl); + }; + From ea53b99aa155752b1c3d15bf0e724411458ee9a9 Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Thu, 3 Sep 2020 09:28:09 +0200 Subject: [PATCH 2/4] adding suggestions --- build/patches/Timezone-Override.patch | 244 ++++++++++++++------------ 1 file changed, 133 insertions(+), 111 deletions(-) diff --git a/build/patches/Timezone-Override.patch b/build/patches/Timezone-Override.patch index d09e5278..940945d7 100644 --- a/build/patches/Timezone-Override.patch +++ b/build/patches/Timezone-Override.patch @@ -1,12 +1,12 @@ -From: root -Date: Tue, 1 Sep 2020 13:42:04 +0000 -Subject: Timezone Override +From: uazo +Date: Thu, 3 Sep 2020 06:15:07 +0000 +Subject: rev2 --- .../ChromeSiteSettingsHelpClient.java | 20 ++ .../browser_ui/site_settings/android/BUILD.gn | 3 + - .../res/layout/time_zone_select_dialog.xml | 18 ++ - ...ezoneoverride_site_settings_preference.xml | 56 +++++ + .../res/layout/time_zone_select_dialog.xml | 36 ++++ + ...ezoneoverride_site_settings_preference.xml | 68 ++++++ .../res/xml/single_website_preferences.xml | 2 + .../res/xml/site_settings_preferences.xml | 4 + .../java/res/xml/website_preferences.xml | 9 + @@ -15,12 +15,12 @@ Subject: Timezone Override .../site_settings/SingleCategorySettings.java | 70 ++++++- .../site_settings/SingleWebsiteSettings.java | 21 +- .../site_settings/SiteSettings.java | 2 +- - .../site_settings/SiteSettingsCategory.java | 9 +- + .../site_settings/SiteSettingsCategory.java | 11 +- .../site_settings/SiteSettingsHelpClient.java | 7 + ...imezoneOverrideSiteSettingsPreference.java | 193 ++++++++++++++++++ .../browser_ui/site_settings/Website.java | 10 + .../WebsitePermissionsFetcher.java | 4 + - .../WebsitePreferenceBridge.java | 11 + + .../WebsitePreferenceBridge.java | 12 ++ .../android/website_preference_bridge.cc | 16 ++ .../strings/android/site_settings.grdp | 35 ++++ .../browser/content_settings_pref_provider.cc | 17 ++ @@ -37,9 +37,9 @@ Subject: Timezone Override .../core/common/content_settings_types.h | 3 + .../core/common/pref_names.cc | 3 + .../content_settings/core/common/pref_names.h | 2 + - .../renderer/content_settings_agent_impl.cc | 110 ++++++++++ + .../renderer/content_settings_agent_impl.cc | 92 +++++++++ .../renderer/content_settings_agent_impl.h | 4 + - 36 files changed, 710 insertions(+), 13 deletions(-) + 36 files changed, 724 insertions(+), 14 deletions(-) create mode 100755 components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml create mode 100755 components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml create mode 100755 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java @@ -103,8 +103,26 @@ diff --git a/components/browser_ui/site_settings/android/java/res/layout/time_zo new file mode 100755 --- /dev/null +++ b/components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml -@@ -0,0 +1,18 @@ +@@ -0,0 +1,36 @@ + ++ ++ ++ + + -+ +@@ -0,0 +1,68 @@ ++ + + + @@ -192,7 +222,7 @@ diff --git a/components/browser_ui/site_settings/android/java/res/xml/single_web + ++ android:key="timezone_override_permission_list" /> -+ ++ + @@ -585,11 +615,13 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c @Retention(RetentionPolicy.SOURCE) public @interface Type { // Values used to address array index - should be enumerated from 0 and can't have gaps. -@@ -70,10 +70,11 @@ public class SiteSettingsCategory { +@@ -69,11 +69,12 @@ public class SiteSettingsCategory { + int USB = 18; int BLUETOOTH = 19; int VIRTUAL_REALITY = 20; - int USE_STORAGE = 21; // Always last as it should appear in the UI at the bottom. -+ int TIMEZONE_OVERRIDE = 22; +- int USE_STORAGE = 21; // Always last as it should appear in the UI at the bottom. ++ int USE_STORAGE = 21; ++ int TIMEZONE_OVERRIDE = 22; // Always last as it should appear in the UI at the bottom. /** * Number of handled categories used for calculating array sizes. */ @@ -636,9 +668,22 @@ new file mode 100755 --- /dev/null +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java @@ -0,0 +1,193 @@ -+// Copyright 2018 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++/* ++ This file is part of Bromite. ++ ++ Bromite is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 3 of the License, or ++ (at your option) any later version. ++ ++ Bromite is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Bromite. If not, see . ++*/ + +package org.chromium.components.browser_ui.site_settings; + @@ -689,19 +734,6 @@ new file mode 100755 + + private BrowserContextHandle mBrowserContextHandle; + -+ // reference for translation -+ // 4746227879892920228 "Allow sites to use System Timezone" -+ // 8984679974863410689 "SELECT TIMEZONE FROM LIST" -+ // 3394263620263751240 "bla bla bla" -+ // 5477585238714637279 "Select Timezone" -+ // 6450629284808068080 "Use custom timezone" -+ // 1774419748905152303 "Random Value" -+ // 6315329332061924002 "Default UTC" -+ // 7790128239055164249 "Timezone override" -+ // 2520215895798545849 "Use System Timezone" -+ // 7337126996643069922 "Use random timezone for each page" -+ // remember, hash change if you change default text (not key!) -+ + public TimezoneOverrideSiteSettingsPreference(Context context, AttributeSet attrs) { + super(context, attrs); + @@ -882,13 +914,14 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c default: return false; } -@@ -599,6 +601,13 @@ public class WebsitePreferenceBridge { +@@ -599,6 +601,14 @@ public class WebsitePreferenceBridge { contentSettingType, primaryPattern, secondaryPattern, setting); } + public static String getCustomTimezone(BrowserContextHandle browserContextHandle) { + return WebsitePreferenceBridgeJni.get().getCustomTimezone(browserContextHandle); + } ++ + public static void setCustomTimezone(BrowserContextHandle browserContextHandle, String timezone) { + WebsitePreferenceBridgeJni.get().setCustomTimezone(browserContextHandle, timezone); + } @@ -896,7 +929,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c @VisibleForTesting @NativeMethods public interface Natives { -@@ -734,5 +743,7 @@ public class WebsitePreferenceBridge { +@@ -734,5 +744,7 @@ public class WebsitePreferenceBridge { void setSensorsEnabled(BrowserContextHandle browserContextHandle, boolean enabled); void setSoundEnabled(BrowserContextHandle browserContextHandle, boolean enabled); void setVrEnabled(BrowserContextHandle browserContextHandle, boolean enabled); @@ -951,28 +984,28 @@ diff --git a/components/browser_ui/strings/android/site_settings.grdp b/componen + + Use System Timezone + -+ ++ + Random Value + + + Allow sites to use System Timezone + -+ ++ + Use custom timezone + -+ ++ + Default UTC + -+ ++ + Use random timezone for each page + -+ ++ + SELECT TIMEZONE FROM LIST + -+ ++ + Select Timezone + -+ ++ + Select + + @@ -1056,7 +1089,7 @@ diff --git a/components/content_settings/core/browser/content_settings_registry. + CONTENT_SETTING_ASK, // utc + CONTENT_SETTING_BLOCK), // random + WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE, -+ WebsiteSettingsRegistry::ALL_PLATFORMS, // MAY BE PLATFORM_ANDROID ++ WebsiteSettingsRegistry::PLATFORM_ANDROID, + ContentSettingsInfo::INHERIT_IN_INCOGNITO, + ContentSettingsInfo::PERSISTENT, + ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); @@ -1227,18 +1260,25 @@ diff --git a/components/content_settings/core/common/pref_names.h b/components/c diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc --- a/components/content_settings/renderer/content_settings_agent_impl.cc +++ b/components/content_settings/renderer/content_settings_agent_impl.cc -@@ -38,6 +38,11 @@ +@@ -9,6 +9,7 @@ + + #include "base/bind.h" + #include "base/feature_list.h" ++#include "base/logging.h" + #include "base/metrics/histogram_macros.h" + #include "base/strings/string_number_conversions.h" + #include "components/client_hints/common/client_hints.h" +@@ -35,6 +36,10 @@ + #include "third_party/blink/public/web/web_local_frame.h" + #include "third_party/blink/public/web/web_local_frame_client.h" + #include "third_party/blink/public/web/web_view.h" ++#include "third_party/blink/renderer/core/inspector/locale_controller.h" ++#include "third_party/blink/renderer/core/timezone/timezone_controller.h" ++#include "third_party/icu/source/common/unicode/strenum.h" ++#include "third_party/icu/source/i18n/unicode/timezone.h" #include "url/gurl.h" #include "url/origin.h" #include "url/url_constants.h" -+#include "third_party/blink/renderer/core/timezone/timezone_controller.h" -+#include "third_party/blink/renderer/core/inspector/locale_controller.h" -+#include "third_party/blink/renderer/core/inspector/locale_controller.h" -+#include "third_party/icu/source/common/unicode/strenum.h" -+#include "third_party/icu/source/i18n/unicode/timezone.h" - - using blink::WebDocument; - using blink::WebFrame; @@ -48,6 +53,8 @@ using blink::WebURL; using blink::WebView; using content::DocumentState; @@ -1248,17 +1288,18 @@ diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc namespace content_settings { namespace { -@@ -346,6 +353,9 @@ bool ContentSettingsAgentImpl::AllowScript(bool enabled_per_settings) { +@@ -346,6 +353,10 @@ bool ContentSettingsAgentImpl::AllowScript(bool enabled_per_settings) { allow = allow || IsWhitelistedForContentSettings(); cached_script_permissions_[frame] = allow; -+ -+ if (allow) UpdateOverrides(); ++ ++ if (allow) ++ UpdateOverrides(); + return allow; } -@@ -572,4 +582,104 @@ bool ContentSettingsAgentImpl::AllowStorageAccess( +@@ -572,4 +583,85 @@ bool ContentSettingsAgentImpl::AllowStorageAccess( return result; } @@ -1273,15 +1314,16 @@ diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc + content_setting_rules_->timezone_override_rules, frame, + url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()); + } -+ return UpdateTimeZoneOverride(setting, content_setting_rules_->timezone_override_value); -+ //&& UpdateLocaleOverride(setting); ++ return UpdateTimeZoneOverride( ++ setting, content_setting_rules_->timezone_override_value); ++ //&& UpdateLocaleOverride(setting); +} + +// bromite #331: Customize Timezone -+bool ContentSettingsAgentImpl::UpdateTimeZoneOverride(ContentSetting setting, const std::string& timezone_override_value) { ++bool ContentSettingsAgentImpl::UpdateTimeZoneOverride( ++ ContentSetting setting, ++ const std::string& timezone_override_value) { + // base/i18n/icu_util.cc # 329 -+ //VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride start"; -+ //VLOG(0) << "---" << timezone_override_value; + + /* timezone_id: third_party/icu/source/i18n/timezone.cpp + We first try to lookup the zone ID in our system list. If this @@ -1291,76 +1333,56 @@ diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc + */ + String timezone_id; + -+ if(setting == CONTENT_SETTING_ALLOW) { ++ if (setting == CONTENT_SETTING_ALLOW) { + // system time -+ if(timezone_override_) { ++ if (timezone_override_) { + timezone_override_.reset(); + } + return true; -+ } else if(setting == CONTENT_SETTING_BLOCK) { ++ } else if (setting == CONTENT_SETTING_BLOCK) { + // timezone random + UErrorCode ec = U_ZERO_ERROR; -+ int32_t rawOffset = ((rand() % 24)-12) * 3600 * 1000; -+ icu::StringEnumeration* timezones = icu::TimeZone::createEnumeration(rawOffset); // Obtain timezones by GMT timezone offset ++ int32_t rawOffset = ((rand() % 24) - 12) * 3600 * 1000; ++ icu::StringEnumeration* timezones = icu::TimeZone::createEnumeration( ++ rawOffset); // Obtain timezones by GMT timezone offset + if (timezones) { -+ const char *tzID; ++ const char* tzID; + int32_t length; -+ if((tzID = timezones->next(&length, ec)) != NULL) { ++ if ((tzID = timezones->next(&length, ec)) != NULL) { + timezone_id = String(tzID); + } + delete timezones; + } -+ } else if( setting == CONTENT_SETTING_ASK) { -+ if(timezone_override_value.empty()) -+ timezone_id = "GMT+00:00"; -+ else ++ } else if (setting == CONTENT_SETTING_ASK) { ++ if (timezone_override_value.empty()) ++ timezone_id = "Europe/London"; ++ else + timezone_id = String(timezone_override_value.c_str()); + } + -+ if(blink::TimeZoneController::HasTimeZoneOverride() == false) { ++ if (blink::TimeZoneController::HasTimeZoneOverride() == false) { + timezone_override_.reset(); -+ timezone_override_ = blink::TimeZoneController::SetTimeZoneOverride(timezone_id); ++ timezone_override_ = ++ blink::TimeZoneController::SetTimeZoneOverride(timezone_id); + if (!timezone_override_) { -+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - Invalid timezone id '" << timezone_id << "'"; -+ return false; ++ LOG(WARNING) << "---Bromite:ContentSettingsAgentImpl::" ++ "UpdateTimeZoneOverride - Invalid timezone id '" ++ << timezone_id << "'"; ++ return false; + } else { -+ // VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - setting to " << timezone_id; -+ return true; ++ LOG(INFO) ++ << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride " ++ "- setting to " ++ << timezone_id; ++ return true; + } + } else { -+ // VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - already set"; ++ LOG(INFO) ++ << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - " ++ "already set"; + return false; + } +} -+ -+ -+// this code is never call -+// just for future reference -+bool ContentSettingsAgentImpl::UpdateLocaleOverride(ContentSetting setting) { -+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride start"; -+ -+ String locale_id; -+ -+ if(setting == CONTENT_SETTING_ALLOW) { -+ // system locale -+ blink::LocaleController::instance().SetLocaleOverride(""); -+ return true; -+ } else if(setting == CONTENT_SETTING_BLOCK) { -+ // third_party/icu/source/common/locid.cpp -+ locale_id = "en"; -+ } else if( setting == CONTENT_SETTING_ASK) { -+ locale_id = "en"; -+ } -+ -+ String override_ = blink::LocaleController::instance().SetLocaleOverride(locale_id); -+ if (!override_.IsEmpty()) { -+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride - " << override_; -+ return false; -+ } else { -+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateLocaleOverride - setting to " << locale_id; -+ return true; -+ } -+} + } // namespace content_settings diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h From 3a9a3672598116d2b08a40fefccc61427c811d74 Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Thu, 3 Sep 2020 17:56:18 +0200 Subject: [PATCH 3/4] fix for 85.0.4183.86 without session-only patch --- build/patches/Timezone-Override.patch | 133 ++++++++++++-------------- 1 file changed, 59 insertions(+), 74 deletions(-) diff --git a/build/patches/Timezone-Override.patch b/build/patches/Timezone-Override.patch index 940945d7..8d76125a 100644 --- a/build/patches/Timezone-Override.patch +++ b/build/patches/Timezone-Override.patch @@ -1,6 +1,6 @@ From: uazo -Date: Thu, 3 Sep 2020 06:15:07 +0000 -Subject: rev2 +Date: Thu, 3 Sep 2020 15:53:15 +0000 +Subject: second version --- .../ChromeSiteSettingsHelpClient.java | 20 ++ @@ -13,7 +13,7 @@ Subject: rev2 .../ContentSettingException.java | 7 +- .../ContentSettingsResources.java | 29 +++ .../site_settings/SingleCategorySettings.java | 70 ++++++- - .../site_settings/SingleWebsiteSettings.java | 21 +- + .../site_settings/SingleWebsiteSettings.java | 18 ++ .../site_settings/SiteSettings.java | 2 +- .../site_settings/SiteSettingsCategory.java | 11 +- .../site_settings/SiteSettingsHelpClient.java | 7 + @@ -39,7 +39,7 @@ Subject: rev2 .../content_settings/core/common/pref_names.h | 2 + .../renderer/content_settings_agent_impl.cc | 92 +++++++++ .../renderer/content_settings_agent_impl.h | 4 + - 36 files changed, 724 insertions(+), 14 deletions(-) + 36 files changed, 723 insertions(+), 12 deletions(-) create mode 100755 components/browser_ui/site_settings/android/java/res/layout/time_zone_select_dialog.xml create mode 100755 components/browser_ui/site_settings/android/java/res/layout/timezoneoverride_site_settings_preference.xml create mode 100755 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TimezoneOverrideSiteSettingsPreference.java @@ -315,7 +315,31 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c sResourceInfo = localMap; } return sResourceInfo; -@@ -420,6 +425,13 @@ public class ContentSettingsResources { +@@ -315,6 +320,23 @@ public class ContentSettingsResources { + } + } + ++ public static int getCategorySummary(int contentType, @ContentSettingValues int value) { ++ if(contentType == ContentSettingsType.TIMEZONE_OVERRIDE) { ++ switch (value) { ++ case ContentSettingValues.ALLOW: ++ return R.string.website_settings_category_timezone_override_allowed; ++ case ContentSettingValues.ASK: ++ return R.string.website_settings_category_timezone_override_custom; ++ case ContentSettingValues.BLOCK: ++ return R.string.website_settings_category_timezone_override_random; ++ default: ++ return 0; ++ } ++ } ++ else ++ return getCategorySummary(value); ++ } ++ + /** + * Returns the string resource id for a content type to show with a permission category. + * @param enabled Whether the content type is enabled. +@@ -418,6 +440,13 @@ public class ContentSettingsResources { return descriptionIDs; } } @@ -329,28 +353,6 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c assert false; return null; -@@ -431,4 +443,21 @@ public class ContentSettingsResources { - public static int getCookieSessionOnlySummary() { - return R.string.website_settings_category_cookie_session_only_title; - } -+ -+ public static int getCategorySummary(int contentType, @ContentSettingValues int value) { -+ if(contentType == ContentSettingsType.TIMEZONE_OVERRIDE) { -+ switch (value) { -+ case ContentSettingValues.ALLOW: -+ return R.string.website_settings_category_timezone_override_allowed; -+ case ContentSettingValues.ASK: -+ return R.string.website_settings_category_timezone_override_custom; -+ case ContentSettingValues.BLOCK: -+ return R.string.website_settings_category_timezone_override_random; -+ default: -+ return 0; -+ } -+ } -+ else -+ return getCategorySummary(value); -+ } - } diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java @@ -426,7 +428,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c } else if (FOUR_STATE_COOKIE_TOGGLE_KEY.equals(preference.getKey())) { setCookieSettingsPreference((CookieSettingsState) newValue); getInfoForOrigins(); -@@ -664,6 +683,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -642,6 +661,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment ? R.string.website_settings_add_site_description_cookies_block : R.string.website_settings_add_site_description_cookies_allow; } @@ -435,7 +437,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c } assert resource > 0; return getString(resource); -@@ -704,6 +725,13 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -682,6 +703,13 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES) && mRequiresFourStateSetting) { setting = cookieSettingsExceptionShouldBlock() ? ContentSettingValues.BLOCK : ContentSettingValues.ALLOW; @@ -449,7 +451,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c } else { setting = (WebsitePreferenceBridge.isCategoryEnabled( browserContextHandle, mCategory.getContentSettingsType())) -@@ -761,6 +789,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -739,6 +767,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment && !WebsitePreferenceBridge.isCategoryEnabled( browserContextHandle, ContentSettingsType.AUTOMATIC_DOWNLOADS)) { exception = true; @@ -458,7 +460,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c } if (exception) { getPreferenceScreen().addPreference(new AddExceptionPreference(getStyledContext(), -@@ -934,7 +964,14 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -912,7 +942,14 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment TriStateSiteSettingsPreference triStateToggle = (TriStateSiteSettingsPreference) getPreferenceScreen().findPreference( TRI_STATE_TOGGLE_KEY); @@ -474,7 +476,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c } else if (mRequiresFourStateSetting) { FourStateCookieSettingsPreference fourStateCookieToggle = (FourStateCookieSettingsPreference) getPreferenceScreen().findPreference( -@@ -962,6 +999,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -940,6 +977,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment FourStateCookieSettingsPreference fourStateCookieToggle = (FourStateCookieSettingsPreference) screen.findPreference( FOUR_STATE_COOKIE_TOGGLE_KEY); @@ -484,7 +486,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c Preference thirdPartyCookies = screen.findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY); Preference notificationsVibrate = screen.findPreference(NOTIFICATIONS_VIBRATE_TOGGLE_KEY); Preference notificationsQuietUi = screen.findPreference(NOTIFICATIONS_QUIET_UI_TOGGLE_KEY); -@@ -979,17 +1019,27 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -957,17 +997,27 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment screen.removePreference(binaryToggle); screen.removePreference(triStateToggle); screen.removePreference(fourStateCookieToggle); @@ -513,7 +515,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c configureBinaryToggle(binaryToggle, contentType); } -@@ -1002,6 +1052,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -980,6 +1030,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment ContentSettingsFeatureList.IMPROVED_COOKIE_CONTROLS))) { screen.removePreference(screen.findPreference(COOKIE_INFO_TEXT_KEY)); } @@ -523,7 +525,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c if (hideSecondaryToggles) { screen.removePreference(thirdPartyCookies); -@@ -1132,6 +1185,15 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment +@@ -1103,6 +1156,15 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment triStateToggle.initialize(setting, descriptionIds); } @@ -550,51 +552,34 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c }; private static final int REQUEST_CODE_NOTIFICATION_CHANNEL_SETTINGS = 1; -@@ -750,6 +751,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment +@@ -750,6 +751,23 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment setUpPreferenceCommon(preference); ListPreference listPreference = (ListPreference) preference; -+ int index = (value == ContentSettingValues.ALLOW ? 0 : 1); - if (getContentSettingsTypeFromPreferenceKey(preference.getKey()) == ContentSettingsType.COOKIES) { - CharSequence[] keys = new String[3]; - CharSequence[] descriptions = new String[3]; -@@ -764,7 +766,23 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment - getString(ContentSettingsResources.getSiteSummary(ContentSettingValues.SESSION_ONLY)); - listPreference.setEntryValues(keys); - listPreference.setEntries(descriptions); -- } else { -+ index = (value == ContentSettingValues.SESSION_ONLY ? 2 : (value == ContentSettingValues.ALLOW ? 0 : 1)); ++ if (getContentSettingsTypeFromPreferenceKey(preference.getKey()) == ContentSettingsType.TIMEZONE_OVERRIDE) { ++ CharSequence[] keys = new String[3]; ++ keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); ++ keys[1] = ContentSetting.toString(ContentSettingValues.ASK); ++ keys[2] = ContentSetting.toString(ContentSettingValues.BLOCK); ++ int[] descriptionsId = ContentSettingsResources.getTriStateSettingDescriptionIDs(ContentSettingsType.TIMEZONE_OVERRIDE); ++ CharSequence[] descriptions = new String[3]; ++ descriptions[0] = getString(descriptionsId[0]); ++ descriptions[1] = getString(descriptionsId[1]); ++ descriptions[2] = getString(descriptionsId[2]); ++ listPreference.setEntryValues(keys); ++ listPreference.setEntries(descriptions); ++ int indexSelected = (value == ContentSettingValues.ASK ? 1 : (value == ContentSettingValues.ALLOW ? 0 : 2)); ++ listPreference.setValueIndex(indexSelected); ++ return; + } -+ else if (getContentSettingsTypeFromPreferenceKey(preference.getKey()) == ContentSettingsType.TIMEZONE_OVERRIDE) { -+ CharSequence[] keys = new String[3]; -+ keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); -+ keys[1] = ContentSetting.toString(ContentSettingValues.ASK); -+ keys[2] = ContentSetting.toString(ContentSettingValues.BLOCK); -+ int[] descriptionsId = ContentSettingsResources.getTriStateSettingDescriptionIDs(ContentSettingsType.TIMEZONE_OVERRIDE); -+ CharSequence[] descriptions = new String[3]; -+ descriptions[0] = getString(descriptionsId[0]); -+ descriptions[1] = getString(descriptionsId[1]); -+ descriptions[2] = getString(descriptionsId[2]); -+ listPreference.setEntryValues(keys); -+ listPreference.setEntries(descriptions); -+ index = (value == ContentSettingValues.ASK ? 1 : (value == ContentSettingValues.ALLOW ? 0 : 2)); -+ } -+ else { - CharSequence[] keys = new String[2]; - CharSequence[] descriptions = new String[2]; - keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); -@@ -780,7 +798,6 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment - listPreference.setSummary(isEmbargoed ? getString(R.string.automatically_blocked) : "%s"); - // TODO(crbug.com/735110): Figure out if this is the correct thing to do - here we are - // effectively treating non-ALLOW values as BLOCK. -- int index = (value == ContentSettingValues.SESSION_ONLY ? 2 : (value == ContentSettingValues.ALLOW ? 0 : 1)); - listPreference.setValueIndex(index); - } - ++ + CharSequence[] keys = new String[2]; + CharSequence[] descriptions = new String[2]; + keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW); diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettings.java -@@ -120,7 +120,7 @@ public class SiteSettings +@@ -111,7 +111,7 @@ public class SiteSettings } else if (Type.SOUND == prefCategory && !checked) { p.setSummary(ContentSettingsResources.getSoundBlockedListSummary()); } else if (requiresTriStateSetting) { @@ -973,7 +958,7 @@ diff --git a/components/browser_ui/strings/android/site_settings.grdp b/componen -@@ -468,6 +471,38 @@ +@@ -462,6 +465,38 @@ Block sites from playing protected content From a865bcdedd6f5b49a2b499bc3844ef7048013d3a Mon Sep 17 00:00:00 2001 From: Carl <32685696+csagan5@users.noreply.github.com> Date: Thu, 3 Sep 2020 20:56:51 +0200 Subject: [PATCH 4/4] English text improvements --- build/patches/Timezone-Override.patch | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build/patches/Timezone-Override.patch b/build/patches/Timezone-Override.patch index 8d76125a..446bca50 100644 --- a/build/patches/Timezone-Override.patch +++ b/build/patches/Timezone-Override.patch @@ -963,34 +963,34 @@ diff --git a/components/browser_ui/strings/android/site_settings.grdp b/componen + -+ -+ bla bla bla ++ ++ Override timezone with a custom or random one + -+ -+ Use System Timezone ++ ++ System + -+ -+ Random Value ++ ++ Random + -+ -+ Allow sites to use System Timezone ++ ++ Allow sites to access the system timezone + + -+ Use custom timezone ++ Custom timezone + + -+ Default UTC ++ Specify a custom timezone (default UTC) + -+ -+ Use random timezone for each page ++ ++ Use a random timezone for each tab + -+ -+ SELECT TIMEZONE FROM LIST ++ ++ Choose timezone + -+ -+ Select Timezone ++ ++ Choose Timezone + -+ ++ + Select + + @@ -1071,7 +1071,7 @@ diff --git a/components/content_settings/core/browser/content_settings_registry. + WebsiteSettingsInfo::SYNCABLE, + WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme), + ValidSettings(CONTENT_SETTING_ALLOW, // use system time -+ CONTENT_SETTING_ASK, // utc ++ CONTENT_SETTING_ASK, // custom timezone, default UTC + CONTENT_SETTING_BLOCK), // random + WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE, + WebsiteSettingsRegistry::PLATFORM_ANDROID,