blob: 256007b47ff7fe1eae17e84b6892f4e0d1d19a35 [file] [log] [blame]
sergeyub9d14402015-08-26 23:23:431// Copyright 2015 The Chromium Authors. All rights reserved.
[email protected]fc877cf2013-07-31 23:08:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sergeyub9d14402015-08-26 23:23:435#include "remoting/host/resources.h"
[email protected]d0a89a32013-08-03 02:13:376
7#include <dlfcn.h>
8
9#include "base/files/file_path.h"
10#include "base/logging.h"
[email protected]fc877cf2013-07-31 23:08:3911#include "base/mac/bundle_locations.h"
12#include "ui/base/l10n/l10n_util_mac.h"
13#include "ui/base/resource/resource_bundle.h"
14
[email protected]fc877cf2013-07-31 23:08:3915namespace remoting {
16
17bool LoadResources(const std::string& pref_locale) {
18 if (ui::ResourceBundle::HasSharedInstance()) {
19 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale);
20 } else {
[email protected]d0a89a32013-08-03 02:13:3721 // Retrieve the path to the module containing this function.
22 Dl_info info;
23 CHECK(dladdr(reinterpret_cast<void*>(&LoadResources), &info) != 0);
24
25 // Use the plugin's bundle instead of the hosting app bundle. The three
26 // DirName() calls strip "Contents/MacOS/<binary>" from the path.
27 base::FilePath path =
28 base::FilePath(info.dli_fname).DirName().DirName().DirName();
29 base::mac::SetOverrideFrameworkBundlePath(path);
[email protected]fc877cf2013-07-31 23:08:3930
31 // Override the locale with the value from Cocoa.
32 if (pref_locale.empty())
33 l10n_util::OverrideLocaleWithCocoaLocale();
34
[email protected]4ce2aa62014-08-14 01:05:4935 ui::ResourceBundle::InitSharedInstanceWithLocale(
36 pref_locale, NULL, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
[email protected]fc877cf2013-07-31 23:08:3937 }
38
39 return true;
40}
41
42void UnloadResources() {
43 ui::ResourceBundle::CleanupSharedInstance();
44}
45
46} // namespace remoting