add-flag-for-custom-ntp.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --- a/chrome/browser/chrome_content_browser_client.cc
  2. +++ b/chrome/browser/chrome_content_browser_client.cc
  3. @@ -871,10 +871,14 @@ bool HandleNewTabPageLocationOverride(
  4. // Don't change the URL when incognito mode.
  5. if (profile->IsOffTheRecord())
  6. + if (!base::CommandLine::ForCurrentProcess()->HasSwitch("custom-ntp"))
  7. return false;
  8. std::string ntp_location =
  9. profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
  10. + if (base::CommandLine::ForCurrentProcess()->HasSwitch("custom-ntp"))
  11. + ntp_location = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("custom-ntp");
  12. + if (profile->IsOffTheRecord() && ntp_location.find("chrome://") != std::string::npos) return false;
  13. if (ntp_location.empty())
  14. return false;
  15. url::Component scheme;
  16. --- a/chrome/browser/ungoogled_flag_entries.h
  17. +++ b/chrome/browser/ungoogled_flag_entries.h
  18. @@ -76,4 +76,8 @@
  19. "Close Confirmation",
  20. "Show a warning prompt when closing the browser window. ungoogled-chromium flag",
  21. kOsDesktop, MULTI_VALUE_TYPE(kCloseConfirmation)},
  22. + {"custom-ntp",
  23. + "Custom New Tab Page",
  24. + "Allows setting a custom URL for the new tab page. Value can be internal (e.g. `about:blank` or `chrome://new-tab-page`), external (e.g. `example.com`), or local (e.g. `file:///tmp/startpage.html`). This applies for incognito windows as well when not set to a `chrome://` internal page. ungoogled-chromium flag",
  25. + kOsDesktop, ORIGIN_LIST_VALUE_TYPE("custom-ntp", "")},
  26. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_
  27. --- a/components/flags_ui/flags_state.cc
  28. +++ b/components/flags_ui/flags_state.cc
  29. @@ -222,6 +222,7 @@ std::string GetCombinedOriginListValue(c
  30. command_line.GetSwitchValueASCII(command_line_switch);
  31. const std::string new_value =
  32. flags_storage.GetOriginListFlag(internal_entry_name);
  33. + if (command_line_switch == "custom-ntp") return existing_value.empty() ? new_value : existing_value;
  34. return CombineAndSanitizeOriginLists(existing_value, new_value);
  35. }
  36. @@ -460,6 +461,7 @@ void FlagsState::SetOriginListFlag(const
  37. const std::string& value,
  38. FlagsStorage* flags_storage) {
  39. const std::string new_value =
  40. + internal_name == "custom-ntp" ? value :
  41. CombineAndSanitizeOriginLists(std::string(), value);
  42. flags_storage->SetOriginListFlag(internal_name, new_value);