feature_list.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "electron/shell/browser/feature_list.h"
  5. #include <string>
  6. #include "base/base_switches.h"
  7. #include "base/command_line.h"
  8. #include "base/feature_list.h"
  9. #include "base/metrics/field_trial.h"
  10. #include "components/spellcheck/common/spellcheck_features.h"
  11. #include "content/common/features.h"
  12. #include "content/public/common/content_features.h"
  13. #include "electron/buildflags/buildflags.h"
  14. #include "media/base/media_switches.h"
  15. #include "net/base/features.h"
  16. #include "services/network/public/cpp/features.h"
  17. #include "third_party/blink/public/common/features.h"
  18. #if BUILDFLAG(IS_MAC)
  19. #include "device/base/features.h" // nogncheck
  20. #endif
  21. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  22. #include "pdf/pdf_features.h"
  23. #endif
  24. #if BUILDFLAG(IS_LINUX)
  25. #include "printing/printing_features.h"
  26. #endif
  27. namespace electron {
  28. void InitializeFeatureList() {
  29. auto* cmd_line = base::CommandLine::ForCurrentProcess();
  30. auto enable_features =
  31. cmd_line->GetSwitchValueASCII(::switches::kEnableFeatures);
  32. auto disable_features =
  33. cmd_line->GetSwitchValueASCII(::switches::kDisableFeatures);
  34. // Disable creation of spare renderer process with site-per-process mode,
  35. // it interferes with our process preference tracking for non sandboxed mode.
  36. // Can be reenabled when our site instance policy is aligned with chromium
  37. // when node integration is enabled.
  38. disable_features +=
  39. std::string(",") + features::kSpareRendererForSitePerProcess.name;
  40. #if BUILDFLAG(IS_WIN)
  41. disable_features +=
  42. // Delayed spellcheck initialization is causing the
  43. // 'custom dictionary word list API' spec to crash.
  44. std::string(",") + spellcheck::kWinDelaySpellcheckServiceInit.name;
  45. #endif
  46. #if BUILDFLAG(IS_MAC)
  47. disable_features +=
  48. // MacWebContentsOcclusion is causing some odd visibility
  49. // issues with multiple web contents
  50. std::string(",") + features::kMacWebContentsOcclusion.name;
  51. #endif
  52. #if BUILDFLAG(IS_LINUX)
  53. disable_features +=
  54. // EnableOopPrintDrivers is still a bit half-baked on Linux and
  55. // causes crashes when trying to show dialogs.
  56. // TODO(codebytere): figure out how to re-enable this with our patches.
  57. std::string(",") + printing::features::kEnableOopPrintDrivers.name;
  58. #endif
  59. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  60. // Enable window.showSaveFilePicker api for saving pdf files.
  61. // Refs https://issues.chromium.org/issues/373852607
  62. enable_features +=
  63. std::string(",") + chrome_pdf::features::kPdfUseShowSaveFilePicker.name;
  64. #endif
  65. std::string platform_specific_enable_features =
  66. EnablePlatformSpecificFeatures();
  67. if (platform_specific_enable_features.size() > 0) {
  68. enable_features += std::string(",") + platform_specific_enable_features;
  69. }
  70. std::string platform_specific_disable_features =
  71. DisablePlatformSpecificFeatures();
  72. if (platform_specific_disable_features.size() > 0) {
  73. disable_features += std::string(",") + platform_specific_disable_features;
  74. }
  75. base::FeatureList::InitInstance(enable_features, disable_features);
  76. }
  77. void InitializeFieldTrials() {
  78. auto* cmd_line = base::CommandLine::ForCurrentProcess();
  79. auto force_fieldtrials =
  80. cmd_line->GetSwitchValueASCII(::switches::kForceFieldTrials);
  81. base::FieldTrialList::CreateTrialsFromString(force_fieldtrials);
  82. }
  83. #if !BUILDFLAG(IS_MAC)
  84. std::string EnablePlatformSpecificFeatures() {
  85. return "";
  86. }
  87. std::string DisablePlatformSpecificFeatures() {
  88. return "";
  89. }
  90. #endif
  91. } // namespace electron