forked from uazo/cromite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-custom-tab-intents-privacy-option.patch
242 lines (227 loc) · 13.9 KB
/
Add-custom-tab-intents-privacy-option.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
From: csagan5 <[email protected]>
Date: Wed, 29 Aug 2018 11:03:44 +0200
Subject: Add custom tab intents privacy option
Add custom tab intents privacy option and force
open external links in incognito flag.
Flags are mutually exclusive.
See also: https://github.com/bromite/bromite/issues/1474
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
.../java/res/xml/privacy_preferences.xml | 10 ++++++++
.../browser/LaunchIntentDispatcher.java | 21 ++++++++++++++++
.../customtabs/CustomTabsConnection.java | 1 +
.../IncognitoCustomTabIntentDataProvider.java | 6 +++++
.../privacy/settings/PrivacySettings.java | 24 +++++++++++++++++++
.../chrome/browser/tab/TabAssociatedApp.java | 6 ++++-
.../strings/android_chrome_strings.grd | 14 +++++++++++
.../core/common/language_experiments.cc | 1 +
.../add-custom-tab-intents-privacy-option.inc | 1 +
9 files changed, 83 insertions(+), 1 deletion(-)
create mode 100644 cromite_flags/chrome/browser/flags/android/chrome_feature_list_cc/add-custom-tab-intents-privacy-option.inc
diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
--- a/chrome/android/java/res/xml/privacy_preferences.xml
+++ b/chrome/android/java/res/xml/privacy_preferences.xml
@@ -43,6 +43,16 @@ found in the LICENSE file.
android:key="do_not_track"
android:title="@string/do_not_track_title"
android:fragment="org.chromium.chrome.browser.privacy.settings.DoNotTrackSettings" />
+ <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
+ android:key="allow_custom_tab_intents"
+ android:title="@string/allow_custom_tab_intents_title"
+ android:summary="@string/allow_custom_tab_intents_summary"
+ android:defaultValue="false" />
+ <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
+ android:key="open_external_links_incognito"
+ android:title="@string/open_external_links_incognito_title"
+ android:summary="@string/open_external_links_incognito_summary"
+ android:defaultValue="false" />
<Preference
android:key="preload_pages"
android:title="@string/preload_pages_title"
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
@@ -55,6 +55,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Set;
+import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
+import org.chromium.chrome.browser.tab.TabLaunchType;
+
/**
* Dispatches incoming intents to the appropriate activity based on the current configuration and
* Intent fired.
@@ -244,6 +247,9 @@ public class LaunchIntentDispatcher {
*/
public static boolean isCustomTabIntent(Intent intent) {
if (intent == null) return false;
+ if (!ContextUtils.getAppSharedPreferences()
+ .getBoolean(PrivacySettings.PREF_ALLOW_CUSTOM_TAB_INTENTS, false))
+ return false;
Log.w(
TAG,
"CustomTabsIntent#shouldAlwaysUseBrowserUI() = "
@@ -265,6 +271,10 @@ public class LaunchIntentDispatcher {
newIntent.setData(uri);
newIntent.setClassName(context, CustomTabActivity.class.getName());
+ if (ContextUtils.getAppSharedPreferences()
+ .getBoolean(PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false))
+ newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
+
// Since configureIntentForResizableCustomTab() might change the componenet/class
// associated with the passed intent, it needs to be called after #setClassName(context,
// CustomTabActivity.class.getName());
@@ -410,6 +420,17 @@ public class LaunchIntentDispatcher {
if (Intent.ACTION_VIEW.equals(newIntent.getAction())
&& !IntentHandler.wasIntentSenderChrome(newIntent)) {
+
+ if (ContextUtils.getAppSharedPreferences().getBoolean(
+ PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false)) {
+ Context applicationContext = ContextUtils.getApplicationContext();
+ newIntent = IntentHandler.createTrustedOpenNewTabIntent(applicationContext,
+ /*incognito*/true);
+ newIntent.setData(mIntent.getData());
+ newIntent.setPackage(applicationContext.getPackageName());
+ IntentHandler.setTabLaunchType(newIntent, TabLaunchType.FROM_EXTERNAL_APP);
+ newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
if (!chromeTabbedTaskExists()) {
newIntent.putExtra(IntentHandler.EXTRA_STARTED_TABBED_CHROME_TASK, true);
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
@@ -850,6 +850,7 @@ public class CustomTabsConnection {
PostTask.postTask(
TaskTraits.UI_DEFAULT,
() -> {
+ if ((true)) return; // Disable CCTPostMessageAPI
// Attempt to verify origin synchronously. If successful directly initialize
// postMessage channel for session.
Uri verifiedOrigin = verifyOriginForSession(session, uid, postMessageOrigin);
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java
@@ -38,6 +38,9 @@ import org.chromium.components.browser_ui.widget.TintedDrawable;
import java.util.ArrayList;
import java.util.List;
+import org.chromium.base.ContextUtils;
+import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
+
/**
* A model class that parses the incoming intent for incognito Custom Tabs specific customization
* data.
@@ -115,6 +118,9 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
}
private static boolean isIntentFromThirdPartyAllowed() {
+ if (ContextUtils.getAppSharedPreferences()
+ .getBoolean(PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false))
+ return true;
return ChromeFeatureList.sCctIncognitoAvailableToThirdParty.isEnabled();
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
@@ -96,6 +96,9 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
private ManagedPreferenceDelegate mManagedPreferenceDelegate;
private IncognitoLockSettings mIncognitoLockSettings;
+ private ChromeSwitchPreference allowCustomTabIntentsPref;
+ private ChromeSwitchPreference openExternalLinksPref;
+
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getActivity().setTitle(R.string.prefs_privacy_security);
@@ -274,6 +277,9 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
new SpanApplier.SpanInfo("<link2>", "</link2>", servicesLink));
}
+ public static final String PREF_ALLOW_CUSTOM_TAB_INTENTS = "allow_custom_tab_intents";
+ public static final String PREF_OPEN_EXTERNAL_LINKS_INCOGNITO = "open_external_links_incognito";
+
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
@@ -290,6 +296,14 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
} else if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
UserPrefs.get(getProfile())
.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue);
+ } else if (PREF_ALLOW_CUSTOM_TAB_INTENTS.equals(key)) {
+ SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
+ sharedPreferencesEditor.putBoolean(PREF_ALLOW_CUSTOM_TAB_INTENTS, (boolean)newValue);
+ sharedPreferencesEditor.apply();
+ } else if (PREF_OPEN_EXTERNAL_LINKS_INCOGNITO.equals(key)) {
+ SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
+ sharedPreferencesEditor.putBoolean(PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, (boolean)newValue);
+ sharedPreferencesEditor.apply();
}
return true;
}
@@ -312,6 +326,16 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
UserPrefs.get(getProfile()).getBoolean(Pref.CAN_MAKE_PAYMENT_ENABLED));
}
+ allowCustomTabIntentsPref =
+ (ChromeSwitchPreference) findPreference(PREF_ALLOW_CUSTOM_TAB_INTENTS);
+ allowCustomTabIntentsPref.setOnPreferenceChangeListener(this);
+ allowCustomTabIntentsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
+ openExternalLinksPref =
+ (ChromeSwitchPreference) findPreference(PREF_OPEN_EXTERNAL_LINKS_INCOGNITO);
+ openExternalLinksPref.setOnPreferenceChangeListener(this);
+ openExternalLinksPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK);
if (doNotTrackPref != null) {
doNotTrackPref.setSummary(
diff --git a/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java b/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java
--- a/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java
+++ b/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java
@@ -87,7 +87,11 @@ public final class TabAssociatedApp extends TabWebContentsUserData implements Im
public static boolean isOpenedFromExternalApp(Tab tab) {
TabAssociatedApp app = get(tab);
if (app == null) return false;
-
+ if (ContextUtils.getAppSharedPreferences()
+ .getBoolean("open_external_links_incognito", false) &&
+ tab.isIncognito() &&
+ tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP)
+ return true;
String packageName = ContextUtils.getApplicationContext().getPackageName();
return tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP
&& !TextUtils.equals(app.getAppId(), packageName);
diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd
--- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
+++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
@@ -5152,6 +5152,20 @@ To change this setting, <ph name="BEGIN_LINK">BEGIN_LINK</ph>clear the Chrome da
<message name="IDS_NEAR_OOM_INTERVENTION_DECLINE" desc="The text of the button letting the user decline the browser's intervention, so that the page can resume what it was doing.">
Resume
</message>
+ <!-- Allow custom tab intents -->
+ <message name="IDS_ALLOW_CUSTOM_TAB_INTENTS_TITLE" desc="Text for 'Allow custom tab intents' settings-privacy option.">
+ Allow custom tab intents
+ </message>
+ <message name="IDS_ALLOW_CUSTOM_TAB_INTENTS_SUMMARY" desc="Summary text for 'Allow custom tab intents' settings-privacy option.">
+ Allow applications to open custom tab intents, similar to webview.
+ </message>
+ <!-- Open External Links in Incognito -->
+ <message name="IDS_OPEN_EXTERNAL_LINKS_INCOGNITO_TITLE" desc="Text for 'Open external links in incognito' settings-privacy option.">
+ Open external links in incognito
+ </message>
+ <message name="IDS_OPEN_EXTERNAL_LINKS_INCOGNITO_SUMMARY" desc="Summary text for 'Open external links in incognito' settings-privacy option.">
+ Force the opening of all external links in incognito mode
+ </message>
<!-- Usage Stats strings -->
<message name="IDS_USAGE_STATS_CONSENT_TITLE" desc="Title for activity authorizing Digital Wellbeing to access Chrome usage data">
Show your Chrome activity in Digital Wellbeing?
diff --git a/components/language/core/common/language_experiments.cc b/components/language/core/common/language_experiments.cc
--- a/components/language/core/common/language_experiments.cc
+++ b/components/language/core/common/language_experiments.cc
@@ -24,4 +24,5 @@ BASE_FEATURE(kCctAutoTranslate,
// Params:
const char kContentLanguagesDisableObserversParam[] = "disable_observers";
+SET_CROMITE_FEATURE_DISABLED(kCctAutoTranslate);
} // namespace language
diff --git a/cromite_flags/chrome/browser/flags/android/chrome_feature_list_cc/add-custom-tab-intents-privacy-option.inc b/cromite_flags/chrome/browser/flags/android/chrome_feature_list_cc/add-custom-tab-intents-privacy-option.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/chrome/browser/flags/android/chrome_feature_list_cc/add-custom-tab-intents-privacy-option.inc
@@ -0,0 +1 @@
+SET_CROMITE_FEATURE_DISABLED(kCCTIntentFeatureOverrides);
--