Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / mandoline / ui / aura / aura_init.cc
blob9f865f99ffecc179112bbeacae0666c88095f434
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
3 // found in the LICENSE file.
5 #include "mandoline/ui/aura/aura_init.h"
7 #include "base/i18n/icu_util.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
10 #include "components/view_manager/public/cpp/view.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "ui/aura/env.h"
13 #include "ui/base/ime/input_method_initializer.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/ui_base_paths.h"
17 #if defined(OS_ANDROID)
18 #include "components/resource_provider/public/cpp/resource_loader.h"
19 #endif
21 namespace mandoline {
23 #if defined(OS_ANDROID)
24 namespace {
26 // Paths resources are loaded from.
27 const char kResourceIcudtl[] = "icudtl.dat";
28 const char kResourceUIPak[] = "ui_test.pak";
30 std::set<std::string> GetResourcePaths() {
31 std::set<std::string> paths;
32 paths.insert(kResourceIcudtl);
33 paths.insert(kResourceUIPak);
34 return paths;
37 } // namespace
38 #endif // defined(OS_ANDROID)
40 // TODO(sky): the 1.f should be view->viewport_metrics().device_scale_factor,
41 // but that causes clipping problems. No doubt we're not scaling a size
42 // correctly.
43 AuraInit::AuraInit(mojo::View* view, mojo::Shell* shell)
44 : ui_init_(view->viewport_metrics().size_in_pixels.To<gfx::Size>(), 1.f) {
45 aura::Env::CreateInstance(false);
47 InitializeResources(shell);
49 ui::InitializeInputMethodForTesting();
52 AuraInit::~AuraInit() {
55 void AuraInit::InitializeResources(mojo::Shell* shell) {
56 if (ui::ResourceBundle::HasSharedInstance())
57 return;
58 #if defined(OS_ANDROID)
59 resource_provider::ResourceLoader resource_loader(shell, GetResourcePaths());
60 if (!resource_loader.BlockUntilLoaded())
61 return;
62 CHECK(resource_loader.loaded());
63 base::i18n::InitializeICUWithFileDescriptor(
64 resource_loader.ReleaseFile(kResourceIcudtl).TakePlatformFile(),
65 base::MemoryMappedFile::Region::kWholeFile);
66 ui::RegisterPathProvider();
67 ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath());
68 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
69 resource_loader.ReleaseFile(kResourceUIPak),
70 ui::SCALE_FACTOR_100P);
71 #else
72 base::i18n::InitializeICU();
74 ui::RegisterPathProvider();
76 base::FilePath ui_test_pak_path;
77 CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
78 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
79 #endif
81 // There is a bunch of static state in gfx::Font, by running this now,
82 // before any other apps load, we ensure all the state is set up.
83 gfx::Font();
86 } // namespace mandoline