Revert of Sandbox html_viewer on Linux. (patchset #6 id:100001 of https://codereview...
[chromium-blink-merge.git] / remoting / base / resources_mac.cc
blobd848e67c04190d2ee51fe92ce77b906d0b159c8e
1 // Copyright 2013 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 "remoting/base/resources.h"
7 #include <dlfcn.h>
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/mac/bundle_locations.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13 #include "ui/base/resource/resource_bundle.h"
15 namespace remoting {
17 bool LoadResources(const std::string& pref_locale) {
18 if (ui::ResourceBundle::HasSharedInstance()) {
19 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale);
20 } else {
21 // Retrieve the path to the module containing this function.
22 Dl_info info;
23 CHECK(dladdr(reinterpret_cast<void*>(&LoadResources), &info) != 0);
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);
31 // Override the locale with the value from Cocoa.
32 if (pref_locale.empty())
33 l10n_util::OverrideLocaleWithCocoaLocale();
35 ui::ResourceBundle::InitSharedInstanceWithLocale(
36 pref_locale, NULL, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
39 return true;
42 void UnloadResources() {
43 ui::ResourceBundle::CleanupSharedInstance();
46 } // namespace remoting