views_content_main_delegate.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2014 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 "ui/views_content_client/views_content_main_delegate.h"
  5. #include <string>
  6. #include "base/command_line.h"
  7. #include "base/files/file_path.h"
  8. #include "base/logging.h"
  9. #include "base/path_service.h"
  10. #include "build/build_config.h"
  11. #include "content/public/common/content_switches.h"
  12. #include "content/shell/browser/shell_paths.h"
  13. #include "ui/base/resource/resource_bundle.h"
  14. #include "ui/base/ui_base_paths.h"
  15. #include "ui/views_content_client/views_content_browser_client.h"
  16. #include "ui/views_content_client/views_content_client.h"
  17. #include "ui/views_content_client/views_content_client_main_parts.h"
  18. #if BUILDFLAG(IS_WIN)
  19. #include "base/logging_win.h"
  20. #endif
  21. namespace ui {
  22. namespace {
  23. #if BUILDFLAG(IS_WIN)
  24. // {83FAC8EE-7A0E-4dbb-A3F6-6F500D7CAB1A}
  25. const GUID kViewsContentClientProviderName =
  26. { 0x83fac8ee, 0x7a0e, 0x4dbb,
  27. { 0xa3, 0xf6, 0x6f, 0x50, 0xd, 0x7c, 0xab, 0x1a } };
  28. #endif
  29. } // namespace
  30. ViewsContentMainDelegate::ViewsContentMainDelegate(
  31. ViewsContentClient* views_content_client)
  32. : views_content_client_(views_content_client) {
  33. }
  34. ViewsContentMainDelegate::~ViewsContentMainDelegate() {
  35. }
  36. absl::optional<int> ViewsContentMainDelegate::BasicStartupComplete() {
  37. const base::CommandLine& command_line =
  38. *base::CommandLine::ForCurrentProcess();
  39. std::string process_type =
  40. command_line.GetSwitchValueASCII(switches::kProcessType);
  41. logging::LoggingSettings settings;
  42. settings.logging_dest =
  43. logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
  44. bool success = logging::InitLogging(settings);
  45. CHECK(success);
  46. #if BUILDFLAG(IS_WIN)
  47. logging::LogEventProvider::Initialize(kViewsContentClientProviderName);
  48. #endif
  49. content::RegisterShellPathProvider();
  50. return absl::nullopt;
  51. }
  52. void ViewsContentMainDelegate::PreSandboxStartup() {
  53. base::FilePath ui_test_pak_path;
  54. CHECK(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  55. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  56. // Load content resources to provide, e.g., sandbox configuration data on Mac.
  57. base::FilePath content_resources_pak_path;
  58. base::PathService::Get(base::DIR_ASSETS, &content_resources_pak_path);
  59. ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
  60. content_resources_pak_path.AppendASCII("content_resources.pak"),
  61. ui::k100Percent);
  62. if (ui::ResourceBundle::IsScaleFactorSupported(ui::k200Percent)) {
  63. base::FilePath ui_test_resources_200 = ui_test_pak_path.DirName().Append(
  64. FILE_PATH_LITERAL("ui_test_200_percent.pak"));
  65. ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
  66. ui_test_resources_200, ui::k200Percent);
  67. }
  68. views_content_client_->OnResourcesLoaded();
  69. }
  70. absl::optional<int> ViewsContentMainDelegate::PreBrowserMain() {
  71. absl::optional<int> exit_code =
  72. content::ContentMainDelegate::PreBrowserMain();
  73. if (exit_code.has_value())
  74. return exit_code;
  75. ViewsContentClientMainParts::PreBrowserMain();
  76. return absl::nullopt;
  77. }
  78. content::ContentClient* ViewsContentMainDelegate::CreateContentClient() {
  79. return &content_client_;
  80. }
  81. content::ContentBrowserClient*
  82. ViewsContentMainDelegate::CreateContentBrowserClient() {
  83. browser_client_ =
  84. std::make_unique<ViewsContentBrowserClient>(views_content_client_);
  85. return browser_client_.get();
  86. }
  87. } // namespace ui