adding suggestions

This commit is contained in:
Carmelo Messina 2020-09-03 09:28:09 +02:00
parent 6d9c47e8e6
commit ea53b99aa1

View file

@ -1,12 +1,12 @@
From: root <root@ubuntu.cabponte>
Date: Tue, 1 Sep 2020 13:42:04 +0000
Subject: Timezone Override
From: uazo <uazo@users.noreply.github.com>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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 <https://www.gnu.org/licenses/>.
+-->
+
+<!-- Layout used by the TimezoneOverrideSettingsPreference. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
@ -127,11 +145,23 @@ diff --git a/components/browser_ui/site_settings/android/java/res/layout/timezon
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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. -->
@@ -0,0 +1,68 @@
+<!--
+ 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 <https://www.gnu.org/licenses/>.
+-->
+
+<!-- Layout used by the TimezoneOverrideSettingsPreference. -->
+
@ -192,7 +222,7 @@ diff --git a/components/browser_ui/site_settings/android/java/res/xml/single_web
<ListPreference
android:key="javascript_permission_list" />
+ <ListPreference
+ android:key="timezone_override_permission_list" /> <!-- bromite #331 -->
+ android:key="timezone_override_permission_list" />
<ListPreference
android:key="popup_permission_list" />
<ListPreference
@ -203,7 +233,7 @@ diff --git a/components/browser_ui/site_settings/android/java/res/xml/site_setti
<org.chromium.components.browser_ui.settings.IconPreference
android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings"
android:key="javascript" />
+ <!-- Timezone Override (bromite #331) -->
+ <!-- Timezone Override -->
+ <org.chromium.components.browser_ui.settings.IconPreference
+ android:key="timezone_override"
+ android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings" />
@ -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 <https://www.gnu.org/licenses/>.
+*/
+
+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
+ <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_RANDOM_TEXT" desc="Primary text explaining that sites are not allowed to access system timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_RANDOM_TEXT" desc="Primary text for random 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_CUSTOM" desc="Summary text explaining that that sites are not allowed to access system timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_CUSTOM" desc="Summary text explaining that sites use custom timezone.">
+ Use custom timezone
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_CUSTOM_HINT" desc="Summary text explaining that that sites are not allowed to access system timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_CUSTOM_HINT" desc="Hint text for edit custom timezone.">
+ Default UTC
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_RANDOM" desc="Summary text explaining that sites are not allowed to access system timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_TIMEZONE_OVERRIDE_RANDOM" desc="Summary text for random timezone.">
+ Use random timezone for each page
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_BUTTON" desc="Primary button text for select timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_BUTTON" desc="Primary button text for select timezone from list.">
+ SELECT TIMEZONE FROM LIST
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_DIALOG_TITLE" desc="Primary button text for select timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_DIALOG_TITLE" desc="Text of dialog select timezone.">
+ Select Timezone
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_DIALOG_BUTTON" desc="Primary button text for select timezone.">
+ <message name="IDS_WEBSITE_SETTINGS_SELECT_DIALOG_BUTTON" desc="Primary button text in dialog for select timezone.">
+ Select
+ </message>
+
@ -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