OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "blimp/client/app/blimp_startup.h" | 12 #include "blimp/client/app/blimp_startup.h" |
13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h" | 13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h" |
14 #include "blimp/client/app/linux/blimp_display_manager.h" | 14 #include "blimp/client/app/linux/blimp_display_manager.h" |
15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h" | 15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h" |
16 #include "blimp/client/core/settings/settings_prefs.h" | 16 #include "blimp/client/core/settings/settings_prefs.h" |
| 17 #include "blimp/client/core/switches/blimp_client_switches.h" |
17 #include "blimp/client/public/blimp_client_context.h" | 18 #include "blimp/client/public/blimp_client_context.h" |
18 #include "blimp/client/public/contents/blimp_navigation_controller.h" | 19 #include "blimp/client/public/contents/blimp_navigation_controller.h" |
19 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" | 20 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "components/prefs/command_line_pref_store.h" | 22 #include "components/prefs/command_line_pref_store.h" |
22 #include "components/prefs/in_memory_pref_store.h" | 23 #include "components/prefs/in_memory_pref_store.h" |
23 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
24 #include "components/prefs/pref_service_factory.h" | 25 #include "components/prefs/pref_service_factory.h" |
| 26 #include "skia/ext/fontmgr_default_linux.h" |
| 27 #include "third_party/skia/include/ports/SkFontConfigInterface.h" |
| 28 #include "third_party/skia/include/ports/SkFontMgr.h" |
| 29 #include "third_party/skia/include/ports/SkFontMgr_android.h" |
25 #include "ui/gfx/x/x11_connection.h" | 30 #include "ui/gfx/x/x11_connection.h" |
26 | 31 |
27 namespace { | 32 namespace { |
28 const char kDefaultUrl[] = "https://www.google.com"; | 33 const char kDefaultUrl[] = "https://www.google.com"; |
29 constexpr int kWindowWidth = 800; | 34 constexpr int kWindowWidth = 800; |
30 constexpr int kWindowHeight = 600; | 35 constexpr int kWindowHeight = 600; |
31 | 36 |
32 class BlimpShellCommandLinePrefStore : public CommandLinePrefStore { | 37 class BlimpShellCommandLinePrefStore : public CommandLinePrefStore { |
33 public: | 38 public: |
34 explicit BlimpShellCommandLinePrefStore(const base::CommandLine* command_line) | 39 explicit BlimpShellCommandLinePrefStore(const base::CommandLine* command_line) |
35 : CommandLinePrefStore(command_line) { | 40 : CommandLinePrefStore(command_line) { |
36 blimp::client::BlimpClientContext::ApplyBlimpSwitches(this); | 41 blimp::client::BlimpClientContext::ApplyBlimpSwitches(this); |
37 } | 42 } |
38 | 43 |
39 protected: | 44 protected: |
40 ~BlimpShellCommandLinePrefStore() override = default; | 45 ~BlimpShellCommandLinePrefStore() override = default; |
41 }; | 46 }; |
| 47 |
| 48 bool HasAndroidFontSwitch() { |
| 49 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 50 blimp::switches::kAndroidFontsPath); |
| 51 } |
| 52 |
| 53 std::string GetAndroidFontsDirectory() { |
| 54 std::string android_fonts_dir = |
| 55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 56 blimp::switches::kAndroidFontsPath); |
| 57 if (android_fonts_dir.size() > 0 && android_fonts_dir.back() != '/') { |
| 58 android_fonts_dir += '/'; |
| 59 } |
| 60 return android_fonts_dir; |
| 61 } |
| 62 |
| 63 SkFontMgr* CreateAndroidFontMgr(std::string android_fonts_dir) { |
| 64 SkFontMgr_Android_CustomFonts custom; |
| 65 custom.fSystemFontUse = |
| 66 SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom; |
| 67 custom.fBasePath = android_fonts_dir.c_str(); |
| 68 |
| 69 std::string font_config; |
| 70 std::string fallback_font_config; |
| 71 if (android_fonts_dir.find("kitkat") != std::string::npos) { |
| 72 font_config = android_fonts_dir + "system_fonts.xml"; |
| 73 fallback_font_config = android_fonts_dir + "fallback_fonts.xml"; |
| 74 custom.fFallbackFontsXml = fallback_font_config.c_str(); |
| 75 } else { |
| 76 font_config = android_fonts_dir + "fonts.xml"; |
| 77 custom.fFallbackFontsXml = nullptr; |
| 78 } |
| 79 custom.fFontsXml = font_config.c_str(); |
| 80 custom.fIsolated = true; |
| 81 |
| 82 return SkFontMgr_New_Android(&custom); |
| 83 } |
| 84 |
| 85 void SetupAndroidFontManager() { |
| 86 if (HasAndroidFontSwitch()) { |
| 87 SetDefaultSkiaFactory(CreateAndroidFontMgr(GetAndroidFontsDirectory())); |
| 88 } |
| 89 } |
42 } // namespace | 90 } // namespace |
43 | 91 |
44 int main(int argc, const char**argv) { | 92 int main(int argc, const char**argv) { |
45 base::AtExitManager at_exit; | 93 base::AtExitManager at_exit; |
46 base::CommandLine::Init(argc, argv); | 94 base::CommandLine::Init(argc, argv); |
| 95 SetupAndroidFontManager(); |
47 | 96 |
48 CHECK(gfx::InitializeThreadedX11()); | 97 CHECK(gfx::InitializeThreadedX11()); |
49 | 98 |
50 blimp::client::InitializeLogging(); | 99 blimp::client::InitializeLogging(); |
51 blimp::client::InitializeMainMessageLoop(); | 100 blimp::client::InitializeMainMessageLoop(); |
52 blimp::client::InitializeResourceBundle(); | 101 blimp::client::InitializeResourceBundle(); |
53 | 102 |
54 base::Thread io_thread("BlimpIOThread"); | 103 base::Thread io_thread("BlimpIOThread"); |
55 base::Thread::Options options; | 104 base::Thread::Options options; |
56 options.message_loop_type = base::MessageLoop::TYPE_IO; | 105 options.message_loop_type = base::MessageLoop::TYPE_IO; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate> | 152 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate> |
104 display_manager_delegate = | 153 display_manager_delegate = |
105 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>(); | 154 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>(); |
106 blimp::client::BlimpDisplayManager display_manager( | 155 blimp::client::BlimpDisplayManager display_manager( |
107 display_manager_delegate.get(), compositor_dependencies); | 156 display_manager_delegate.get(), compositor_dependencies); |
108 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight)); | 157 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight)); |
109 display_manager.SetBlimpContents(std::move(contents)); | 158 display_manager.SetBlimpContents(std::move(contents)); |
110 | 159 |
111 base::RunLoop().Run(); | 160 base::RunLoop().Run(); |
112 } | 161 } |
OLD | NEW |