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