feature_list.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. namespace electron {
  25. void InitializeFeatureList() {
  26. auto* cmd_line = base::CommandLine::ForCurrentProcess();
  27. auto enable_features =
  28. cmd_line->GetSwitchValueASCII(::switches::kEnableFeatures);
  29. auto disable_features =
  30. cmd_line->GetSwitchValueASCII(::switches::kDisableFeatures);
  31. // Disable creation of spare renderer process with site-per-process mode,
  32. // it interferes with our process preference tracking for non sandboxed mode.
  33. // Can be reenabled when our site instance policy is aligned with chromium
  34. // when node integration is enabled.
  35. disable_features +=
  36. std::string(",") + features::kSpareRendererForSitePerProcess.name;
  37. #if BUILDFLAG(IS_WIN)
  38. disable_features +=
  39. // Delayed spellcheck initialization is causing the
  40. // 'custom dictionary word list API' spec to crash.
  41. std::string(",") + spellcheck::kWinDelaySpellcheckServiceInit.name;
  42. #endif
  43. #if BUILDFLAG(IS_MAC)
  44. disable_features +=
  45. // MacWebContentsOcclusion is causing some odd visibility
  46. // issues with multiple web contents
  47. std::string(",") + features::kMacWebContentsOcclusion.name;
  48. #endif
  49. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  50. // Enable window.showSaveFilePicker api for saving pdf files.
  51. // Refs https://issues.chromium.org/issues/373852607
  52. enable_features +=
  53. std::string(",") + chrome_pdf::features::kPdfUseShowSaveFilePicker.name;
  54. #endif
  55. std::string platform_specific_enable_features =
  56. EnablePlatformSpecificFeatures();
  57. if (platform_specific_enable_features.size() > 0) {
  58. enable_features += std::string(",") + platform_specific_enable_features;
  59. }
  60. std::string platform_specific_disable_features =
  61. DisablePlatformSpecificFeatures();
  62. if (platform_specific_disable_features.size() > 0) {
  63. disable_features += std::string(",") + platform_specific_disable_features;
  64. }
  65. base::FeatureList::InitInstance(enable_features, disable_features);
  66. }
  67. void InitializeFieldTrials() {
  68. auto* cmd_line = base::CommandLine::ForCurrentProcess();
  69. auto force_fieldtrials =
  70. cmd_line->GetSwitchValueASCII(::switches::kForceFieldTrials);
  71. base::FieldTrialList::CreateTrialsFromString(force_fieldtrials);
  72. }
  73. #if !BUILDFLAG(IS_MAC)
  74. std::string EnablePlatformSpecificFeatures() {
  75. return "";
  76. }
  77. std::string DisablePlatformSpecificFeatures() {
  78. return "";
  79. }
  80. #endif
  81. } // namespace electron