Disable-text-fragments-by-default.patch 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sat, 22 Aug 2020 12:46:20 +0200
  3. Subject: Disable text fragments by default
  4. Revert "[Text Fragment] Unflag fragment directive removal."
  5. ---
  6. chrome/browser/about_flags.cc | 1 +
  7. chrome/browser/flag-metadata.json | 2 +-
  8. chrome/browser/ui/prefs/prefs_tab_helper.cc | 2 +-
  9. content/child/runtime_features.cc | 1 +
  10. third_party/blink/common/features.cc | 2 +-
  11. .../blink/renderer/core/dom/document.cc | 5 ++++
  12. .../text_fragment_anchor_metrics_test.cc | 29 +++++++------------
  13. .../platform/runtime_enabled_features.json5 | 3 +-
  14. 8 files changed, 21 insertions(+), 24 deletions(-)
  15. diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  16. --- a/chrome/browser/about_flags.cc
  17. +++ b/chrome/browser/about_flags.cc
  18. @@ -5612,6 +5612,7 @@ const FeatureEntry kFeatureEntries[] = {
  19. flag_descriptions::kSharingHubDesktopOmniboxDescription, kOsDesktop,
  20. FEATURE_VALUE_TYPE(sharing_hub::kSharingHubDesktopOmnibox)},
  21. #endif // defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX)
  22. + // will override runtime text fragment identifiers setting too
  23. #if BUILDFLAG(IS_CHROMEOS_ASH)
  24. {"ash-enable-pip-rounded-corners",
  25. diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
  26. --- a/chrome/browser/flag-metadata.json
  27. +++ b/chrome/browser/flag-metadata.json
  28. @@ -3058,7 +3058,7 @@
  29. {
  30. "name": "ev-details-in-page-info",
  31. "owners": [ "cthomp" ],
  32. - "expiry_milestone": 83
  33. + "expiry_milestone": -1
  34. },
  35. {
  36. "name": "exo-gamepad-vibration",
  37. diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc
  38. --- a/chrome/browser/ui/prefs/prefs_tab_helper.cc
  39. +++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc
  40. @@ -360,7 +360,7 @@ void PrefsTabHelper::RegisterProfilePrefs(
  41. prefs::kEnableReferrers,
  42. !base::FeatureList::IsEnabled(features::kNoReferrers));
  43. registry->RegisterBooleanPref(prefs::kEnableEncryptedMedia, true);
  44. - registry->RegisterBooleanPref(prefs::kScrollToTextFragmentEnabled, true);
  45. + registry->RegisterBooleanPref(prefs::kScrollToTextFragmentEnabled, false);
  46. #if defined(OS_ANDROID)
  47. registry->RegisterDoublePref(prefs::kWebKitFontScaleFactor, 1.0);
  48. registry->RegisterBooleanPref(prefs::kWebKitForceEnableZoom,
  49. diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc
  50. --- a/content/child/runtime_features.cc
  51. +++ b/content/child/runtime_features.cc
  52. @@ -263,6 +263,7 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
  53. {wf::EnableMouseSubframeNoImplicitCapture,
  54. features::kMouseSubframeNoImplicitCapture},
  55. {wf::EnableNeverSlowMode, features::kNeverSlowMode},
  56. + // will set the TextFragmentIdentifiers runtime feature
  57. {wf::EnableNotificationContentImage, features::kNotificationContentImage,
  58. kSetOnlyIfOverridden},
  59. {wf::EnableParseUrlProtocolHandler,
  60. diff --git a/third_party/blink/common/features.cc b/third_party/blink/common/features.cc
  61. --- a/third_party/blink/common/features.cc
  62. +++ b/third_party/blink/common/features.cc
  63. @@ -379,7 +379,7 @@ const base::Feature kStorageAccessAPI{"StorageAccessAPI",
  64. // Enable text snippets in URL fragments. https://crbug.com/919204.
  65. const base::Feature kTextFragmentAnchor{"TextFragmentAnchor",
  66. - base::FEATURE_ENABLED_BY_DEFAULT};
  67. + base::FEATURE_DISABLED_BY_DEFAULT};
  68. // File handling integration. https://crbug.com/829689
  69. const base::Feature kFileHandlingAPI{"FileHandlingAPI",
  70. diff --git a/third_party/blink/renderer/core/dom/document.cc b/third_party/blink/renderer/core/dom/document.cc
  71. --- a/third_party/blink/renderer/core/dom/document.cc
  72. +++ b/third_party/blink/renderer/core/dom/document.cc
  73. @@ -4063,6 +4063,10 @@ void Document::SetURL(const KURL& url) {
  74. }
  75. }
  76. + // If text fragment identifiers are enabled, we strip the fragment directive
  77. + // from the URL fragment.
  78. + // E.g. "#id:~:text=a" --> "#id"
  79. + if (RuntimeEnabledFeatures::TextFragmentIdentifiersEnabled(domWindow())) {
  80. // Strip the fragment directive from the URL fragment. E.g. "#id:~:text=a"
  81. // --> "#id". See https://github.com/WICG/scroll-to-text-fragment.
  82. String fragment = new_url.FragmentIdentifier();
  83. @@ -4076,6 +4080,7 @@ void Document::SetURL(const KURL& url) {
  84. else
  85. new_url.SetFragmentIdentifier(fragment.Substring(0, start_pos));
  86. }
  87. + }
  88. url_ = new_url;
  89. access_entry_from_url_ = nullptr;
  90. diff --git a/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_metrics_test.cc b/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_metrics_test.cc
  91. --- a/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_metrics_test.cc
  92. +++ b/third_party/blink/renderer/core/page/scrolling/text_fragment_anchor_metrics_test.cc
  93. @@ -1249,34 +1249,25 @@ TEST_P(TextFragmentRelatedMetricTest, ElementIdSuccessFailureCounts) {
  94. // result of the element-id fragment if a text directive is successfully
  95. // parsed. If the feature is off we treat the text directive as an element-id
  96. // and should count the result.
  97. + const int kUncountedOrNotFound = GetParam() ? kUncounted : kNotFound;
  98. const int kUncountedOrFound = GetParam() ? kUncounted : kFound;
  99. - // Note: We'll strip the fragment directive (i.e. anything after :~:) leaving
  100. - // just the element anchor. The fragment directive stripping behavior is now
  101. - // shipped unflagged so it should always be performed.
  102. + // When the TextFragmentAnchors feature is on, we'll strip the fragment
  103. + // directive (i.e. anything after :~:) leaving just the element anchor.
  104. + const int kFoundIfDirectiveStripped = GetParam() ? kFound : kNotFound;
  105. Vector<std::pair<String, int>> test_cases = {
  106. {"", kUncounted},
  107. {"#element", kFound},
  108. {"#doesntExist", kNotFound},
  109. - // `:~:foo` will be stripped so #element will be found and #doesntexist
  110. - // ##element will be not found.
  111. - {"#element:~:foo", kFound},
  112. + {"#element:~:foo", kFoundIfDirectiveStripped},
  113. {"#doesntexist:~:foo", kNotFound},
  114. {"##element", kNotFound},
  115. - // If the feature is on, `:~:text=` will parse so we shouldn't count.
  116. - // Otherwise, it'll just be stripped so #element will be found.
  117. - {"#element:~:text=doesntexist", kUncountedOrFound},
  118. - {"#element:~:text=page", kUncountedOrFound},
  119. - // If the feature is on, `:~:text` is parsed so we don't count. If it's
  120. - // off the entire fragment is a directive that's stripped so no search is
  121. - // performed either.
  122. - {"#:~:text=doesntexist", kUncounted},
  123. - {"#:~:text=page", kUncounted},
  124. - {"#:~:text=name", kUncounted},
  125. - // If the feature is enabled, `:~:text` parses and we don't count the
  126. - // element-id. If the feature is off, we still strip the :~: directive
  127. - // and the remaining fragment does match an element id.
  128. + {"#element:~:text=doesntexist", kUncountedOrNotFound},
  129. + {"#element:~:text=page", kUncountedOrNotFound},
  130. + {"#:~:text=doesntexist", kUncountedOrNotFound},
  131. + {"#:~:text=page", kUncountedOrNotFound},
  132. + {"#:~:text=name", kUncountedOrFound},
  133. {"#element:~:text=name", kUncountedOrFound}};
  134. const int kNotFoundSample = 0;
  135. diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  136. --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
  137. +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  138. @@ -2173,8 +2173,7 @@
  139. },
  140. {
  141. name: "TextFragmentIdentifiers",
  142. - origin_trial_feature_name: "TextFragmentIdentifiers",
  143. - status: "stable",
  144. + origin_trial_feature_name: "TextFragmentIdentifiers"
  145. },
  146. {
  147. name: "TextFragmentTapOpensContextMenu",
  148. --
  149. 2.20.1