Created
August 28, 2020 10:08
-
-
Save uazo/8536dcb8483b157fcbc489acc13ceae5 to your computer and use it in GitHub Desktop.
[wip] add timezone override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
old mode 100644 | |
new mode 100755 | |
index f9993744e2..9c6949618a | |
--- 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,15 @@ public class ChromeSiteSettingsHelpClient implements SiteSettingsHelpClient { | |
currentActivity.getString(R.string.help_context_protected_content), | |
Profile.getLastUsedRegularProfile(), null); | |
} | |
+ | |
+ @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/java/res/xml/single_website_preferences.xml b/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml | |
old mode 100644 | |
new mode 100755 | |
index c78921a19c..5157ae7dfe | |
--- 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" /> | |
<ListPreference | |
android:key="javascript_permission_list" /> | |
+ <ListPreference | |
+ android:key="timezone_override_permission_list" /> | |
<ListPreference | |
android:key="popup_permission_list" /> | |
<ListPreference | |
diff --git a/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml b/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml | |
old mode 100644 | |
new mode 100755 | |
index b9b237e08e..bf083fa1be | |
--- a/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml | |
+++ b/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml | |
@@ -41,6 +41,10 @@ | |
<org.chromium.components.browser_ui.settings.IconPreference | |
android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings" | |
android:key="javascript" /> | |
+ <!-- Timezone Override --> | |
+ <org.chromium.components.browser_ui.settings.IconPreference | |
+ android:key="timezone_override" | |
+ android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings" /> | |
<!-- Popups --> | |
<org.chromium.components.browser_ui.settings.IconPreference | |
android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings" | |
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingException.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingException.java | |
old mode 100644 | |
new mode 100755 | |
index d6bdef38e7..c1ca6d4fdc | |
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingException.java | |
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingException.java | |
@@ -36,10 +36,11 @@ public class ContentSettingException implements Serializable { | |
int SOUND = 5; | |
int AUTOMATIC_DOWNLOADS = 6; | |
int BLUETOOTH_SCANNING = 7; | |
+ int TIMEZONE_OVERRIDE = 8; | |
/** | |
* Number of handled exceptions used for calculating array sizes. | |
*/ | |
- int NUM_ENTRIES = 8; | |
+ int NUM_ENTRIES = 9; | |
} | |
private final int mContentSettingType; | |
@@ -121,6 +122,8 @@ public class ContentSettingException implements Serializable { | |
return ContentSettingsType.POPUPS; | |
case Type.SOUND: | |
return ContentSettingsType.SOUND; | |
+ case Type.TIMEZONE_OVERRIDE: | |
+ return ContentSettingsType.TIMEZONE_OVERRIDE; | |
default: | |
assert false; | |
return ContentSettingsType.DEFAULT; | |
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java | |
index fab57d5ae1..797d3c9c53 100755 | |
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java | |
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java | |
@@ -233,6 +233,11 @@ public class ContentSettingsResources { | |
R.string.vr_permission_title, ContentSettingValues.ASK, | |
ContentSettingValues.BLOCK, R.string.website_settings_category_vr_ask, | |
R.string.website_settings_category_vr_blocked)); | |
+ localMap.put(ContentSettingsType.TIMEZONE_OVERRIDE, | |
+ new ResourceItem(R.drawable.web_asset, R.string.timezone_override_permission_title, | |
+ R.string.timezone_override_permission_title, ContentSettingValues.ALLOW, | |
+ ContentSettingValues.BLOCK, R.string.website_settings_category_timezone_override_utc, | |
+ R.string.website_settings_category_timezone_override_random)); | |
sResourceInfo = localMap; | |
} | |
return sResourceInfo; | |
@@ -420,6 +425,13 @@ public class ContentSettingsResources { | |
return descriptionIDs; | |
} | |
} | |
+ else if(contentType == ContentSettingsType.TIMEZONE_OVERRIDE) { | |
+ int[] descriptionIDs = { | |
+ R.string.website_settings_category_timezone_override_allowed, // ALLOWED | |
+ R.string.website_settings_category_timezone_override_utc, // ASK | |
+ R.string.website_settings_category_timezone_override_random}; // BLOCKED | |
+ return descriptionIDs; | |
+ } | |
assert false; | |
return null; | |
@@ -431,4 +443,38 @@ 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_utc; | |
+ case ContentSettingValues.BLOCK: | |
+ return R.string.website_settings_category_timezone_override_random; | |
+ default: | |
+ return 0; | |
+ } | |
+ } | |
+ else | |
+ return getCategorySummary(value); | |
+ } | |
+ | |
+ public static int[] getTriStateSettingPrimaryTextIDs(int contentType) { | |
+ if (contentType == ContentSettingsType.TIMEZONE_OVERRIDE) { | |
+ int[] primaryTextIDs = { | |
+ R.string.website_settings_category_timezone_override_allowed_text, // ALLOWED | |
+ R.string.website_settings_category_timezone_override_utc_text, // ASK | |
+ R.string.website_settings_category_timezone_override_random_text}; // BLOCKED | |
+ return primaryTextIDs; | |
+ } | |
+ else { | |
+ int[] primaryTextIDs = { | |
+ R.string.website_settings_category_allowed, // ALLOWED | |
+ R.string.website_settings_category_ask, // ASK | |
+ R.string.website_settings_category_blocked}; // BLOCKED | |
+ return primaryTextIDs; | |
+ } | |
+ } | |
} | |
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 | |
index 0e52c8897f..7cff61873c 100755 | |
--- 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 | |
@@ -414,7 +414,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment | |
if (queryHasChanged) getInfoForOrigins(); | |
}); | |
- if (getSiteSettingsClient().getSiteSettingsHelpClient().isHelpAndFeedbackEnabled()) { | |
+ if (getSiteSettingsClient().getSiteSettingsHelpClient().isHelpAndFeedbackEnabled() || | |
+ mCategory.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE) ) { | |
MenuItem help = menu.add( | |
Menu.NONE, R.id.menu_id_site_settings_help, Menu.NONE, R.string.menu_help); | |
help.setIcon(VectorDrawableCompat.create( | |
@@ -425,7 +426,11 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
if (item.getItemId() == R.id.menu_id_site_settings_help) { | |
- if (mCategory.showSites(SiteSettingsCategory.Type.PROTECTED_MEDIA)) { | |
+ if (mCategory.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE)) { | |
+ getSiteSettingsClient() | |
+ .getSiteSettingsHelpClient() | |
+ .launchTimeZoneOverrideHelpAndFeedbackActivity(getActivity()); | |
+ } else if (mCategory.showSites(SiteSettingsCategory.Type.PROTECTED_MEDIA)) { | |
getSiteSettingsClient() | |
.getSiteSettingsHelpClient() | |
.launchProtectedContentHelpAndFeedbackActivity(getActivity()); | |
@@ -664,6 +669,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment | |
? R.string.website_settings_add_site_description_cookies_block | |
: R.string.website_settings_add_site_description_cookies_allow; | |
} | |
+ } else if (mCategory.showSites(SiteSettingsCategory.Type.TIMEZONE_OVERRIDE)) { | |
+ resource = R.string.website_settings_category_timezone_override_allowed; | |
} | |
assert resource > 0; | |
return getString(resource); | |
@@ -704,6 +711,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 +775,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(), | |
@@ -1129,7 +1145,9 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment | |
getSiteSettingsClient().getBrowserContextHandle(), contentType); | |
int[] descriptionIds = | |
ContentSettingsResources.getTriStateSettingDescriptionIDs(contentType); | |
- triStateToggle.initialize(setting, descriptionIds); | |
+ int[] textIds = | |
+ ContentSettingsResources.getTriStateSettingPrimaryTextIDs(contentType); | |
+ triStateToggle.initialize(setting, descriptionIds, textIds); | |
} | |
private void configureBinaryToggle(ChromeSwitchPreference binaryToggle, int 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 | |
index 0362feb6b8..c93e7a47f4 100755 | |
--- 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,25 @@ 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[] descriptions_id = ContentSettingsResources.getTriStateSettingPrimaryTextIDs(ContentSettingsType.TIMEZONE_OVERRIDE); | |
+ CharSequence[] descriptions = new String[3]; | |
+ descriptions[0] = getContext().getText(descriptions_id[0]); | |
+ descriptions[1] = getContext().getText(descriptions_id[1]); | |
+ descriptions[2] = getContext().getText(descriptions_id[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 +800,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 | |
index bcae314763..80f1bb908c 100755 | |
--- 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 | |
old mode 100644 | |
new mode 100755 | |
index ae11552e0e..08dc5a4fe2 | |
--- 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 | |
old mode 100644 | |
new mode 100755 | |
index b8bc808757..f2eaa610cf | |
--- 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 timezonne 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/TriStateSiteSettingsPreference.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TriStateSiteSettingsPreference.java | |
old mode 100644 | |
new mode 100755 | |
index 1c08be9377..2aae16302c | |
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TriStateSiteSettingsPreference.java | |
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/TriStateSiteSettingsPreference.java | |
@@ -21,6 +21,7 @@ public class TriStateSiteSettingsPreference | |
extends Preference implements RadioGroup.OnCheckedChangeListener { | |
private @ContentSettingValues int mSetting = ContentSettingValues.DEFAULT; | |
private int[] mDescriptionIds; | |
+ private int[] mPrimaryTextIds; | |
private RadioButtonWithDescription mAllowed; | |
private RadioButtonWithDescription mAsk; | |
private RadioButtonWithDescription mBlocked; | |
@@ -44,9 +45,10 @@ public class TriStateSiteSettingsPreference | |
* @param descriptionIds An array of 3 resource IDs for descriptions for | |
* Allowed, Ask and Blocked states, in that order. | |
*/ | |
- public void initialize(@ContentSettingValues int setting, int[] descriptionIds) { | |
+ public void initialize(@ContentSettingValues int setting, int[] descriptionIds, int[] primaryTextIds) { | |
mSetting = setting; | |
mDescriptionIds = descriptionIds; | |
+ mPrimaryTextIds = primaryTextIds; | |
} | |
/** | |
@@ -84,6 +86,11 @@ public class TriStateSiteSettingsPreference | |
mAsk.setDescriptionText(getContext().getText(mDescriptionIds[1])); | |
mBlocked.setDescriptionText(getContext().getText(mDescriptionIds[2])); | |
} | |
+ if (mPrimaryTextIds != null) { | |
+ mAllowed.setPrimaryText(getContext().getText(mPrimaryTextIds[0])); | |
+ mAsk.setPrimaryText(getContext().getText(mPrimaryTextIds[1])); | |
+ mBlocked.setPrimaryText(getContext().getText(mPrimaryTextIds[2])); | |
+ } | |
RadioButtonWithDescription radioButton = findRadioButton(mSetting); | |
if (radioButton != null) radioButton.setChecked(true); | |
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 | |
old mode 100644 | |
new mode 100755 | |
index d119a594e8..e417c90f74 | |
--- 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 | |
old mode 100644 | |
new mode 100755 | |
index bddd75f7b3..e16d08e0a2 | |
--- 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 | |
old mode 100644 | |
new mode 100755 | |
index b40b44ea05..080027dedd | |
--- 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; | |
} | |
diff --git a/components/browser_ui/strings/android/site_settings.grdp b/components/browser_ui/strings/android/site_settings.grdp | |
index 183738d0ae..0b589aed0d 100755 | |
--- a/components/browser_ui/strings/android/site_settings.grdp | |
+++ b/components/browser_ui/strings/android/site_settings.grdp | |
@@ -66,6 +66,9 @@ | |
<message name="IDS_VR_PERMISSION_TITLE" desc="Title of the permission to use Virtual Reality [CHAR-LIMIT=32]"> | |
Virtual reality | |
</message> | |
+ <message name="IDS_TIMEZONE_OVERRIDE_PERMISSION_TITLE" desc="Title of the permission to use TimeZone Override [CHAR-LIMIT=32]"> | |
+ Timezone override | |
+ </message> | |
<!-- Site settings global toggles --> | |
@@ -468,6 +471,26 @@ | |
Block sites from playing protected content | |
</message> | |
+ <!-- Timezone override --> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_ALLOWED_TEXT" desc="Primary text explaining that sites are allowed to access system timezone."> | |
+ Use System Timezone | |
+ </message> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_UTC_TEXT" desc="Primary text explaining that that sites are not allowed to access system timezone."> | |
+ Always UTC locale EN | |
+ </message> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_RANDOM_TEXT" desc="Primary text explaining that sites are not allowed to access system timezone."> | |
+ Random Value | |
+ </message> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_ALLOWED" desc="Summary text explaining that sites are allowed to access system timezone."> | |
+ Allow sites to use System Timezone | |
+ </message> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_UTC" desc="Summary text explaining that that sites are not allowed to access system timezone."> | |
+ Use always UTC with locale EN | |
+ </message> | |
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_RANDOM" desc="Summary text explaining that sites are not allowed to access system timezone."> | |
+ Use Random UTC and locale for each page | |
+ </message> | |
+ | |
<!-- Sound --> | |
<message name="IDS_WEBSITE_SETTINGS_CATEGORY_SOUND_ALLOWED" desc="Summary text explaining that sites are allowed to play sound and that it is the recommended setting."> | |
diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc | |
index ed68e8311e..bb04ad96cb 100755 | |
--- a/components/content_settings/core/browser/content_settings_registry.cc | |
+++ b/components/content_settings/core/browser/content_settings_registry.cc | |
@@ -590,6 +590,18 @@ void ContentSettingsRegistry::Init() { | |
ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE, | |
ContentSettingsInfo::PERSISTENT, | |
ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); | |
+ | |
+ Register(ContentSettingsType::TIMEZONE_OVERRIDE, "timezone-override", CONTENT_SETTING_ALLOW, | |
+ WebsiteSettingsInfo::SYNCABLE, | |
+ WhitelistedSchemes(kChromeUIScheme, kChromeDevToolsScheme), | |
+ ValidSettings(CONTENT_SETTING_ALLOW, | |
+ CONTENT_SETTING_ASK, | |
+ CONTENT_SETTING_BLOCK), | |
+ 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 | |
old mode 100644 | |
new mode 100755 | |
index b33cb6e52a..addba34ad6 | |
--- a/components/content_settings/core/browser/content_settings_utils.cc | |
+++ b/components/content_settings/core/browser/content_settings_utils.cc | |
@@ -148,6 +148,8 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map, | |
&(rules->client_hints_rules)); | |
map->GetSettingsForOneType(ContentSettingsType::POPUPS, ResourceIdentifier(), | |
&(rules->popup_redirect_rules)); | |
+ map->GetSettingsForOneType(ContentSettingsType::TIMEZONE_OVERRIDE, | |
+ ResourceIdentifier(), &(rules->timezone_override_rules)); | |
} | |
bool IsMorePermissive(ContentSetting a, ContentSetting b) { | |
diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc | |
old mode 100644 | |
new mode 100755 | |
index a27c4b5509..1a85986385 | |
--- 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}, | |
}; | |
} // 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; | |
} | |
RendererContentSettingRules::RendererContentSettingRules() {} | |
diff --git a/components/content_settings/core/common/content_settings.h b/components/content_settings/core/common/content_settings.h | |
old mode 100644 | |
new mode 100755 | |
index dd1198aa98..0cd7a4e23b | |
--- a/components/content_settings/core/common/content_settings.h | |
+++ b/components/content_settings/core/common/content_settings.h | |
@@ -79,6 +79,7 @@ struct RendererContentSettingRules { | |
ContentSettingsForOneType client_hints_rules; | |
ContentSettingsForOneType popup_redirect_rules; | |
ContentSettingsForOneType mixed_content_rules; | |
+ ContentSettingsForOneType timezone_override_rules; | |
}; | |
namespace content_settings { | |
diff --git a/components/content_settings/core/common/content_settings.mojom b/components/content_settings/core/common/content_settings.mojom | |
old mode 100644 | |
new mode 100755 | |
index cb8b3d2aaa..1576934cf5 | |
--- a/components/content_settings/core/common/content_settings.mojom | |
+++ b/components/content_settings/core/common/content_settings.mojom | |
@@ -78,4 +78,5 @@ struct RendererContentSettingRules { | |
array<ContentSettingPatternSource> client_hints_rules; | |
array<ContentSettingPatternSource> popup_redirect_rules; | |
array<ContentSettingPatternSource> mixed_content_rules; | |
+ array<ContentSettingPatternSource> timezone_override_rules; | |
}; | |
diff --git a/components/content_settings/core/common/content_settings_mojom_traits.cc b/components/content_settings/core/common/content_settings_mojom_traits.cc | |
old mode 100644 | |
new mode 100755 | |
index 3cdb9450d8..f076601be6 | |
--- 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,8 @@ bool StructTraits<content_settings::mojom::RendererContentSettingRulesDataView, | |
data.ReadScriptRules(&out->script_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); | |
} | |
} // 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 | |
old mode 100644 | |
new mode 100755 | |
index 2192c55d2b..b6e0d207f4 | |
--- 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,11 @@ struct StructTraits< | |
return r.mixed_content_rules; | |
} | |
+ static const std::vector<ContentSettingPatternSource>& timezone_override_rules( | |
+ const RendererContentSettingRules& r) { | |
+ return r.timezone_override_rules; | |
+ } | |
+ | |
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 | |
old mode 100644 | |
new mode 100755 | |
index 2d4892a43d..206ae1fa27 | |
--- 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, | |
+ // to add | |
+ TIMEZONE_OVERRIDE, | |
+ | |
NUM_TYPES, | |
}; | |
diff --git a/components/content_settings/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc | |
old mode 100644 | |
new mode 100755 | |
index 660223c0bf..fc7463b916 | |
--- a/components/content_settings/renderer/content_settings_agent_impl.cc | |
+++ b/components/content_settings/renderer/content_settings_agent_impl.cc | |
@@ -38,6 +38,8 @@ | |
#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" | |
using blink::WebDocument; | |
using blink::WebFrame; | |
@@ -48,6 +50,8 @@ using blink::WebURL; | |
using blink::WebView; | |
using content::DocumentState; | |
+std::unique_ptr<blink::TimeZoneController::TimeZoneOverride> timezone_override_; | |
+ | |
namespace content_settings { | |
namespace { | |
@@ -151,7 +155,9 @@ ContentSettingsAgentImpl::GetContentSettingsManager() { | |
void ContentSettingsAgentImpl::SetContentSettingRules( | |
const RendererContentSettingRules* content_setting_rules) { | |
+ VLOG(0) << "---ContentSettingsAgentImpl::SetContentSettingRules"; | |
content_setting_rules_ = content_setting_rules; | |
+ //UpdateOverrides(); | |
UMA_HISTOGRAM_COUNTS_1M("ClientHints.CountRulesReceived", | |
content_setting_rules_->client_hints_rules.size()); | |
} | |
@@ -346,6 +352,9 @@ bool ContentSettingsAgentImpl::AllowScript(bool enabled_per_settings) { | |
allow = allow || IsWhitelistedForContentSettings(); | |
cached_script_permissions_[frame] = allow; | |
+ | |
+ if (allow) UpdateOverrides(); | |
+ | |
return allow; | |
} | |
@@ -572,4 +581,91 @@ 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(); | |
+ | |
+ if( frame ) { VLOG(0) << "---Frame is not null"; } else { VLOG(0) << "---Frame is null"; } | |
+ VLOG(0) << "---" << url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL().spec(); | |
+ | |
+ setting = GetContentSettingFromRules( | |
+ content_setting_rules_->timezone_override_rules, frame, | |
+ url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()); | |
+ } | |
+ return UpdateTimeZoneOverride(setting) & | |
+ UpdateLocaleOverride(setting); | |
+} | |
+ | |
+bool ContentSettingsAgentImpl::UpdateTimeZoneOverride(ContentSetting setting) { | |
+ // base/i18n/icu_util.cc # 329 | |
+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride start"; | |
+ | |
+ /* 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 | |
+ timezone_id = "GMT+01:00"; | |
+ } else if( setting == CONTENT_SETTING_ASK) { | |
+ timezone_id = "GMT+00:00"; | |
+ // timezone 0 | |
+ } | |
+ | |
+ 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"; | |
+ return false; | |
+ } else { | |
+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - setting to " << timezone_id; | |
+ return true; | |
+ } | |
+ } else { | |
+ VLOG(0) << "---Bromite:ContentSettingsAgentImpl::UpdateTimeZoneOverride - already set"; | |
+ return false; | |
+ } | |
+} | |
+ | |
+ | |
+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 | |
old mode 100644 | |
new mode 100755 | |
index 3484035136..c83f98c01c | |
--- 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<mojom::ContentSettingsAgent> receivers_; | |
+ bool UpdateOverrides(); | |
+ bool UpdateTimeZoneOverride(ContentSetting setting); | |
+ bool UpdateLocaleOverride(ContentSetting setting); | |
+ | |
DISALLOW_COPY_AND_ASSIGN(ContentSettingsAgentImpl); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment