web_engine_main.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/command_line.h"
  5. #include "base/logging.h"
  6. #include "components/fuchsia_component_support/config_reader.h"
  7. #include "content/public/app/content_main.h"
  8. #include "content/public/common/content_switches.h"
  9. #include "fuchsia_web/webengine/browser/web_engine_config.h"
  10. #include "fuchsia_web/webengine/context_provider_main.h"
  11. #include "fuchsia_web/webengine/switches.h"
  12. #include "fuchsia_web/webengine/web_engine_main_delegate.h"
  13. static void LoadConfigAndUpdateCommandLine(base::CommandLine* command_line) {
  14. // Config file needs to be loaded only in the browser process.
  15. bool is_browser_process =
  16. command_line->GetSwitchValueASCII(switches::kProcessType).empty();
  17. if (!is_browser_process)
  18. return;
  19. const absl::optional<base::Value>& config =
  20. fuchsia_component_support::LoadPackageConfig();
  21. if (!config)
  22. return;
  23. bool config_valid =
  24. UpdateCommandLineFromConfigFile(config.value(), command_line);
  25. if (!config_valid)
  26. LOG(FATAL) << "WebEngine config is invalid.";
  27. }
  28. int main(int argc, const char** argv) {
  29. base::CommandLine::Init(argc, argv);
  30. auto* const command_line = base::CommandLine::ForCurrentProcess();
  31. if (command_line->HasSwitch(switches::kContextProvider))
  32. return ContextProviderMain();
  33. LoadConfigAndUpdateCommandLine(command_line);
  34. WebEngineMainDelegate delegate;
  35. content::ContentMainParams params(&delegate);
  36. // Repeated base::CommandLine::Init() is ignored, so it's safe to pass null
  37. // args here.
  38. params.argc = 0;
  39. params.argv = nullptr;
  40. return content::ContentMain(std::move(params));
  41. }