Add-custom-tab-intents-privacy-option.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Wed, 29 Aug 2018 11:03:44 +0200
  3. Subject: Add custom tab intents privacy option
  4. Add custom tab intents privacy option and force
  5. open external links in incognito flag.
  6. Flags are mutually exclusive.
  7. See also: https://github.com/bromite/bromite/issues/1474
  8. ---
  9. .../java/res/xml/privacy_preferences.xml | 10 ++++++++
  10. .../browser/LaunchIntentDispatcher.java | 22 +++++++++++++++++
  11. .../IncognitoCustomTabIntentDataProvider.java | 6 +++++
  12. .../privacy/settings/PrivacySettings.java | 24 +++++++++++++++++++
  13. .../chrome/browser/tab/TabAssociatedApp.java | 6 ++++-
  14. .../strings/android_chrome_strings.grd | 15 ++++++++++++
  15. 6 files changed, 82 insertions(+), 1 deletion(-)
  16. diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
  17. --- a/chrome/android/java/res/xml/privacy_preferences.xml
  18. +++ b/chrome/android/java/res/xml/privacy_preferences.xml
  19. @@ -65,6 +65,16 @@
  20. android:fragment="org.chromium.chrome.browser.privacy.settings.DoNotTrackSettings"
  21. android:key="do_not_track"
  22. android:title="@string/do_not_track_title"/>
  23. + <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
  24. + android:key="allow_custom_tab_intents"
  25. + android:title="@string/allow_custom_tab_intents_title"
  26. + android:summary="@string/allow_custom_tab_intents_summary"
  27. + android:defaultValue="false" />
  28. + <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
  29. + android:key="open_external_links_incognito"
  30. + android:title="@string/open_external_links_incognito_title"
  31. + android:summary="@string/open_external_links_incognito_summary"
  32. + android:defaultValue="false" />
  33. <Preference
  34. android:key="privacy_sandbox"
  35. android:title="@string/prefs_privacy_sandbox"
  36. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
  37. --- a/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
  38. +++ b/chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java
  39. @@ -46,6 +46,7 @@ import org.chromium.chrome.browser.notifications.NotificationPlatformBridge;
  40. import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
  41. import org.chromium.chrome.browser.searchwidget.SearchActivity;
  42. import org.chromium.chrome.browser.tab.Tab;
  43. +import org.chromium.chrome.browser.tab.TabLaunchType;
  44. import org.chromium.chrome.browser.translate.TranslateIntentHandler;
  45. import org.chromium.chrome.browser.util.AndroidTaskUtils;
  46. import org.chromium.chrome.browser.vr.VrModuleProvider;
  47. @@ -59,6 +60,8 @@ import java.lang.annotation.Retention;
  48. import java.lang.annotation.RetentionPolicy;
  49. import java.util.Set;
  50. +import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
  51. +
  52. /**
  53. * Dispatches incoming intents to the appropriate activity based on the current configuration and
  54. * Intent fired.
  55. @@ -279,6 +282,9 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
  56. */
  57. public static boolean isCustomTabIntent(Intent intent) {
  58. if (intent == null) return false;
  59. + if (!ContextUtils.getAppSharedPreferences()
  60. + .getBoolean(PrivacySettings.PREF_ALLOW_CUSTOM_TAB_INTENTS, false))
  61. + return false;
  62. if (CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)
  63. || !intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)) {
  64. return false;
  65. @@ -298,6 +304,10 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
  66. newIntent.setData(uri);
  67. newIntent.setClassName(context, CustomTabActivity.class.getName());
  68. + if (ContextUtils.getAppSharedPreferences()
  69. + .getBoolean(PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false))
  70. + newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
  71. +
  72. // Since configureIntentForResizableCustomTab() might change the componenet/class
  73. // associated with the passed intent, it needs to be called after #setClassName(context,
  74. // CustomTabActivity.class.getName());
  75. @@ -417,6 +427,18 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
  76. if (Intent.ACTION_VIEW.equals(newIntent.getAction())
  77. && !IntentHandler.wasIntentSenderChrome(newIntent)) {
  78. +
  79. + if (ContextUtils.getAppSharedPreferences().getBoolean(
  80. + PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false)) {
  81. + Context applicationContext = ContextUtils.getApplicationContext();
  82. + newIntent = IntentHandler.createTrustedOpenNewTabIntent(applicationContext,
  83. + /*incognito*/true);
  84. + newIntent.setData(mIntent.getData());
  85. + newIntent.setPackage(applicationContext.getPackageName());
  86. + IntentHandler.setTabLaunchType(newIntent, TabLaunchType.FROM_EXTERNAL_APP);
  87. + newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  88. + }
  89. +
  90. long time = SystemClock.elapsedRealtime();
  91. if (!chromeTabbedTaskExists()) {
  92. newIntent.putExtra(IntentHandler.EXTRA_STARTED_TABBED_CHROME_TASK, true);
  93. 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
  94. --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java
  95. +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java
  96. @@ -36,6 +36,9 @@ import org.chromium.components.browser_ui.widget.TintedDrawable;
  97. import java.util.ArrayList;
  98. import java.util.List;
  99. +import org.chromium.base.ContextUtils;
  100. +import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
  101. +
  102. /**
  103. * A model class that parses the incoming intent for incognito Custom Tabs specific customization
  104. * data.
  105. @@ -109,6 +112,9 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
  106. }
  107. private static boolean isIntentFromThirdPartyAllowed() {
  108. + if (ContextUtils.getAppSharedPreferences()
  109. + .getBoolean(PrivacySettings.PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, false))
  110. + return true;
  111. return CachedFeatureFlags.isEnabled(
  112. ChromeFeatureList.CCT_INCOGNITO_AVAILABLE_TO_THIRD_PARTY);
  113. }
  114. 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
  115. --- a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
  116. +++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
  117. @@ -94,6 +94,9 @@ public class PrivacySettings
  118. private ManagedPreferenceDelegate mManagedPreferenceDelegate;
  119. private IncognitoLockSettings mIncognitoLockSettings;
  120. + private ChromeSwitchPreference allowCustomTabIntentsPref;
  121. + private ChromeSwitchPreference openExternalLinksPref;
  122. +
  123. @Override
  124. public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
  125. PrivacyPreferencesManagerImpl privacyPrefManager =
  126. @@ -206,6 +209,9 @@ public class PrivacySettings
  127. updatePreferences();
  128. }
  129. + public static final String PREF_ALLOW_CUSTOM_TAB_INTENTS = "allow_custom_tab_intents";
  130. + public static final String PREF_OPEN_EXTERNAL_LINKS_INCOGNITO = "open_external_links_incognito";
  131. +
  132. @Override
  133. public boolean onPreferenceChange(Preference preference, Object newValue) {
  134. String key = preference.getKey();
  135. @@ -237,6 +243,14 @@ public class PrivacySettings
  136. } else if (PREF_INCOGNITO_TAB_HISTORY_ENABLED.equals(key)) {
  137. UserPrefs.get(Profile.getLastUsedRegularProfile())
  138. .setBoolean(Pref.INCOGNITO_TAB_HISTORY_ENABLED, (boolean) newValue);
  139. + } else if (PREF_ALLOW_CUSTOM_TAB_INTENTS.equals(key)) {
  140. + SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
  141. + sharedPreferencesEditor.putBoolean(PREF_ALLOW_CUSTOM_TAB_INTENTS, (boolean)newValue);
  142. + sharedPreferencesEditor.apply();
  143. + } else if (PREF_OPEN_EXTERNAL_LINKS_INCOGNITO.equals(key)) {
  144. + SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
  145. + sharedPreferencesEditor.putBoolean(PREF_OPEN_EXTERNAL_LINKS_INCOGNITO, (boolean)newValue);
  146. + sharedPreferencesEditor.apply();
  147. }
  148. return true;
  149. }
  150. @@ -271,6 +285,16 @@ public class PrivacySettings
  151. canMakePaymentPref.setChecked(prefService.getBoolean(Pref.CAN_MAKE_PAYMENT_ENABLED));
  152. }
  153. + allowCustomTabIntentsPref =
  154. + (ChromeSwitchPreference) findPreference(PREF_ALLOW_CUSTOM_TAB_INTENTS);
  155. + allowCustomTabIntentsPref.setOnPreferenceChangeListener(this);
  156. + allowCustomTabIntentsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
  157. +
  158. + openExternalLinksPref =
  159. + (ChromeSwitchPreference) findPreference(PREF_OPEN_EXTERNAL_LINKS_INCOGNITO);
  160. + openExternalLinksPref.setOnPreferenceChangeListener(this);
  161. + openExternalLinksPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
  162. +
  163. Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK);
  164. if (doNotTrackPref != null) {
  165. doNotTrackPref.setSummary(prefService.getBoolean(Pref.ENABLE_DO_NOT_TRACK)
  166. 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
  167. --- a/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java
  168. +++ b/chrome/browser/tab/java/src/org/chromium/chrome/browser/tab/TabAssociatedApp.java
  169. @@ -84,7 +84,11 @@ public final class TabAssociatedApp extends TabWebContentsUserData implements Im
  170. public static boolean isOpenedFromExternalApp(Tab tab) {
  171. TabAssociatedApp app = get(tab);
  172. if (app == null) return false;
  173. -
  174. + if (ContextUtils.getAppSharedPreferences()
  175. + .getBoolean("open_external_links_incognito", false) &&
  176. + tab.isIncognito() &&
  177. + tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP)
  178. + return true;
  179. String packageName = ContextUtils.getApplicationContext().getPackageName();
  180. return tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP
  181. && !TextUtils.equals(app.getAppId(), packageName);
  182. diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd
  183. --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
  184. +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
  185. @@ -4625,6 +4625,21 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
  186. <message name="IDS_NEAR_OOM_REDUCTION_DECLINE" desc="The text of the button letting the user decline the browser's intervention, so that the page can be reloaded.">
  187. Show original
  188. </message>
  189. + <!-- Allow custom tab intents -->
  190. + <message name="IDS_ALLOW_CUSTOM_TAB_INTENTS_TITLE" desc="Text for 'Allow custom tab intents' settings-privacy option.">
  191. + Allow custom tab intents
  192. + </message>
  193. + <message name="IDS_ALLOW_CUSTOM_TAB_INTENTS_SUMMARY" desc="Summary text for 'Allow custom tab intents' settings-privacy option.">
  194. + Allow applications to open custom tab intents, similar to webview.
  195. + </message>
  196. +
  197. + <!-- Open External Links in Incognito -->
  198. + <message name="IDS_OPEN_EXTERNAL_LINKS_INCOGNITO_TITLE" desc="Text for 'Open external links in incognito' settings-privacy option.">
  199. + Open external links in incognito
  200. + </message>
  201. + <message name="IDS_OPEN_EXTERNAL_LINKS_INCOGNITO_SUMMARY" desc="Summary text for 'Open external links in incognito' settings-privacy option.">
  202. + Force the opening of all external links in incognito mode
  203. + </message>
  204. <!-- Autofill Assistant preferences -->
  205. <!-- TODO(b/168178344): Move to Assistant settings strings section below. -->
  206. --
  207. 2.20.1