OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/mus/aura_init.h" | 5 #include "ui/views/mus/aura_init.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "services/catalog/public/cpp/resource_loader.h" | 13 #include "services/catalog/public/cpp/resource_loader.h" |
14 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
16 #include "ui/base/ime/input_method_initializer.h" | 16 #include "ui/base/ime/input_method_initializer.h" |
17 #include "ui/base/material_design/material_design_controller.h" | 17 #include "ui/base/material_design/material_design_controller.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/base/ui_base_paths.h" | 19 #include "ui/base/ui_base_paths.h" |
20 #include "ui/views/views_delegate.h" | 20 #include "ui/views/views_delegate.h" |
21 | 21 |
22 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
23 #include "components/font_service/public/cpp/font_loader.h" | 23 #include "components/font_service/public/cpp/font_loader.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace views { | 26 namespace views { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 std::set<std::string> GetResourcePaths(const std::string& resource_file) { | |
31 std::set<std::string> paths; | |
32 paths.insert(resource_file); | |
33 return paths; | |
34 } | |
35 | |
36 class MusViewsDelegate : public ViewsDelegate { | 30 class MusViewsDelegate : public ViewsDelegate { |
37 public: | 31 public: |
38 MusViewsDelegate() {} | 32 MusViewsDelegate() {} |
39 ~MusViewsDelegate() override {} | 33 ~MusViewsDelegate() override {} |
40 | 34 |
41 private: | 35 private: |
42 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
43 HICON GetSmallWindowIcon() const override { return nullptr; } | 37 HICON GetSmallWindowIcon() const override { return nullptr; } |
44 #endif | 38 #endif |
45 void OnBeforeWidgetInit( | 39 void OnBeforeWidgetInit( |
46 Widget::InitParams* params, | 40 Widget::InitParams* params, |
47 internal::NativeWidgetDelegate* delegate) override {} | 41 internal::NativeWidgetDelegate* delegate) override {} |
48 | 42 |
49 DISALLOW_COPY_AND_ASSIGN(MusViewsDelegate); | 43 DISALLOW_COPY_AND_ASSIGN(MusViewsDelegate); |
50 }; | 44 }; |
51 | 45 |
52 } // namespace | 46 } // namespace |
53 | 47 |
54 AuraInit::AuraInit(shell::Connector* connector, | 48 AuraInit::AuraInit(shell::Connector* connector, |
55 const std::string& resource_file) | 49 const std::string& resource_file, |
| 50 const std::string& resource_file_200) |
56 : resource_file_(resource_file), | 51 : resource_file_(resource_file), |
| 52 resource_file_200_(resource_file_200), |
57 env_(aura::Env::CreateInstance()), | 53 env_(aura::Env::CreateInstance()), |
58 views_delegate_(new MusViewsDelegate) { | 54 views_delegate_(new MusViewsDelegate) { |
59 ui::MaterialDesignController::Initialize(); | 55 ui::MaterialDesignController::Initialize(); |
60 InitializeResources(connector); | 56 InitializeResources(connector); |
61 | 57 |
62 ui::InitializeInputMethodForTesting(); | 58 ui::InitializeInputMethodForTesting(); |
63 } | 59 } |
64 | 60 |
65 AuraInit::~AuraInit() { | 61 AuraInit::~AuraInit() { |
66 #if defined(OS_LINUX) | 62 #if defined(OS_LINUX) |
67 if (font_loader_.get()) { | 63 if (font_loader_.get()) { |
68 SkFontConfigInterface::SetGlobal(nullptr); | 64 SkFontConfigInterface::SetGlobal(nullptr); |
69 // FontLoader is ref counted. We need to explicitly shutdown the background | 65 // FontLoader is ref counted. We need to explicitly shutdown the background |
70 // thread, otherwise the background thread may be shutdown after the app is | 66 // thread, otherwise the background thread may be shutdown after the app is |
71 // torn down, when we're in a bad state. | 67 // torn down, when we're in a bad state. |
72 font_loader_->Shutdown(); | 68 font_loader_->Shutdown(); |
73 } | 69 } |
74 #endif | 70 #endif |
75 } | 71 } |
76 | 72 |
77 void AuraInit::InitializeResources(shell::Connector* connector) { | 73 void AuraInit::InitializeResources(shell::Connector* connector) { |
78 if (ui::ResourceBundle::HasSharedInstance()) | 74 if (ui::ResourceBundle::HasSharedInstance()) |
79 return; | 75 return; |
| 76 |
| 77 std::set<std::string> resource_paths({resource_file_}); |
| 78 if (!resource_file_200_.empty()) |
| 79 resource_paths.insert(resource_file_200_); |
| 80 |
80 catalog::ResourceLoader loader; | 81 catalog::ResourceLoader loader; |
81 filesystem::mojom::DirectoryPtr directory; | 82 filesystem::mojom::DirectoryPtr directory; |
82 connector->ConnectToInterface("mojo:catalog", &directory); | 83 connector->ConnectToInterface("mojo:catalog", &directory); |
83 CHECK(loader.OpenFiles(std::move(directory), | 84 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); |
84 GetResourcePaths(resource_file_))); | |
85 ui::RegisterPathProvider(); | 85 ui::RegisterPathProvider(); |
86 base::File pak_file = loader.TakeFile(resource_file_); | 86 base::File pak_file = loader.TakeFile(resource_file_); |
87 base::File pak_file_2 = pak_file.Duplicate(); | 87 base::File pak_file_2 = pak_file.Duplicate(); |
88 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 88 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
89 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); | 89 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); |
90 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 90 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
91 std::move(pak_file_2), ui::SCALE_FACTOR_100P); | 91 std::move(pak_file_2), ui::SCALE_FACTOR_100P); |
| 92 if (!resource_file_200_.empty()) |
| 93 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 94 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); |
92 | 95 |
93 // Initialize the skia font code to go ask fontconfig underneath. | 96 // Initialize the skia font code to go ask fontconfig underneath. |
94 #if defined(OS_LINUX) | 97 #if defined(OS_LINUX) |
95 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); | 98 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); |
96 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 99 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
97 #endif | 100 #endif |
98 | 101 |
99 // There is a bunch of static state in gfx::Font, by running this now, | 102 // There is a bunch of static state in gfx::Font, by running this now, |
100 // before any other apps load, we ensure all the state is set up. | 103 // before any other apps load, we ensure all the state is set up. |
101 gfx::Font(); | 104 gfx::Font(); |
102 } | 105 } |
103 | 106 |
104 } // namespace views | 107 } // namespace views |
OLD | NEW |